17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
559042621SAjaykumar Venkatesulu * Common Development and Distribution License (the "License").
659042621SAjaykumar Venkatesulu * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
227c478bd9Sstevel@tonic-gate /* All Rights Reserved */
237c478bd9Sstevel@tonic-gate
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate /*
2659042621SAjaykumar Venkatesulu * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
277c478bd9Sstevel@tonic-gate */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #include <stdio.h>
327c478bd9Sstevel@tonic-gate #include <string.h>
337c478bd9Sstevel@tonic-gate #include <ctype.h>
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <stdlib.h>
367c478bd9Sstevel@tonic-gate #include <limits.h>
377c478bd9Sstevel@tonic-gate #include "libadm.h"
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate static int fmtcheck(char *);
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate #define MSGSIZ 64
427c478bd9Sstevel@tonic-gate #define PROMPT "Enter the date"
437c478bd9Sstevel@tonic-gate #define MESG "Please enter a date"
447c478bd9Sstevel@tonic-gate #define DEFAULT "%m/%d/%y"
457c478bd9Sstevel@tonic-gate
467c478bd9Sstevel@tonic-gate static char *p_ndigit(char *, int *, int);
477c478bd9Sstevel@tonic-gate static char *p_date(char *, int, int, int);
487c478bd9Sstevel@tonic-gate static char *p_eday(char *, int, int);
497c478bd9Sstevel@tonic-gate static char *p_dlm(char *, char);
507c478bd9Sstevel@tonic-gate
5159042621SAjaykumar Venkatesulu #define MLIM 10
527c478bd9Sstevel@tonic-gate #define STDIG 2
537c478bd9Sstevel@tonic-gate #define LD2 10
547c478bd9Sstevel@tonic-gate #define LD 01
557c478bd9Sstevel@tonic-gate #define UD 31
567c478bd9Sstevel@tonic-gate #define LM 01
577c478bd9Sstevel@tonic-gate #define UM 12
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate * All digits are valid for a YY year format
607c478bd9Sstevel@tonic-gate * 70-99 refer to the 20th Century
617c478bd9Sstevel@tonic-gate * 00-69 refer to the 21st Century
627c478bd9Sstevel@tonic-gate */
637c478bd9Sstevel@tonic-gate #define LY 00
647c478bd9Sstevel@tonic-gate #define UY 99
657c478bd9Sstevel@tonic-gate #define LCY 1970
667c478bd9Sstevel@tonic-gate #define UCY 9999
677c478bd9Sstevel@tonic-gate #define CCYY 4
687c478bd9Sstevel@tonic-gate #define DELIM1 '/'
697c478bd9Sstevel@tonic-gate #define DELIM2 '-'
707c478bd9Sstevel@tonic-gate #define BLANK ' '
717c478bd9Sstevel@tonic-gate #define TAB ' '
727c478bd9Sstevel@tonic-gate
737c478bd9Sstevel@tonic-gate static void
setmsg(char * msg,char * fmt,size_t sz)74*4656d474SGarrett D'Amore setmsg(char *msg, char *fmt, size_t sz)
757c478bd9Sstevel@tonic-gate {
767c478bd9Sstevel@tonic-gate if ((fmt == NULL) || strcmp(fmt, "%D") == 0)
777c478bd9Sstevel@tonic-gate fmt = "%m/%d/%y";
78*4656d474SGarrett D'Amore (void) snprintf(msg, sz, "%s. Format is <%s>.", MESG, fmt);
797c478bd9Sstevel@tonic-gate }
807c478bd9Sstevel@tonic-gate
817c478bd9Sstevel@tonic-gate static char *
p_ndigit(char * string,int * value,int n)827c478bd9Sstevel@tonic-gate p_ndigit(char *string, int *value, int n)
837c478bd9Sstevel@tonic-gate {
847c478bd9Sstevel@tonic-gate char *ptr;
857c478bd9Sstevel@tonic-gate int accum = 0;
867c478bd9Sstevel@tonic-gate
877c478bd9Sstevel@tonic-gate if (!string)
887c478bd9Sstevel@tonic-gate return (NULL);
897c478bd9Sstevel@tonic-gate for (ptr = string; *ptr && n > 0; n--, ptr++) {
907c478bd9Sstevel@tonic-gate if (! isdigit((unsigned char)*ptr))
917c478bd9Sstevel@tonic-gate return (NULL);
927c478bd9Sstevel@tonic-gate accum = (10 * accum) + (*ptr - '0');
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate if (n)
957c478bd9Sstevel@tonic-gate return (NULL);
967c478bd9Sstevel@tonic-gate *value = accum;
977c478bd9Sstevel@tonic-gate return (ptr);
987c478bd9Sstevel@tonic-gate }
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate static char *
p_date(char * string,int llim,int ulim,int ndig)1017c478bd9Sstevel@tonic-gate p_date(char *string, int llim, int ulim, int ndig)
1027c478bd9Sstevel@tonic-gate {
1037c478bd9Sstevel@tonic-gate char *ptr;
1047c478bd9Sstevel@tonic-gate int begin = -1;
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate if (!(ptr = p_ndigit(string, &begin, ndig)))
1077c478bd9Sstevel@tonic-gate return (NULL);
1087c478bd9Sstevel@tonic-gate if (begin >= llim && begin <= ulim)
1097c478bd9Sstevel@tonic-gate return (ptr);
1107c478bd9Sstevel@tonic-gate else
1117c478bd9Sstevel@tonic-gate return (NULL);
1127c478bd9Sstevel@tonic-gate }
1137c478bd9Sstevel@tonic-gate
1147c478bd9Sstevel@tonic-gate static char *
p_eday(char * string,int llim,int ulim)1157c478bd9Sstevel@tonic-gate p_eday(char *string, int llim, int ulim)
1167c478bd9Sstevel@tonic-gate {
1177c478bd9Sstevel@tonic-gate char *ptr, *copy;
1187c478bd9Sstevel@tonic-gate char daynum[3];
1197c478bd9Sstevel@tonic-gate int begin = -1;
1207c478bd9Sstevel@tonic-gate int iday = 0;
1217c478bd9Sstevel@tonic-gate int idaymax = 2;
1227c478bd9Sstevel@tonic-gate
1237c478bd9Sstevel@tonic-gate daynum[0] = '\0';
1247c478bd9Sstevel@tonic-gate if (*string == BLANK) {
1257c478bd9Sstevel@tonic-gate string++;
1267c478bd9Sstevel@tonic-gate idaymax--;
1277c478bd9Sstevel@tonic-gate }
1287c478bd9Sstevel@tonic-gate copy = string;
1297c478bd9Sstevel@tonic-gate while (isdigit((unsigned char)*copy) && (iday < idaymax)) {
1307c478bd9Sstevel@tonic-gate daynum[iday] = *copy++;
1317c478bd9Sstevel@tonic-gate iday++;
1327c478bd9Sstevel@tonic-gate }
1337c478bd9Sstevel@tonic-gate daynum[iday] = '\0';
1347c478bd9Sstevel@tonic-gate if (iday == 1) {
1357c478bd9Sstevel@tonic-gate llim = 1;
1367c478bd9Sstevel@tonic-gate ulim = 9;
1377c478bd9Sstevel@tonic-gate } else if (iday == 2) {
1387c478bd9Sstevel@tonic-gate llim = 10;
1397c478bd9Sstevel@tonic-gate ulim = 31;
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate if (iday == 0)
1427c478bd9Sstevel@tonic-gate return (NULL);
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate if (!(ptr = p_ndigit(string, &begin, iday)))
1457c478bd9Sstevel@tonic-gate return (NULL);
1467c478bd9Sstevel@tonic-gate
1477c478bd9Sstevel@tonic-gate if (begin >= llim && begin <= ulim)
1487c478bd9Sstevel@tonic-gate return (ptr);
1497c478bd9Sstevel@tonic-gate else
1507c478bd9Sstevel@tonic-gate return (NULL);
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate /* p_month will parse the string for the month - abbr. form i.e. JAN - DEC */
1547c478bd9Sstevel@tonic-gate
1557c478bd9Sstevel@tonic-gate static char *
p_month(char * string,char mnabr)1567c478bd9Sstevel@tonic-gate p_month(char *string, char mnabr)
1577c478bd9Sstevel@tonic-gate {
1587c478bd9Sstevel@tonic-gate static char *fmonth[] = {
1597c478bd9Sstevel@tonic-gate "JANUARY", "FEBRUARY", "MARCH", "APRIL",
1607c478bd9Sstevel@tonic-gate "MAY", "JUNE", "JULY", "AUGUST",
1617c478bd9Sstevel@tonic-gate "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"
1627c478bd9Sstevel@tonic-gate };
1637c478bd9Sstevel@tonic-gate static char *amonth[] = {
1647c478bd9Sstevel@tonic-gate "JAN", "FEB", "MAR", "APR", "MAY", "JUN",
1657c478bd9Sstevel@tonic-gate "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"
1667c478bd9Sstevel@tonic-gate };
1677c478bd9Sstevel@tonic-gate int ichng, icnt;
1687c478bd9Sstevel@tonic-gate char *mnth[12];
1697c478bd9Sstevel@tonic-gate char *copy;
1707c478bd9Sstevel@tonic-gate char mletter[MLIM];
1717c478bd9Sstevel@tonic-gate int mlen;
1727c478bd9Sstevel@tonic-gate int imnth = 0;
1737c478bd9Sstevel@tonic-gate int legit = 0;
1747c478bd9Sstevel@tonic-gate int n = 0;
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate if (mnabr == 'a') {
1777c478bd9Sstevel@tonic-gate mlen = 3;
1787c478bd9Sstevel@tonic-gate for (icnt = 0; icnt < 12; icnt++)
1797c478bd9Sstevel@tonic-gate mnth[icnt] = amonth[icnt];
1807c478bd9Sstevel@tonic-gate } else {
1817c478bd9Sstevel@tonic-gate mlen = 9;
1827c478bd9Sstevel@tonic-gate for (icnt = 0; icnt < 12; icnt++)
1837c478bd9Sstevel@tonic-gate mnth[icnt] = fmonth[icnt];
1847c478bd9Sstevel@tonic-gate }
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate copy = string;
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate while (((islower((unsigned char)*copy)) ||
1897c478bd9Sstevel@tonic-gate (isupper((unsigned char)*copy))) && (imnth < mlen)) {
1907c478bd9Sstevel@tonic-gate mletter[imnth] = toupper((unsigned char)*copy++);
1917c478bd9Sstevel@tonic-gate imnth++;
1927c478bd9Sstevel@tonic-gate }
1937c478bd9Sstevel@tonic-gate mletter[imnth] = '\0';
1947c478bd9Sstevel@tonic-gate while (!(legit) && (n < 12)) {
1957c478bd9Sstevel@tonic-gate if (strncmp(mletter, mnth[n],
1967c478bd9Sstevel@tonic-gate (imnth = (int)strlen(mnth[n]))) == 0)
1977c478bd9Sstevel@tonic-gate legit = 1; /* found legitimate string */
1987c478bd9Sstevel@tonic-gate n++;
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate if (legit) {
2017c478bd9Sstevel@tonic-gate for (ichng = 0; ichng < imnth; ichng++) {
2027c478bd9Sstevel@tonic-gate *string = toupper((unsigned char)*string);
2037c478bd9Sstevel@tonic-gate string++;
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate
2067c478bd9Sstevel@tonic-gate return (string);
2077c478bd9Sstevel@tonic-gate /*
2087c478bd9Sstevel@tonic-gate * I know this causes side effects, but it's less
2097c478bd9Sstevel@tonic-gate * code than adding in a copy for string and using that
2107c478bd9Sstevel@tonic-gate */
2117c478bd9Sstevel@tonic-gate } else
2127c478bd9Sstevel@tonic-gate return (NULL);
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate
2157c478bd9Sstevel@tonic-gate static char *
p_dlm(char * string,char dchoice)2167c478bd9Sstevel@tonic-gate p_dlm(char *string, char dchoice)
2177c478bd9Sstevel@tonic-gate {
2187c478bd9Sstevel@tonic-gate char dlm;
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate if (! string)
2227c478bd9Sstevel@tonic-gate return (NULL);
2237c478bd9Sstevel@tonic-gate (void) sscanf(string, "%1c", &dlm);
2247c478bd9Sstevel@tonic-gate if (dchoice == '/')
2257c478bd9Sstevel@tonic-gate return (((dlm == DELIM1) || (dlm == DELIM2)) ? string+1 : NULL);
2267c478bd9Sstevel@tonic-gate else
2277c478bd9Sstevel@tonic-gate return ((dlm == dchoice) ? string + 1 : NULL);
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate int
ckdate_err(char * fmt,char * error)2317c478bd9Sstevel@tonic-gate ckdate_err(char *fmt, char *error)
2327c478bd9Sstevel@tonic-gate {
2337c478bd9Sstevel@tonic-gate char defmesg[MSGSIZ];
2347c478bd9Sstevel@tonic-gate
2357c478bd9Sstevel@tonic-gate if ((fmt != NULL) && (fmtcheck(fmt) == 1))
2367c478bd9Sstevel@tonic-gate return (4);
237*4656d474SGarrett D'Amore setmsg(defmesg, fmt, MSGSIZ);
2387c478bd9Sstevel@tonic-gate puterror(stdout, defmesg, error);
2397c478bd9Sstevel@tonic-gate return (0);
2407c478bd9Sstevel@tonic-gate }
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate int
ckdate_hlp(char * fmt,char * help)2437c478bd9Sstevel@tonic-gate ckdate_hlp(char *fmt, char *help)
2447c478bd9Sstevel@tonic-gate {
2457c478bd9Sstevel@tonic-gate char defmesg[MSGSIZ];
2467c478bd9Sstevel@tonic-gate
2477c478bd9Sstevel@tonic-gate if ((fmt != NULL) && (fmtcheck(fmt) == 1))
2487c478bd9Sstevel@tonic-gate return (4);
249*4656d474SGarrett D'Amore setmsg(defmesg, fmt, MSGSIZ);
2507c478bd9Sstevel@tonic-gate puthelp(stdout, defmesg, help);
2517c478bd9Sstevel@tonic-gate return (0);
2527c478bd9Sstevel@tonic-gate }
2537c478bd9Sstevel@tonic-gate
2547c478bd9Sstevel@tonic-gate /*
2557c478bd9Sstevel@tonic-gate * A little state machine that checks out the format to
2567c478bd9Sstevel@tonic-gate * make sure it is acceptable.
2577c478bd9Sstevel@tonic-gate * return value 1: NG
2587c478bd9Sstevel@tonic-gate * return value 0: OK
2597c478bd9Sstevel@tonic-gate */
2607c478bd9Sstevel@tonic-gate static int
fmtcheck(char * fmt)2617c478bd9Sstevel@tonic-gate fmtcheck(char *fmt)
2627c478bd9Sstevel@tonic-gate {
2637c478bd9Sstevel@tonic-gate int percent = 0;
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate while (*fmt) {
2667c478bd9Sstevel@tonic-gate switch (*fmt++) {
2677c478bd9Sstevel@tonic-gate case '%': /* previous state must be start or letter */
2687c478bd9Sstevel@tonic-gate if (percent == 0)
2697c478bd9Sstevel@tonic-gate percent = 1;
2707c478bd9Sstevel@tonic-gate else
2717c478bd9Sstevel@tonic-gate return (1);
2727c478bd9Sstevel@tonic-gate break;
2737c478bd9Sstevel@tonic-gate case 'd': /* previous state must be "%" */
2747c478bd9Sstevel@tonic-gate case 'e':
2757c478bd9Sstevel@tonic-gate case 'm':
2767c478bd9Sstevel@tonic-gate case 'y':
2777c478bd9Sstevel@tonic-gate case 'Y':
2787c478bd9Sstevel@tonic-gate case 'D':
2797c478bd9Sstevel@tonic-gate case 'h':
2807c478bd9Sstevel@tonic-gate case 'b':
2817c478bd9Sstevel@tonic-gate case 'B':
2827c478bd9Sstevel@tonic-gate if (percent == 1)
2837c478bd9Sstevel@tonic-gate percent = 0;
2847c478bd9Sstevel@tonic-gate else
2857c478bd9Sstevel@tonic-gate return (1);
2867c478bd9Sstevel@tonic-gate break;
2877c478bd9Sstevel@tonic-gate case TAB: /* previous state must be start or letter */
2887c478bd9Sstevel@tonic-gate case BLANK:
2897c478bd9Sstevel@tonic-gate case DELIM1:
2907c478bd9Sstevel@tonic-gate case DELIM2:
2917c478bd9Sstevel@tonic-gate if (percent == 1)
2927c478bd9Sstevel@tonic-gate return (1);
2937c478bd9Sstevel@tonic-gate break;
2947c478bd9Sstevel@tonic-gate default:
2957c478bd9Sstevel@tonic-gate return (1);
2967c478bd9Sstevel@tonic-gate }
2977c478bd9Sstevel@tonic-gate }
2987c478bd9Sstevel@tonic-gate return (percent);
2997c478bd9Sstevel@tonic-gate }
3007c478bd9Sstevel@tonic-gate
3017c478bd9Sstevel@tonic-gate int
ckdate_val(char * fmt,char * input)3027c478bd9Sstevel@tonic-gate ckdate_val(char *fmt, char *input)
3037c478bd9Sstevel@tonic-gate {
3047c478bd9Sstevel@tonic-gate char ltrl, dfl;
3057c478bd9Sstevel@tonic-gate int valid = 1; /* time of day string is valid for format */
3067c478bd9Sstevel@tonic-gate
3077c478bd9Sstevel@tonic-gate if ((fmt != NULL) && (fmtcheck(fmt) == 1))
3087c478bd9Sstevel@tonic-gate return (4);
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate if (fmt == NULL)
3117c478bd9Sstevel@tonic-gate fmt = DEFAULT;
3127c478bd9Sstevel@tonic-gate ltrl = '\0';
3137c478bd9Sstevel@tonic-gate while (*fmt && valid) {
3147c478bd9Sstevel@tonic-gate if ((*fmt) == '%') {
3157c478bd9Sstevel@tonic-gate fmt++;
3167c478bd9Sstevel@tonic-gate switch (*fmt) {
3177c478bd9Sstevel@tonic-gate case 'd':
3187c478bd9Sstevel@tonic-gate input = p_date(input, LD, UD, STDIG);
3197c478bd9Sstevel@tonic-gate if (!input)
3207c478bd9Sstevel@tonic-gate valid = 0;
3217c478bd9Sstevel@tonic-gate break;
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate case 'e':
3247c478bd9Sstevel@tonic-gate input = p_eday(input, LD2, UD);
3257c478bd9Sstevel@tonic-gate if (!input)
3267c478bd9Sstevel@tonic-gate valid = 0;
3277c478bd9Sstevel@tonic-gate break;
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate case 'm':
3307c478bd9Sstevel@tonic-gate input = p_date(input, LM, UM, STDIG);
3317c478bd9Sstevel@tonic-gate if (!input)
3327c478bd9Sstevel@tonic-gate valid = 0;
3337c478bd9Sstevel@tonic-gate break;
3347c478bd9Sstevel@tonic-gate
3357c478bd9Sstevel@tonic-gate case 'y':
3367c478bd9Sstevel@tonic-gate input = p_date(input, LY, UY, STDIG);
3377c478bd9Sstevel@tonic-gate if (!input)
3387c478bd9Sstevel@tonic-gate valid = 0;
3397c478bd9Sstevel@tonic-gate break;
3407c478bd9Sstevel@tonic-gate
3417c478bd9Sstevel@tonic-gate case 'Y':
3427c478bd9Sstevel@tonic-gate input = p_date(input, LCY, UCY, CCYY);
3437c478bd9Sstevel@tonic-gate if (!input)
3447c478bd9Sstevel@tonic-gate valid = 0;
3457c478bd9Sstevel@tonic-gate break;
3467c478bd9Sstevel@tonic-gate
3477c478bd9Sstevel@tonic-gate case 'D':
3487c478bd9Sstevel@tonic-gate input = p_date(input, LM, UM, STDIG);
3497c478bd9Sstevel@tonic-gate if (!input) {
3507c478bd9Sstevel@tonic-gate valid = 0;
3517c478bd9Sstevel@tonic-gate break;
3527c478bd9Sstevel@tonic-gate }
3537c478bd9Sstevel@tonic-gate input = p_dlm(input, DELIM1);
3547c478bd9Sstevel@tonic-gate if (!input) {
3557c478bd9Sstevel@tonic-gate valid = 0;
3567c478bd9Sstevel@tonic-gate break;
3577c478bd9Sstevel@tonic-gate }
3587c478bd9Sstevel@tonic-gate input = p_date(input, LD, UD, STDIG);
3597c478bd9Sstevel@tonic-gate if (!input) {
3607c478bd9Sstevel@tonic-gate valid = 0;
3617c478bd9Sstevel@tonic-gate break;
3627c478bd9Sstevel@tonic-gate }
3637c478bd9Sstevel@tonic-gate input = p_dlm(input, DELIM1);
3647c478bd9Sstevel@tonic-gate if (!input) {
3657c478bd9Sstevel@tonic-gate valid = 0;
3667c478bd9Sstevel@tonic-gate break;
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate input = p_date(input, LY, UY, STDIG);
3697c478bd9Sstevel@tonic-gate if (!input)
3707c478bd9Sstevel@tonic-gate valid = 0;
3717c478bd9Sstevel@tonic-gate break;
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate case 'h':
3747c478bd9Sstevel@tonic-gate case 'b':
3757c478bd9Sstevel@tonic-gate input = p_month(input, 'a');
3767c478bd9Sstevel@tonic-gate if (!input)
3777c478bd9Sstevel@tonic-gate valid = 0;
3787c478bd9Sstevel@tonic-gate break;
3797c478bd9Sstevel@tonic-gate
3807c478bd9Sstevel@tonic-gate case 'B':
3817c478bd9Sstevel@tonic-gate input = p_month(input, 'f');
3827c478bd9Sstevel@tonic-gate if (!input)
3837c478bd9Sstevel@tonic-gate valid = 0;
3847c478bd9Sstevel@tonic-gate break;
3857c478bd9Sstevel@tonic-gate
3867c478bd9Sstevel@tonic-gate default:
3877c478bd9Sstevel@tonic-gate (void) sscanf(input, "%1c", <rl);
3887c478bd9Sstevel@tonic-gate input++;
3897c478bd9Sstevel@tonic-gate }
3907c478bd9Sstevel@tonic-gate } else {
3917c478bd9Sstevel@tonic-gate dfl = '\0';
3927c478bd9Sstevel@tonic-gate (void) sscanf(input, "%1c", &dfl);
3937c478bd9Sstevel@tonic-gate input++;
3947c478bd9Sstevel@tonic-gate }
3957c478bd9Sstevel@tonic-gate fmt++;
3967c478bd9Sstevel@tonic-gate } /* end of while fmt and valid */
3977c478bd9Sstevel@tonic-gate
3987c478bd9Sstevel@tonic-gate if ((*fmt == NULL) && ((input != NULL) && *input != 0)) {
3997c478bd9Sstevel@tonic-gate if (*input != NULL)
4007c478bd9Sstevel@tonic-gate valid = 0;
4017c478bd9Sstevel@tonic-gate }
4027c478bd9Sstevel@tonic-gate return ((valid == 0));
4037c478bd9Sstevel@tonic-gate }
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate int
ckdate(char * date,char * fmt,char * defstr,char * error,char * help,char * prompt)4067c478bd9Sstevel@tonic-gate ckdate(char *date, char *fmt, char *defstr, char *error, char *help,
4077c478bd9Sstevel@tonic-gate char *prompt)
4087c478bd9Sstevel@tonic-gate {
4097c478bd9Sstevel@tonic-gate char defmesg[MSGSIZ];
4107c478bd9Sstevel@tonic-gate char input[MAX_INPUT];
4117c478bd9Sstevel@tonic-gate char *ept, end[128];
4127c478bd9Sstevel@tonic-gate
4137c478bd9Sstevel@tonic-gate ept = end;
4147c478bd9Sstevel@tonic-gate *ept = '\0';
4157c478bd9Sstevel@tonic-gate
4167c478bd9Sstevel@tonic-gate if ((fmt != NULL) && (fmtcheck(fmt) == 1))
4177c478bd9Sstevel@tonic-gate return (4);
4187c478bd9Sstevel@tonic-gate
419*4656d474SGarrett D'Amore setmsg(defmesg, fmt, MSGSIZ);
4207c478bd9Sstevel@tonic-gate (void) sprintf(ept, "[?,q]");
4217c478bd9Sstevel@tonic-gate
4227c478bd9Sstevel@tonic-gate if (!prompt)
4237c478bd9Sstevel@tonic-gate prompt = PROMPT;
4247c478bd9Sstevel@tonic-gate
4257c478bd9Sstevel@tonic-gate start:
4267c478bd9Sstevel@tonic-gate putprmpt(stderr, prompt, NULL, defstr);
4277c478bd9Sstevel@tonic-gate if (getinput(input))
4287c478bd9Sstevel@tonic-gate return (1);
4297c478bd9Sstevel@tonic-gate
4307c478bd9Sstevel@tonic-gate if (!strlen(input)) {
4317c478bd9Sstevel@tonic-gate if (defstr) {
4327c478bd9Sstevel@tonic-gate (void) strcpy(date, defstr);
4337c478bd9Sstevel@tonic-gate return (0);
4347c478bd9Sstevel@tonic-gate }
4357c478bd9Sstevel@tonic-gate puterror(stderr, defmesg, error);
4367c478bd9Sstevel@tonic-gate goto start;
4377c478bd9Sstevel@tonic-gate } else if (strcmp(input, "?") == 0) {
4387c478bd9Sstevel@tonic-gate puthelp(stderr, defmesg, help);
4397c478bd9Sstevel@tonic-gate goto start;
4407c478bd9Sstevel@tonic-gate } else if (ckquit && strcmp(input, "q") == 0) {
4417c478bd9Sstevel@tonic-gate return (3);
4427c478bd9Sstevel@tonic-gate } else if (ckdate_val(fmt, input)) {
4437c478bd9Sstevel@tonic-gate puterror(stderr, defmesg, error);
4447c478bd9Sstevel@tonic-gate goto start;
4457c478bd9Sstevel@tonic-gate }
4467c478bd9Sstevel@tonic-gate (void) strcpy(date, input);
4477c478bd9Sstevel@tonic-gate return (0);
4487c478bd9Sstevel@tonic-gate }
449