home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8707 / 44 / dclk.c next >
Encoding:
C/C++ Source or Header  |  1990-07-13  |  4.7 KB  |  216 lines

  1. #include <time.h>
  2. #include <curses.h>
  3. #include <signal.h>
  4.  
  5. /*
  6.  *           10        20        30        40        50        60
  7.  *  V----+----V----+----V----+----V----+----V----+----V----+----V----+----
  8.  *   --   --   --   --   --     --   --      --   --     --   --     --   --
  9.  *  |  | |  | |  | |  | |  |   |  | |  |    |  | |  | @ |  | |  | @ |  | |  |
  10.  *   --   --   --   --   --     --   --      --   --     --   --     --   --
  11.  *  |  | |  | |  | |  | |  |   |  | |  |    |  | |  | @ |  | |  | @ |  | |  |
  12.  *   --   --   --   --   --  @  --   --      --   --     --   --     --   --
  13.  *    Y    Y    Y    M    M      D    D       H    H      M    M      S    S
  14.  */
  15.  
  16. #define Y_COORD        10
  17. #define HR_X        40
  18. #define MIN_X        52
  19. #define SEC_X        64
  20. #define DY_X        27
  21. #define MN_X        15
  22. #define YR_X         0
  23. #define NUMWIDTH     5
  24.  
  25. #define NUMDOTS         5
  26. static int    dot[NUMDOTS][2]    = {
  27.             25, 4,   50, 1,  50, 3,  62, 1,  62, 3
  28.         };
  29.  
  30. /*
  31.  *      a
  32.  *     b c
  33.  *      d
  34.  *     e f
  35.  *      g
  36.  */
  37. #define a_flg    0100
  38. #define b_flg    0040
  39. #define c_flg    0020
  40. #define d_flg    0010
  41. #define e_flg    0004
  42. #define f_flg    0002
  43. #define g_flg    0001
  44.  
  45. static int    radix        = 10;
  46. static int    bitpat[16]    = {
  47.             0167,    /* 0 */
  48.             0022,    /* 1 */
  49.             0135,    /* 2 */
  50.             0133,    /* 3 */
  51.             0072,    /* 4 */
  52.             0153,    /* 5 */
  53.             0157,    /* 6 */
  54.             0122,    /* 7 */
  55.             0177,    /* 8 */
  56.             0173,    /* 9 */
  57.             0176,    /* A */
  58.             0057,    /* B */
  59.             0145,    /* C */
  60.             0037,    /* D */
  61.             0155,    /* E */
  62.             0154    /* F */
  63.         };
  64.  
  65. drawdigit(x,y,n)
  66. int    x, y, n;
  67. {
  68.     move(y,x);
  69.     if (bitpat[n]&a_flg) {
  70.     if (bitpat[n]&b_flg)    addch('.');
  71.     else            addch('-');
  72.     addstr("--");
  73.     if (bitpat[n]&c_flg)    addch('.');
  74.     else            addch('-');
  75.     } else {
  76.     if (bitpat[n]&b_flg)    addch('.');
  77.     else            addch(' ');
  78.     addstr("  ");
  79.     if (bitpat[n]&c_flg)    addch('.');
  80.     else            addch(' ');
  81.     }
  82.  
  83.     move(++y,x);
  84.     if (bitpat[n]&b_flg)    addch('|');
  85.     else            addch(' ');
  86.     addstr("  ");
  87.     if (bitpat[n]&c_flg)    addch('|');
  88.     else            addch(' ');
  89.  
  90.     move(++y,x);
  91.     if (bitpat[n]&d_flg) {
  92.     if (bitpat[n]&b_flg
  93.         && bitpat[n]&e_flg)        addch('+');
  94.     else if (bitpat[n]&b_flg)    addch('`');
  95.     else if (bitpat[n]&e_flg)    addch('.');
  96.     else                addch('-');
  97.     addstr("--");
  98.     if (bitpat[n]&c_flg
  99.         && bitpat[n]&f_flg)        addch('+');
  100.     else if (bitpat[n]&c_flg)    addch('\'');
  101.     else if (bitpat[n]&f_flg)    addch('.');
  102.     else                addch('-');
  103.     } else {
  104.     if (bitpat[n]&(b_flg|e_flg))    addch('|');
  105.     else                addch(' ');
  106.     addstr("  ");
  107.     if (bitpat[n]&(c_flg|f_flg))    addch('|');
  108.     else                addch(' ');
  109.     }
  110.  
  111.     move(++y,x);
  112.     if (bitpat[n]&e_flg)    addch('|');
  113.     else            addch(' ');
  114.     addstr("  ");
  115.     if (bitpat[n]&f_flg)    addch('|');
  116.     else            addch(' ');
  117.  
  118.     move(++y,x);
  119.     if (bitpat[n]&g_flg) {
  120.     if (bitpat[n]&e_flg)    addch('`');
  121.     else            addch('-');
  122.     addstr("--");
  123.     if (bitpat[n]&f_flg)    addch('\'');
  124.     else            addch('-');
  125.     } else {
  126.     if (bitpat[n]&e_flg)    addch('`');
  127.     else            addch(' ');
  128.     addstr("  ");
  129.     if (bitpat[n]&f_flg)    addch('\'');
  130.     else            addch(' ');
  131.     }
  132. }
  133.  
  134. usage(n)
  135. char    *n;
  136. {
  137.     printf("usage: %s [ -x | -o ]\n",n);
  138.     puts("     -d     -- represent time in decimal      (default)");
  139.     puts("     -x     -- represent time in hexadecimal");
  140.     puts("     -o     -- represent time in octal");
  141.     exit(0);
  142. }
  143.  
  144. terminate()
  145. {
  146.     standend();
  147.     refresh();
  148.     endwin();
  149.     exit(0);
  150. }
  151.  
  152. main(argc,argv)
  153. int    argc;
  154. char    **argv;
  155. {
  156.     struct tm    *timerec;
  157.     long    ltime;
  158.     int        i;
  159.     char    *pname;
  160.  
  161.     pname = *argv;
  162.     while (argv++, --argc) {
  163.     if (*(*argv)++ != '-')
  164.         usage(pname);
  165.     while (**argv != NULL)
  166.         switch(*(*argv)++) {
  167.         case 'd':
  168.         case 'D':   radix = 10;
  169.                 break;
  170.         case 'x':
  171.         case 'X':   radix = 16;
  172.                 break;
  173.         case 'o':
  174.         case 'O':   radix = 8;
  175.                 break;
  176.         default:    usage();
  177.         }
  178.     }
  179.  
  180.     signal(SIGINT, terminate);
  181.     signal(SIGQUIT, terminate);
  182.     initscr();
  183.     clear();
  184.  
  185.     for(i=0; i<NUMDOTS; i++)
  186.     mvaddch(dot[i][1]+Y_COORD, dot[i][0], '@');
  187.  
  188.     for(;;) {
  189.     time(<ime);
  190.     timerec = localtime(<ime);
  191.  
  192.     drawdigit(HR_X, Y_COORD,        timerec->tm_hour/radix);
  193.     drawdigit(HR_X+NUMWIDTH, Y_COORD,    timerec->tm_hour%radix);
  194.  
  195.     drawdigit(MIN_X, Y_COORD,        timerec->tm_min/radix);
  196.     drawdigit(MIN_X+NUMWIDTH, Y_COORD,    timerec->tm_min%radix);
  197.  
  198.     drawdigit(SEC_X, Y_COORD,        timerec->tm_sec/radix);
  199.     drawdigit(SEC_X+NUMWIDTH, Y_COORD,    timerec->tm_sec%radix);
  200.  
  201.     drawdigit(DY_X, Y_COORD,        timerec->tm_mday/radix);
  202.     drawdigit(DY_X+NUMWIDTH, Y_COORD,    timerec->tm_mday%radix);
  203.  
  204.     drawdigit(MN_X, Y_COORD,        (timerec->tm_mon+1)/radix);
  205.     drawdigit(MN_X+NUMWIDTH, Y_COORD,    (timerec->tm_mon+1)%radix);
  206.  
  207.     drawdigit(YR_X, Y_COORD,        timerec->tm_year/(radix*radix));
  208.     drawdigit(YR_X+NUMWIDTH, Y_COORD,    (timerec->tm_year/radix)%radix);
  209.     drawdigit(YR_X+2*NUMWIDTH, Y_COORD,    timerec->tm_year%radix);
  210.     move(dot[0][1]+Y_COORD, dot[0][0]);
  211.  
  212.     refresh();
  213.     sleep(1);
  214.     }
  215. }
  216.