Annotation of researchv9/X11/src/X.V11R1/clients/xload/xload.c, revision 1.1.1.2

1.1       root        1: #ifndef lint
                      2: static char *rcsid_xload_c = "$Header: xload.c,v 1.32 87/09/09 12:06:08 swick Exp $";
                      3: #endif  lint
                      4:  
                      5: /*
                      6:  * Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
                      7:  * 
                      8:  *                         All Rights Reserved
                      9:  * 
                     10:  * Permission to use, copy, modify, and distribute this software and its 
                     11:  * documentation for any purpose and without fee is hereby granted, 
                     12:  * provided that the above copyright notice appear in all copies and that
                     13:  * both that copyright notice and this permission notice appear in 
                     14:  * supporting documentation, and that the name of Digital Equipment
                     15:  * Corporation not be used in advertising or publicity pertaining to
                     16:  * distribution of the software without specific, written prior permission.  
                     17:  * 
                     18:  * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
                     19:  * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
                     20:  * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
                     21:  * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
                     22:  * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
                     23:  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
                     24:  * SOFTWARE.
                     25:  */
                     26: 
                     27: #include <stdio.h>
                     28: #include <strings.h>
                     29: #include <X11/Xatom.h>
                     30: #include <X11/Xlib.h>
                     31: #include <X11/Xutil.h>
                     32: #include <X11/Intrinsic.h>
                     33: #include <X11/Atoms.h>
                     34: #include <X11/Load.h>
                     35: #include <pwd.h>
                     36: #include "xload.bit"
                     37: 
                     38: extern void exit();
                     39: 
                     40: /* Command line options table.  Only resources are entered here...there is a
                     41:    pass over the remaining options after XtParseCommand is let loose. */
                     42: 
                     43: static XrmOptionDescRec opTable[] = {
                     44: {"=",          "geometry",     XrmoptionIsArg,         (caddr_t) NULL},
                     45: {"-bd",                XtNborder,      XrmoptionSepArg,        (caddr_t) NULL},
                     46: {"-bg",                XtNbackground,  XrmoptionSepArg,        (caddr_t) NULL},
                     47: {"-bw",                XtNborderWidth, XrmoptionSepArg,        (caddr_t) NULL},
                     48: {"-fg",                XtNforeground,  XrmoptionSepArg,        (caddr_t) NULL},
                     49: {"-fn",                XtNfont,        XrmoptionSepArg,        (caddr_t) NULL},
                     50: {"-update",    XtNupdate,      XrmoptionSepArg,        (caddr_t) NULL},
                     51: {"-scale",     XtNminScale,    XrmoptionSepArg,        (caddr_t) NULL},
                     52: {"-rv",                XtNreverseVideo, XrmoptionNoArg,        (caddr_t) "on"},
                     53: {"+rv",                XtNreverseVideo, XrmoptionNoArg,        (caddr_t) "off"}
                     54: };
                     55: 
                     56: static char *geostr;
                     57: 
                     58: static Resource rlist[]=
                     59: {
                     60:       {"geometry", "Geometry", XrmRString,
                     61:         sizeof(char *), (caddr_t) &geostr, (caddr_t) NULL}
                     62: };
                     63: 
                     64: 
                     65: 
                     66: /* Exit with message describing command line format */
                     67: 
                     68: void usage()
                     69: {
                     70:     (void) fprintf(stderr,
                     71: "usage: xload [-fn {font}] [-update {seconds}] [-scale {integer}] [-rv]\n"
                     72: );
                     73:     (void) fprintf(stderr,
                     74: "             [=[{width}][x{height}][{+-}{xoff}[{+-}{yoff}]]] [[{host}]:[{vs}]]\n"
                     75: );
                     76:     (void) fprintf(stderr,
                     77: "             [-fg {color}] [-bg {color}] [-hl {color}] [-bd {color}] [-bw {pixels}]\n");
                     78:     exit(1);
                     79: }
                     80: void XtGetUsersDataBase()
                     81: {
                     82:        XrmResourceDataBase resources, userResources;
                     83:        int uid;
                     84:        extern struct passwd *getpwuid();
                     85:        struct passwd *pw;
                     86:        char filename[1024];
                     87:        FILE *f;
                     88: 
                     89:        /* Open .Xdefaults file and merge into existing data base */
                     90:        uid = getuid();
                     91:        pw = getpwuid(uid);
                     92:        if (pw) {
                     93:                (void) strcpy(filename, pw->pw_dir);
                     94:                (void) strcat(filename, "/.Xdefaults");
                     95:                f = fopen(filename, "r");
                     96:                if (f) {
                     97:                        XrmGetCurrentDataBase(&resources);
                     98:                        XrmGetDataBase(f, &userResources);
                     99:                        XrmMergeDataBases(userResources, &resources);
                    100:                        XrmSetCurrentDataBase(userResources);
                    101:                        (void) fclose(f);
                    102:                }
                    103:        }
                    104: }
                    105: 
                    106: void main(argc, argv)
                    107:     int argc;
                    108:     char **argv;
                    109: {
                    110:     char display[256];                      /* will contain vs host */
                    111:     char host[256];
                    112:     Display *dpy;
                    113:     Window win;
                    114:     XrmNameList         names;
                    115:     XrmClassList classes;
                    116:     Arg arglist[20];
                    117:     int x, y;
                    118:     unsigned int height, width;
                    119:     int argCount = 0;
                    120:     long flags;
                    121:     XSizeHints sizehints;
                    122:     XWMHints   wmhints, *oldwmhints;
1.1.1.2 ! root      123:     int i, fd;
1.1       root      124: 
1.1.1.2 ! root      125:     fd = open("/etc/whoami", 0);
        !           126:     if (fd < 0)
        !           127:        strcpy(host,"unknown");
        !           128:     else {
        !           129:        i = read(fd, host, 255);
        !           130:        if (i <= 0)
        !           131:                strcpy(host,"unknown");
        !           132:        else
        !           133:                host[i-1] = 0;
        !           134:        close(fd);
        !           135:     }
1.1       root      136:     XtSetArg(arglist[argCount], XtNlabel, host);
                    137:     argCount++;
                    138:     XtSetArg(arglist[argCount], XtNname, argv[0]);
                    139:     argCount++;
                    140:     display[0] = '\0';
                    141:     XtInitialize();
                    142:     XtGetUsersDataBase();
                    143:       
                    144:     XrmParseCommand( opTable, XtNumber(opTable), argv[0], &argc, argv);
                    145: 
                    146:     if(argc > 1 && index(argv[1], ':') != NULL) {
                    147:            argc--;
                    148:            (void) strncpy(display, argv[1], sizeof(display));
                    149:        }
                    150: 
                    151:     if (argc != 1) usage();
                    152:     /* Open display  */
                    153:     if (!(dpy = XOpenDisplay(display))) {
                    154:        (void) fprintf(stderr, "%s: Can't open display '%s'\n",
                    155:                argv[0], XDisplayName(display));
                    156:        exit(1);
                    157:     }
                    158:     geostr = NULL;
                    159:     XtGetResources(dpy,  rlist, XtNumber(rlist),arglist,2,
                    160:                   DefaultRootWindow(dpy),
                    161:                   "Xload",  "xload", &names, &classes);
                    162:     sizehints.flags = PAspect | PMinSize | PPosition | PSize;
                    163:     sizehints.min_aspect.x = 1;
                    164:     sizehints.min_aspect.y = 5;
                    165:     sizehints.max_aspect.x = 5;
                    166:     sizehints.max_aspect.y = 1;
                    167:     sizehints.min_width = sizehints.min_height = 15;
                    168:     sizehints.width = 100;
                    169:     sizehints.height = 100;
                    170:     sizehints.x = 0;
                    171:     sizehints.y = 200;
                    172: 
                    173:     if( geostr != NULL ) {
                    174:          flags = XParseGeometry(geostr, &x, &y, &width, &height);
                    175:          if(WidthValue & flags) {
                    176:                sizehints.flags |= USSize;
                    177:                sizehints.width = width;
                    178:                XtSetArg(arglist[argCount], XtNwidth, width);
                    179:                argCount++;
                    180:          }
                    181:          if(HeightValue & flags) {
                    182:                sizehints.flags |= USSize;
                    183:                sizehints.height = height;
                    184:                XtSetArg(arglist[argCount], XtNheight, height);
                    185:                argCount++;
                    186:          }
                    187:          if(XValue & flags) {
                    188:            if(XNegative & flags)
                    189:              x = DisplayWidth(dpy, DefaultScreen(dpy)) + x
                    190:                -sizehints.width;
                    191:            sizehints.flags |= USPosition;
                    192:            sizehints.x = x;
                    193:            XtSetArg(arglist[argCount], XtNx, x);
                    194:            argCount++;
                    195:          }
                    196:          if(YValue & flags) {
                    197:            if(YNegative & flags)
                    198:              y = DisplayHeight(dpy, DefaultScreen(dpy)) + y
                    199:                -sizehints.height;
                    200:            sizehints.flags |= USPosition;
                    201:            sizehints.y = y;
                    202:            XtSetArg(arglist[argCount], XtNy, y);
                    203:            argCount++;
                    204:          }
                    205:     }
                    206:     
                    207:     win = XtLoadCreate(dpy,  DefaultRootWindow(dpy),
                    208:        arglist, argCount);
                    209:     XtMakeMaster(dpy,  win);
                    210: /*    XSetSizeHints(dpy, win, &sizehints, XA_WM_NORMAL_HINTS);   
                    211:   */  
                    212:     XSetStandardProperties ( dpy, win, "xload","Load Ave",
                    213:                    XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), 
                    214:                        xload_bits, xload_width, xload_height),
                    215:                            argv, argc, &sizehints);
                    216:     oldwmhints = XGetWMHints(dpy, win);
                    217:     if (oldwmhints) {
                    218:         wmhints = *oldwmhints;
                    219:         free((char *)oldwmhints);
                    220:     } else wmhints.flags = 0;
                    221:     wmhints.flags |= InputHint /* | StateHint */;
                    222:     wmhints.input = FALSE;
                    223: /*    wmhints.initial_state = IconicState; */
                    224:     XSetWMHints( dpy, win, &wmhints);
                    225:     XMapWindow(dpy, win);                          /* Map window to screen */
                    226:     for(;;) {
                    227:        XEvent event;
                    228:          
                    229:        XtNextEvent(dpy,  &event);
                    230:        (void) XtDispatchEvent(&event);
                    231:     }
                    232: }

unix.superglobalmegacorp.com

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