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