kernel - MPSAFE stabilization
[dragonfly.git] / usr.sbin / zic / scheck.c
bloba6c11b12ef913a7ee2756255f002c6c6df24a8b1
1 /*
2 * @(#)scheck.c 8.19
3 * $FreeBSD: src/usr.sbin/zic/scheck.c,v 1.4 1999/08/28 01:21:19 peter Exp $
4 * $DragonFly: src/usr.sbin/zic/scheck.c,v 1.4 2008/10/19 20:15:58 swildner Exp $
5 */
6 /*LINTLIBRARY*/
8 #include "private.h"
10 const char *
11 scheck(const char * const string, const char * const format)
13 char *fbuf;
14 const char *fp;
15 char *tp;
16 int c;
17 const char *result;
18 char dummy;
20 result = "";
21 if (string == NULL || format == NULL)
22 return result;
23 fbuf = imalloc((int) (2 * strlen(format) + 4));
24 if (fbuf == NULL)
25 return result;
26 fp = format;
27 tp = fbuf;
28 while ((*tp++ = c = *fp++) != '\0') {
29 if (c != '%')
30 continue;
31 if (*fp == '%') {
32 *tp++ = *fp++;
33 continue;
35 *tp++ = '*';
36 if (*fp == '*')
37 ++fp;
38 while (is_digit(*fp))
39 *tp++ = *fp++;
40 if (*fp == 'l' || *fp == 'h')
41 *tp++ = *fp++;
42 else if (*fp == '[')
43 do *tp++ = *fp++;
44 while (*fp != '\0' && *fp != ']');
45 if ((*tp++ = *fp++) == '\0')
46 break;
48 *(tp - 1) = '%';
49 *tp++ = 'c';
50 *tp = '\0';
51 if (sscanf(string, fbuf, &dummy) != 1)
52 result = (char *) format;
53 ifree(fbuf);
54 return result;