calendar.c revision 1.28 1 1.28 agc /* $NetBSD: calendar.c,v 1.28 2003/08/07 11:13:14 agc Exp $ */
2 1.7 glass
3 1.1 cgd /*
4 1.7 glass * Copyright (c) 1989, 1993, 1994
5 1.7 glass * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * Redistribution and use in source and binary forms, with or without
8 1.1 cgd * modification, are permitted provided that the following conditions
9 1.1 cgd * are met:
10 1.1 cgd * 1. Redistributions of source code must retain the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer.
12 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 cgd * notice, this list of conditions and the following disclaimer in the
14 1.1 cgd * documentation and/or other materials provided with the distribution.
15 1.28 agc * 3. Neither the name of the University nor the names of its contributors
16 1.1 cgd * may be used to endorse or promote products derived from this software
17 1.1 cgd * without specific prior written permission.
18 1.1 cgd *
19 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 cgd * SUCH DAMAGE.
30 1.1 cgd */
31 1.1 cgd
32 1.11 lukem #include <sys/cdefs.h>
33 1.1 cgd #ifndef lint
34 1.11 lukem __COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
35 1.11 lukem The Regents of the University of California. All rights reserved.\n");
36 1.1 cgd #endif /* not lint */
37 1.1 cgd
38 1.1 cgd #ifndef lint
39 1.7 glass #if 0
40 1.8 jtc static char sccsid[] = "@(#)calendar.c 8.4 (Berkeley) 1/7/95";
41 1.7 glass #endif
42 1.28 agc __RCSID("$NetBSD: calendar.c,v 1.28 2003/08/07 11:13:14 agc Exp $");
43 1.1 cgd #endif /* not lint */
44 1.1 cgd
45 1.1 cgd #include <sys/param.h>
46 1.1 cgd #include <sys/time.h>
47 1.1 cgd #include <sys/stat.h>
48 1.1 cgd #include <sys/uio.h>
49 1.7 glass #include <sys/wait.h>
50 1.7 glass
51 1.7 glass #include <ctype.h>
52 1.7 glass #include <err.h>
53 1.7 glass #include <errno.h>
54 1.7 glass #include <fcntl.h>
55 1.1 cgd #include <pwd.h>
56 1.7 glass #include <stdio.h>
57 1.7 glass #include <stdlib.h>
58 1.7 glass #include <string.h>
59 1.13 kleink #include <time.h>
60 1.1 cgd #include <tzfile.h>
61 1.1 cgd #include <unistd.h>
62 1.7 glass
63 1.1 cgd #include "pathnames.h"
64 1.1 cgd
65 1.10 thorpej #ifndef TRUE
66 1.10 thorpej #define TRUE 1
67 1.10 thorpej #endif
68 1.10 thorpej #ifndef FALSE
69 1.10 thorpej #define FALSE 0
70 1.10 thorpej #endif
71 1.10 thorpej
72 1.26 christos static unsigned short lookahead = 1, weekend = 2;
73 1.26 christos static char *fname = "calendar", *datestr = NULL;
74 1.26 christos static struct passwd *pw;
75 1.26 christos static int doall;
76 1.26 christos static char path[MAXPATHLEN + 1];
77 1.26 christos
78 1.26 christos /* 1-based month, 0-based days, cumulative */
79 1.26 christos static int daytab[][14] = {
80 1.26 christos { 0, -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364 },
81 1.26 christos { 0, -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
82 1.26 christos };
83 1.26 christos static struct tm *tp;
84 1.26 christos static int *cumdays, offset, yrdays;
85 1.26 christos static char dayname[10];
86 1.26 christos
87 1.26 christos static struct iovec header[] = {
88 1.26 christos { "From: ", 6 },
89 1.26 christos { NULL, 0 },
90 1.26 christos { " (Reminder Service)\nTo: ", 24 },
91 1.26 christos { NULL, 0 },
92 1.26 christos { "\nSubject: ", 10 },
93 1.26 christos { NULL, 0 },
94 1.26 christos { "'s Calendar\nPrecedence: bulk\n\n", 30 },
95 1.26 christos };
96 1.26 christos
97 1.26 christos static char *days[] = {
98 1.26 christos "sun", "mon", "tue", "wed", "thu", "fri", "sat", NULL,
99 1.26 christos };
100 1.26 christos
101 1.26 christos static char *months[] = {
102 1.26 christos "jan", "feb", "mar", "apr", "may", "jun",
103 1.26 christos "jul", "aug", "sep", "oct", "nov", "dec", NULL,
104 1.26 christos };
105 1.26 christos
106 1.26 christos int main(int, char **);
107 1.26 christos
108 1.26 christos static void atodays(int, char *, unsigned short *);
109 1.26 christos static void cal(void);
110 1.26 christos static void closecal(FILE *);
111 1.26 christos static int getday(char *);
112 1.26 christos static int getfield(char *, char **, int *);
113 1.26 christos static void getmmdd(struct tm *, char *);
114 1.26 christos static int getmonth(char *);
115 1.26 christos static int isnow(char *);
116 1.26 christos static FILE *opencal(void);
117 1.26 christos static void settime(void);
118 1.26 christos static void usage(void) __attribute__((__noreturn__));
119 1.7 glass
120 1.7 glass int
121 1.1 cgd main(argc, argv)
122 1.1 cgd int argc;
123 1.7 glass char *argv[];
124 1.1 cgd {
125 1.1 cgd int ch;
126 1.15 mycroft const char *caldir;
127 1.1 cgd
128 1.20 lukem while ((ch = getopt(argc, argv, "-ad:f:l:w:")) != -1)
129 1.7 glass switch (ch) {
130 1.1 cgd case '-': /* backward contemptible */
131 1.1 cgd case 'a':
132 1.1 cgd if (getuid()) {
133 1.7 glass errno = EPERM;
134 1.21 drochner err(1, NULL);
135 1.1 cgd }
136 1.1 cgd doall = 1;
137 1.1 cgd break;
138 1.10 thorpej case 'd':
139 1.10 thorpej datestr = optarg;
140 1.10 thorpej break;
141 1.10 thorpej case 'f':
142 1.10 thorpej fname = optarg;
143 1.10 thorpej break;
144 1.10 thorpej case 'l':
145 1.10 thorpej atodays(ch, optarg, &lookahead);
146 1.10 thorpej break;
147 1.10 thorpej case 'w':
148 1.10 thorpej atodays(ch, optarg, &weekend);
149 1.10 thorpej break;
150 1.1 cgd case '?':
151 1.1 cgd default:
152 1.1 cgd usage();
153 1.1 cgd }
154 1.1 cgd argc -= optind;
155 1.1 cgd argv += optind;
156 1.1 cgd
157 1.1 cgd if (argc)
158 1.1 cgd usage();
159 1.1 cgd
160 1.1 cgd settime();
161 1.26 christos if (doall) {
162 1.7 glass while ((pw = getpwent()) != NULL) {
163 1.1 cgd (void)setegid(pw->pw_gid);
164 1.1 cgd (void)seteuid(pw->pw_uid);
165 1.1 cgd if (!chdir(pw->pw_dir))
166 1.1 cgd cal();
167 1.1 cgd (void)seteuid(0);
168 1.1 cgd }
169 1.26 christos } else if ((caldir = getenv("CALENDAR_DIR")) != NULL) {
170 1.26 christos if(!chdir(caldir))
171 1.26 christos cal();
172 1.26 christos } else {
173 1.1 cgd cal();
174 1.26 christos }
175 1.1 cgd exit(0);
176 1.1 cgd }
177 1.1 cgd
178 1.26 christos static void
179 1.26 christos cal(void)
180 1.1 cgd {
181 1.11 lukem int printing;
182 1.7 glass FILE *fp;
183 1.26 christos char *line;
184 1.1 cgd
185 1.7 glass if ((fp = opencal()) == NULL)
186 1.1 cgd return;
187 1.26 christos while ((line = fparseln(stdin, NULL, NULL, NULL, 0)) != NULL) {
188 1.26 christos if (line[0] == '\0')
189 1.1 cgd continue;
190 1.26 christos if (line[0] != '\t')
191 1.26 christos printing = isnow(line) ? 1 : 0;
192 1.1 cgd if (printing)
193 1.26 christos (void)fprintf(fp, "%s\n", line);
194 1.26 christos free(line);
195 1.26 christos
196 1.1 cgd }
197 1.1 cgd closecal(fp);
198 1.1 cgd }
199 1.1 cgd
200 1.1 cgd
201 1.26 christos static void
202 1.26 christos settime(void)
203 1.1 cgd {
204 1.7 glass time_t now;
205 1.1 cgd
206 1.1 cgd (void)time(&now);
207 1.1 cgd tp = localtime(&now);
208 1.10 thorpej if (datestr) {
209 1.10 thorpej getmmdd(tp, datestr);
210 1.10 thorpej }
211 1.12 christos if (isleap(tp->tm_year + TM_YEAR_BASE)) {
212 1.1 cgd yrdays = DAYSPERLYEAR;
213 1.1 cgd cumdays = daytab[1];
214 1.1 cgd } else {
215 1.1 cgd yrdays = DAYSPERNYEAR;
216 1.1 cgd cumdays = daytab[0];
217 1.1 cgd }
218 1.1 cgd /* Friday displays Monday's events */
219 1.10 thorpej offset = tp->tm_wday == 5 ? lookahead + weekend : lookahead;
220 1.1 cgd header[5].iov_base = dayname;
221 1.1 cgd header[5].iov_len = strftime(dayname, sizeof(dayname), "%A", tp);
222 1.1 cgd }
223 1.1 cgd
224 1.1 cgd /*
225 1.1 cgd * Possible date formats include any combination of:
226 1.1 cgd * 3-charmonth (January, Jan, Jan)
227 1.1 cgd * 3-charweekday (Friday, Monday, mon.)
228 1.1 cgd * numeric month or day (1, 2, 04)
229 1.1 cgd *
230 1.1 cgd * Any character may separate them, or they may not be separated. Any line,
231 1.1 cgd * following a line that is matched, that starts with "whitespace", is shown
232 1.1 cgd * along with the matched line.
233 1.1 cgd */
234 1.26 christos static int
235 1.1 cgd isnow(endp)
236 1.1 cgd char *endp;
237 1.1 cgd {
238 1.1 cgd int day, flags, month, v1, v2;
239 1.1 cgd
240 1.1 cgd #define F_ISMONTH 0x01
241 1.1 cgd #define F_ISDAY 0x02
242 1.1 cgd flags = 0;
243 1.1 cgd /* didn't recognize anything, skip it */
244 1.1 cgd if (!(v1 = getfield(endp, &endp, &flags)))
245 1.7 glass return (0);
246 1.7 glass if (flags & F_ISDAY || v1 > 12) {
247 1.1 cgd /* found a day */
248 1.1 cgd day = v1;
249 1.6 hpeyerl month = tp->tm_mon + 1;
250 1.7 glass } else if (flags & F_ISMONTH) {
251 1.1 cgd month = v1;
252 1.1 cgd /* if no recognizable day, assume the first */
253 1.1 cgd if (!(day = getfield(endp, &endp, &flags)))
254 1.1 cgd day = 1;
255 1.1 cgd } else {
256 1.1 cgd v2 = getfield(endp, &endp, &flags);
257 1.7 glass if (flags & F_ISMONTH) {
258 1.1 cgd day = v1;
259 1.1 cgd month = v2;
260 1.1 cgd } else {
261 1.1 cgd /* F_ISDAY set, v2 > 12, or no way to tell */
262 1.1 cgd month = v1;
263 1.1 cgd /* if no recognizable day, assume the first */
264 1.1 cgd day = v2 ? v2 : 1;
265 1.1 cgd }
266 1.1 cgd }
267 1.7 glass if (flags & F_ISDAY)
268 1.4 cgd day = tp->tm_mday + (((day - 1) - tp->tm_wday + 7) % 7);
269 1.1 cgd day = cumdays[month] + day;
270 1.1 cgd
271 1.1 cgd /* if today or today + offset days */
272 1.1 cgd if (day >= tp->tm_yday && day <= tp->tm_yday + offset)
273 1.7 glass return (1);
274 1.1 cgd /* if number of days left in this year + days to event in next year */
275 1.1 cgd if (yrdays - tp->tm_yday + day <= offset)
276 1.7 glass return (1);
277 1.7 glass return (0);
278 1.1 cgd }
279 1.1 cgd
280 1.26 christos static int
281 1.1 cgd getfield(p, endp, flags)
282 1.1 cgd char *p, **endp;
283 1.1 cgd int *flags;
284 1.1 cgd {
285 1.1 cgd int val;
286 1.1 cgd char *start, savech;
287 1.1 cgd
288 1.18 christos #define FLDCHAR(a) (*p != '\0' && !isdigit((unsigned char)*p) && \
289 1.18 christos !isalpha((unsigned char)*p) && *p != '*')
290 1.18 christos
291 1.18 christos for (; FLDCHAR(*p); ++p)
292 1.26 christos continue;
293 1.1 cgd if (*p == '*') { /* `*' is current month */
294 1.1 cgd *flags |= F_ISMONTH;
295 1.3 cgd *endp = p+1;
296 1.7 glass return (tp->tm_mon + 1);
297 1.1 cgd }
298 1.18 christos if (isdigit((unsigned char)*p)) {
299 1.1 cgd val = strtol(p, &p, 10); /* if 0, it's failure */
300 1.18 christos for (; FLDCHAR(*p); ++p)
301 1.26 christos continue;
302 1.1 cgd *endp = p;
303 1.7 glass return (val);
304 1.1 cgd }
305 1.18 christos for (start = p; *p != '\0' && isalpha((unsigned char)*++p);)
306 1.26 christos continue;
307 1.1 cgd savech = *p;
308 1.1 cgd *p = '\0';
309 1.26 christos if ((val = getmonth(start)) != 0) {
310 1.1 cgd *flags |= F_ISMONTH;
311 1.26 christos } else if ((val = getday(start)) != 0) {
312 1.1 cgd *flags |= F_ISDAY;
313 1.26 christos } else {
314 1.4 cgd *p = savech;
315 1.7 glass return (0);
316 1.4 cgd }
317 1.18 christos for (*p = savech; FLDCHAR(*p); ++p)
318 1.26 christos continue;
319 1.1 cgd *endp = p;
320 1.7 glass return (val);
321 1.1 cgd }
322 1.1 cgd
323 1.26 christos static FILE *
324 1.26 christos opencal(void)
325 1.1 cgd {
326 1.1 cgd int fd, pdes[2];
327 1.1 cgd
328 1.1 cgd /* open up calendar file as stdin */
329 1.23 christos if (!freopen(fname, "rf", stdin)) {
330 1.1 cgd if (doall)
331 1.7 glass return (NULL);
332 1.23 christos err(1, "Cannot open `%s'", fname);
333 1.1 cgd }
334 1.26 christos if (pipe(pdes) < 0) {
335 1.26 christos warn("Cannot open pipe");
336 1.7 glass return (NULL);
337 1.26 christos }
338 1.26 christos switch (fork()) {
339 1.1 cgd case -1: /* error */
340 1.1 cgd (void)close(pdes[0]);
341 1.1 cgd (void)close(pdes[1]);
342 1.7 glass return (NULL);
343 1.1 cgd case 0:
344 1.1 cgd /* child -- stdin already setup, set stdout to pipe input */
345 1.1 cgd if (pdes[1] != STDOUT_FILENO) {
346 1.1 cgd (void)dup2(pdes[1], STDOUT_FILENO);
347 1.1 cgd (void)close(pdes[1]);
348 1.1 cgd }
349 1.1 cgd (void)close(pdes[0]);
350 1.26 christos (void)execl(_PATH_CPP, "cpp", "-traditional", "-P", "-I.",
351 1.26 christos "-I" _PATH_CALENDARS, NULL);
352 1.26 christos err(1, "Cannot exec `%s'", _PATH_CPP);
353 1.26 christos /*NOTREACHED*/
354 1.1 cgd }
355 1.1 cgd /* parent -- set stdin to pipe output */
356 1.1 cgd (void)dup2(pdes[0], STDIN_FILENO);
357 1.1 cgd (void)close(pdes[0]);
358 1.1 cgd (void)close(pdes[1]);
359 1.1 cgd
360 1.1 cgd /* not reading all calendar files, just set output to stdout */
361 1.1 cgd if (!doall)
362 1.7 glass return (stdout);
363 1.1 cgd
364 1.1 cgd /* set output to a temporary file, so if no output don't send mail */
365 1.7 glass (void)snprintf(path, sizeof(path), "%s/_calXXXXXX", _PATH_TMP);
366 1.26 christos if ((fd = mkstemp(path)) < 0) {
367 1.26 christos warn("Cannot create temporary file");
368 1.7 glass return (NULL);
369 1.26 christos }
370 1.7 glass return (fdopen(fd, "w+"));
371 1.1 cgd }
372 1.1 cgd
373 1.26 christos static void
374 1.1 cgd closecal(fp)
375 1.1 cgd FILE *fp;
376 1.1 cgd {
377 1.1 cgd struct stat sbuf;
378 1.1 cgd int nread, pdes[2], status;
379 1.7 glass char buf[1024];
380 1.1 cgd
381 1.1 cgd if (!doall)
382 1.1 cgd return;
383 1.1 cgd
384 1.1 cgd (void)rewind(fp);
385 1.1 cgd if (fstat(fileno(fp), &sbuf) || !sbuf.st_size)
386 1.1 cgd goto done;
387 1.10 thorpej if (pipe(pdes) < 0)
388 1.1 cgd goto done;
389 1.26 christos switch (fork()) {
390 1.1 cgd case -1: /* error */
391 1.1 cgd (void)close(pdes[0]);
392 1.1 cgd (void)close(pdes[1]);
393 1.1 cgd goto done;
394 1.10 thorpej case 0:
395 1.1 cgd /* child -- set stdin to pipe output */
396 1.1 cgd if (pdes[0] != STDIN_FILENO) {
397 1.1 cgd (void)dup2(pdes[0], STDIN_FILENO);
398 1.1 cgd (void)close(pdes[0]);
399 1.1 cgd }
400 1.1 cgd (void)close(pdes[1]);
401 1.26 christos (void)execl(_PATH_SENDMAIL, "sendmail", "-i", "-t", "-F",
402 1.1 cgd "\"Reminder Service\"", "-f", "root", NULL);
403 1.26 christos err(1, "Cannot exec `%s'", _PATH_SENDMAIL);
404 1.26 christos /*NOTREACHED*/
405 1.1 cgd }
406 1.1 cgd /* parent -- write to pipe input */
407 1.1 cgd (void)close(pdes[0]);
408 1.1 cgd
409 1.14 mycroft header[1].iov_base = header[3].iov_base = (void *)pw->pw_name;
410 1.1 cgd header[1].iov_len = header[3].iov_len = strlen(pw->pw_name);
411 1.1 cgd writev(pdes[1], header, 7);
412 1.1 cgd while ((nread = read(fileno(fp), buf, sizeof(buf))) > 0)
413 1.1 cgd (void)write(pdes[1], buf, nread);
414 1.1 cgd (void)close(pdes[1]);
415 1.26 christos
416 1.1 cgd done: (void)fclose(fp);
417 1.1 cgd (void)unlink(path);
418 1.26 christos while (wait(&status) >= 0)
419 1.26 christos continue;
420 1.1 cgd }
421 1.1 cgd
422 1.26 christos static int
423 1.1 cgd getmonth(s)
424 1.11 lukem char *s;
425 1.1 cgd {
426 1.11 lukem char **p;
427 1.1 cgd
428 1.1 cgd for (p = months; *p; ++p)
429 1.1 cgd if (!strncasecmp(s, *p, 3))
430 1.7 glass return ((p - months) + 1);
431 1.7 glass return (0);
432 1.1 cgd }
433 1.1 cgd
434 1.26 christos static int
435 1.1 cgd getday(s)
436 1.11 lukem char *s;
437 1.1 cgd {
438 1.11 lukem char **p;
439 1.1 cgd
440 1.1 cgd for (p = days; *p; ++p)
441 1.1 cgd if (!strncasecmp(s, *p, 3))
442 1.7 glass return ((p - days) + 1);
443 1.7 glass return (0);
444 1.1 cgd }
445 1.1 cgd
446 1.26 christos static void
447 1.26 christos atodays(int ch, char *optarg, unsigned short *days)
448 1.10 thorpej {
449 1.10 thorpej int u;
450 1.10 thorpej
451 1.10 thorpej u = atoi(optarg);
452 1.10 thorpej if ((u < 0) || (u > 366)) {
453 1.26 christos warnx("-%c %d out of range 0-366, ignored.", ch, u);
454 1.10 thorpej } else {
455 1.10 thorpej *days = u;
456 1.10 thorpej }
457 1.10 thorpej }
458 1.10 thorpej
459 1.10 thorpej #define todigit(x) ((x) - '0')
460 1.10 thorpej #define ATOI2(x) (todigit((x)[0]) * 10 + todigit((x)[1]))
461 1.18 christos #define ISDIG2(x) (isdigit((unsigned char)(x)[0]) && isdigit((unsigned char)(x)[1]))
462 1.10 thorpej
463 1.26 christos static void
464 1.10 thorpej getmmdd(struct tm *tp, char *ds)
465 1.10 thorpej {
466 1.10 thorpej int ok = FALSE;
467 1.10 thorpej struct tm ttm;
468 1.10 thorpej
469 1.10 thorpej ttm = *tp;
470 1.10 thorpej ttm.tm_isdst = -1;
471 1.10 thorpej
472 1.10 thorpej if (ISDIG2(ds)) {
473 1.10 thorpej ttm.tm_mon = ATOI2(ds) - 1;
474 1.10 thorpej ds += 2;
475 1.10 thorpej }
476 1.10 thorpej
477 1.10 thorpej if (ISDIG2(ds)) {
478 1.10 thorpej ttm.tm_mday = ATOI2(ds);
479 1.10 thorpej ds += 2;
480 1.10 thorpej
481 1.10 thorpej ok = TRUE;
482 1.10 thorpej }
483 1.10 thorpej
484 1.10 thorpej if (ok) {
485 1.10 thorpej if (ISDIG2(ds) && ISDIG2(ds + 2)) {
486 1.12 christos ttm.tm_year = ATOI2(ds) * 100 - TM_YEAR_BASE;
487 1.10 thorpej ds += 2;
488 1.10 thorpej ttm.tm_year += ATOI2(ds);
489 1.10 thorpej } else if (ISDIG2(ds)) {
490 1.10 thorpej ttm.tm_year = ATOI2(ds);
491 1.12 christos if (ttm.tm_year < 69)
492 1.12 christos ttm.tm_year += 2000 - TM_YEAR_BASE;
493 1.12 christos else
494 1.12 christos ttm.tm_year += 1900 - TM_YEAR_BASE;
495 1.10 thorpej }
496 1.10 thorpej }
497 1.10 thorpej
498 1.10 thorpej if (ok && (mktime(&ttm) < 0)) {
499 1.10 thorpej ok = FALSE;
500 1.10 thorpej }
501 1.10 thorpej
502 1.10 thorpej if (ok) {
503 1.10 thorpej *tp = ttm;
504 1.10 thorpej } else {
505 1.26 christos warnx("Can't convert `%s' to date, ignored.", ds);
506 1.10 thorpej usage();
507 1.10 thorpej }
508 1.10 thorpej }
509 1.10 thorpej
510 1.26 christos static void
511 1.26 christos usage(void)
512 1.1 cgd {
513 1.26 christos (void)fprintf(stderr, "Usage: %s [-a] [-d MMDD[[YY]YY]"
514 1.26 christos " [-f fname] [-l days] [-w days]\n", getprogname());
515 1.1 cgd exit(1);
516 1.1 cgd }
517