]>
Commit | Line | Data |
---|---|---|
887d5eed A |
1 | /* |
2 | ** This file is in the public domain, so clarified as of | |
3 | ** 2006-07-17 by Arthur David Olson. | |
4 | */ | |
5 | ||
2fc1e207 A |
6 | #ifndef lint |
7 | #ifndef NOID | |
887d5eed | 8 | static const char elsieid[] = "@(#)scheck.c 8.19"; |
2fc1e207 A |
9 | #endif /* !defined lint */ |
10 | #endif /* !defined NOID */ | |
11 | ||
12 | #ifndef lint | |
887d5eed A |
13 | static const char rcsid[] = |
14 | "$FreeBSD: head/contrib/tzcode/zic/scheck.c 192625 2009-05-23 06:31:50Z edwin $"; | |
2fc1e207 | 15 | #endif /* not lint */ |
1815bff5 A |
16 | |
17 | /*LINTLIBRARY*/ | |
18 | ||
19 | #include "private.h" | |
20 | ||
887d5eed A |
21 | const char * |
22 | scheck(string, format) | |
23 | const char * const string; | |
24 | const char * const format; | |
1815bff5 | 25 | { |
887d5eed A |
26 | register char * fbuf; |
27 | register const char * fp; | |
28 | register char * tp; | |
29 | register int c; | |
30 | register const char * result; | |
31 | char dummy; | |
1815bff5 | 32 | |
887d5eed | 33 | result = ""; |
1815bff5 A |
34 | if (string == NULL || format == NULL) |
35 | return result; | |
36 | fbuf = imalloc((int) (2 * strlen(format) + 4)); | |
37 | if (fbuf == NULL) | |
38 | return result; | |
39 | fp = format; | |
40 | tp = fbuf; | |
41 | while ((*tp++ = c = *fp++) != '\0') { | |
42 | if (c != '%') | |
43 | continue; | |
44 | if (*fp == '%') { | |
45 | *tp++ = *fp++; | |
46 | continue; | |
47 | } | |
48 | *tp++ = '*'; | |
49 | if (*fp == '*') | |
50 | ++fp; | |
51 | while (is_digit(*fp)) | |
52 | *tp++ = *fp++; | |
53 | if (*fp == 'l' || *fp == 'h') | |
54 | *tp++ = *fp++; | |
55 | else if (*fp == '[') | |
56 | do *tp++ = *fp++; | |
57 | while (*fp != '\0' && *fp != ']'); | |
58 | if ((*tp++ = *fp++) == '\0') | |
59 | break; | |
60 | } | |
61 | *(tp - 1) = '%'; | |
62 | *tp++ = 'c'; | |
63 | *tp = '\0'; | |
64 | if (sscanf(string, fbuf, &dummy) != 1) | |
65 | result = (char *) format; | |
66 | ifree(fbuf); | |
67 | return result; | |
68 | } |