home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume07 / gcl < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  4.7 KB

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