]> git.saurik.com Git - apple/system_cmds.git/blame - zic.tproj/scheck.c
system_cmds-175.tar.gz
[apple/system_cmds.git] / zic.tproj / scheck.c
CommitLineData
1815bff5
A
1/*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License."
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24#if defined(LIBC_SCCS) && !defined(lint)
25#if 0
26static char elsieid[] = "@(#)scheck.c 8.13";
27#else
28static char rcsid[] = "$OpenBSD: scheck.c,v 1.4 1997/01/14 03:16:49 millert Exp $";
29#endif
30#endif /* LIBC_SCCS and not lint */
31
32/*LINTLIBRARY*/
33
34#include "private.h"
35
36extern char * imalloc P((int n));
37extern void ifree P((char * p));
38
39char *
40scheck(string, format)
41const char * const string;
42char * const format;
43{
44 register char * fbuf;
45 register const char * fp;
46 register char * tp;
47 register int c;
48 register char * result;
49 char dummy;
50 static char nada;
51
52 result = &nada;
53 if (string == NULL || format == NULL)
54 return result;
55 fbuf = imalloc((int) (2 * strlen(format) + 4));
56 if (fbuf == NULL)
57 return result;
58 fp = format;
59 tp = fbuf;
60 while ((*tp++ = c = *fp++) != '\0') {
61 if (c != '%')
62 continue;
63 if (*fp == '%') {
64 *tp++ = *fp++;
65 continue;
66 }
67 *tp++ = '*';
68 if (*fp == '*')
69 ++fp;
70 while (is_digit(*fp))
71 *tp++ = *fp++;
72 if (*fp == 'l' || *fp == 'h')
73 *tp++ = *fp++;
74 else if (*fp == '[')
75 do *tp++ = *fp++;
76 while (*fp != '\0' && *fp != ']');
77 if ((*tp++ = *fp++) == '\0')
78 break;
79 }
80 *(tp - 1) = '%';
81 *tp++ = 'c';
82 *tp = '\0';
83 if (sscanf(string, fbuf, &dummy) != 1)
84 result = (char *) format;
85 ifree(fbuf);
86 return result;
87}