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