mirror of
https://frontier.innolan.net/rainlance/amiga-tz.git
synced 2026-05-06 19:29:06 +00:00
Remove need for scheck.c
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.
This commit is contained in:
5
Makefile
5
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
|
||||
|
||||
@@ -452,12 +452,6 @@ time_t time2posix_z(timezone_t, time_t) ATTRIBUTE_PURE;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
** Private function declarations.
|
||||
*/
|
||||
|
||||
const char * scheck(const char * string, const char * format);
|
||||
|
||||
/*
|
||||
** Finally, some convenience items.
|
||||
*/
|
||||
|
||||
64
scheck.c
64
scheck.c
@@ -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;
|
||||
}
|
||||
21
zic.c
21
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"));
|
||||
|
||||
Reference in New Issue
Block a user