scheck.c revision 30829
1#ifndef lint
2#ifndef NOID
3static char	elsieid[] = "@(#)scheck.c	8.13";
4#endif /* !defined lint */
5#endif /* !defined NOID */
6
7#ifndef lint
8static const char rcsid[] =
9	"$Id$";
10#endif /* not lint */
11
12/*LINTLIBRARY*/
13
14#include "private.h"
15
16extern char *	imalloc P((int n));
17extern void	ifree P((char * p));
18
19char *
20scheck(string, format)
21const char * const	string;
22char * const		format;
23{
24	register char *		fbuf;
25	register const char *	fp;
26	register char *		tp;
27	register int		c;
28	register char *		result;
29	char			dummy;
30	static char		nada;
31
32	result = &nada;
33	if (string == NULL || format == NULL)
34		return result;
35	fbuf = imalloc((int) (2 * strlen(format) + 4));
36	if (fbuf == NULL)
37		return result;
38	fp = format;
39	tp = fbuf;
40	while ((*tp++ = c = *fp++) != '\0') {
41		if (c != '%')
42			continue;
43		if (*fp == '%') {
44			*tp++ = *fp++;
45			continue;
46		}
47		*tp++ = '*';
48		if (*fp == '*')
49			++fp;
50		while (is_digit(*fp))
51			*tp++ = *fp++;
52		if (*fp == 'l' || *fp == 'h')
53			*tp++ = *fp++;
54		else if (*fp == '[')
55			do *tp++ = *fp++;
56				while (*fp != '\0' && *fp != ']');
57		if ((*tp++ = *fp++) == '\0')
58			break;
59	}
60	*(tp - 1) = '%';
61	*tp++ = 'c';
62	*tp = '\0';
63	if (sscanf(string, fbuf, &dummy) != 1)
64		result = (char *) format;
65	ifree(fbuf);
66	return result;
67}
68