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"
46 static char *deflt
= NULL
, *prompt
= NULL
, *error
= NULL
, *help
= NULL
;
48 static int kpid
= BADPID
;
49 static char *fmt
= NULL
;
51 static const char vusage
[] = "f";
52 static const char husage
[] = "fWh";
53 static const char eusage
[] = "fWe";
55 #define MYFMT "%s:ERROR:invalid format\n" \
56 "valid format descriptors are:\n" \
57 "\t%%b #abbreviated month name\n" \
58 "\t%%B #full month name\n" \
59 "\t%%d #day of month (01-31)\n" \
60 "\t%%D #date as %%m/%%d/%%y or %%m-%%d-%%y (default)\n" \
61 "\t%%e #day of month (1-31)\n" \
62 "\t%%m #month of year (01-12)\n" \
63 "\t%%y #year within century (YY)\n" \
64 "\t%%Y #year as CCYY\n"
71 (void) fprintf(stderr
,
72 gettext("usage: %s [options] [-f format]\n"), prog
);
73 (void) fprintf(stderr
, gettext(OPTMESG
));
74 (void) fprintf(stderr
, gettext(STDOPTS
));
78 (void) fprintf(stderr
,
79 gettext("usage: %s [-f format] input\n"), prog
);
83 (void) fprintf(stderr
,
84 gettext("usage: %s [options] [-f format]\n"), prog
);
85 (void) fprintf(stderr
, gettext(OPTMESG
));
86 (void) fprintf(stderr
,
87 gettext("\t-W width\n\t-h help\n"));
91 (void) fprintf(stderr
,
92 gettext("usage: %s [options] [-f format]\n"), prog
);
93 (void) fprintf(stderr
, gettext(OPTMESG
));
94 (void) fprintf(stderr
,
95 gettext("\t-W width\n\t-h error\n"));
102 * Given argv[0], return a pointer to the basename of the program.
105 prog_name(char *arg0
)
109 /* first strip trailing '/' characters (exec() allows these!) */
110 str
= arg0
+ strlen(arg0
);
111 while (str
> arg0
&& *--str
== '/')
113 if ((str
= strrchr(arg0
, '/')) != NULL
)
119 main(int argc
, char **argv
)
125 (void) setlocale(LC_ALL
, "");
127 #if !defined(TEXT_DOMAIN)
128 #define TEXT_DOMAIN "SYS_TEST"
130 (void) textdomain(TEXT_DOMAIN
);
132 prog
= prog_name(argv
[0]);
134 while ((c
= getopt(argc
, argv
, "f:d:p:e:h:k:s:QW:?")) != EOF
) {
135 /* check for invalid option */
136 if ((*prog
== 'v') && !strchr(vusage
, c
))
138 if ((*prog
== 'e') && !strchr(eusage
, c
))
140 if ((*prog
== 'h') && !strchr(husage
, c
))
149 ckwidth
= atoi(optarg
);
151 (void) fprintf(stderr
,
152 gettext("%s: ERROR: negative display width specified\n"),
183 signo
= atoi(optarg
);
198 if (argc
!= (optind
+ 1))
200 n
= (ckdate_val(fmt
, argv
[optind
]));
202 (void) fprintf(stderr
, gettext(MYFMT
), prog
);
211 if (ckdate_err(fmt
, error
)) {
212 (void) fprintf(stderr
, gettext(MYFMT
), prog
);
217 } else if (*prog
== 'h') {
219 if (ckdate_hlp(fmt
, help
)) {
220 (void) fprintf(stderr
, gettext(MYFMT
), prog
);
228 len
= strlen(deflt
) + 1;
234 date
= (char *)malloc(len
);
236 (void) fprintf(stderr
,
237 gettext("Not enough memory\n"));
240 n
= ckdate(date
, fmt
, deflt
, error
, help
, prompt
);
243 (void) kill(kpid
, signo
);
246 (void) printf("%s", date
);
248 (void) fprintf(stderr
, gettext(MYFMT
), prog
);