Add subr_diskgpt.c - oops. part of the GPT commit.
[dragonfly/vkernel-mp.git] / usr.sbin / zic / scheck.c
blob86baffb80634c123894aa89c5f3fbf8b1d23cb98
1 #ifndef lint
2 #ifndef NOID
3 static char elsieid[] = "@(#)scheck.c 8.15";
4 #endif /* !defined lint */
5 #endif /* !defined NOID */
7 /*
8 * @(#)scheck.c 8.15
9 * $FreeBSD: src/usr.sbin/zic/scheck.c,v 1.4 1999/08/28 01:21:19 peter Exp $
10 * $DragonFly: src/usr.sbin/zic/scheck.c,v 1.3 2004/02/29 17:55:28 joerg Exp $
12 /*LINTLIBRARY*/
14 #include "private.h"
16 char *
17 scheck(const char * const string, const char * const format)
19 char *fbuf;
20 const char *fp;
21 char *tp;
22 int c;
23 char *result;
24 char dummy;
25 static char nada;
27 result = &nada;
28 if (string == NULL || format == NULL)
29 return result;
30 fbuf = imalloc((int) (2 * strlen(format) + 4));
31 if (fbuf == NULL)
32 return result;
33 fp = format;
34 tp = fbuf;
35 while ((*tp++ = c = *fp++) != '\0') {
36 if (c != '%')
37 continue;
38 if (*fp == '%') {
39 *tp++ = *fp++;
40 continue;
42 *tp++ = '*';
43 if (*fp == '*')
44 ++fp;
45 while (is_digit(*fp))
46 *tp++ = *fp++;
47 if (*fp == 'l' || *fp == 'h')
48 *tp++ = *fp++;
49 else if (*fp == '[')
50 do *tp++ = *fp++;
51 while (*fp != '\0' && *fp != ']');
52 if ((*tp++ = *fp++) == '\0')
53 break;
55 *(tp - 1) = '%';
56 *tp++ = 'c';
57 *tp = '\0';
58 if (sscanf(string, fbuf, &dummy) != 1)
59 result = (char *) format;
60 ifree(fbuf);
61 return result;