Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 exptools; site ihlpg.UUCP Path: utzoo!linus!decvax!bellcore!petrus!sabre!zeta!epsilon!gamma!ulysses!mhuxr!mhuxt!houxm!ihnp4!ihlpg!jchvr From: jchvr@ihlpg.UUCP (VanRietschote) Newsgroups: net.sources Subject: DYNAKEY prgm to dynamically display info on function key labels Message-ID: <1534@ihlpg.UUCP> Date: Tue, 7-Jan-86 13:23:43 EST Article-I.D.: ihlpg.1534 Posted: Tue Jan 7 13:23:43 1986 Date-Received: Wed, 8-Jan-86 08:05:53 EST Distribution: net Organization: AT&T Bell Laboratories Lines: 552 -- dynakey will allow you to use a background process to dynamically change the contents of your programmable function key labels when certain events happen (example: arriving of mail, netnews, rje-stuff). As distributed it works only on hp2392 terminls but very little is needed to make it work on other terms. which have programmable function key labels. Feel free to use or abuse this program at your own risk. for more info see next newsitem with manual page. #-- cut here --- /* dynakey.c -*-update-version-*- ** to activate background work and output to HP2392 labels ** HFVR VERSION=Wed Dec 11 07:51:21 1985 */ #include #include #include #include #include #include #define MAXKEYS 8 typedef enum {FALSE,TRUE} BOOL; typedef struct act /* activity record */ { char *watch; /* file to watch */ char *onmsg; /* message if file is on */ char *offmsg; /* msg if file is off */ int key; /* key to display to */ BOOL beep; /* TRUE then beep if changed */ BOOL BEEP; /* TRUE then beep if diff. label */ int sleepfor; /* length of sleep in sec */ long nexttime; /* when to wake up */ struct act *next; /* ptr to next act */ long mtime; /* modification time of file */ } ACT; struct utimbuf *null = NULL; /* for setting read access time /dev/tty */ char terminal[32]; /* terminal name */ int minsleep; /* minimum of all sleepfor */ long NOW; /* start time of program */ char MAILFILE[100]; char NEWSFILE[100]; char NEWSRC[100]; ACT *root = NULL; /* root of activities */ char forward[] = "Forward to "; /* used for mail */ char NAME[] = "dynakey"; BOOL dflag = FALSE; /* debug flag */ int fflag = 1; /* default function=1 */ int sflag = 60; /* default seconds to wait=60 */ char *keys[MAXKEYS+1] = {"XXXXXXXXXXXXXXXX", /* key labels */ "XXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXX", }; int min(i,j) { if ( i < j) return (i); return(j); }/*min*/ int max(i,j) { if ( i > j ) return (i); return(j); }/*max*/ /* fsize: return size of file or 0 if file not stat'able */ long fsize(file) char file[]; { struct stat filbuf; /* file desc */ /* treat special files first */ if ( strcmp(file,"NETNEWS") == 0 ) return(1L); if ( strcmp(file,"TIME" ) == 0 ) return(1L); if ( strcmp(file,"MAIL" ) == 0 ) file = MAILFILE; if ( stat(file,&filbuf) == -1 ) return(0L); return((long)filbuf.st_size); }/*fsize*/ /* mtime: return mtime of file or 0 if file not stat'able */ long mtime(file) char file[]; { extern long time(); struct stat filbuf; /* file desc */ /* treat special files first */ if ( strcmp(file,"NETNEWS") == 0 ) file = NEWSFILE; if ( strcmp(file,"TIME" ) == 0 ) return(time(0)); if ( strcmp(file,"MAIL" ) == 0 ) file = MAILFILE; if ( stat(file,&filbuf) == -1 ) return(0L) ;/* file not exist or not read */ return((long)filbuf.st_mtime); }/*mtime*/ /* TIME: return pointer to \0 terminated string with HH:MM in it */ char *TIME() { extern long time(); extern struct tm *localtime(); struct tm *local; long seconds; static char times[6]; seconds = time(0); local = localtime(&seconds); sprintf(times,"%2d:%.2d",local->tm_hour,local->tm_min); return(times); }/*TIME*/ /*SIZE: return \0 terminated string with size in it %ld */ char *SIZE(file) char file[]; { static char sizes[12]; sprintf(sizes,"%8ld",fsize(file)); return(sizes); }/*SIZE*/ /*MTIME: return \0 terminated string with mtime in it HH:MM */ char *MTIME(file) char file[]; { static char times[6]; struct stat filbuf; /* file desc */ time_t mtime1; extern struct tm *localtime(); struct tm *local; /* treat special cases */ if ( strcmp(file,"TIME" ) == 0 ) return(TIME()); if ( strcmp(file,"MAIL" ) == 0 ) file = MAILFILE; if ( strcmp(file,"NETNEWS" ) == 0 ) file = NEWSFILE; if ( stat(file,&filbuf) == -1 ) { strcpy(times,"??:??"); return(times); } mtime1 = filbuf.st_mtime; local = localtime(&mtime1); sprintf(times,"%2d:%.2d",local->tm_hour,local->tm_min); return(times); }/*MTIME*/ /* newactivity: returns ptr to new intialized activity record */ ACT *newactivity() { ACT *ptr; extern ACT *malloc(); static char EMPTY[] = ""; /* empty string */ extern long time(); ptr = malloc(sizeof(ACT)); if ( ptr == NULL ) { fprintf(stderr,"\007%s: Out of memory. Aborting.\n",NAME); exit(1); } ptr->watch = EMPTY; ptr->onmsg = EMPTY; ptr->offmsg = EMPTY; ptr->key = fflag; /* default */ ptr->beep = FALSE; ptr->BEEP = FALSE; ptr->sleepfor = sflag; ptr->nexttime = NOW; ptr->next = NULL; ptr->mtime = 0L; return(ptr); }/*newactivity*/ /* checkTERM: see if TERM=hp2392 */ /* exit if not good */ void checkTERM() { if ( strcmp("hp2392",getenv("TERM")) != 0 ) { fprintf(stderr,"\007%s : ERROR : you are not a hp2392 terminal\n",NAME); exit(1); }/*fi*/ strcpy(terminal,getenv("LOGTTY")); }/*checkTERM*/ void init() { extern long time(); checkTERM(); NOW = time(0); /* MAILFILE=/usr/mail/$LOGNAME */ strcpy(MAILFILE,"/usr/mail/"); strcat(MAILFILE,getenv("LOGNAME")); /* NEWSFILE=$TOOLS/lib/netnews/history */ strcpy(NEWSFILE,getenv("TOOLS")); strcat(NEWSFILE,"/lib/netnews/history"); /* NEWSRC=$HOME/.newsrc */ strcpy(NEWSRC,getenv("HOME")); strcat(NEWSRC,"/.newsrc"); root = NULL; }/*init*/ /*usage: */ void usage() { fprintf(stderr,"\007Usage: %s { -w -l [-L] [-b] [-B] -f [-s] }* -dV\n",NAME); fprintf(stderr,"Where: -w to watch\n"); fprintf(stderr," Special watches are: TIME, MAIL, NETNEWS\n"); fprintf(stderr," -l