xref: /onnv-gate/usr/src/cmd/zic/scheck.c (revision 1138:3eec486d02fb)
10Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
20Sstevel@tonic-gate 
3*1138Srobbin /* static char	elsieid[] = "@(#)scheck.c	8.16"; */
40Sstevel@tonic-gate 
50Sstevel@tonic-gate /*LINTLIBRARY*/
60Sstevel@tonic-gate 
70Sstevel@tonic-gate #include "private.h"
80Sstevel@tonic-gate 
90Sstevel@tonic-gate char *
100Sstevel@tonic-gate scheck(string, format)
110Sstevel@tonic-gate const char * const	string;
12*1138Srobbin char * const		format;
130Sstevel@tonic-gate {
14*1138Srobbin 	register char		*fbuf;
15*1138Srobbin 	register const char	*fp;
16*1138Srobbin 	register char		*tp;
170Sstevel@tonic-gate 	register int		c;
18*1138Srobbin 	register char		*result;
190Sstevel@tonic-gate 	char			dummy;
200Sstevel@tonic-gate 	static char		nada;
210Sstevel@tonic-gate 
220Sstevel@tonic-gate 	result = &nada;
230Sstevel@tonic-gate 	if (string == NULL || format == NULL)
240Sstevel@tonic-gate 		return (result);
25*1138Srobbin 	fbuf = imalloc((int)(2 * strlen(format) + 4));
260Sstevel@tonic-gate 	if (fbuf == NULL)
270Sstevel@tonic-gate 		return (result);
280Sstevel@tonic-gate 	fp = format;
290Sstevel@tonic-gate 	tp = fbuf;
300Sstevel@tonic-gate 	while ((*tp++ = c = *fp++) != '\0') {
310Sstevel@tonic-gate 		if (c != '%')
320Sstevel@tonic-gate 			continue;
330Sstevel@tonic-gate 		if (*fp == '%') {
340Sstevel@tonic-gate 			*tp++ = *fp++;
350Sstevel@tonic-gate 			continue;
360Sstevel@tonic-gate 		}
370Sstevel@tonic-gate 		*tp++ = '*';
380Sstevel@tonic-gate 		if (*fp == '*')
390Sstevel@tonic-gate 			++fp;
400Sstevel@tonic-gate 		while (is_digit(*fp))
410Sstevel@tonic-gate 			*tp++ = *fp++;
420Sstevel@tonic-gate 		if (*fp == 'l' || *fp == 'h')
430Sstevel@tonic-gate 			*tp++ = *fp++;
440Sstevel@tonic-gate 		else if (*fp == '[')
450Sstevel@tonic-gate 			do *tp++ = *fp++;
460Sstevel@tonic-gate 				while (*fp != '\0' && *fp != ']');
470Sstevel@tonic-gate 		if ((*tp++ = *fp++) == '\0')
480Sstevel@tonic-gate 			break;
490Sstevel@tonic-gate 	}
500Sstevel@tonic-gate 	*(tp - 1) = '%';
510Sstevel@tonic-gate 	*tp++ = 'c';
520Sstevel@tonic-gate 	*tp = '\0';
530Sstevel@tonic-gate 	if (sscanf(string, fbuf, &dummy) != 1)
54*1138Srobbin 		result = (char *)format;
550Sstevel@tonic-gate 	ifree(fbuf);
560Sstevel@tonic-gate 	return (result);
570Sstevel@tonic-gate }
58