]> diplodocus.org Git - nmh/blob - docs/historical/mh-nov-1983/subs/putdate.c
Update XOAUTH2 documentation.
[nmh] / docs / historical / mh-nov-1983 / subs / putdate.c
1 #include <stdio.h>
2 #include <sys/types.h>
3 #include <sys/timeb.h>
4 #include <sys/time.h>
5
6 /*
7 * Output the date in right format gotten from
8 * the passed ctime(3) format date.
9 * If the passed date is NULL, output the current
10 * date and time.
11 */
12
13 putdate(timestr, out)
14 char *timestr;
15 register FILE *out;
16 {
17 register char *t, *p, *cp;
18 char *timezone();
19 struct tm *tmp;
20 struct tm *localtime();
21 struct timeb tb;
22 long now;
23 int isdst;
24 char *asctime();
25 static char *str = "SunMonTueWedThuFriSat";
26 static char *daytag[] = {
27 "Sunday",
28 "Monday",
29 "Tuesday",
30 "Wednesday",
31 "Thursday",
32 "Friday",
33 "Saturday"
34 };
35
36 now = time((long *) 0);
37 tmp = localtime(&now);
38 isdst = tmp->tm_isdst;
39 if (timestr == 0)
40 timestr = asctime(tmp);
41 cp = str;
42 t = timestr;
43 while (*cp) {
44 if (strcmpn(cp, t, 3) == 0)
45 break;
46 cp += 3;
47 }
48 if (*cp)
49 cp = daytag[(cp - str) / 3];
50 else
51 cp = 0;
52 ftime(&tb);
53 /*
54 * This call to timezone() may be wrong:
55 * really need the tm_isdst whoever generated timestr.
56 */
57 p = timezone(tb.timezone, isdst);
58
59 if (cp == 0)
60 fprintf(out, "Date: %.2s %.3s %.4s %.2s%.2s-%.3s\n",
61 t+8, t+4, t+20, t+11, t+14, p);
62 else
63 fprintf(out, "Date: %.2s %.3s %.4s %.2s%.2s-%.3s (%s)\n",
64 t+8, t+4, t+20, t+11, t+14, p, cp);
65 }