Path: utzoo!attcan!utgpu!watmath!maytag!aries5!lhf From: lhf@aries5 (Luiz H. deFigueiredo) Newsgroups: alt.sources Subject: correct qtime Summary: previously posted qtime was buggy Message-ID: <472@maytag.waterloo.edu> Date: 12 Sep 89 18:56:39 GMT Sender: daemon@maytag.waterloo.edu Reply-To: lhf@aries5 (Luiz H. deFigueiredo) Organization: Computer Systems Group, University of Waterloo Lines: 91 Just the other day some Ade Lovett posted qtime. Unfortunately it had a bug in it (I'll let you discover/come across it). Here is my version. I've changed some names and removed the need for a buffer. Also, it now outputs a single line. Enjoy! ------------------------------------------------------------------------------- Luiz Henrique de Figueiredo internet: lhf@aries5.uwaterloo.ca Computer Systems Group bitnet: lhf@watcsg.bitnet University of Waterloo ------------------------------------------------------------------------------- /* * qtime.c * displays time in real English, also chimes * Luiz Henrique de Figueiredo * original by Mike Cowlishaw, Mark Dapoz and Ade Lovett * 11 Sep 89 */ #include #include #include #define show(s) fputs(s,stdout) #define divide(m,x) (((x)%(m))==0) static char *adverb[]= { NULL, "just after ", "a little after ", "nearly ", "almost " }; static char *mark[]= { NULL, "five past ", "ten past ", "a quarter past ", "twenty past ", "twenty-five past ", "half past ", "twenty-five to ", "twenty to ", "a quarter to ", "ten to ", "five to ", "" }; static char *hour[]= { NULL, "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven" }; void main() { int h, m; time_t clock, time(); struct tm *tm, *localtime(); time(&clock); tm = localtime(&clock); h = tm->tm_hour + (tm->tm_min >= 33); m = tm->tm_min + (tm->tm_sec >= 30); if (divide(15,m)) { if (!divide(60,m)) show("(Ding-Dong!) "); else { int n; n=h%12; if (n==0) n=12; show("("); while (--n>0) show("Bong,"); show("Bong!) "); } } show("It's "); show(adverb[m%5]); show(mark[(m+2)/5]); switch (h) { case 0: case 24: show("midnight"); break; case 12: show("noon"); break; default: show(hour[h%12]); if (divide(60,m)) show(" o'clock"); break; } show(".\n"); }