correct qtime
Luiz H. deFigueiredo
lhf at aries5
Wed Sep 13 04:56:39 AEST 1989
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 at aries5.uwaterloo.ca
Computer Systems Group bitnet: lhf at 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 <stdio.h>
#include <sys/types.h>
#include <time.h>
#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");
}
More information about the Alt.sources
mailing list