A newer version of qtime - a friendly clock
Ade Lovett
ade at cs.warwick.ac.uk
Fri Sep 8 20:03:40 AEST 1989
I was looking through the old archives recently, and found a cute little
program called 'qtime' which displayed the time of day in a more interesting
format than date(1). It worked fine, but then I looked at the code, and it
was rather messy (a couple of *huge* case statements), so I decided to rewrite
it, making it a bit more efficient and smaller (on my system, it compiles to
just under 9k, the original taking ~15k).
Being a public-spirited sort of chap, I decided to post it to alt.sources
just in case anyone else either missed the original version, or wants to
have a look at this new all-improved :-) version.
It compiles and runs under Suns (both SunOS 4.0 and 3.4) and VAXen (running
Ultrix 3.0 and 2.0) - I don't know about any other machine/operating system
combinations.
Enjoy,
aDe
PS: Don't forget to remove the .sig from the end :-)
---- cut here ----
/* qtime.c Displays time in real English, also chimes
**
** 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);
hr = tm->tm_hour+(tm->tm_min>32);
mn = tm->tm_min+(tm->tm_sec>29);
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 at cs.warwick.ac.uk ------ +44 932 842478 -------+
| Computer Science | INTERNET: ade%cs.warwick.ac.uk at nsfnet-relay.ac.uk |
| Warwick University | UUCP : ...!mcvax!ukc!warwick!ade |
| Coventry CV4 7AL, UK | BITNET : ade%uk.ac.warwick.cs at ukacrl |
+-----------------------+----------------------------------------------------+
More information about the Alt.sources
mailing list