xref: /csrg-svn/share/zoneinfo/scheck.c (revision 62584)
148425Sbostic /*-
2*62584Sbostic  * Copyright (c) 1991, 1993
3*62584Sbostic  *	The Regents of the University of California.  All rights reserved.
448425Sbostic  *
548425Sbostic  * This code is derived from software contributed to Berkeley by
648425Sbostic  * Arthur David Olson of the National Cancer Institute.
748425Sbostic  *
848425Sbostic  * %sccs.include.redist.c%
948425Sbostic  */
1048425Sbostic 
1139984Sbostic #ifndef lint
12*62584Sbostic static char sccsid[] = "@(#)scheck.c	8.1 (Berkeley) 06/08/93";
1348425Sbostic #endif /* not lint */
1448425Sbostic 
1548425Sbostic #ifdef notdef
1639984Sbostic static char	elsieid[] = "@(#)scheck.c	8.9";
1748425Sbostic #endif
1839984Sbostic 
1939984Sbostic /*LINTLIBRARY*/
2039984Sbostic 
2146793Sbostic #include <stdio.h>
2246793Sbostic #include <ctype.h>
2346793Sbostic #include <string.h>
2446793Sbostic #include <stdlib.h>
2539984Sbostic 
2639984Sbostic char *
scheck(string,format)2739984Sbostic scheck(string, format)
2839984Sbostic const char * const	string;
2939984Sbostic const char * const	format;
3039984Sbostic {
3139984Sbostic 	register char *		fbuf;
3239984Sbostic 	register const char *	fp;
3339984Sbostic 	register char *		tp;
3439984Sbostic 	register int		c;
3539984Sbostic 	register char *		result;
3639984Sbostic 	char			dummy;
3739984Sbostic 
3839984Sbostic 	result = "";
3939984Sbostic 	if (string == NULL || format == NULL)
4039984Sbostic 		return result;
4146793Sbostic 	fbuf = malloc(2 * strlen(format) + 4);
4239984Sbostic 	if (fbuf == NULL)
4339984Sbostic 		return result;
4439984Sbostic 	fp = format;
4539984Sbostic 	tp = fbuf;
4639984Sbostic 	while ((*tp++ = c = *fp++) != '\0') {
4739984Sbostic 		if (c != '%')
4839984Sbostic 			continue;
4939984Sbostic 		if (*fp == '%') {
5039984Sbostic 			*tp++ = *fp++;
5139984Sbostic 			continue;
5239984Sbostic 		}
5339984Sbostic 		*tp++ = '*';
5439984Sbostic 		if (*fp == '*')
5539984Sbostic 			++fp;
5639984Sbostic 		while (isascii(*fp) && isdigit(*fp))
5739984Sbostic 			*tp++ = *fp++;
5839984Sbostic 		if (*fp == 'l' || *fp == 'h')
5939984Sbostic 			*tp++ = *fp++;
6039984Sbostic 		else if (*fp == '[')
6139984Sbostic 			do *tp++ = *fp++;
6239984Sbostic 				while (*fp != '\0' && *fp != ']');
6339984Sbostic 		if ((*tp++ = *fp++) == '\0')
6439984Sbostic 			break;
6539984Sbostic 	}
6639984Sbostic 	*(tp - 1) = '%';
6739984Sbostic 	*tp++ = 'c';
6839984Sbostic 	*tp = '\0';
6946793Sbostic 	if (sscanf((char *)string, fbuf, &dummy) != 1)
7039984Sbostic 		result = (char *) format;
7139984Sbostic 	ifree(fbuf);
7239984Sbostic 	return result;
7339984Sbostic }
74