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

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;
        !           123: 
        !           124:     
        !           125:     (void) gethostname(host,255);
        !           126:     XtSetArg(arglist[argCount], XtNlabel, host);
        !           127:     argCount++;
        !           128:     XtSetArg(arglist[argCount], XtNname, argv[0]);
        !           129:     argCount++;
        !           130:     display[0] = '\0';
        !           131:     XtInitialize();
        !           132:     XtGetUsersDataBase();
        !           133:       
        !           134:     XrmParseCommand( opTable, XtNumber(opTable), argv[0], &argc, argv);
        !           135: 
        !           136:     if(argc > 1 && index(argv[1], ':') != NULL) {
        !           137:            argc--;
        !           138:            (void) strncpy(display, argv[1], sizeof(display));
        !           139:        }
        !           140: 
        !           141:     if (argc != 1) usage();
        !           142:     /* Open display  */
        !           143:     if (!(dpy = XOpenDisplay(display))) {
        !           144:        (void) fprintf(stderr, "%s: Can't open display '%s'\n",
        !           145:                argv[0], XDisplayName(display));
        !           146:        exit(1);
        !           147:     }
        !           148:     geostr = NULL;
        !           149:     XtGetResources(dpy,  rlist, XtNumber(rlist),arglist,2,
        !           150:                   DefaultRootWindow(dpy),
        !           151:                   "Xload",  "xload", &names, &classes);
        !           152:     sizehints.flags = PAspect | PMinSize | PPosition | PSize;
        !           153:     sizehints.min_aspect.x = 1;
        !           154:     sizehints.min_aspect.y = 5;
        !           155:     sizehints.max_aspect.x = 5;
        !           156:     sizehints.max_aspect.y = 1;
        !           157:     sizehints.min_width = sizehints.min_height = 15;
        !           158:     sizehints.width = 100;
        !           159:     sizehints.height = 100;
        !           160:     sizehints.x = 0;
        !           161:     sizehints.y = 200;
        !           162: 
        !           163:     if( geostr != NULL ) {
        !           164:          flags = XParseGeometry(geostr, &x, &y, &width, &height);
        !           165:          if(WidthValue & flags) {
        !           166:                sizehints.flags |= USSize;
        !           167:                sizehints.width = width;
        !           168:                XtSetArg(arglist[argCount], XtNwidth, width);
        !           169:                argCount++;
        !           170:          }
        !           171:          if(HeightValue & flags) {
        !           172:                sizehints.flags |= USSize;
        !           173:                sizehints.height = height;
        !           174:                XtSetArg(arglist[argCount], XtNheight, height);
        !           175:                argCount++;
        !           176:          }
        !           177:          if(XValue & flags) {
        !           178:            if(XNegative & flags)
        !           179:              x = DisplayWidth(dpy, DefaultScreen(dpy)) + x
        !           180:                -sizehints.width;
        !           181:            sizehints.flags |= USPosition;
        !           182:            sizehints.x = x;
        !           183:            XtSetArg(arglist[argCount], XtNx, x);
        !           184:            argCount++;
        !           185:          }
        !           186:          if(YValue & flags) {
        !           187:            if(YNegative & flags)
        !           188:              y = DisplayHeight(dpy, DefaultScreen(dpy)) + y
        !           189:                -sizehints.height;
        !           190:            sizehints.flags |= USPosition;
        !           191:            sizehints.y = y;
        !           192:            XtSetArg(arglist[argCount], XtNy, y);
        !           193:            argCount++;
        !           194:          }
        !           195:     }
        !           196:     
        !           197:     win = XtLoadCreate(dpy,  DefaultRootWindow(dpy),
        !           198:        arglist, argCount);
        !           199:     XtMakeMaster(dpy,  win);
        !           200: /*    XSetSizeHints(dpy, win, &sizehints, XA_WM_NORMAL_HINTS);   
        !           201:   */  
        !           202:     XSetStandardProperties ( dpy, win, "xload","Load Ave",
        !           203:                    XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), 
        !           204:                        xload_bits, xload_width, xload_height),
        !           205:                            argv, argc, &sizehints);
        !           206:     oldwmhints = XGetWMHints(dpy, win);
        !           207:     if (oldwmhints) {
        !           208:         wmhints = *oldwmhints;
        !           209:         free((char *)oldwmhints);
        !           210:     } else wmhints.flags = 0;
        !           211:     wmhints.flags |= InputHint /* | StateHint */;
        !           212:     wmhints.input = FALSE;
        !           213: /*    wmhints.initial_state = IconicState; */
        !           214:     XSetWMHints( dpy, win, &wmhints);
        !           215:     XMapWindow(dpy, win);                          /* Map window to screen */
        !           216:     for(;;) {
        !           217:        XEvent event;
        !           218:          
        !           219:        XtNextEvent(dpy,  &event);
        !           220:        (void) XtDispatchEvent(&event);
        !           221:     }
        !           222: }

unix.superglobalmegacorp.com

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