Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / usr.sbin / zic / scheck.c
1 #ifndef lint
2 #ifndef NOID
3 static char     elsieid[] = "@(#)scheck.c       8.15";
4 #endif /* !defined lint */
5 #endif /* !defined NOID */
6
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.2 2003/06/17 04:30:05 dillon Exp $
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 }