ckdate.c (0:68f95e015346) ckdate.c (13114:80cabdfb1113)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
1/*
2 * CDDL HEADER START
3 *
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
7 * with the License.
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 *
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.
13 *
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]
19 *
20 * CDDL HEADER END
21 */
22/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23/* All Rights Reserved */
24
25
26/*
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22/* All Rights Reserved */
23
24
25/*
27 * Copyright (c) 1997,1998 by Sun Microsystems, Inc.
28 * All rights reserved.
26 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
29 */
30
31/*LINTLIBRARY*/
27 */
28
29/*LINTLIBRARY*/
32#pragma ident "%Z%%M% %I% %E% SMI"
33
34#include <stdio.h>
35#include <string.h>
36#include <ctype.h>
37#include <sys/types.h>
38#include <stdlib.h>
39#include <limits.h>
40#include "libadm.h"

--- 5 unchanged lines hidden (view full) ---

46#define MESG "Please enter a date"
47#define DEFAULT "%m/%d/%y"
48
49static char *p_ndigit(char *, int *, int);
50static char *p_date(char *, int, int, int);
51static char *p_eday(char *, int, int);
52static char *p_dlm(char *, char);
53
30
31#include <stdio.h>
32#include <string.h>
33#include <ctype.h>
34#include <sys/types.h>
35#include <stdlib.h>
36#include <limits.h>
37#include "libadm.h"

--- 5 unchanged lines hidden (view full) ---

43#define MESG "Please enter a date"
44#define DEFAULT "%m/%d/%y"
45
46static char *p_ndigit(char *, int *, int);
47static char *p_date(char *, int, int, int);
48static char *p_eday(char *, int, int);
49static char *p_dlm(char *, char);
50
54#define MLIM 9
51#define MLIM 10
55#define STDIG 2
56#define LD2 10
57#define LD 01
58#define UD 31
59#define LM 01
60#define UM 12
61/*
62 * All digits are valid for a YY year format

--- 121 unchanged lines hidden (view full) ---

184 mlen = 9;
185 for (icnt = 0; icnt < 12; icnt++)
186 mnth[icnt] = fmonth[icnt];
187 }
188
189 copy = string;
190
191 while (((islower((unsigned char)*copy)) ||
52#define STDIG 2
53#define LD2 10
54#define LD 01
55#define UD 31
56#define LM 01
57#define UM 12
58/*
59 * All digits are valid for a YY year format

--- 121 unchanged lines hidden (view full) ---

181 mlen = 9;
182 for (icnt = 0; icnt < 12; icnt++)
183 mnth[icnt] = fmonth[icnt];
184 }
185
186 copy = string;
187
188 while (((islower((unsigned char)*copy)) ||
192 (isupper((unsigned char)*copy))) && (imnth < mlen)) {
189 (isupper((unsigned char)*copy))) && (imnth < mlen)) {
193 mletter[imnth] = toupper((unsigned char)*copy++);
194 imnth++;
195 }
196 mletter[imnth] = '\0';
197 while (!(legit) && (n < 12)) {
198 if (strncmp(mletter, mnth[n],
199 (imnth = (int)strlen(mnth[n]))) == 0)
200 legit = 1; /* found legitimate string */

--- 111 unchanged lines hidden (view full) ---

312
313 if (fmt == NULL)
314 fmt = DEFAULT;
315 ltrl = '\0';
316 while (*fmt && valid) {
317 if ((*fmt) == '%') {
318 fmt++;
319 switch (*fmt) {
190 mletter[imnth] = toupper((unsigned char)*copy++);
191 imnth++;
192 }
193 mletter[imnth] = '\0';
194 while (!(legit) && (n < 12)) {
195 if (strncmp(mletter, mnth[n],
196 (imnth = (int)strlen(mnth[n]))) == 0)
197 legit = 1; /* found legitimate string */

--- 111 unchanged lines hidden (view full) ---

309
310 if (fmt == NULL)
311 fmt = DEFAULT;
312 ltrl = '\0';
313 while (*fmt && valid) {
314 if ((*fmt) == '%') {
315 fmt++;
316 switch (*fmt) {
320 case 'd':
321 input = p_date(input, LD, UD, STDIG);
322 if (!input)
323 valid = 0;
324 break;
317 case 'd':
318 input = p_date(input, LD, UD, STDIG);
319 if (!input)
320 valid = 0;
321 break;
325
322
326 case 'e':
327 input = p_eday(input, LD2, UD);
328 if (!input)
329 valid = 0;
330 break;
323 case 'e':
324 input = p_eday(input, LD2, UD);
325 if (!input)
326 valid = 0;
327 break;
331
328
332 case 'm':
333 input = p_date(input, LM, UM, STDIG);
334 if (!input)
335 valid = 0;
336 break;
329 case 'm':
330 input = p_date(input, LM, UM, STDIG);
331 if (!input)
332 valid = 0;
333 break;
337
334
338 case 'y':
339 input = p_date(input, LY, UY, STDIG);
340 if (!input)
341 valid = 0;
342 break;
335 case 'y':
336 input = p_date(input, LY, UY, STDIG);
337 if (!input)
338 valid = 0;
339 break;
343
340
344 case 'Y':
345 input = p_date(input, LCY, UCY, CCYY);
346 if (!input)
347 valid = 0;
348 break;
341 case 'Y':
342 input = p_date(input, LCY, UCY, CCYY);
343 if (!input)
344 valid = 0;
345 break;
349
346
350 case 'D':
351 input = p_date(input, LM, UM, STDIG);
352 if (!input) {
353 valid = 0;
347 case 'D':
348 input = p_date(input, LM, UM, STDIG);
349 if (!input) {
350 valid = 0;
354 break;
355 }
356 input = p_dlm(input, DELIM1);
357 if (!input) {
358 valid = 0;
359 break;
360 }
361 input = p_date(input, LD, UD, STDIG);

--- 6 unchanged lines hidden (view full) ---

368 valid = 0;
369 break;
370 }
371 input = p_date(input, LY, UY, STDIG);
372 if (!input)
373 valid = 0;
374 break;
375
351 break;
352 }
353 input = p_dlm(input, DELIM1);
354 if (!input) {
355 valid = 0;
356 break;
357 }
358 input = p_date(input, LD, UD, STDIG);

--- 6 unchanged lines hidden (view full) ---

365 valid = 0;
366 break;
367 }
368 input = p_date(input, LY, UY, STDIG);
369 if (!input)
370 valid = 0;
371 break;
372
376 case 'h':
377 case 'b':
378 input = p_month(input, 'a');
379 if (!input)
380 valid = 0;
381 break;
373 case 'h':
374 case 'b':
375 input = p_month(input, 'a');
376 if (!input)
377 valid = 0;
378 break;
382
379
383 case 'B':
384 input = p_month(input, 'f');
385 if (!input)
386 valid = 0;
387 break;
380 case 'B':
381 input = p_month(input, 'f');
382 if (!input)
383 valid = 0;
384 break;
388
385
389 default:
390 (void) sscanf(input, "%1c", <rl);
391 input++;
386 default:
387 (void) sscanf(input, "%1c", &ltrl);
388 input++;
392 }
393 } else {
394 dfl = '\0';
395 (void) sscanf(input, "%1c", &dfl);
396 input++;
397 }
398 fmt++;
399 } /* end of while fmt and valid */

--- 52 unchanged lines hidden ---
389 }
390 } else {
391 dfl = '\0';
392 (void) sscanf(input, "%1c", &dfl);
393 input++;
394 }
395 fmt++;
396 } /* end of while fmt and valid */

--- 52 unchanged lines hidden ---