allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc) (07/09/89)
Posting-number: Volume 7, Issue 66 Submitted-by: Amos Shapir <amdahl!nsc!taux01!nsc.uucp!taux01!amos@uunet.uu.net> Archive-name: gcl The recently posted digital clock reminded me of something from my remote past. I have dug it out, and here it is - the Grand Digital Clock. It displays the time in very big reverse video characters. Since it was written before the days of termcap it only fits VT100 and ANSI-compatible terminals, but all the terminal-dependent routines are concentrated at the end, and can be easily hacked. This source was run successfully on BSD4.3 and sysV.3 systems. Usage: 'gclock [-s] [n]' to run for n seconds, default infinity (well, actually 2**32 seconds, or 136 years). The -s flag causes the displayed digits to scroll when they change. Happy hacking! o / o / o / o / --Cut-here-------X---------------X---------------X---------------X---- o \ o \ o \ o \ #!/bin/sh : "This is a shell archive, meaning: " : "1. Remove everything above the #! /bin/sh line. " : "2. Save the rest in a file. " : "3. Execute the file with /bin/sh (not csh) to create the files:" : " gcl.6" : " gcl.c" : "This archive created: Thu Jun 23 13:29:43 GMT+3:00 1988 " if [ -f gcl.6 ] then echo file gcl.6 exists else echo extracting file: gcl.6 sed 's/^X//' >gcl.6 << 'END-of-gcl.6' X.TH GCLOCK 6 X.SH NAME Xgclock \- grand digital clock X.SH SYNOPSIS X.B gclock X[-s] [ X.I n X] X.SH DESCRIPTION X.I Gclock Xruns a digital clock made of reverse-video blanks on a vt100 or ANSI Xcompatible VDU screen. With an optional numeric argument X.I n Xit stops after X.I n Xseconds (default never). XThe optional X.B -s Xflag makes digits scroll as they change. X.SH AUTHOR XAmos Shapir X.SH BUGS XShould use the termlib(3) routines for terminal adaptibility. END-of-gcl.6 fi if [ -f gcl.c ] then echo file gcl.c exists else echo extracting file: gcl.c sed 's/^X//' >gcl.c << 'END-of-gcl.c' X/* X * Grand digital clock for vt100 and clones X * Usage: gclock [-s] n -- run for n seconds (default infinity) X * Flags: -s: scroll X */ X#include <stdio.h> X#include <time.h> Xlong now; Xstruct tm *tm; Xshort disp[11] = { X 075557, 011111, 071747, 071717, 055711, X 074717, 074757, 071111, 075757, 075717, 002020 X}; Xlong old[6], next[6], new[6], mask; Xchar scrol; Xmain(argc, argv) X char **argv; X{ X register long t, a; X register i, j, s, n, k; X X clear(); X while(--argc > 0) { X if(**++argv == '-') X scrol = 1; X else X n = atoi(*argv); X } X do { X mask = 0; X time(&now); X tm = localtime(&now); X set(tm->tm_sec%10, 0); X set(tm->tm_sec/10, 4); X set(tm->tm_min%10, 10); X set(tm->tm_min/10, 14); X set(tm->tm_hour%10, 20); X set(tm->tm_hour/10, 24); X set(10, 7); X set(10, 17); X for(k=0; k<6; k++) { X if(scrol) { X for(i=0; i<5; i++) X new[i] = new[i]&~mask | new[i+1]&mask; X new[5] = new[5]&~mask | next[k]&mask; X } else X new[k] = new[k]&~mask | next[k]&mask; X next[k] = 0; X for(s=1; s>=0; s--) { X standout(s); X for(i=0; i<6; i++) { X if(a = (new[i]^old[i])&(s ? new : old)[i]) X for(j=0,t=1<<26; t; t>>=1,j++) X if(a&t) { X if(!(a&(t<<1))) { X movto(i, 2*j); X } X printf(" "); X } X if(!s) X old[i] = new[i]; X } X } X } X movto(6, 0); X fflush(stdout); X sleep(1); X } while(--n); X return(0); X} X Xset(t, n) X register n; X{ X register i, m; X X m = 7<<n; X for(i=0; i<5; i++) { X next[i] |= ((disp[t]>>(4-i)*3)&07)<<n; X mask |= (next[i]^old[i])&m; X } X if(mask&m) X mask |= m; X} X X/* terminal-dependent routines */ Xclear() X{ X printf("\033[H\033[2J"); X} X Xstandout(on) X{ X printf("\033[%sm", on ? "7" : ""); X} X Xmovto(line,col) X{ X printf("\033[%d;%dH", line+1, col+1); X} END-of-gcl.c fi exit o / o / o / o / --Cut-here-------X---------------X---------------X---------------X---- o \ o \ o \ o \ May the Source be with you, always... -- Amos Shapir (My other cpu is a NS32532) National Semiconductor (Israel) 6 Maskit st. P.O.B. 3007, Herzlia 46104, Israel Tel. +972 52 522261 amos%taux01@nsc.com 34 48 E / 32 10 N