home *** CD-ROM | disk | FTP | other *** search
- Path: wuarchive!wugate!uunet!bbn.com!rsalz
- From: rsalz@uunet.uu.net (Rich Salz)
- Newsgroups: comp.sources.unix
- Subject: v20i045: Curses-based digital clock
- Message-ID: <2052@papaya.bbn.com>
- Date: 24 Oct 89 00:17:33 GMT
- Lines: 222
- Approved: rsalz@uunet.UU.NET
-
- Submitted-by: John Lupien <jrl@mvuxr.att.com>
- Posting-number: Volume 20, Issue 45
- Archive-name: curses-clock
-
- [ Yes, Virginia, not everyone was bitmapped graphics... /r$ ]
-
- Amos Shapir wrote this digital clock program for VT100 compatibles,
- and posted it without makefile to some relatively lax newsgroup.
-
- I upgraded my terminal to an AT&T 5620, and of course the clock
- stopped working, so I converted the screen management stuff to curses.
- It is short and sweet, and now runs quietly in my topmost window.
-
- -------------------cut here--------------------cut here---------------------
- #To unpack, delete all lines before this and feed to /bin/sh
- echo Makefile 1>&2
- sed -e 's/^X//' >Makefile <<'END'
- X# Makefile for gdc curses version 10-18-89
- X
- Xgdc: gdc.c
- X cc -o gdc -O gdc.c -lcurses
- X
- END
- echo gdc.6 1>&2
- sed -e 's/^X//' >gdc.6 <<'END'
- X.TH GDC 6
- X.SH NAME
- Xgdc \- grand digital clock (curses)
- X.SH SYNOPSIS
- X.B gdc
- X[-s] [
- X.I n
- X]
- X.SH DESCRIPTION
- X.I Gdc
- Xruns a digital clock made of reverse-video blanks on a curses
- 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. In this curses mode implementation,
- Xthe scrolling option has trouble keeping up.
- X.SH AUTHOR
- XAmos Shapir, modified for curses by John Lupien.
- END
- echo gdc.c 1>&2
- sed -e 's/^X//' >gdc.c <<'END'
- X/*
- X * Grand digital clock for curses compatible terminals
- X * Usage: gdc [-s] [n] -- run for n seconds (default infinity)
- X * Flags: -s: scroll
- X *
- X * modified 10-18-89 for curses (jrl)
- X * 10-18-89 added signal handling
- X */
- X
- X#include <stdio.h>
- X#include <time.h>
- X#include <curses.h>
- X
- X/* it won't be */
- Xlong now; /* yeah! */
- Xstruct tm *tm;
- X
- 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;
- X
- Xint sigtermed=0;
- X
- Xvoid sighndl(signo)
- Xint signo;
- X{
- X signal(signo, sighndl);
- X sigtermed=signo;
- X}
- X
- Xmain(argc, argv)
- X char **argv;
- X{
- X register long t, a;
- X register i, j, s, n, k;
- X signal(1,sighndl);
- X signal(2,sighndl);
- X signal(3,sighndl);
- X signal(15,sighndl);
- X
- X initscr();
- X clr();
- X refresh();
- 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 {
- X standt(s);
- X for(i=0; i<6; i++)
- X {
- X if(a = (new[i]^old[i])&(s ? new : old)[i])
- X {
- X for(j=0,t=1<<26; t; t>>=1,j++)
- X {
- X if(a&t)
- X {
- X if(!(a&(t<<1)))
- X {
- X movto(i, 2*j);
- X }
- X addstr(" ");
- X }
- X }
- X }
- X if(!s)
- X {
- X old[i] = new[i];
- X }
- X }
- X if(!s)
- X {
- X refresh();
- X }
- X }
- X }
- X movto(6, 0);
- X refresh();
- X sleep(1);
- X if (sigtermed)
- X {
- X standend();
- X clear();
- X refresh();
- X endwin();
- X fprintf(stderr, "gcl terminated by signal %d\n", sigtermed);
- X exit(1);
- X }
- X } while(--n);
- X standend();
- X clear();
- X refresh();
- X endwin();
- 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 */
- Xclr()
- X{
- X clear();
- X refresh();
- X}
- X
- Xstandt(on)
- Xint on;
- X{
- X if (on)
- X {
- X standout();
- X }
- X else
- X {
- X standend();
- X }
- X}
- X
- Xmovto(line,col)
- X{
- X move(line, col);
- X}
- X
- END
-
- --
- -John Lupien
- mvuxr!jrl
- jrl@mvuxr.att.com
-
-
- --
- Please send comp.sources.unix-related mail to rsalz@uunet.uu.net.
- Use a domain-based address or give alternate paths, or you may lose out.
-