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