home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume1 / dclock / part01 / dclock.c next >
Encoding:
C/C++ Source or Header  |  1988-09-15  |  2.4 KB  |  80 lines

  1. /*
  2.  * dclock -- program to demonstrate how to use the digital-clock widget.
  3.  * To specify a date, the date format is a string of characters.  If a
  4.  * character in the string is a %-sign, the next character is examined
  5.  * and a value is inserted into the string.  Example:
  6.  *    dclock -date "Today is %W"
  7.  * The date string will print "Today is" and then the %W will be replaced
  8.  * by the current weekday name.  The parameters are:
  9.  *    %W    full weekday name
  10.  *    %w    three-char weekday name (sun, mon, tue, wed...)
  11.  *    %M    full month name
  12.  *    %m        three-char abbreviation for that month (jan, feb, mar...)
  13.  *    %d    The date (numerical number of the month)
  14.  *    %Y    full year (4 digits)
  15.  *    %y    2-digit year number
  16.  *
  17.  * To specify seconds to be displayed, use "-seconds" or use the resource
  18.  * manager: *Dclock.seconds: on
  19.  */
  20. #include <stdio.h>
  21. #include <X11/Intrinsic.h>
  22. #include "Dclock.h"
  23.  
  24. static XrmOptionDescRec options[] = {
  25.     {"-date",     "*Dclock.date",    XrmoptionSepArg, NULL },
  26.     {"-seconds", "*Dclock.seconds",    XrmoptionNoArg, "TRUE" },
  27.     {"-bell",     "*Dclock.bell",    XrmoptionNoArg, "TRUE" },
  28.     {"-scroll",  "*Dclock.scroll",    XrmoptionNoArg, "TRUE" },
  29.     {"-noscroll","*Dclock.scroll",    XrmoptionNoArg, "FALSE" },
  30. };
  31.  
  32. static void
  33. Usage(name)
  34. String name;
  35. {
  36.     static char *help_message[] = {
  37.     "where options include:",
  38.     "    -bg color                  background color",
  39.     "    -fg color                  foreground color",
  40.     "    -fn font            font name",
  41.     "    -rv                        reverse video",
  42.     "    -geometry geom             size of mailbox",
  43.     "    -display host:dpy          X server to contact",
  44.     "    -seconds [on/off]        display seconds",
  45.     "    -bell [on/off]        ring bell each half hour",
  46.     "    -scroll [on/off]        turn off scrolling",
  47.     "    -date \"date format\"    show the date in specified format",
  48.     NULL
  49.     };
  50.     char **cpp;
  51.  
  52.     fprintf(stderr, "usage: %s [-options ...]\n", name);
  53.     for (cpp = help_message; *cpp; cpp++)
  54.     fprintf(stderr, "%s\n", *cpp);
  55.     exit(1);
  56. }
  57.  
  58. main(argc, argv)
  59. char *argv[];
  60. {
  61.     Widget toplevel;
  62.     char *name, *rindex();
  63.  
  64.     if (name = rindex(argv[0], '/'))
  65.     name++;
  66.     else
  67.     name = argv[0];
  68.  
  69.     toplevel = XtInitialize(name, "DClock", options, XtNumber(options),
  70.                 &argc,argv);
  71.  
  72.     if (argc != 1)
  73.     Usage(name);
  74.  
  75.     XtCreateManagedWidget("dclock", dclockWidgetClass, toplevel, NULL, 0);
  76.  
  77.     XtRealizeWidget(toplevel);
  78.     XtMainLoop();
  79. }
  80.