[tz] [PROPOSED PATCH 2/3] Remove need for scheck.c
Paul Eggert
eggert at cs.ucla.edu
Mon Apr 20 06:13:13 UTC 2015
Its function 'scheck' can be done more efficiently inline.
* Makefile (TZCOBJS): Remove scheck.o.
(NONLIBSRCS): Remove scheck.c.
(scheck.o): Remove.
* private.h (scheck): Remove decl.
* scheck.c: Remove.
* zic.c (gethms, inleap, rulesub): Instead of scheck, use sscanf
directly, with %c appended to the format to detect excess input.
---
Makefile | 5 ++---
private.h | 6 ------
scheck.c | 64 ---------------------------------------------------------------
zic.c | 21 ++++++++++++---------
4 files changed, 14 insertions(+), 82 deletions(-)
delete mode 100644 scheck.c
diff --git a/Makefile b/Makefile
index af52b36..cd585be 100644
--- a/Makefile
+++ b/Makefile
@@ -331,13 +331,13 @@ AR= ar
# ':' on typical hosts; 'ranlib' on the ancient hosts that still need ranlib.
RANLIB= :
-TZCOBJS= zic.o scheck.o
+TZCOBJS= zic.o
TZDOBJS= zdump.o localtime.o asctime.o
DATEOBJS= date.o localtime.o strftime.o asctime.o
LIBSRCS= localtime.c asctime.c difftime.c
LIBOBJS= localtime.o asctime.o difftime.o
HEADERS= tzfile.h private.h
-NONLIBSRCS= zic.c zdump.c scheck.c
+NONLIBSRCS= zic.c zdump.c
NEWUCBSRCS= date.c strftime.c
SOURCES= $(HEADERS) $(LIBSRCS) $(NONLIBSRCS) $(NEWUCBSRCS) \
tzselect.ksh workman.sh
@@ -656,7 +656,6 @@ asctime.o: private.h tzfile.h
date.o: private.h
difftime.o: private.h
localtime.o: private.h tzfile.h
-scheck.o: private.h
strftime.o: private.h tzfile.h
zdump.o: version.h
zic.o: private.h tzfile.h version.h
diff --git a/private.h b/private.h
index 05316a1..61cf922 100644
--- a/private.h
+++ b/private.h
@@ -453,12 +453,6 @@ time_t time2posix_z(timezone_t, time_t) ATTRIBUTE_PURE;
#endif
/*
-** Private function declarations.
-*/
-
-const char * scheck(const char * string, const char * format);
-
-/*
** Finally, some convenience items.
*/
diff --git a/scheck.c b/scheck.c
deleted file mode 100644
index 8bd01a8..0000000
--- a/scheck.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
-** This file is in the public domain, so clarified as of
-** 2006-07-17 by Arthur David Olson.
-*/
-
-/*LINTLIBRARY*/
-
-#include "private.h"
-
-const char *
-scheck(const char *const string, const char *const format)
-{
- register char * fbuf;
- register const char * fp;
- register char * tp;
- register int c;
- register 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;
-
- /*
- ** Copy directives, suppressing each conversion that is not
- ** already suppressed. Scansets containing '%' are not
- ** supported; e.g., the conversion specification "%[%]" is not
- ** supported. Also, multibyte characters containing a
- ** non-leading '%' byte are not supported.
- */
- while ((*tp++ = c = *fp++) != '\0') {
- if (c != '%')
- continue;
- if (is_digit(*fp)) {
- char const *f = fp;
- char *t = tp;
- do {
- *t++ = c = *f++;
- } while (is_digit(c));
- if (c == '$') {
- fp = f;
- tp = t;
- }
- }
- *tp++ = '*';
- if (*fp == '*')
- ++fp;
- if ((*tp++ = *fp++) == '\0')
- break;
- }
-
- *(tp - 1) = '%';
- *tp++ = 'c';
- *tp = '\0';
- if (sscanf(string, fbuf, &dummy) != 1)
- result = format;
- free(fbuf);
- return result;
-}
diff --git a/zic.c b/zic.c
index b28d5c3..ce3576b 100644
--- a/zic.c
+++ b/zic.c
@@ -1053,6 +1053,7 @@ gethms(char const *string, char const *errstring, bool signable)
{
zic_t hh;
int mm, ss, sign;
+ char xs;
if (string == NULL || *string == '\0')
return 0;
@@ -1062,12 +1063,12 @@ gethms(char const *string, char const *errstring, bool signable)
sign = -1;
++string;
} else sign = 1;
- if (sscanf(string, scheck(string, "%"SCNdZIC), &hh) == 1)
+ if (sscanf(string, "%"SCNdZIC"%c", &hh, &xs) == 1)
mm = ss = 0;
- else if (sscanf(string, scheck(string, "%"SCNdZIC":%d"), &hh, &mm) == 2)
+ else if (sscanf(string, "%"SCNdZIC":%d%c", &hh, &mm, &xs) == 2)
ss = 0;
- else if (sscanf(string, scheck(string, "%"SCNdZIC":%d:%d"),
- &hh, &mm, &ss) != 3) {
+ else if (sscanf(string, "%"SCNdZIC":%d:%d%c", &hh, &mm, &ss, &xs)
+ != 3) {
error("%s", errstring);
return 0;
}
@@ -1245,6 +1246,7 @@ inleap(register char ** const fields, const int nfields)
int month, day;
zic_t dayoff, tod;
zic_t t;
+ char xs;
if (nfields != LEAP_FIELDS) {
error(_("wrong number of fields on Leap line"));
@@ -1252,7 +1254,7 @@ inleap(register char ** const fields, const int nfields)
}
dayoff = 0;
cp = fields[LP_YEAR];
- if (sscanf(cp, scheck(cp, "%"SCNdZIC), &year) != 1) {
+ if (sscanf(cp, "%"SCNdZIC"%c", &year, &xs) != 1) {
/*
** Leapin' Lizards!
*/
@@ -1287,7 +1289,7 @@ inleap(register char ** const fields, const int nfields)
++j;
}
cp = fields[LP_DAY];
- if (sscanf(cp, scheck(cp, "%d"), &day) != 1 ||
+ if (sscanf(cp, "%d%c", &day, &xs) != 1 ||
day <= 0 || day > len_months[isleap(year)][month]) {
error(_("invalid day of month"));
return;
@@ -1377,6 +1379,7 @@ rulesub(register struct rule *const rp,
register const char * cp;
register char * dp;
register char * ep;
+ char xs;
if ((lp = byword(monthp, mon_names)) == NULL) {
error(_("invalid month name"));
@@ -1428,7 +1431,7 @@ rulesub(register struct rule *const rp,
_("%s: panic: Invalid l_value %d\n"),
progname, lp->l_value);
exit(EXIT_FAILURE);
- } else if (sscanf(cp, scheck(cp, "%"SCNdZIC), &rp->r_loyear) != 1) {
+ } else if (sscanf(cp, "%"SCNdZIC"%c", &rp->r_loyear, &xs) != 1) {
error(_("invalid starting year"));
return;
}
@@ -1450,7 +1453,7 @@ rulesub(register struct rule *const rp,
_("%s: panic: Invalid l_value %d\n"),
progname, lp->l_value);
exit(EXIT_FAILURE);
- } else if (sscanf(cp, scheck(cp, "%"SCNdZIC), &rp->r_hiyear) != 1) {
+ } else if (sscanf(cp, "%"SCNdZIC"%c", &rp->r_hiyear, &xs) != 1) {
error(_("invalid ending year"));
return;
}
@@ -1503,7 +1506,7 @@ rulesub(register struct rule *const rp,
}
rp->r_wday = lp->l_value;
}
- if (sscanf(ep, scheck(ep, "%d"), &rp->r_dayofmonth) != 1 ||
+ if (sscanf(ep, "%d%c", &rp->r_dayofmonth, &xs) != 1 ||
rp->r_dayofmonth <= 0 ||
(rp->r_dayofmonth > len_months[1][rp->r_month])) {
error(_("invalid day of month"));
--
2.1.0
More information about the tz
mailing list