diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2015-02-10 05:44:51 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2015-02-10 05:44:51 +0000 |
commit | 78087f23e3d1c98d39ae9eb28c63639cedccb8d9 (patch) | |
tree | b37650620cf8d7c07ce4bfe018e9c50edb479e99 /usr.sbin/zic/zic.c | |
parent | 1311dcaf2254c18057fce1330c5b927f63282a82 (diff) |
move scheck.c into zic.c
Diffstat (limited to 'usr.sbin/zic/zic.c')
-rw-r--r-- | usr.sbin/zic/zic.c | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/usr.sbin/zic/zic.c b/usr.sbin/zic/zic.c index a06e36dfd04..ec034cd55c9 100644 --- a/usr.sbin/zic/zic.c +++ b/usr.sbin/zic/zic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: zic.c,v 1.13 2015/02/10 03:35:46 tedu Exp $ */ +/* $OpenBSD: zic.c,v 1.14 2015/02/10 05:44:50 tedu Exp $ */ /* ** This file is in the public domain, so clarified as of ** 2006-07-17 by Arthur David Olson. @@ -430,6 +430,54 @@ warning(const char *string) --errors; } + +static const char * +scheck(const char *string, const char *format) +{ + char * fbuf; + const char * fp; + char * tp; + int c; + const char * result; + char dummy; + + result = ""; + if (string == NULL || format == NULL) + return result; + fbuf = malloc(2 * strlen(format) + 4); + if (fbuf == NULL) + return result; + fp = format; + tp = fbuf; + while ((*tp++ = c = *fp++) != '\0') { + if (c != '%') + continue; + if (*fp == '%') { + *tp++ = *fp++; + continue; + } + *tp++ = '*'; + if (*fp == '*') + ++fp; + while (isdigit((unsigned char)*fp)) + *tp++ = *fp++; + if (*fp == 'l' || *fp == 'h') + *tp++ = *fp++; + else if (*fp == '[') + do *tp++ = *fp++; + while (*fp != '\0' && *fp != ']'); + if ((*tp++ = *fp++) == '\0') + break; + } + *(tp - 1) = '%'; + *tp++ = 'c'; + *tp = '\0'; + if (sscanf(string, fbuf, &dummy) != 1) + result = format; + free(fbuf); + return result; +} + static void usage(void) { |