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