]> git.saurik.com Git - apple/system_cmds.git/blob - zic.tproj/scheck.c
dcd4d01131387bd152d72a158a768ea37d8a5467
[apple/system_cmds.git] / zic.tproj / scheck.c
1 #ifndef lint
2 #ifndef NOID
3 #include <sys/cdefs.h>
4 __unused static const char elsieid[] = "@(#)scheck.c 8.15";
5 #endif /* !defined lint */
6 #endif /* !defined NOID */
7
8 #ifndef lint
9 __unused static const char rcsid[] =
10 "$FreeBSD: src/usr.sbin/zic/scheck.c,v 1.7 2001/07/18 11:27:04 dd Exp $";
11 #endif /* not lint */
12
13 /*LINTLIBRARY*/
14
15 #include "private.h"
16
17 char *
18 scheck(const char * const string, const char * const format)
19 {
20 char * fbuf;
21 const char * fp;
22 char * tp;
23 int c;
24 char * result;
25 char dummy;
26 static char nada;
27
28 result = &nada;
29 if (string == NULL || format == NULL)
30 return result;
31 fbuf = imalloc((int) (2 * strlen(format) + 4));
32 if (fbuf == NULL)
33 return result;
34 fp = format;
35 tp = fbuf;
36 while ((*tp++ = c = *fp++) != '\0') {
37 if (c != '%')
38 continue;
39 if (*fp == '%') {
40 *tp++ = *fp++;
41 continue;
42 }
43 *tp++ = '*';
44 if (*fp == '*')
45 ++fp;
46 while (is_digit(*fp))
47 *tp++ = *fp++;
48 if (*fp == 'l' || *fp == 'h')
49 *tp++ = *fp++;
50 else if (*fp == '[')
51 do *tp++ = *fp++;
52 while (*fp != '\0' && *fp != ']');
53 if ((*tp++ = *fp++) == '\0')
54 break;
55 }
56 *(tp - 1) = '%';
57 *tp++ = 'c';
58 *tp = '\0';
59 if (sscanf(string, fbuf, &dummy) != 1)
60 result = (char *) format;
61 ifree(fbuf);
62 return result;
63 }