|
|
1.1 ! root 1: #ifndef lint ! 2: static char rcs_id[] = "$Header: xrdb.c,v 11.5 87/09/11 19:57:36 jg Exp $"; ! 3: #endif ! 4: ! 5: /* ! 6: * COPYRIGHT 1987 ! 7: * DIGITAL EQUIPMENT CORPORATION ! 8: * MAYNARD, MASSACHUSETTS ! 9: * ALL RIGHTS RESERVED. ! 10: * ! 11: * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND ! 12: * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. ! 13: * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ! 14: * ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. ! 15: * ! 16: * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT RIGHTS, ! 17: * APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN ADDITION TO THAT ! 18: * SET FORTH ABOVE. ! 19: * ! 20: * ! 21: * Permission to use, copy, modify, and distribute this software and its ! 22: * documentation for any purpose and without fee is hereby granted, provided ! 23: * that the above copyright notice appear in all copies and that both that ! 24: * copyright notice and this permission notice appear in supporting documentation, ! 25: * and that the name of Digital Equipment Corporation not be used in advertising ! 26: * or publicity pertaining to distribution of the software without specific, ! 27: * written prior permission. ! 28: */ ! 29: ! 30: /* ! 31: * this program is used to load, or dump the resource manager database ! 32: * in the server. ! 33: * ! 34: * Author: Jim Gettys, August 28, 1987 ! 35: */ ! 36: ! 37: #include <stdio.h> ! 38: #include <X11/Xlib.h> ! 39: #include <strings.h> ! 40: #include <X11/Xatom.h> ! 41: #include <ctype.h> ! 42: ! 43: #define MAXRDB 100000 ! 44: #define DBOK 0 ! 45: ! 46: char *SanityCheck(); ! 47: ! 48: main (argc, argv) ! 49: int argc; ! 50: char **argv; ! 51: { ! 52: Display * dpy; ! 53: int i; ! 54: char *displayname = NULL; ! 55: char *filename = NULL; ! 56: FILE *fp; ! 57: int nbytes; ! 58: char *bptr, *endptr; ! 59: char buffer[MAXRDB]; ! 60: int printit = 0; ! 61: ! 62: for (i = 1; i < argc; i++) { ! 63: if (index (argv[i], ':') != NULL) displayname = argv[i]; ! 64: else filename = argv[i]; ! 65: if (strcmp ("-q", argv[i]) == NULL) printit = 1; ! 66: } ! 67: ! 68: /* Open display */ ! 69: if (!(dpy = XOpenDisplay (displayname))) { ! 70: (void) fprintf (stderr, "%s: Can't open display '%s'\n", ! 71: argv[0], XDisplayName (displayname)); ! 72: exit (1); ! 73: } ! 74: ! 75: if (printit == 1) { ! 76: /* user wants to print contents */ ! 77: if (dpy->xdefaults) ! 78: fputs(dpy->xdefaults, stdout); ! 79: exit(0); ! 80: } ! 81: else { ! 82: if (filename != NULL) { ! 83: fp = freopen (filename, "r", stdin); ! 84: if (fp == NULL) { ! 85: fprintf(stderr, "%s: can't open file '%s'\n", ! 86: argv[0], filename); ! 87: exit(1); ! 88: } ! 89: } ! 90: nbytes = fread(buffer, sizeof(char), MAXRDB, stdin); ! 91: if ((bptr = SanityCheck (buffer)) != DBOK) { ! 92: fprintf(stderr, "%s: database fails sanity check \n'%s'\n", ! 93: argv[0], bptr); ! 94: exit(1); ! 95: } ! 96: XChangeProperty (dpy, RootWindow(dpy, 0), XA_RESOURCE_MANAGER, ! 97: XA_STRING, 8, PropModeReplace, buffer, nbytes); ! 98: } ! 99: XCloseDisplay(dpy); ! 100: ! 101: } ! 102: ! 103: char *getline(buffer, buf) ! 104: register char *buffer; ! 105: register char *buf; ! 106: { ! 107: register char c; ! 108: while (*buffer != '\0') { ! 109: c = *buffer++; ! 110: if (c == '\n') { ! 111: *buf = '\0'; ! 112: return (buffer); ! 113: } ! 114: if ( ! isspace(c)) *buf++ = c; ! 115: } ! 116: return (NULL); ! 117: } ! 118: ! 119: /* ! 120: * does simple sanity check on data base. Lines can either be ! 121: * commented, be all white space, or must contain ':'. ! 122: */ ! 123: char *SanityCheck (buffer) ! 124: char *buffer; ! 125: { ! 126: static char buf[BUFSIZ]; ! 127: register char *s; ! 128: char *b = buffer; ! 129: register char *i; ! 130: while (1) { ! 131: if ((b = getline(b, buf)) == NULL) return (DBOK); ! 132: if (buf[0] == '#' || buf[0] == '\0') continue; ! 133: if ((i = index (buf, ':')) == NULL) return buf; ! 134: } ! 135: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.