ade@cs.warwick.ac.uk (Ade Lovett) (09/18/89)
Something silly happened in the last posting, and the wrong version got sent
out somehow. There was another bug in qtime (pointed out locally and also
by Ian Feldman <ianf@se.kth.nada>) that wierd things start to happen as
you approach midnight.
Anyway, this is definitely the fixed version, if you're interested, I could
snail mail you the line printer test output whcih tested it for every second
of the day :-) :-)
aDe
/* qtime.c Displays time in real English, also chimes
** This version current from 18/9/89
**
** 09/89 Ade Lovett Complete rewrite
** 04/86 Mark Dapoz Converted to C for UNIX
** 12/79-12/82 Mike Cowlishaw
**
*/
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
char *minutesaying[] = {
"","just after ","a little after ","nearly ","almost "
};
char *fiveminsaying[] = {
"","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 ",""
};
char *hoursaying[] = {
"one","two","three","four","five","six","seven","eight","nine",
"ten","eleven",""
};
void main()
{
char qtime[200];
int i, hr, mn;
time_t clock, time();
struct tm *tm, *localtime();
time(&clock);
tm = localtime(&clock);
mn = tm->tm_min+(tm->tm_sec>29);
hr = tm->tm_hour+(mn>32);
strcpy(qtime, "It's ");
strcat(qtime, minutesaying[mn%5]);
strcat(qtime, fiveminsaying[mn/5+(mn%5>2)]);
if (hr%12) {
strcat(qtime, hoursaying[(hr -= (hr>12)*12+1)]);
strcat(qtime, (mn%60) ? "." : " o'clock.");
} else {
strcat(qtime, (hr == 12) ? "Noon." : "Midnight.");
hr = 12;
}
if (!(mn%15))
if (mn%60)
printf("(Ding-Dong!)\n\n");
else {
printf("(");
for (i=hr; i>=0; i--)
printf("Bong%s",(i==0 ? "!)\n\n" : ","));
}
printf("%s\n",qtime);
}
--
+--- Ade Lovett --------+- ade@cs.warwick.ac.uk ------ +44 932 842478 -------+
| Computer Science | INTERNET: ade%cs.warwick.ac.uk@nsfnet-relay.ac.uk |
| Warwick University | UUCP : ...!mcvax!ukc!warwick!ade |
| Coventry CV4 7AL, UK | BITNET : ade%uk.ac.warwick.cs@ukacrl |
+-----------------------+----------------------------------------------------+