xref: /titanic_51/usr/src/cmd/zic/scheck.c (revision f430f59ab82e479697d158ab37aa51e306625e9a)
17c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
27c478bd9Sstevel@tonic-gate 
3*f430f59aSrobbin /* static char	elsieid[] = "@(#)scheck.c	8.17"; */
47c478bd9Sstevel@tonic-gate 
57c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
67c478bd9Sstevel@tonic-gate 
77c478bd9Sstevel@tonic-gate #include "private.h"
87c478bd9Sstevel@tonic-gate 
9*f430f59aSrobbin const char *
107c478bd9Sstevel@tonic-gate scheck(string, format)
117c478bd9Sstevel@tonic-gate const char * const	string;
12*f430f59aSrobbin const char * const	format;
137c478bd9Sstevel@tonic-gate {
147c478bd9Sstevel@tonic-gate 	register char		*fbuf;
157c478bd9Sstevel@tonic-gate 	register const char	*fp;
167c478bd9Sstevel@tonic-gate 	register char		*tp;
177c478bd9Sstevel@tonic-gate 	register int		c;
18*f430f59aSrobbin 	register const char	*result;
197c478bd9Sstevel@tonic-gate 	char			dummy;
207c478bd9Sstevel@tonic-gate 
21*f430f59aSrobbin 	result = "";
227c478bd9Sstevel@tonic-gate 	if (string == NULL || format == NULL)
237c478bd9Sstevel@tonic-gate 		return (result);
247c478bd9Sstevel@tonic-gate 	fbuf = imalloc((int)(2 * strlen(format) + 4));
257c478bd9Sstevel@tonic-gate 	if (fbuf == NULL)
267c478bd9Sstevel@tonic-gate 		return (result);
277c478bd9Sstevel@tonic-gate 	fp = format;
287c478bd9Sstevel@tonic-gate 	tp = fbuf;
297c478bd9Sstevel@tonic-gate 	while ((*tp++ = c = *fp++) != '\0') {
307c478bd9Sstevel@tonic-gate 		if (c != '%')
317c478bd9Sstevel@tonic-gate 			continue;
327c478bd9Sstevel@tonic-gate 		if (*fp == '%') {
337c478bd9Sstevel@tonic-gate 			*tp++ = *fp++;
347c478bd9Sstevel@tonic-gate 			continue;
357c478bd9Sstevel@tonic-gate 		}
367c478bd9Sstevel@tonic-gate 		*tp++ = '*';
377c478bd9Sstevel@tonic-gate 		if (*fp == '*')
387c478bd9Sstevel@tonic-gate 			++fp;
397c478bd9Sstevel@tonic-gate 		while (is_digit(*fp))
407c478bd9Sstevel@tonic-gate 			*tp++ = *fp++;
417c478bd9Sstevel@tonic-gate 		if (*fp == 'l' || *fp == 'h')
427c478bd9Sstevel@tonic-gate 			*tp++ = *fp++;
437c478bd9Sstevel@tonic-gate 		else if (*fp == '[')
447c478bd9Sstevel@tonic-gate 			do *tp++ = *fp++;
457c478bd9Sstevel@tonic-gate 				while (*fp != '\0' && *fp != ']');
467c478bd9Sstevel@tonic-gate 		if ((*tp++ = *fp++) == '\0')
477c478bd9Sstevel@tonic-gate 			break;
487c478bd9Sstevel@tonic-gate 	}
497c478bd9Sstevel@tonic-gate 	*(tp - 1) = '%';
507c478bd9Sstevel@tonic-gate 	*tp++ = 'c';
517c478bd9Sstevel@tonic-gate 	*tp = '\0';
527c478bd9Sstevel@tonic-gate 	if (sscanf(string, fbuf, &dummy) != 1)
537c478bd9Sstevel@tonic-gate 		result = (char *)format;
547c478bd9Sstevel@tonic-gate 	ifree(fbuf);
557c478bd9Sstevel@tonic-gate 	return (result);
567c478bd9Sstevel@tonic-gate }
57