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 2004 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"
40 static int number(char *);
41 static int jan1(const int);
42 static void badmonth(void);
43 static void badyear(void);
44 static void usage(void);
45 static void cal(const int, const int, char *, const int);
46 static void load_months(void);
47 static void pstr(char *, const int);
49 #define DAYW " S M Tu W Th F S"
50 #define TITLE " %s %u\n"
51 #define YEAR "\n\n\n\t\t\t\t%u\n\n"
52 #define MONTH "\t%4.3s\t\t\t%.3s\t\t%10.3s\n"
54 static char *months
[] = {
55 "January", "February", "March", "April",
56 "May", "June", "July", "August",
57 "September", "October", "November", "December",
60 static char *short_months
[] = {
61 "Jan", "Feb", "Mar", "Apr",
62 "May", "Jun", "Jul", "Aug",
63 "Sep", "Oct", "Nov", "Dec",
74 static char string
[432];
75 static struct tm
*thetime
;
79 main(int argc
, char *argv
[])
88 (void) setlocale(LC_ALL
, "");
89 #if !defined(TEXT_DOMAIN)
90 #define TEXT_DOMAIN "SYS_TEST"
92 (void) textdomain(TEXT_DOMAIN
);
95 while (getopt(argc
, argv
, "") != EOF
)
101 time_locale
= setlocale(LC_TIME
, NULL
);
102 if ((time_locale
[0] != 'C') || (time_locale
[1] != '\0'))
107 * This message is to be used for displaying
108 * the names of the seven days, from Sunday to Saturday.
109 * The length of the name of each one should be two or less.
111 ldayw
= dcgettext(NULL
, DAYW
, LC_TIME
);
115 timbuf
= time(&timbuf
);
116 thetime
= localtime(&timbuf
);
117 m
= thetime
->tm_mon
+ 1;
118 y
= thetime
->tm_year
+ 1900;
131 * print out just month
136 if (y
< 1 || y
> 9999)
140 * This message is to be used for displaying
141 * specified month and year.
143 (void) printf(dcgettext(NULL
, TITLE
, LC_TIME
), months
[m
-1], y
);
144 (void) printf("%s\n", ldayw
);
145 cal(m
, y
, string
, 24);
146 for (i
= 0; i
< 6*24; i
+= 24)
151 * print out complete year
156 if (y
< 1 || y
> 9999)
160 * This message is to be used for displaying
163 (void) printf(dcgettext(NULL
, YEAR
, LC_TIME
), y
);
164 for (i
= 0; i
< 12; i
+= 3) {
165 for (j
= 0; j
< 6*72; j
++)
169 * This message is to be used for displaying
170 * names of three months per a line and should be
171 * correctly translated according to the display width
172 * of the names of months.
175 dcgettext(NULL
, MONTH
, LC_TIME
),
176 short_months
[i
], short_months
[i
+1], short_months
[i
+2]);
177 (void) printf("%s %s %s\n", ldayw
, ldayw
, ldayw
);
178 cal(i
+1, y
, string
, 72);
179 cal(i
+2, y
, string
+23, 72);
180 cal(i
+3, y
, string
+46, 72);
181 for (j
= 0; j
< 6*72; j
+= 72)
184 (void) printf("\n\n\n");
198 if (c
< '0' || c
> '9')
206 pstr(char *str
, const int n
)
221 (void) printf("%s\n", str
);
225 cal(const int m
, const int y
, char *p
, const int w
)
235 switch ((jan1(y
+1)+7-d
)%7) {
257 for (i
= 1; i
< m
; i
++)
261 for (i
= 1; i
<= mon
[m
]; i
++) {
262 if (i
== 3 && mon
[m
] == 19) {
280 * return day of the week
281 * of jan 1 of given year
290 * normal gregorian calendar
291 * one extra day per four years
300 * less three days per 400
309 * great calendar changeover instant
323 for (month
= MON_1
; month
<= MON_12
; month
++)
324 months
[month
- MON_1
] = nl_langinfo(month
);
325 for (month
= ABMON_1
; month
<= ABMON_12
; month
++)
326 short_months
[month
- ABMON_1
] = nl_langinfo(month
);
332 (void) fprintf(stderr
, gettext("%s: bad month\n"), myname
);
339 (void) fprintf(stderr
, gettext("%s: bad year\n"), myname
);
346 (void) fprintf(stderr
, gettext("usage: %s [ [month] year ]\n"), myname
);