home *** CD-ROM | disk | FTP | other *** search
- #include <time.h>
- #include <curses.h>
- #include <signal.h>
-
- /*
- * 10 20 30 40 50 60
- * V----+----V----+----V----+----V----+----V----+----V----+----V----+----
- * -- -- -- -- -- -- -- -- -- -- -- -- --
- * | | | | | | | | | | | | | | | | | | @ | | | | @ | | | |
- * -- -- -- -- -- -- -- -- -- -- -- -- --
- * | | | | | | | | | | | | | | | | | | @ | | | | @ | | | |
- * -- -- -- -- -- @ -- -- -- -- -- -- -- --
- * Y Y Y M M D D H H M M S S
- */
-
- #define Y_COORD 10
- #define HR_X 40
- #define MIN_X 52
- #define SEC_X 64
- #define DY_X 27
- #define MN_X 15
- #define YR_X 0
- #define NUMWIDTH 5
-
- #define NUMDOTS 5
- static int dot[NUMDOTS][2] = {
- 25, 4, 50, 1, 50, 3, 62, 1, 62, 3
- };
-
- /*
- * a
- * b c
- * d
- * e f
- * g
- */
- #define a_flg 0100
- #define b_flg 0040
- #define c_flg 0020
- #define d_flg 0010
- #define e_flg 0004
- #define f_flg 0002
- #define g_flg 0001
-
- static int radix = 10;
- static int bitpat[16] = {
- 0167, /* 0 */
- 0022, /* 1 */
- 0135, /* 2 */
- 0133, /* 3 */
- 0072, /* 4 */
- 0153, /* 5 */
- 0157, /* 6 */
- 0122, /* 7 */
- 0177, /* 8 */
- 0173, /* 9 */
- 0176, /* A */
- 0057, /* B */
- 0145, /* C */
- 0037, /* D */
- 0155, /* E */
- 0154 /* F */
- };
-
- drawdigit(x,y,n)
- int x, y, n;
- {
- move(y,x);
- if (bitpat[n]&a_flg) {
- if (bitpat[n]&b_flg) addch('.');
- else addch('-');
- addstr("--");
- if (bitpat[n]&c_flg) addch('.');
- else addch('-');
- } else {
- if (bitpat[n]&b_flg) addch('.');
- else addch(' ');
- addstr(" ");
- if (bitpat[n]&c_flg) addch('.');
- else addch(' ');
- }
-
- move(++y,x);
- if (bitpat[n]&b_flg) addch('|');
- else addch(' ');
- addstr(" ");
- if (bitpat[n]&c_flg) addch('|');
- else addch(' ');
-
- move(++y,x);
- if (bitpat[n]&d_flg) {
- if (bitpat[n]&b_flg
- && bitpat[n]&e_flg) addch('+');
- else if (bitpat[n]&b_flg) addch('`');
- else if (bitpat[n]&e_flg) addch('.');
- else addch('-');
- addstr("--");
- if (bitpat[n]&c_flg
- && bitpat[n]&f_flg) addch('+');
- else if (bitpat[n]&c_flg) addch('\'');
- else if (bitpat[n]&f_flg) addch('.');
- else addch('-');
- } else {
- if (bitpat[n]&(b_flg|e_flg)) addch('|');
- else addch(' ');
- addstr(" ");
- if (bitpat[n]&(c_flg|f_flg)) addch('|');
- else addch(' ');
- }
-
- move(++y,x);
- if (bitpat[n]&e_flg) addch('|');
- else addch(' ');
- addstr(" ");
- if (bitpat[n]&f_flg) addch('|');
- else addch(' ');
-
- move(++y,x);
- if (bitpat[n]&g_flg) {
- if (bitpat[n]&e_flg) addch('`');
- else addch('-');
- addstr("--");
- if (bitpat[n]&f_flg) addch('\'');
- else addch('-');
- } else {
- if (bitpat[n]&e_flg) addch('`');
- else addch(' ');
- addstr(" ");
- if (bitpat[n]&f_flg) addch('\'');
- else addch(' ');
- }
- }
-
- usage(n)
- char *n;
- {
- printf("usage: %s [ -x | -o ]\n",n);
- puts(" -d -- represent time in decimal (default)");
- puts(" -x -- represent time in hexadecimal");
- puts(" -o -- represent time in octal");
- exit(0);
- }
-
- terminate()
- {
- standend();
- refresh();
- endwin();
- exit(0);
- }
-
- main(argc,argv)
- int argc;
- char **argv;
- {
- struct tm *timerec;
- long ltime;
- int i;
- char *pname;
-
- pname = *argv;
- while (argv++, --argc) {
- if (*(*argv)++ != '-')
- usage(pname);
- while (**argv != NULL)
- switch(*(*argv)++) {
- case 'd':
- case 'D': radix = 10;
- break;
- case 'x':
- case 'X': radix = 16;
- break;
- case 'o':
- case 'O': radix = 8;
- break;
- default: usage();
- }
- }
-
- signal(SIGINT, terminate);
- signal(SIGQUIT, terminate);
- initscr();
- clear();
-
- for(i=0; i<NUMDOTS; i++)
- mvaddch(dot[i][1]+Y_COORD, dot[i][0], '@');
-
- for(;;) {
- time(<ime);
- timerec = localtime(<ime);
-
- drawdigit(HR_X, Y_COORD, timerec->tm_hour/radix);
- drawdigit(HR_X+NUMWIDTH, Y_COORD, timerec->tm_hour%radix);
-
- drawdigit(MIN_X, Y_COORD, timerec->tm_min/radix);
- drawdigit(MIN_X+NUMWIDTH, Y_COORD, timerec->tm_min%radix);
-
- drawdigit(SEC_X, Y_COORD, timerec->tm_sec/radix);
- drawdigit(SEC_X+NUMWIDTH, Y_COORD, timerec->tm_sec%radix);
-
- drawdigit(DY_X, Y_COORD, timerec->tm_mday/radix);
- drawdigit(DY_X+NUMWIDTH, Y_COORD, timerec->tm_mday%radix);
-
- drawdigit(MN_X, Y_COORD, (timerec->tm_mon+1)/radix);
- drawdigit(MN_X+NUMWIDTH, Y_COORD, (timerec->tm_mon+1)%radix);
-
- drawdigit(YR_X, Y_COORD, timerec->tm_year/(radix*radix));
- drawdigit(YR_X+NUMWIDTH, Y_COORD, (timerec->tm_year/radix)%radix);
- drawdigit(YR_X+2*NUMWIDTH, Y_COORD, timerec->tm_year%radix);
- move(dot[0][1]+Y_COORD, dot[0][0]);
-
- refresh();
- sleep(1);
- }
- }
-