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

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

unix.superglobalmegacorp.com

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