Annotation of researchv9/X11/src/X.V11R1/lib/Xrm/XGetDflt.c, revision 1.1.1.1

1.1       root        1: #include <copyright.h>
                      2: 
                      3: /* $Header: XGetDflt.c,v 1.1 87/08/22 10:24:06 ham Exp $ */
                      4: /* Copyright (c) 1985, Massachusetts Institute of Technology */
                      5: 
                      6: /*
                      7:  * This routine returns options out of the X user preferences file
                      8:  * found in the RESOURCE_MANAGER property, possibly modified by the 
                      9:  * .Xdefaults in the user's home
                     10:  * directory.  It either returns a pointer to
                     11:  * the option or returns NULL if option not set.  It is patterned after
                     12:  * Andrew's file format (why be different for the sake of being different?).
                     13:  * Andrew's code was NOT examined before writing this routine.
                     14:  * It parses lines of the format "progname.option:value" and returns a pointer
                     15:  * to value.
                     16:  */
                     17: 
                     18: #include <stdio.h>
                     19: #include <strings.h>
                     20: #include <ctype.h>
                     21: #include "Xlibint.h"
                     22: #include "Xresource.h"
                     23: #include "Quarks.h"
                     24: 
                     25: #define XOPTIONFILE "/.Xdefaults"      /* name in home directory of options
                     26:                                           file. */
                     27: 
                     28: static XrmResourceDataBase InitDefaults (dpy)
                     29:     Display *dpy;                      /* display for defaults.... */
                     30: {
                     31:     XrmResourceDataBase userdb = NULL;
                     32:     XrmResourceDataBase xdb = NULL;
                     33:     char fname[BUFSIZ];             /* longer than any conceivable size */
                     34:     char *getenv();
                     35:     char *home = getenv("HOME");
                     36: 
                     37:     /*
                     38:      * attempt to generate user's file name
                     39:      */
                     40:     fname[0] = '\0';
                     41:     if (home != NULL) {
                     42:        strcpy (fname, home);
                     43:        strcat (fname, XOPTIONFILE);
                     44:        }
                     45:     XrmInitialize();
                     46: 
                     47:     if (fname[0] != '\0') userdb =  XrmGetDataBase(fname);
                     48:     xdb = XrmLoadDataBase(dpy->xdefaults);
                     49:     XrmMergeDataBases(userdb, &xdb);
                     50:     return xdb;
                     51: }
                     52: 
                     53: char *XGetDefault(dpy, prog, name)
                     54:        Display *dpy;                   /* display for defaults.... */
                     55:        register char *name;            /* name of option program wants */
                     56:        char *prog;                     /* name of program for option   */
                     57: 
                     58: {                                      /* to get, for example, "font"  */
                     59:        char temp[BUFSIZ];
                     60:        XrmName namelist[5];
                     61:        XrmClass classlist[5];
                     62:        XrmValue result;
                     63: 
                     64:        /*
                     65:         * see if database has ever been initialized.  Lookups can be done
                     66:         * without locks held.
                     67:         */
                     68:        LockDisplay(dpy);
                     69:        if (dpy->db == NULL) {
                     70:                dpy->db = InitDefaults(dpy);
                     71:                }
                     72:        UnlockDisplay(dpy);
                     73:        sprintf(temp, "%s.%s", prog, name);
                     74:        XrmStringToNameList(temp, namelist);
                     75:        XrmStringToClassList("Program.Name", classlist);
                     76: 
                     77:        XrmGetResource(DefaultScreen(dpy), dpy->db, 
                     78:                namelist, classlist, XrmQString, &result);
                     79:        return (result.addr);
                     80: }
                     81: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.