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