abcscnuk@csun.UUCP (Naoto Kimura) (07/14/87)
Here's a fairly useless program which displays the date and time (YYYMM.DD hh:mm:ss) in a fasion similar to a digital clock display. The program can display the date and time in decimal, octal and hexadecimal (that might sound strange, but I know someone who has a digital clock that displays the time in hexadecimal). One problem with this program is that it requires 80 columns for the display. --- cut here ------ cut here ------ cut here ------ cut here --- #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # Makefile # dclk.c # This archive created: Tue Jul 7 21:01:02 1987 export PATH; PATH=/bin:$PATH echo shar: extracting "'Makefile'" '(159 characters)' if test -f 'Makefile' then echo shar: will not over-write existing file "'Makefile'" else sed 's/^ X//' << \SHAR_EOF > 'Makefile' XSRCS = Makefile dclk.c XDIST = sharfile X Xdclk: dclk.c X cc -o dclk -O -DMINICURSES dclk.c -lcurses X Xdist: ${DIST} X X${DIST}: ${SRCS} X shar -a ${SRCS} > ${DIST} SHAR_EOF if test 159 -ne "`wc -c < 'Makefile'`" then echo shar: error transmitting "'Makefile'" '(should have been 159 characters)' fi fi # end of overwriting check echo shar: extracting "'dclk.c'" '(4823 characters)' if test -f 'dclk.c' then echo shar: will not over-write existing file "'dclk.c'" else sed 's/^ X//' << \SHAR_EOF > 'dclk.c' X#include <time.h> X#include <curses.h> X#include <signal.h> X X/* X * 10 20 30 40 50 60 X * V----+----V----+----V----+----V----+----V----+----V----+----V----+---- X * -- -- -- -- -- -- -- -- -- -- -- -- -- X * | | | | | | | | | | | | | | | | | | @ | | | | @ | | | | X * -- -- -- -- -- -- -- -- -- -- -- -- -- X * | | | | | | | | | | | | | | | | | | @ | | | | @ | | | | X * -- -- -- -- -- @ -- -- -- -- -- -- -- -- X * Y Y Y M M D D H H M M S S X */ X X#define Y_COORD 10 X#define HR_X 40 X#define MIN_X 52 X#define SEC_X 64 X#define DY_X 27 X#define MN_X 15 X#define YR_X 0 X#define NUMWIDTH 5 X X#define NUMDOTS 5 Xstatic int dot[NUMDOTS][2] = { X 25, 4, 50, 1, 50, 3, 62, 1, 62, 3 X }; X X/* X * a X * b c X * d X * e f X * g X */ X#define a_flg 0100 X#define b_flg 0040 X#define c_flg 0020 X#define d_flg 0010 X#define e_flg 0004 X#define f_flg 0002 X#define g_flg 0001 X Xstatic int radix = 10; Xstatic int bitpat[16] = { X 0167, /* 0 */ X 0022, /* 1 */ X 0135, /* 2 */ X 0133, /* 3 */ X 0072, /* 4 */ X 0153, /* 5 */ X 0157, /* 6 */ X 0122, /* 7 */ X 0177, /* 8 */ X 0173, /* 9 */ X 0176, /* A */ X 0057, /* B */ X 0145, /* C */ X 0037, /* D */ X 0155, /* E */ X 0154 /* F */ X }; X Xdrawdigit(x,y,n) Xint x, y, n; X{ X move(y,x); X if (bitpat[n]&a_flg) { X if (bitpat[n]&b_flg) addch('.'); X else addch('-'); X addstr("--"); X if (bitpat[n]&c_flg) addch('.'); X else addch('-'); X } else { X if (bitpat[n]&b_flg) addch('.'); X else addch(' '); X addstr(" "); X if (bitpat[n]&c_flg) addch('.'); X else addch(' '); X } X X move(++y,x); X if (bitpat[n]&b_flg) addch('|'); X else addch(' '); X addstr(" "); X if (bitpat[n]&c_flg) addch('|'); X else addch(' '); X X move(++y,x); X if (bitpat[n]&d_flg) { X if (bitpat[n]&b_flg X && bitpat[n]&e_flg) addch('+'); X else if (bitpat[n]&b_flg) addch('`'); X else if (bitpat[n]&e_flg) addch('.'); X else addch('-'); X addstr("--"); X if (bitpat[n]&c_flg X && bitpat[n]&f_flg) addch('+'); X else if (bitpat[n]&c_flg) addch('\''); X else if (bitpat[n]&f_flg) addch('.'); X else addch('-'); X } else { X if (bitpat[n]&(b_flg|e_flg)) addch('|'); X else addch(' '); X addstr(" "); X if (bitpat[n]&(c_flg|f_flg)) addch('|'); X else addch(' '); X } X X move(++y,x); X if (bitpat[n]&e_flg) addch('|'); X else addch(' '); X addstr(" "); X if (bitpat[n]&f_flg) addch('|'); X else addch(' '); X X move(++y,x); X if (bitpat[n]&g_flg) { X if (bitpat[n]&e_flg) addch('`'); X else addch('-'); X addstr("--"); X if (bitpat[n]&f_flg) addch('\''); X else addch('-'); X } else { X if (bitpat[n]&e_flg) addch('`'); X else addch(' '); X addstr(" "); X if (bitpat[n]&f_flg) addch('\''); X else addch(' '); X } X} X X Xusage(n) Xchar *n; X{ X printf("usage: %s [ -x | -o ]\n",n); X puts(" -d -- represent time in decimal (default)"); X puts(" -x -- represent time in hexadecimal"); X puts(" -o -- represent time in octal"); X exit(0); X} X Xterminate() X{ X standend(); X refresh(); X endwin(); X exit(0); X} X Xmain(argc,argv) Xint argc; Xchar **argv; X{ X struct tm *timerec; X long ltime; X int i; X char *pname; X X pname = *argv; X while (argv++, --argc) { X if (*(*argv)++ != '-') X usage(pname); X while (**argv != NULL) X switch(*(*argv)++) { X case 'd': X case 'D': radix = 10; X break; X case 'x': X case 'X': radix = 16; X break; X case 'o': X case 'O': radix = 8; X break; X default: usage(); X } X } X X signal(SIGINT, terminate); X signal(SIGQUIT, terminate); X initscr(); X clear(); X X for(i=0; i<NUMDOTS; i++) X mvaddch(dot[i][1]+Y_COORD, dot[i][0], '@'); X X for(;;) { X time(<ime); X timerec = localtime(<ime); X X drawdigit(HR_X, Y_COORD, timerec->tm_hour/radix); X drawdigit(HR_X+NUMWIDTH, Y_COORD, timerec->tm_hour%radix); X X drawdigit(MIN_X, Y_COORD, timerec->tm_min/radix); X drawdigit(MIN_X+NUMWIDTH, Y_COORD, timerec->tm_min%radix); X X drawdigit(SEC_X, Y_COORD, timerec->tm_sec/radix); X drawdigit(SEC_X+NUMWIDTH, Y_COORD, timerec->tm_sec%radix); X X drawdigit(DY_X, Y_COORD, timerec->tm_mday/radix); X drawdigit(DY_X+NUMWIDTH, Y_COORD, timerec->tm_mday%radix); X X drawdigit(MN_X, Y_COORD, (timerec->tm_mon+1)/radix); X drawdigit(MN_X+NUMWIDTH, Y_COORD, (timerec->tm_mon+1)%radix); X X drawdigit(YR_X, Y_COORD, timerec->tm_year/(radix*radix)); X drawdigit(YR_X+NUMWIDTH, Y_COORD, (timerec->tm_year/radix)%radix); X drawdigit(YR_X+2*NUMWIDTH, Y_COORD, timerec->tm_year%radix); X move(dot[0][1]+Y_COORD, dot[0][0]); X X refresh(); X sleep(1); X } X} SHAR_EOF if test 4823 -ne "`wc -c < 'dclk.c'`" then echo shar: error transmitting "'dclk.c'" '(should have been 4823 characters)' fi fi # end of overwriting check # End of shell archive exit 0 --- cut here ------ cut here ------ cut here ------ cut here --- //-n-\\ Naoto Kimura _____---=======---_____ (csun!abcscnuk) ====____\ /.. ..\ /____==== // ---\__O__/--- \\ Enterprise... Surrender or we'll \_\ /_/ send back your *&^$% tribbles !!