xref: /titanic_52/usr/src/cmd/zic/scheck.c (revision bdfc6d18da790deeec2e0eb09c625902defe2498)
1 #pragma ident	"%Z%%M%	%I%	%E% SMI"
2 
3 /* static char	elsieid[] = "@(#)scheck.c	8.15"; */
4 
5 /*LINTLIBRARY*/
6 
7 #include "private.h"
8 
9 char *
10 scheck(string, format)
11 const char * const	string;
12 const char * const	format;
13 {
14 	register char *		fbuf;
15 	register const char *	fp;
16 	register char *		tp;
17 	register int		c;
18 	register char *		result;
19 	char			dummy;
20 	static char		nada;
21 
22 	result = &nada;
23 	if (string == NULL || format == NULL)
24 		return (result);
25 	fbuf = imalloc((int) (2 * strlen(format) + 4));
26 	if (fbuf == NULL)
27 		return (result);
28 	fp = format;
29 	tp = fbuf;
30 	while ((*tp++ = c = *fp++) != '\0') {
31 		if (c != '%')
32 			continue;
33 		if (*fp == '%') {
34 			*tp++ = *fp++;
35 			continue;
36 		}
37 		*tp++ = '*';
38 		if (*fp == '*')
39 			++fp;
40 		while (is_digit(*fp))
41 			*tp++ = *fp++;
42 		if (*fp == 'l' || *fp == 'h')
43 			*tp++ = *fp++;
44 		else if (*fp == '[')
45 			do *tp++ = *fp++;
46 				while (*fp != '\0' && *fp != ']');
47 		if ((*tp++ = *fp++) == '\0')
48 			break;
49 	}
50 	*(tp - 1) = '%';
51 	*tp++ = 'c';
52 	*tp = '\0';
53 	if (sscanf(string, fbuf, &dummy) != 1)
54 		result = (char *) format;
55 	ifree(fbuf);
56 	return (result);
57 }
58