xref: /original-bsd/share/zoneinfo/scheck.c (revision 14054b48)
1 #ifndef lint
2 #ifndef NOID
3 static char	elsieid[] = "@(#)scheck.c	8.9";
4 #endif /* !defined lint */
5 #endif /* !defined NOID */
6 
7 /*LINTLIBRARY*/
8 
9 #include <stdio.h>
10 #include <ctype.h>
11 #include <string.h>
12 #include <stdlib.h>
13 
14 char *
15 scheck(string, format)
16 const char * const	string;
17 const char * const	format;
18 {
19 	register char *		fbuf;
20 	register const char *	fp;
21 	register char *		tp;
22 	register int		c;
23 	register char *		result;
24 	char			dummy;
25 
26 	result = "";
27 	if (string == NULL || format == NULL)
28 		return result;
29 	fbuf = malloc(2 * strlen(format) + 4);
30 	if (fbuf == NULL)
31 		return result;
32 	fp = format;
33 	tp = fbuf;
34 	while ((*tp++ = c = *fp++) != '\0') {
35 		if (c != '%')
36 			continue;
37 		if (*fp == '%') {
38 			*tp++ = *fp++;
39 			continue;
40 		}
41 		*tp++ = '*';
42 		if (*fp == '*')
43 			++fp;
44 		while (isascii(*fp) && isdigit(*fp))
45 			*tp++ = *fp++;
46 		if (*fp == 'l' || *fp == 'h')
47 			*tp++ = *fp++;
48 		else if (*fp == '[')
49 			do *tp++ = *fp++;
50 				while (*fp != '\0' && *fp != ']');
51 		if ((*tp++ = *fp++) == '\0')
52 			break;
53 	}
54 	*(tp - 1) = '%';
55 	*tp++ = 'c';
56 	*tp = '\0';
57 	if (sscanf((char *)string, fbuf, &dummy) != 1)
58 		result = (char *) format;
59 	ifree(fbuf);
60 	return result;
61 }
62