intl/icu/source/tools/tzcode/scheck.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/tools/tzcode/scheck.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,63 @@
     1.4 +/*
     1.5 +** This file is in the public domain, so clarified as of
     1.6 +** 2006-07-17 by Arthur David Olson.
     1.7 +*/
     1.8 +
     1.9 +#ifndef lint
    1.10 +#ifndef NOID
    1.11 +static char	elsieid[] = "@(#)scheck.c	8.19";
    1.12 +#endif /* !defined lint */
    1.13 +#endif /* !defined NOID */
    1.14 +
    1.15 +/*LINTLIBRARY*/
    1.16 +
    1.17 +#include "private.h"
    1.18 +
    1.19 +const char *
    1.20 +scheck(string, format)
    1.21 +const char * const	string;
    1.22 +const char * const	format;
    1.23 +{
    1.24 +	register char *		fbuf;
    1.25 +	register const char *	fp;
    1.26 +	register char *		tp;
    1.27 +	register int		c;
    1.28 +	register const char *	result;
    1.29 +	char			dummy;
    1.30 +
    1.31 +	result = "";
    1.32 +	if (string == NULL || format == NULL)
    1.33 +		return result;
    1.34 +	fbuf = imalloc((int) (2 * strlen(format) + 4));
    1.35 +	if (fbuf == NULL)
    1.36 +		return result;
    1.37 +	fp = format;
    1.38 +	tp = fbuf;
    1.39 +	while ((*tp++ = c = *fp++) != '\0') {
    1.40 +		if (c != '%')
    1.41 +			continue;
    1.42 +		if (*fp == '%') {
    1.43 +			*tp++ = *fp++;
    1.44 +			continue;
    1.45 +		}
    1.46 +		*tp++ = '*';
    1.47 +		if (*fp == '*')
    1.48 +			++fp;
    1.49 +		while (is_digit(*fp))
    1.50 +			*tp++ = *fp++;
    1.51 +		if (*fp == 'l' || *fp == 'h')
    1.52 +			*tp++ = *fp++;
    1.53 +		else if (*fp == '[')
    1.54 +			do *tp++ = *fp++;
    1.55 +				while (*fp != '\0' && *fp != ']');
    1.56 +		if ((*tp++ = *fp++) == '\0')
    1.57 +			break;
    1.58 +	}
    1.59 +	*(tp - 1) = '%';
    1.60 +	*tp++ = 'c';
    1.61 +	*tp = '\0';
    1.62 +	if (sscanf(string, fbuf, &dummy) != 1)
    1.63 +		result = (char *) format;
    1.64 +	ifree(fbuf);
    1.65 +	return result;
    1.66 +}

mercurial