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