/* Displays the time remaining until Bush departs office. Public domain. Unabashedly adulterated from Jamie Zawinski's "xdebt". Understands most X cmd line opts - "-font", "-fg", "-bg", etc. It's X. The oath is 36 words long..... gcc -O -o xbushbyebye xbushbyebye.c -lXaw -lXmu -lXt -lX11 or, for systems with Xaw3d: gcc -O -o xbushbyebye xbushbyebye.c -lXaw3d -lXmu -lXt -lX11 Version 1.0 - Initial release - 080214 */ #include #include #include #include #include #ifdef SYSV #define timelocal mktime #endif static int sbushbyebye; static int update; static char *defaults[] = { "*Label.font: *-times-bold-r-*-*-*-240-*-*-*-*-*-*", "*update: 1", NULL }; static XrmOptionDescRec options [] = { { "-update", "*update", XrmoptionSepArg, 0 }, { "-bushbyebye", "*bushbyebye", XrmoptionSepArg, 0 }, }; static void get_resources (dpy) /* Easier than making a subclass... */ Display *dpy; { char *name, *class, *type, buf1[256], buf2[256]; XrmValue value; XtGetApplicationNameAndClass (dpy, &name, &class); sprintf (buf1, "%s.update", name); sprintf (buf2, "%s.Update", class); XrmGetResource (XtDatabase (dpy), buf1, buf2, &type, &value); if (sscanf (value.addr, " %d ", &update) == 0 || update < 1) { fprintf (stderr, "%s: update must be a positive integer, not \"%s\"\n", name, value.addr); update = 1; } sbushbyebye = 1232470800;/* Noon EST 20 Jan 2009 */ } static void relabel_window (shell) Widget shell; { /* If the user hasn't specified the -title option, set the window title. */ char buf1 [100], buf2 [100], *s; XrmValue value; char *type; XrmDatabase db = XtDatabase (XtDisplay (shell)); char *name, *class; XtGetApplicationNameAndClass (XtDisplay (shell), &name, &class); sprintf (buf1, "%s.title", name); sprintf (buf2, "%s.Title", class); if (XrmGetResource (db, buf1, buf2, &type, &value)) return; s = "Time till Bush is GONE..."; XStoreName (XtDisplay (shell), XtWindow (shell), s); } static void timer (w, id) Widget w; XtIntervalId id; { char buf [255], *b = buf; Arg av [10]; int ac = 0; int ww, d, h, m, s, tfrom; time_t now = time ((time_t *) 0); tfrom = sbushbyebye - now; if(tfrom < 0)tfrom = 0- tfrom; ww = (tfrom) / 604800; d = ((tfrom) % 604800) / 86400; h = ((tfrom) % 86400) / 3600; m = ((tfrom) % 3600) / 60; s = ((tfrom) % 60); sprintf(buf, "Time %s no Bush(!) = %d %s %d %s %2.2d:%2.2d:%2.2d", (sbushbyebye - now) > 0 ? "till" : "since", ww, (ww == 1) ? "week" : "weeks", d, (d == 1) ? "day" : "days", h, m , s); XtSetArg (av [ac], XtNlabel, buf); ac++; XtSetValues (w, av, ac); XtAppAddTimeOut (XtWidgetToApplicationContext (w), update * 1000, timer, w); } int main (argc, argv) int argc; char **argv; { XtAppContext app; Widget shell = XtAppInitialize (&app, "xbushbyebye", options, XtNumber (options), &argc, argv, defaults, NULL, 0); Widget label; int iret; iret = fork(); if(iret != 0){ exit(0); } if (argc > 1) { fprintf (stderr, "%s: unknown option %s\n", argv[0], argv[1]); fprintf (stderr, "options: -update \n\ -font \n"); exit (-1); } get_resources (XtDisplay (shell)); label = XtCreateManagedWidget ("label", labelWidgetClass, shell, NULL, 0); timer (label, 0); XtRealizeWidget (shell); relabel_window (shell); XtAppMainLoop (app); }