home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume7 / gcl < prev    next >
Encoding:
Text File  |  1989-07-08  |  4.4 KB  |  190 lines

  1. Newsgroups: comp.sources.misc
  2. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  3. Subject: v07i066: Grand Digital Clock
  4. Message-Id: <761@taux01.UUCP>
  5. Reply-To: Amos Shapir <nsc!taux01!taux01.UUCP!amos@uunet.uu.net>
  6. Organization: National Semiconductor (IC) Ltd, Israel
  7.  
  8. Posting-number: Volume 7, Issue 66
  9. Submitted-by: Amos Shapir <amdahl!nsc!taux01!nsc.uucp!taux01!amos@uunet.uu.net>
  10. Archive-name: gcl
  11.  
  12. The  recently posted  digital clock  reminded  me of  something from  my
  13. remote past.  I have  dug it  out, and here  it is  - the  Grand Digital
  14. Clock. It displays the time in very big reverse video characters.
  15.  
  16. Since it was written  before the days of termcap it  only fits VT100 and
  17. ANSI-compatible terminals,  but all the terminal-dependent  routines are
  18. concentrated at the  end, and can be easily hacked.  This source was run
  19. successfully on BSD4.3 and sysV.3 systems.
  20.  
  21. Usage: 'gclock [-s]  [n]' to run for n seconds,  default infinity (well,
  22. actually 2**32 seconds, or 136 years).  The -s flag causes the displayed
  23. digits to scroll when they change.
  24.  
  25. Happy hacking!
  26.  
  27.  
  28.         o /        o /        o /        o /
  29. --Cut-here-------X---------------X---------------X---------------X----
  30.         o \        o \        o \        o \
  31.  
  32. #!/bin/sh
  33. : "This is a shell archive, meaning:                              "
  34. : "1. Remove everything above the #! /bin/sh line.                "
  35. : "2. Save the rest in a file.                                    "
  36. : "3. Execute the file with /bin/sh (not csh) to create the files:"
  37. : "    gcl.6"
  38. : "    gcl.c"
  39. : "This archive created:  Thu Jun 23 13:29:43 GMT+3:00 1988 "
  40. if [ -f gcl.6 ]
  41. then
  42. echo file gcl.6 exists
  43. else
  44. echo extracting file: gcl.6
  45. sed 's/^X//' >gcl.6 << 'END-of-gcl.6'
  46. X.TH GCLOCK 6
  47. X.SH NAME
  48. Xgclock \- grand digital clock
  49. X.SH SYNOPSIS
  50. X.B gclock
  51. X[-s] [
  52. X.I n
  53. X]
  54. X.SH DESCRIPTION
  55. X.I Gclock
  56. Xruns a digital clock made of reverse-video blanks on a vt100 or ANSI
  57. Xcompatible VDU screen. With an optional numeric argument
  58. X.I n
  59. Xit stops after
  60. X.I n
  61. Xseconds (default never).
  62. XThe optional
  63. X.B -s
  64. Xflag makes digits scroll as they change.
  65. X.SH AUTHOR
  66. XAmos Shapir
  67. X.SH BUGS
  68. XShould use the termlib(3) routines for terminal adaptibility.
  69. END-of-gcl.6
  70. fi
  71. if [ -f gcl.c ]
  72. then
  73. echo file gcl.c exists
  74. else
  75. echo extracting file: gcl.c
  76. sed 's/^X//' >gcl.c << 'END-of-gcl.c'
  77. X/*
  78. X * Grand digital clock for vt100 and clones
  79. X * Usage: gclock [-s] n   -- run for n seconds (default infinity)
  80. X * Flags: -s: scroll
  81. X */
  82. X#include <stdio.h>
  83. X#include <time.h>
  84. Xlong now;
  85. Xstruct tm *tm;
  86. Xshort disp[11] = {
  87. X    075557, 011111, 071747, 071717, 055711,
  88. X    074717, 074757, 071111, 075757, 075717, 002020
  89. X};
  90. Xlong old[6], next[6], new[6], mask;
  91. Xchar scrol;
  92. Xmain(argc, argv)
  93. X    char **argv;
  94. X{
  95. X    register long t, a;
  96. X    register i, j, s, n, k;
  97. X
  98. X    clear();
  99. X    while(--argc > 0) {
  100. X        if(**++argv == '-')
  101. X            scrol = 1;
  102. X        else
  103. X            n = atoi(*argv);
  104. X    }
  105. X    do {
  106. X        mask = 0;
  107. X        time(&now);
  108. X        tm = localtime(&now);
  109. X        set(tm->tm_sec%10, 0);
  110. X        set(tm->tm_sec/10, 4);
  111. X        set(tm->tm_min%10, 10);
  112. X        set(tm->tm_min/10, 14);
  113. X        set(tm->tm_hour%10, 20);
  114. X        set(tm->tm_hour/10, 24);
  115. X        set(10, 7);
  116. X        set(10, 17);
  117. X        for(k=0; k<6; k++) {
  118. X            if(scrol) {
  119. X                for(i=0; i<5; i++)
  120. X                    new[i] = new[i]&~mask | new[i+1]&mask;
  121. X                new[5] = new[5]&~mask | next[k]&mask;
  122. X            } else
  123. X                new[k] = new[k]&~mask | next[k]&mask;
  124. X            next[k] = 0;
  125. X            for(s=1; s>=0; s--) {
  126. X                standout(s);
  127. X                for(i=0; i<6; i++) {
  128. X                    if(a = (new[i]^old[i])&(s ? new : old)[i])
  129. X                        for(j=0,t=1<<26; t; t>>=1,j++)
  130. X                            if(a&t) {
  131. X                                if(!(a&(t<<1))) {
  132. X                                    movto(i, 2*j);
  133. X                                }
  134. X                                printf("  ");
  135. X                            }
  136. X                    if(!s)
  137. X                        old[i] = new[i];
  138. X                }
  139. X            }
  140. X        }
  141. X        movto(6, 0);
  142. X        fflush(stdout);
  143. X        sleep(1);
  144. X    } while(--n);
  145. X    return(0);
  146. X}
  147. X
  148. Xset(t, n)
  149. X    register n;
  150. X{
  151. X    register i, m;
  152. X
  153. X    m = 7<<n;
  154. X    for(i=0; i<5; i++) {
  155. X        next[i] |= ((disp[t]>>(4-i)*3)&07)<<n;
  156. X        mask |= (next[i]^old[i])&m;
  157. X    }
  158. X    if(mask&m)
  159. X        mask |= m;
  160. X}
  161. X
  162. X/* terminal-dependent routines */
  163. Xclear()
  164. X{
  165. X    printf("\033[H\033[2J");
  166. X}
  167. X
  168. Xstandout(on)
  169. X{
  170. X    printf("\033[%sm", on ? "7" : "");
  171. X}
  172. X
  173. Xmovto(line,col)
  174. X{
  175. X    printf("\033[%d;%dH", line+1, col+1);
  176. X}
  177. END-of-gcl.c
  178. fi
  179. exit
  180.  
  181.         o /        o /        o /        o /
  182. --Cut-here-------X---------------X---------------X---------------X----
  183.         o \        o \        o \        o \
  184. May the Source be with you, always...
  185. -- 
  186.     Amos Shapir            (My other cpu is a NS32532)
  187. National Semiconductor (Israel)
  188. 6 Maskit st. P.O.B. 3007, Herzlia 46104, Israel  Tel. +972 52 522261
  189. amos%taux01@nsc.com  34 48 E / 32 10 N
  190.