4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
34 * /usr/lib/calprog produces an egrep -f file
35 * that will select today's and tomorrow's
36 * calendar entries, with special weekend provisions
37 * used by calendar command
45 #include <sys/types.h>
52 #define DAY (3600*24L)
54 extern char *getenv(), *malloc();
57 static int old_behavior
;
58 static int linenum
= 1;
60 static char errmsg
[128];
61 static char *errlst
[] = {
62 /* 0 */ "error on open of \"%s\", errno = %d",
63 /* 1 */ "could not malloc enough memory",
64 /* 2 */ "error on stat of \"%s\", errno = %d",
65 /* 3 */ "file \"%s\" is not a regular file",
66 /* 4 */ "error in reading the file \"%s\"",
67 /* 5 */ "\"%s\" file: error on line %d",
68 /* 6 */ "\"%s\" file: format descriptions are missing"
87 static void read_tmpl(void);
88 static void error(const char *fmt
, ...);
89 static void generate(char *);
97 ("(^|[ \t(,;])((%s[^ ]* *|0*%d/|\\*/)0*%d)([^0123456789]|$)\n",
98 month
[tm
->tm_mon
], tm
->tm_mon
+ 1, tm
->tm_mday
);
102 main(int argc
, char *argv
[])
105 (void) setlocale(LC_ALL
, "");
107 if (((file
= getenv("DATEMSK")) == 0) || file
[0] == '\0')
113 switch (localtime(&t
)->tm_wday
) {
146 if ((start
= (char *)malloc(512)) == NULL
)
148 if ((fp
= fopen(file
, "r")) == NULL
)
149 error(errlst
[0], file
, errno
);
150 if (fstat(fileno(fp
), &sb
) < 0)
151 error(errlst
[2], file
, errno
);
152 if ((sb
.st_mode
& S_IFMT
) != S_IFREG
)
153 error(errlst
[3], file
);
156 if (!fgets(bp
, 512, fp
)) {
160 error(errlst
[4], file
);
164 if (*(bp
+strlen(bp
)-1) != '\n') /* terminating newline? */
168 error(errlst
[5], file
, linenum
);
171 if (strlen(bp
)) /* anything left? */
181 error(errlst
[6], file
);
190 *(s
+ strlen(s
) -1) = (char)0; /* delete newline */
193 ns
= s
+ strlen(s
) - 1; /* s->start; ns->end */
194 while ((ns
!= s
) && (isspace(*ns
))) {
195 *ns
= (char)0; /* delete terminating spaces */
198 while (*s
) /* delete beginning white spaces */
207 error(const char *fmt
, ...)
212 (void) vsnprintf(errmsg
, sizeof (errmsg
), fmt
, args
);
213 fprintf(stderr
, "%s\n", errmsg
);
222 char outbuf
[2 * 1024];
226 strftime(timebuf
, sizeof (timebuf
), fmt
, localtime(&t
));
247 *ob
++ = toupper(*tb
);
248 *ob
++ = tolower(*tb
++);
254 if (*(tb
- 1) == '0')
258 printf("%s\n", outbuf
);