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
;
47 static int kpid
= BADPID
;
51 static const char vusage
[] = "f";
52 static const char husage
[] = "fWh";
53 static const char eusage
[] = "fWe";
56 "%s:ERROR:invalid format\n" \
57 "valid format descriptors are:\n" \
58 "\t%%H #hour (00-23)\n" \
59 "\t%%I #hour (00-12)\n" \
60 "\t%%M #minute (00-59)\n" \
61 "\t%%p #AM, PM, am or pm\n" \
62 "\t%%r #time as %%I:%%M:%%S %%p\n" \
63 "\t%%R #time as %%H:%%M (default)\n" \
64 "\t%%S #seconds (00-59)\n" \
65 "\t%%T #time as %%H:%%M:%%S\n"
72 (void) fprintf(stderr
,
73 gettext("usage: %s [options] [-f format]\n"),
75 (void) fprintf(stderr
, gettext(OPTMESG
));
76 (void) fprintf(stderr
, gettext(STDOPTS
));
80 (void) fprintf(stderr
,
81 gettext("usage: %s [-f format] input\n"), prog
);
85 (void) fprintf(stderr
,
86 gettext("usage: %s [options] [-f format]\n"),
88 (void) fprintf(stderr
, gettext(OPTMESG
));
89 (void) fprintf(stderr
,
90 gettext("\t-W width\n\t-h help\n"));
94 (void) fprintf(stderr
,
95 gettext("usage: %s [options] [-f format]\n"),
97 (void) fprintf(stderr
, gettext(OPTMESG
));
98 (void) fprintf(stderr
,
99 gettext("\t-W width\n\t-e error\n"));
106 * Given argv[0], return a pointer to the basename of the program.
109 prog_name(char *arg0
)
113 /* first strip trailing '/' characters (exec() allows these!) */
114 str
= arg0
+ strlen(arg0
);
115 while (str
> arg0
&& *--str
== '/')
117 if ((str
= strrchr(arg0
, '/')) != NULL
)
123 main(int argc
, char **argv
)
129 (void) setlocale(LC_ALL
, "");
131 #if !defined(TEXT_DOMAIN)
132 #define TEXT_DOMAIN "SYS_TEST"
134 (void) textdomain(TEXT_DOMAIN
);
136 prog
= prog_name(argv
[0]);
138 while ((c
= getopt(argc
, argv
, "f:d:p:e:h:k:s:QW:?")) != EOF
) {
139 /* check for invalid option */
140 if ((*prog
== 'v') && !strchr(vusage
, c
))
142 if ((*prog
== 'e') && !strchr(eusage
, c
))
144 if ((*prog
== 'h') && !strchr(husage
, c
))
153 ckwidth
= atoi(optarg
);
155 (void) fprintf(stderr
,
156 gettext("%s: ERROR: negative display width specified\n"),
187 signo
= atoi(optarg
);
202 if (argc
!= (optind
+1))
204 n
= cktime_val(fmt
, argv
[optind
]);
207 * In the below, "AM", "PM", "am", and "pm" are
208 * keywords. So, do not translate them.
211 (void) fprintf(stderr
, gettext(MYFMT
), prog
);
220 if (cktime_err(fmt
, error
)) {
221 (void) fprintf(stderr
, gettext(MYFMT
), prog
);
225 } else if (*prog
== 'h') {
227 if (cktime_hlp(fmt
, help
)) {
228 (void) fprintf(stderr
, gettext(MYFMT
), prog
);
235 len
= strlen(deflt
) + 1;
241 tod
= (char *)malloc(len
);
243 (void) fprintf(stderr
,
244 gettext("Not enough memory\n"));
247 n
= cktime(tod
, fmt
, deflt
, error
, help
, prompt
);
250 (void) kill(kpid
, signo
);
253 (void) fputs(tod
, stdout
);
255 (void) fprintf(stderr
, gettext(MYFMT
), prog
);