From 0a322f49b1bdc59686b295766b79fff2a0d18ca3 Mon Sep 17 00:00:00 2001 From: markm Date: Sat, 14 Jun 2003 13:00:21 +0000 Subject: Fix all WARNS. Checked with "make WARNS=9". Remove unused file. --- usr.bin/find/extern.h | 3 + usr.bin/find/find.c | 13 +- usr.bin/find/function.c | 252 ++++---------- usr.bin/find/getdate.y | 98 ++---- usr.bin/find/ls.c | 22 +- usr.bin/find/main.c | 7 +- usr.bin/find/misc.c | 8 +- usr.bin/find/operator.c | 16 +- usr.bin/find/option.c | 10 +- usr.bin/find/parsedate.y | 888 ----------------------------------------------- 10 files changed, 133 insertions(+), 1184 deletions(-) delete mode 100644 usr.bin/find/parsedate.y (limited to 'usr.bin') diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h index 70de480..b259757 100644 --- a/usr.bin/find/extern.h +++ b/usr.bin/find/extern.h @@ -114,3 +114,6 @@ exec_f f_user; extern int ftsoptions, isdeprecated, isdepth, isoutput, issort, isxargs; extern int mindepth, maxdepth; extern int regexp_flags; +extern time_t now; +extern int dotfd; +extern FTS *tree; diff --git a/usr.bin/find/find.c b/usr.bin/find/find.c index 4ef37e8..4b3d2df 100644 --- a/usr.bin/find/find.c +++ b/usr.bin/find/find.c @@ -40,6 +40,7 @@ static char sccsid[] = "@(#)find.c 8.5 (Berkeley) 8/5/94"; #else #endif #endif /* not lint */ + #include __FBSDID("$FreeBSD$"); @@ -51,8 +52,8 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include +#include #include "find.h" @@ -65,8 +66,7 @@ static int find_compare(const FTSENT * const *s1, const FTSENT * const *s2); * order within each directory. */ static int -find_compare(s1, s2) - const FTSENT * const *s1, * const *s2; +find_compare(const FTSENT * const *s1, const FTSENT * const *s2) { return (strcoll((*s1)->fts_name, (*s2)->fts_name)); @@ -78,8 +78,7 @@ find_compare(s1, s2) * command arguments. */ PLAN * -find_formplan(argv) - char **argv; +find_formplan(char *argv[]) { PLAN *plan, *tail, *new; @@ -176,9 +175,7 @@ FTS *tree; /* pointer to top of FTS hierarchy */ * over all FTSENT's returned for the given search paths. */ int -find_execute(plan, paths) - PLAN *plan; /* search plan */ - char **paths; /* array of pathnames to traverse */ +find_execute(PLAN *plan, char *paths[]) { FTSENT *entry; PLAN *p; diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c index 31e1a65..3ba7555 100644 --- a/usr.bin/find/function.c +++ b/usr.bin/find/function.c @@ -39,6 +39,7 @@ static const char sccsid[] = "@(#)function.c 8.10 (Berkeley) 5/4/95"; #endif #endif /* not lint */ + #include __FBSDID("$FreeBSD$"); @@ -86,8 +87,7 @@ extern char **environ; } while(0) static PLAN * -palloc(option) - OPTION *option; +palloc(OPTION *option) { PLAN *new; @@ -104,10 +104,7 @@ palloc(option) * Parse a string of the form [+-]# and return the value. */ static long long -find_parsenum(plan, option, vp, endch) - PLAN *plan; - const char *option; - char *vp, *endch; +find_parsenum(PLAN *plan, const char *option, char *vp, char *endch) { long long value; char *endchar, *str; /* Pointer to character ending conversion. */ @@ -148,10 +145,7 @@ find_parsenum(plan, option, vp, endch) * Parse a string of the form [+-]([0-9]+[smhdw]?)+ and return the value. */ static long long -find_parsetime(plan, option, vp) - PLAN *plan; - const char *option; - char *vp; +find_parsetime(PLAN *plan, const char *option, char *vp) { long long secs, value; char *str, *unit; /* Pointer to character ending conversion. */ @@ -226,9 +220,7 @@ find_parsetime(plan, option, vp) * and increment the argument vector pointer. */ static char * -nextarg(option, argvp) - OPTION *option; - char ***argvp; +nextarg(OPTION *option, char ***argvp) { char *arg; @@ -258,12 +250,8 @@ nextarg(option, argvp) * and the current time is n min periods. */ int -f_Xmin(plan, entry) - PLAN *plan; - FTSENT *entry; +f_Xmin(PLAN *plan, FTSENT *entry) { - extern time_t now; - if (plan->flags & F_TIME_C) { COMPARE((now - entry->fts_statp->st_ctime + 60 - 1) / 60, plan->t_data); @@ -277,9 +265,7 @@ f_Xmin(plan, entry) } PLAN * -c_Xmin(option, argvp) - OPTION *option; - char ***argvp; +c_Xmin(OPTION *option, char ***argvp) { char *nmins; PLAN *new; @@ -304,11 +290,8 @@ c_Xmin(option, argvp) */ int -f_Xtime(plan, entry) - PLAN *plan; - FTSENT *entry; +f_Xtime(PLAN *plan, FTSENT *entry) { - extern time_t now; time_t xtime; if (plan->flags & F_TIME_A) @@ -325,9 +308,7 @@ f_Xtime(plan, entry) } PLAN * -c_Xtime(option, argvp) - OPTION *option; - char ***argvp; +c_Xtime(OPTION *option, char ***argvp) { char *value; PLAN *new; @@ -352,9 +333,7 @@ c_Xtime(option, argvp) * find_execute() so their f_* functions are set to f_always_true(). */ PLAN * -c_mXXdepth(option, argvp) - OPTION *option; - char ***argvp; +c_mXXdepth(OPTION *option, char ***argvp) { char *dstr; PLAN *new; @@ -378,9 +357,7 @@ c_mXXdepth(option, argvp) * True always. Makes its best shot and continues on regardless. */ int -f_delete(plan, entry) - PLAN *plan __unused; - FTSENT *entry; +f_delete(PLAN *plan __unused, FTSENT *entry) { /* ignore these from fts */ if (strcmp(entry->fts_accpath, ".") == 0 || @@ -420,9 +397,7 @@ f_delete(plan, entry) } PLAN * -c_delete(option, argvp) - OPTION *option; - char ***argvp __unused; +c_delete(OPTION *option, char ***argvp __unused) { ftsoptions &= ~FTS_NOSTAT; /* no optimise */ @@ -443,17 +418,13 @@ c_delete(option, argvp) * itself. */ int -f_always_true(plan, entry) - PLAN *plan __unused; - FTSENT *entry __unused; +f_always_true(PLAN *plan __unused, FTSENT *entry __unused) { return 1; } PLAN * -c_depth(option, argvp) - OPTION *option; - char ***argvp __unused; +c_depth(OPTION *option, char ***argvp __unused) { isdepth = 1; @@ -466,9 +437,7 @@ c_depth(option, argvp) * True if the file or directory is empty */ int -f_empty(plan, entry) - PLAN *plan __unused; - FTSENT *entry; +f_empty(PLAN *plan __unused, FTSENT *entry) { if (S_ISREG(entry->fts_statp->st_mode) && entry->fts_statp->st_size == 0) @@ -496,9 +465,7 @@ f_empty(plan, entry) } PLAN * -c_empty(option, argvp) - OPTION *option; - char ***argvp __unused; +c_empty(OPTION *option, char ***argvp __unused) { ftsoptions &= ~FTS_NOSTAT; @@ -521,11 +488,8 @@ c_empty(option, argvp) * of the user before executing the utility. */ int -f_exec(plan, entry) - PLAN *plan; - FTSENT *entry; +f_exec(PLAN *plan, FTSENT *entry) { - extern int dotfd; int cnt; pid_t pid; int status; @@ -601,9 +565,7 @@ doexec: if ((plan->flags & F_NEEDOK) && !queryuser(plan->e_argv)) * strings, but also flags meaning that the string has to be massaged. */ PLAN * -c_exec(option, argvp) - OPTION *option; - char ***argvp; +c_exec(OPTION *option, char ***argvp) { PLAN *new; /* node returned */ long argmax; @@ -695,9 +657,7 @@ done: *argvp = argv + 1; } int -f_flags(plan, entry) - PLAN *plan; - FTSENT *entry; +f_flags(PLAN *plan, FTSENT *entry) { u_long flags; @@ -714,9 +674,7 @@ f_flags(plan, entry) } PLAN * -c_flags(option, argvp) - OPTION *option; - char ***argvp; +c_flags(OPTION *option, char ***argvp) { char *flags_str; PLAN *new; @@ -749,9 +707,7 @@ c_flags(option, argvp) * basis. */ PLAN * -c_follow(option, argvp) - OPTION *option; - char ***argvp __unused; +c_follow(OPTION *option, char ***argvp __unused) { ftsoptions &= ~FTS_PHYSICAL; ftsoptions |= FTS_LOGICAL; @@ -765,9 +721,7 @@ c_follow(option, argvp) * True if the file is of a certain type. */ int -f_fstype(plan, entry) - PLAN *plan; - FTSENT *entry; +f_fstype(PLAN *plan, FTSENT *entry) { static dev_t curdev; /* need a guaranteed illegal dev value */ static int first = 1; @@ -828,9 +782,7 @@ f_fstype(plan, entry) #if !defined(__NetBSD__) PLAN * -c_fstype(option, argvp) - OPTION *option; - char ***argvp; +c_fstype(OPTION *option, char ***argvp) { char *fsname; PLAN *new; @@ -885,17 +837,13 @@ c_fstype(option, argvp) * name, gname is taken as a group ID. */ int -f_group(plan, entry) - PLAN *plan; - FTSENT *entry; +f_group(PLAN *plan, FTSENT *entry) { return entry->fts_statp->st_gid == plan->g_data; } PLAN * -c_group(option, argvp) - OPTION *option; - char ***argvp; +c_group(OPTION *option, char ***argvp) { char *gname; PLAN *new; @@ -924,17 +872,13 @@ c_group(option, argvp) * True if the file has inode # n. */ int -f_inum(plan, entry) - PLAN *plan; - FTSENT *entry; +f_inum(PLAN *plan, FTSENT *entry) { COMPARE(entry->fts_statp->st_ino, plan->i_data); } PLAN * -c_inum(option, argvp) - OPTION *option; - char ***argvp; +c_inum(OPTION *option, char ***argvp) { char *inum_str; PLAN *new; @@ -953,17 +897,13 @@ c_inum(option, argvp) * True if the file has n links. */ int -f_links(plan, entry) - PLAN *plan; - FTSENT *entry; +f_links(PLAN *plan, FTSENT *entry) { COMPARE(entry->fts_statp->st_nlink, plan->l_data); } PLAN * -c_links(option, argvp) - OPTION *option; - char ***argvp; +c_links(OPTION *option, char ***argvp) { char *nlinks; PLAN *new; @@ -982,18 +922,14 @@ c_links(option, argvp) * Always true - prints the current entry to stdout in "ls" format. */ int -f_ls(plan, entry) - PLAN *plan __unused; - FTSENT *entry; +f_ls(PLAN *plan __unused, FTSENT *entry) { printlong(entry->fts_path, entry->fts_accpath, entry->fts_statp); return 1; } PLAN * -c_ls(option, argvp) - OPTION *option; - char ***argvp __unused; +c_ls(OPTION *option, char ***argvp __unused) { ftsoptions &= ~FTS_NOSTAT; isoutput = 1; @@ -1008,18 +944,14 @@ c_ls(option, argvp) * matches pattern using Pattern Matching Notation S3.14 */ int -f_name(plan, entry) - PLAN *plan; - FTSENT *entry; +f_name(PLAN *plan, FTSENT *entry) { return !fnmatch(plan->c_data, entry->fts_name, plan->flags & F_IGNCASE ? FNM_CASEFOLD : 0); } PLAN * -c_name(option, argvp) - OPTION *option; - char ***argvp; +c_name(OPTION *option, char ***argvp) { char *pattern; PLAN *new; @@ -1038,9 +970,7 @@ c_name(option, argvp) * file. */ int -f_newer(plan, entry) - PLAN *plan; - FTSENT *entry; +f_newer(PLAN *plan, FTSENT *entry) { if (plan->flags & F_TIME_C) return entry->fts_statp->st_ctime > plan->t_data; @@ -1051,9 +981,7 @@ f_newer(plan, entry) } PLAN * -c_newer(option, argvp) - OPTION *option; - char ***argvp; +c_newer(OPTION *option, char ***argvp) { char *fn_or_tspec; PLAN *new; @@ -1088,17 +1016,13 @@ c_newer(option, argvp) * of the getgrnam() 9.2.1 [POSIX.1] function returns NULL. */ int -f_nogroup(plan, entry) - PLAN *plan __unused; - FTSENT *entry; +f_nogroup(PLAN *plan __unused, FTSENT *entry) { return group_from_gid(entry->fts_statp->st_gid, 1) == NULL; } PLAN * -c_nogroup(option, argvp) - OPTION *option; - char ***argvp __unused; +c_nogroup(OPTION *option, char ***argvp __unused) { ftsoptions &= ~FTS_NOSTAT; @@ -1112,17 +1036,13 @@ c_nogroup(option, argvp) * of the getpwuid() 9.2.2 [POSIX.1] function returns NULL. */ int -f_nouser(plan, entry) - PLAN *plan __unused; - FTSENT *entry; +f_nouser(PLAN *plan __unused, FTSENT *entry) { return user_from_uid(entry->fts_statp->st_uid, 1) == NULL; } PLAN * -c_nouser(option, argvp) - OPTION *option; - char ***argvp __unused; +c_nouser(OPTION *option, char ***argvp __unused) { ftsoptions &= ~FTS_NOSTAT; @@ -1136,9 +1056,7 @@ c_nouser(option, argvp) * matches pattern using Pattern Matching Notation S3.14 */ int -f_path(plan, entry) - PLAN *plan; - FTSENT *entry; +f_path(PLAN *plan, FTSENT *entry) { return !fnmatch(plan->c_data, entry->fts_path, plan->flags & F_IGNCASE ? FNM_CASEFOLD : 0); @@ -1154,9 +1072,7 @@ f_path(plan, entry) * symbolic mode. */ int -f_perm(plan, entry) - PLAN *plan; - FTSENT *entry; +f_perm(PLAN *plan, FTSENT *entry) { mode_t mode; @@ -1172,9 +1088,7 @@ f_perm(plan, entry) } PLAN * -c_perm(option, argvp) - OPTION *option; - char ***argvp; +c_perm(OPTION *option, char ***argvp) { char *perm; PLAN *new; @@ -1208,18 +1122,14 @@ c_perm(option, argvp) * standard output. */ int -f_print(plan, entry) - PLAN *plan __unused; - FTSENT *entry; +f_print(PLAN *plan __unused, FTSENT *entry) { (void)puts(entry->fts_path); return 1; } PLAN * -c_print(option, argvp) - OPTION *option; - char ***argvp __unused; +c_print(OPTION *option, char ***argvp __unused) { isoutput = 1; @@ -1233,9 +1143,7 @@ c_print(option, argvp) * standard output followed by a NUL character */ int -f_print0(plan, entry) - PLAN *plan __unused; - FTSENT *entry; +f_print0(PLAN *plan __unused, FTSENT *entry) { fputs(entry->fts_path, stdout); fputc('\0', stdout); @@ -1250,12 +1158,8 @@ f_print0(plan, entry) * Prune a portion of the hierarchy. */ int -f_prune(plan, entry) - PLAN *plan __unused; - FTSENT *entry; +f_prune(PLAN *plan __unused, FTSENT *entry) { - extern FTS *tree; - if (fts_set(tree, entry, FTS_SKIP)) err(1, "%s", entry->fts_path); return 1; @@ -1270,9 +1174,7 @@ f_prune(plan, entry) * regular expression. */ int -f_regex(plan, entry) - PLAN *plan; - FTSENT *entry; +f_regex(PLAN *plan, FTSENT *entry) { char *str; int len; @@ -1305,9 +1207,7 @@ f_regex(plan, entry) } PLAN * -c_regex(option, argvp) - OPTION *option; - char ***argvp; +c_regex(OPTION *option, char ***argvp) { PLAN *new; char *pattern; @@ -1337,9 +1237,7 @@ c_regex(option, argvp) /* c_simple covers c_prune, c_openparen, c_closeparen, c_not, c_or */ PLAN * -c_simple(option, argvp) - OPTION *option; - char ***argvp __unused; +c_simple(OPTION *option, char ***argvp __unused) { return palloc(option); } @@ -1355,9 +1253,7 @@ c_simple(option, argvp) static int divsize = 1; int -f_size(plan, entry) - PLAN *plan; - FTSENT *entry; +f_size(PLAN *plan, FTSENT *entry) { off_t size; @@ -1367,9 +1263,7 @@ f_size(plan, entry) } PLAN * -c_size(option, argvp) - OPTION *option; - char ***argvp; +c_size(OPTION *option, char ***argvp) { char *size_str; PLAN *new; @@ -1394,17 +1288,13 @@ c_size(option, argvp) * regular file or whiteout respectively. */ int -f_type(plan, entry) - PLAN *plan; - FTSENT *entry; +f_type(PLAN *plan, FTSENT *entry) { return (entry->fts_statp->st_mode & S_IFMT) == plan->m_data; } PLAN * -c_type(option, argvp) - OPTION *option; - char ***argvp; +c_type(OPTION *option, char ***argvp) { char *typestring; PLAN *new; @@ -1458,17 +1348,13 @@ c_type(option, argvp) * return a valid user name, uname is taken as a user ID. */ int -f_user(plan, entry) - PLAN *plan; - FTSENT *entry; +f_user(PLAN *plan, FTSENT *entry) { return entry->fts_statp->st_uid == plan->u_data; } PLAN * -c_user(option, argvp) - OPTION *option; - char ***argvp; +c_user(OPTION *option, char ***argvp) { char *username; PLAN *new; @@ -1498,9 +1384,7 @@ c_user(option, argvp) * different device ID (st_dev, see stat() S5.6.2 [POSIX.1]) */ PLAN * -c_xdev(option, argvp) - OPTION *option; - char ***argvp __unused; +c_xdev(OPTION *option, char ***argvp __unused) { ftsoptions |= FTS_XDEV; @@ -1513,9 +1397,7 @@ c_xdev(option, argvp) * True if expression is true. */ int -f_expr(plan, entry) - PLAN *plan; - FTSENT *entry; +f_expr(PLAN *plan, FTSENT *entry) { PLAN *p; int state = 0; @@ -1533,17 +1415,13 @@ f_expr(plan, entry) */ int -f_openparen(plan, entry) - PLAN *plan __unused; - FTSENT *entry __unused; +f_openparen(PLAN *plan __unused, FTSENT *entry __unused) { abort(); } int -f_closeparen(plan, entry) - PLAN *plan __unused; - FTSENT *entry __unused; +f_closeparen(PLAN *plan __unused, FTSENT *entry __unused) { abort(); } @@ -1555,9 +1433,7 @@ f_closeparen(plan, entry) * AND operator. Since AND is implicit, no node is allocated. */ PLAN * -c_and(option, argvp) - OPTION *option __unused; - char ***argvp __unused; +c_and(OPTION *option __unused, char ***argvp __unused) { return NULL; } @@ -1568,9 +1444,7 @@ c_and(option, argvp) * Negation of a primary; the unary NOT operator. */ int -f_not(plan, entry) - PLAN *plan; - FTSENT *entry; +f_not(PLAN *plan, FTSENT *entry) { PLAN *p; int state = 0; @@ -1589,9 +1463,7 @@ f_not(plan, entry) * not evaluated if the first expression is true. */ int -f_or(plan, entry) - PLAN *plan; - FTSENT *entry; +f_or(PLAN *plan, FTSENT *entry) { PLAN *p; int state = 0; diff --git a/usr.bin/find/getdate.y b/usr.bin/find/getdate.y index 1531461..b4b15c4 100644 --- a/usr.bin/find/getdate.y +++ b/usr.bin/find/getdate.y @@ -12,7 +12,8 @@ /* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */ /* SUPPRESS 288 on yyerrlab *//* Label unused */ -/* $FreeBSD$ */ +#include +__FBSDID("$FreeBSD$"); #include #include @@ -58,16 +59,17 @@ unportable getdate.c's), but that seems to cause as many problems as it solves. */ -extern struct tm *gmtime(); -extern struct tm *localtime(); +#include #define yyparse getdate_yyparse #define yylex getdate_yylex #define yyerror getdate_yyerror -static int yyparse (); -static int yylex (); -static int yyerror (); +static int yyparse(void); +static int yylex(void); +static int yyerror(const char *); + +time_t get_date(char *, struct timeb *); #define EPOCH 1970 #define HOUR(x) ((time_t)(x) * 60) @@ -78,7 +80,7 @@ static int yyerror (); ** An entry in the lexical lookup table. */ typedef struct _TABLE { - char *name; + const char *name; int type; time_t value; } TABLE; @@ -373,7 +375,7 @@ static TABLE const MonthDayTable[] = { { "thurs", tDAY, 4 }, { "friday", tDAY, 5 }, { "saturday", tDAY, 6 }, - { NULL } + { NULL, 0, 0 } }; /* Time units table. */ @@ -388,7 +390,7 @@ static TABLE const UnitsTable[] = { { "min", tMINUTE_UNIT, 1 }, { "second", tSEC_UNIT, 1 }, { "sec", tSEC_UNIT, 1 }, - { NULL } + { NULL, 0, 0 } }; /* Assorted relative-time words. */ @@ -412,8 +414,8 @@ static TABLE const OtherTable[] = { { "tenth", tUNUMBER, 10 }, { "eleventh", tUNUMBER, 11 }, { "twelfth", tUNUMBER, 12 }, - { "ago", tAGO, 1 }, - { NULL } + { "ago", tAGO, 1 }, + { NULL, 0, 0 } }; /* The timezone table. */ @@ -498,7 +500,7 @@ static TABLE const TimezoneTable[] = { { "nzst", tZONE, -HOUR(12) }, /* New Zealand Standard */ { "nzdt", tDAYZONE, -HOUR(12) }, /* New Zealand Daylight */ { "idle", tZONE, -HOUR(12) }, /* International Date Line East */ - { NULL } + { NULL, 0, 0 } }; /* Military timezone table. */ @@ -528,7 +530,7 @@ static TABLE const MilitaryTable[] = { { "x", tZONE, HOUR(-11) }, { "y", tZONE, HOUR(-12) }, { "z", tZONE, HOUR( 0) }, - { NULL } + { NULL, 0, 0 } }; @@ -536,19 +538,14 @@ static TABLE const MilitaryTable[] = { /* ARGSUSED */ static int -yyerror(s) - char *s __unused; +yyerror(const char *s __unused) { return 0; } static time_t -ToSeconds(Hours, Minutes, Seconds, Meridian) - time_t Hours; - time_t Minutes; - time_t Seconds; - MERIDIAN Meridian; +ToSeconds(time_t Hours, time_t Minutes, time_t Seconds, MERIDIAN Meridian) { if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) return -1; @@ -581,15 +578,9 @@ ToSeconds(Hours, Minutes, Seconds, Meridian) * A number from 0 to 99, which means a year from 1900 to 1999, or * The actual year (>=100). */ static time_t -Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode) - time_t Month; - time_t Day; - time_t Year; - time_t Hours; - time_t Minutes; - time_t Seconds; - MERIDIAN Meridian; - DSTMODE DSTmode; +Convert(time_t Month, time_t Day, time_t Year, + time_t Hours, time_t Minutes, time_t Seconds, + MERIDIAN Meridian, DSTMODE DSTmode) { static int DaysInMonth[12] = { 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 @@ -631,9 +622,7 @@ Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode) static time_t -DSTcorrect(Start, Future) - time_t Start; - time_t Future; +DSTcorrect(time_t Start, time_t Future) { time_t StartDay; time_t FutureDay; @@ -645,10 +634,7 @@ DSTcorrect(Start, Future) static time_t -RelativeDate(Start, DayOrdinal, DayNumber) - time_t Start; - time_t DayOrdinal; - time_t DayNumber; +RelativeDate(time_t Start, time_t DayOrdinal, time_t DayNumber) { struct tm *tm; time_t now; @@ -662,9 +648,7 @@ RelativeDate(Start, DayOrdinal, DayNumber) static time_t -RelativeMonth(Start, RelMonth) - time_t Start; - time_t RelMonth; +RelativeMonth(time_t Start, time_t RelMonth) { struct tm *tm; time_t Month; @@ -684,14 +668,13 @@ RelativeMonth(Start, RelMonth) static int -LookupWord(buff) - char *buff; +LookupWord(char *buff) { - register char *p; - register char *q; - register const TABLE *tp; - int i; - int abbrev; + char *p; + char *q; + const TABLE *tp; + int i; + int abbrev; /* Make it lowercase. */ for (p = buff; *p; p++) @@ -791,13 +774,13 @@ LookupWord(buff) static int -yylex() +yylex(void) { - register char c; - register char *p; - char buff[20]; - int Count; - int sign; + char c; + char *p; + char buff[20]; + int Count; + int sign; for ( ; ; ) { while (isspace(*yyInput)) @@ -846,8 +829,7 @@ yylex() /* Yield A - B, measured in seconds. */ static long -difftm (a, b) - struct tm *a, *b; +difftm (struct tm *a, struct tm *b) { int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); int by = b->tm_year + (TM_YEAR_ORIGIN - 1); @@ -867,9 +849,7 @@ difftm (a, b) } time_t -get_date(p, now) - char *p; - struct timeb *now; +get_date(char *p, struct timeb *now) { struct tm *tm, gmt; struct timeb ftz; @@ -967,9 +947,7 @@ get_date(p, now) /* ARGSUSED */ int -main(ac, av) - int ac; - char *av[]; +main(int ac, char *av[]) { char buff[128]; time_t d; diff --git a/usr.bin/find/ls.c b/usr.bin/find/ls.c index 79e8f59..4fb450b 100644 --- a/usr.bin/find/ls.c +++ b/usr.bin/find/ls.c @@ -36,17 +36,18 @@ static char sccsid[] = "@(#)ls.c 8.1 (Berkeley) 6/6/93"; #endif #endif /* not lint */ + #include __FBSDID("$FreeBSD$"); #include #include -#include #include #include #include #include +#include #include #include #include @@ -62,10 +63,7 @@ static void printlink(char *); static void printtime(time_t); void -printlong(name, accpath, sb) - char *name; /* filename to print */ - char *accpath; /* current valid path to filename */ - struct stat *sb; /* stat buffer */ +printlong(char *name, char *accpath, struct stat *sb) { char modep[15]; @@ -88,21 +86,20 @@ printlong(name, accpath, sb) } static void -printtime(ftime) - time_t ftime; +printtime(time_t ftime) { char longstring[80]; - static time_t now; + static time_t lnow; const char *format; static int d_first = -1; if (d_first < 0) d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); - if (now == 0) - now = time(NULL); + if (lnow == 0) + lnow = time(NULL); #define SIXMONTHS ((365 / 2) * 86400) - if (ftime + SIXMONTHS > now && ftime < now + SIXMONTHS) + if (ftime + SIXMONTHS > lnow && ftime < lnow + SIXMONTHS) /* mmm dd hh:mm || dd mmm hh:mm */ format = d_first ? "%e %b %R " : "%b %e %R "; else @@ -113,8 +110,7 @@ printtime(ftime) } static void -printlink(name) - char *name; +printlink(char *name) { int lnklen; char path[MAXPATHLEN]; diff --git a/usr.bin/find/main.c b/usr.bin/find/main.c index 0ffc178..643f1f8 100644 --- a/usr.bin/find/main.c +++ b/usr.bin/find/main.c @@ -45,6 +45,7 @@ char copyright[] = static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95"; #endif #endif /* not lint */ + #include __FBSDID("$FreeBSD$"); @@ -78,9 +79,7 @@ int regexp_flags = REG_BASIC; /* use the "basic" regexp by default*/ static void usage(void); int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { char **p, **start; int Hflag, Lflag, ch; @@ -162,7 +161,7 @@ main(argc, argv) } static void -usage() +usage(void) { (void)fprintf(stderr, "usage: find [-H | -L | -P] [-EXdsx] [-f file] [file ...] [expression]\n"); diff --git a/usr.bin/find/misc.c b/usr.bin/find/misc.c index 60792cb..fe11e04df 100644 --- a/usr.bin/find/misc.c +++ b/usr.bin/find/misc.c @@ -40,6 +40,7 @@ static char sccsid[] = "@(#)misc.c 8.2 (Berkeley) 4/1/94"; #else #endif #endif /* not lint */ + #include __FBSDID("$FreeBSD$"); @@ -60,9 +61,7 @@ __FBSDID("$FreeBSD$"); * Replace occurrences of {} in s1 with s2 and return the result string. */ void -brace_subst(orig, store, path, len) - char *orig, **store, *path; - int len; +brace_subst(char *orig, char **store, char *path, int len) { int plen; char ch, *p; @@ -87,8 +86,7 @@ brace_subst(orig, store, path, len) * input. If the input is 'y' then 1 is returned. */ int -queryuser(argv) - char **argv; +queryuser(char *argv[]) { int ch, first, nl; diff --git a/usr.bin/find/operator.c b/usr.bin/find/operator.c index c67abc0..c774efa 100644 --- a/usr.bin/find/operator.c +++ b/usr.bin/find/operator.c @@ -39,6 +39,7 @@ static char sccsid[] = "@(#)operator.c 8.1 (Berkeley) 6/6/93"; #endif #endif /* not lint */ + #include __FBSDID("$FreeBSD$"); @@ -58,8 +59,7 @@ static PLAN *yankexpr(PLAN **); * destructively removes the top from the plan */ static PLAN * -yanknode(planp) - PLAN **planp; /* pointer to top of plan (modified) */ +yanknode(PLAN **planp) { PLAN *node; /* top node removed from the plan */ @@ -77,8 +77,7 @@ yanknode(planp) * simple node or a f_expr node containing a list of simple nodes. */ static PLAN * -yankexpr(planp) - PLAN **planp; /* pointer to top of plan (modified) */ +yankexpr(PLAN **planp) { PLAN *next; /* temp node holding subexpression results */ PLAN *node; /* pointer to returned node or expression */ @@ -130,8 +129,7 @@ yankexpr(planp) * replaces "parenthesized" plans in our search plan with "expr" nodes. */ PLAN * -paren_squish(plan) - PLAN *plan; /* plan with ( ) nodes */ +paren_squish(PLAN *plan) { PLAN *expr; /* pointer to next expression */ PLAN *tail; /* pointer to tail of result plan */ @@ -168,8 +166,7 @@ paren_squish(plan) * compresses "!" expressions in our search plan. */ PLAN * -not_squish(plan) - PLAN *plan; /* plan to process */ +not_squish(PLAN *plan) { PLAN *next; /* next node being processed */ PLAN *node; /* temporary node used in f_not processing */ @@ -232,8 +229,7 @@ not_squish(plan) * compresses -o expressions in our search plan. */ PLAN * -or_squish(plan) - PLAN *plan; /* plan with ors to be squished */ +or_squish(PLAN *plan) { PLAN *next; /* next node being processed */ PLAN *tail; /* pointer to tail of result plan */ diff --git a/usr.bin/find/option.c b/usr.bin/find/option.c index ae87e64..9e10e50 100644 --- a/usr.bin/find/option.c +++ b/usr.bin/find/option.c @@ -39,6 +39,7 @@ static char sccsid[] = "@(#)option.c 8.2 (Berkeley) 4/16/94"; */ #endif /* not lint */ + #include __FBSDID("$FreeBSD$"); @@ -138,8 +139,7 @@ static OPTION const options[] = { * this switch stuff. */ PLAN * -find_create(argvp) - char ***argvp; +find_create(char ***argvp) { OPTION *p; PLAN *new; @@ -157,8 +157,7 @@ find_create(argvp) } OPTION * -lookup_option(name) - const char *name; +lookup_option(const char *name) { OPTION tmp; @@ -168,8 +167,7 @@ lookup_option(name) } int -typecompare(a, b) - const void *a, *b; +typecompare(const void *a, const void *b) { return (strcmp(((const OPTION *)a)->name, ((const OPTION *)b)->name)); } diff --git a/usr.bin/find/parsedate.y b/usr.bin/find/parsedate.y deleted file mode 100644 index 7bcfd61..0000000 --- a/usr.bin/find/parsedate.y +++ /dev/null @@ -1,888 +0,0 @@ -%{ -/* $Id: parsedate.y,v 1.9.2.1 2000/12/26 08:39:49 kondou Exp $ -** $FreeBSD$ -** -** Originally written by Steven M. Bellovin while -** at the University of North Carolina at Chapel Hill. Later tweaked by -** a couple of people on Usenet. Completely overhauled by Rich $alz -** and Jim Berets in August, 1990. -** Further revised (removed obsolete constructs and cleaned up timezone -** names) in August, 1991, by Rich. Paul Eggert -** helped in September, 1992. -** -** This grammar has six shift/reduce conflicts. -** -** This code is in the public domain and has no copyright. -*/ -/* SUPPRESS 530 *//* Empty body for statement */ -/* SUPPRESS 593 on yyerrlab *//* Label was not used */ -/* SUPPRESS 593 on yynewstate *//* Label was not used */ -/* SUPPRESS 595 on yypvt *//* Automatic variable may be used before set */ - -#include -#include -#include -#include -#include -#include -#include - -#include "find.h" - -#define CTYPE(isXXXXX, c) (isXXXXX((c))) -#define SIZEOF(array) (sizeof array / sizeof array[0]) -#define ENDOF(array) (&array[SIZEOF(array)]) - -typedef const char *STRING; -typedef struct timeb TIMEINFO; - -#define yylhs date_yylhs -#define yylen date_yylen -#define yydefred date_yydefred -#define yydgoto date_yydgoto -#define yysindex date_yysindex -#define yyrindex date_yyrindex -#define yygindex date_yygindex -#define yytable date_yytable -#define yycheck date_yycheck -#define yyparse date_parse -#define yylex date_lex -#define yyerror date_error - - -static int date_lex(void); -int yyparse(void); - - /* See the LeapYears table in Convert. */ -#define EPOCH 1970 -#define END_OF_TIME 2038 - /* Constants for general time calculations. */ -#define DST_OFFSET 1 -#define SECSPERDAY (24L * 60L * 60L) - /* Readability for TABLE stuff. */ -#define HOUR(x) (x * 60) - -#define LPAREN '(' -#define RPAREN ')' -#define IS7BIT(x) ((unsigned int)(x) < 0200) - - -/* -** An entry in the lexical lookup table. -*/ -typedef struct _TABLE { - STRING name; - int type; - time_t value; -} TABLE; - -/* -** Daylight-savings mode: on, off, or not yet known. -*/ -typedef enum _DSTMODE { - DSTon, DSToff, DSTmaybe -} DSTMODE; - -/* -** Meridian: am, pm, or 24-hour style. -*/ -typedef enum _MERIDIAN { - MERam, MERpm, MER24 -} MERIDIAN; - - -/* -** Global variables. We could get rid of most of them by using a yacc -** union, but this is more efficient. (This routine predates the -** yacc %union construct.) -*/ -static char *yyInput; -static DSTMODE yyDSTmode; -static int yyHaveDate; -static int yyHaveRel; -static int yyHaveTime; -static time_t yyTimezone; -static time_t yyDay; -static time_t yyHour; -static time_t yyMinutes; -static time_t yyMonth; -static time_t yySeconds; -static time_t yyYear; -static MERIDIAN yyMeridian; -static time_t yyRelMonth; -static time_t yyRelSeconds; - -static void date_error(const char *); -%} - -%union { - time_t Number; - enum _MERIDIAN Meridian; -} - -%token tDAY tDAYZONE tMERIDIAN tMONTH tMONTH_UNIT tSEC_UNIT tSNUMBER -%token tUNUMBER tZONE - -%type tDAYZONE tMONTH tMONTH_UNIT tSEC_UNIT -%type tSNUMBER tUNUMBER tZONE numzone zone -%type tMERIDIAN o_merid - -%% - -spec : /* NULL */ - | spec item - ; - -item : time { - yyHaveTime++; -#if defined(lint) - /* I am compulsive about lint natterings... */ - if (yyHaveTime == -1) { - YYERROR; - } -#endif /* defined(lint) */ - } - | time zone { - yyHaveTime++; - yyTimezone = $2; - } - | date { - yyHaveDate++; - } - | rel { - yyHaveRel = 1; - } - ; - -time : tUNUMBER o_merid { - if ($1 < 100) { - yyHour = $1; - yyMinutes = 0; - } - else { - yyHour = $1 / 100; - yyMinutes = $1 % 100; - } - yySeconds = 0; - yyMeridian = $2; - } - | tUNUMBER ':' tUNUMBER o_merid { - yyHour = $1; - yyMinutes = $3; - yySeconds = 0; - yyMeridian = $4; - } - | tUNUMBER ':' tUNUMBER numzone { - yyHour = $1; - yyMinutes = $3; - yyTimezone = $4; - yyMeridian = MER24; - yyDSTmode = DSToff; - } - | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid { - yyHour = $1; - yyMinutes = $3; - yySeconds = $5; - yyMeridian = $6; - } - | tUNUMBER ':' tUNUMBER ':' tUNUMBER numzone { - yyHour = $1; - yyMinutes = $3; - yySeconds = $5; - yyTimezone = $6; - yyMeridian = MER24; - yyDSTmode = DSToff; - } - ; - -zone : tZONE { - $$ = $1; - yyDSTmode = DSToff; - } - | tDAYZONE { - $$ = $1; - yyDSTmode = DSTon; - } - | tZONE numzone { - /* Only allow "GMT+300" and "GMT-0800" */ - if ($1 != 0) { - YYABORT; - } - $$ = $2; - yyDSTmode = DSToff; - } - | numzone { - $$ = $1; - yyDSTmode = DSToff; - } - ; - -numzone : tSNUMBER { - int i; - - /* Unix and GMT and numeric timezones -- a little confusing. */ - if ($1 < 0) { - /* Don't work with negative modulus. */ - $1 = -$1; - if ($1 > 9999 || (i = $1 % 100) >= 60) { - YYABORT; - } - $$ = ($1 / 100) * 60 + i; - } - else { - if ($1 > 9999 || (i = $1 % 100) >= 60) { - YYABORT; - } - $$ = -(($1 / 100) * 60 + i); - } - } - ; - -date : tUNUMBER '/' tUNUMBER { - yyMonth = $1; - yyDay = $3; - } - | tUNUMBER '/' tUNUMBER '/' tUNUMBER { - if ($1 > 100) { - /* assume YYYY/MM/DD format, so need not to add 1900 */ - if ($1 > 999) { - yyYear = $1; - } else { - yyYear = 1900 + $1; - } - yyMonth = $3; - yyDay = $5; - } - else { - /* assume MM/DD/YY* format */ - yyMonth = $1; - yyDay = $3; - if ($5 > 999) { - /* assume year is YYYY format, so need not to add 1900 */ - yyYear = $5; - } else if ($5 < 100) { - /* assume year is YY format, so need to add 1900 */ - yyYear = $5 + (yyYear / 100 + (yyYear % 100 - $5) / 50) * 100; - } else { - yyYear = 1900 + $5; - } - } - } - | tMONTH tUNUMBER { - yyMonth = $1; - yyDay = $2; - } - | tMONTH tUNUMBER ',' tUNUMBER { - yyMonth = $1; - yyDay = $2; - if ($4 > 999) { - /* assume year is YYYY format, so need not to add 1900 */ - yyYear = $4; - } else if ($4 < 100) { - /* assume year is YY format, so need to add 1900 */ - yyYear = $4 + (yyYear / 100 + (yyYear % 100 - $4) / 50) * 100; - } else { - yyYear = 1900 + $4; - } - } - | tUNUMBER tMONTH { - yyDay = $1; - yyMonth = $2; - } - | tUNUMBER tMONTH tUNUMBER { - yyDay = $1; - yyMonth = $2; - if ($3 > 999) { - /* assume year is YYYY format, so need not to add 1900 */ - yyYear = $3; - } else if ($3 < 100) { - /* assume year is YY format, so need to add 1900 */ - yyYear = $3 + (yyYear / 100 + (yyYear % 100 - $3) / 50) * 100; - } else { - yyYear = 1900 + $3; - } - } - | tDAY ',' tUNUMBER tMONTH tUNUMBER { - yyDay = $3; - yyMonth = $4; - if ($5 > 999) { - /* assume year is YYYY format, so need not to add 1900 */ - yyYear = $5; - } else if ($5 < 100) { - /* assume year is YY format, so need to add 1900 */ - yyYear = $5 + (yyYear / 100 + (yyYear % 100 - $5) / 50) * 100; - } else { - yyYear = 1900 + $5; - } - } - ; - -rel : tSNUMBER tSEC_UNIT { - yyRelSeconds += $1 * $2; - } - | tUNUMBER tSEC_UNIT { - yyRelSeconds += $1 * $2; - } - | tSNUMBER tMONTH_UNIT { - yyRelMonth += $1 * $2; - } - | tUNUMBER tMONTH_UNIT { - yyRelMonth += $1 * $2; - } - ; - -o_merid : /* NULL */ { - $$ = MER24; - } - | tMERIDIAN { - $$ = $1; - } - ; - -%% - -/* Month and day table. */ -static TABLE MonthDayTable[] = { - { "january", tMONTH, 1 }, - { "february", tMONTH, 2 }, - { "march", tMONTH, 3 }, - { "april", tMONTH, 4 }, - { "may", tMONTH, 5 }, - { "june", tMONTH, 6 }, - { "july", tMONTH, 7 }, - { "august", tMONTH, 8 }, - { "september", tMONTH, 9 }, - { "october", tMONTH, 10 }, - { "november", tMONTH, 11 }, - { "december", tMONTH, 12 }, - /* The value of the day isn't used... */ - { "sunday", tDAY, 0 }, - { "monday", tDAY, 0 }, - { "tuesday", tDAY, 0 }, - { "wednesday", tDAY, 0 }, - { "thursday", tDAY, 0 }, - { "friday", tDAY, 0 }, - { "saturday", tDAY, 0 }, -}; - -/* Time units table. */ -static TABLE UnitsTable[] = { - { "year", tMONTH_UNIT, 12 }, - { "month", tMONTH_UNIT, 1 }, - { "week", tSEC_UNIT, 7 * 24 * 60 * 60 }, - { "day", tSEC_UNIT, 1 * 24 * 60 * 60 }, - { "hour", tSEC_UNIT, 60 * 60 }, - { "minute", tSEC_UNIT, 60 }, - { "min", tSEC_UNIT, 60 }, - { "second", tSEC_UNIT, 1 }, - { "sec", tSEC_UNIT, 1 }, -}; - -/* Timezone table. */ -static TABLE TimezoneTable[] = { - { "gmt", tZONE, HOUR( 0) }, /* Greenwich Mean */ - { "ut", tZONE, HOUR( 0) }, /* Universal */ - { "utc", tZONE, HOUR( 0) }, /* Universal Coordinated */ - { "cut", tZONE, HOUR( 0) }, /* Coordinated Universal */ - { "z", tZONE, HOUR( 0) }, /* Greenwich Mean */ - { "wet", tZONE, HOUR( 0) }, /* Western European */ - { "bst", tDAYZONE, HOUR( 0) }, /* British Summer */ - { "nst", tZONE, HOUR(3)+30 }, /* Newfoundland Standard */ - { "ndt", tDAYZONE, HOUR(3)+30 }, /* Newfoundland Daylight */ - { "ast", tZONE, HOUR( 4) }, /* Atlantic Standard */ - { "adt", tDAYZONE, HOUR( 4) }, /* Atlantic Daylight */ - { "est", tZONE, HOUR( 5) }, /* Eastern Standard */ - { "edt", tDAYZONE, HOUR( 5) }, /* Eastern Daylight */ - { "cst", tZONE, HOUR( 6) }, /* Central Standard */ - { "cdt", tDAYZONE, HOUR( 6) }, /* Central Daylight */ - { "mst", tZONE, HOUR( 7) }, /* Mountain Standard */ - { "mdt", tDAYZONE, HOUR( 7) }, /* Mountain Daylight */ - { "pst", tZONE, HOUR( 8) }, /* Pacific Standard */ - { "pdt", tDAYZONE, HOUR( 8) }, /* Pacific Daylight */ - { "yst", tZONE, HOUR( 9) }, /* Yukon Standard */ - { "ydt", tDAYZONE, HOUR( 9) }, /* Yukon Daylight */ - { "akst", tZONE, HOUR( 9) }, /* Alaska Standard */ - { "akdt", tDAYZONE, HOUR( 9) }, /* Alaska Daylight */ - { "hst", tZONE, HOUR(10) }, /* Hawaii Standard */ - { "hast", tZONE, HOUR(10) }, /* Hawaii-Aleutian Standard */ - { "hadt", tDAYZONE, HOUR(10) }, /* Hawaii-Aleutian Daylight */ - { "ces", tDAYZONE, -HOUR(1) }, /* Central European Summer */ - { "cest", tDAYZONE, -HOUR(1) }, /* Central European Summer */ - { "mez", tZONE, -HOUR(1) }, /* Middle European */ - { "mezt", tDAYZONE, -HOUR(1) }, /* Middle European Summer */ - { "cet", tZONE, -HOUR(1) }, /* Central European */ - { "met", tZONE, -HOUR(1) }, /* Middle European */ - { "eet", tZONE, -HOUR(2) }, /* Eastern Europe */ - { "msk", tZONE, -HOUR(3) }, /* Moscow Winter */ - { "msd", tDAYZONE, -HOUR(3) }, /* Moscow Summer */ - { "wast", tZONE, -HOUR(8) }, /* West Australian Standard */ - { "wadt", tDAYZONE, -HOUR(8) }, /* West Australian Daylight */ - { "hkt", tZONE, -HOUR(8) }, /* Hong Kong */ - { "cct", tZONE, -HOUR(8) }, /* China Coast */ - { "jst", tZONE, -HOUR(9) }, /* Japan Standard */ - { "kst", tZONE, -HOUR(9) }, /* Korean Standard */ - { "kdt", tZONE, -HOUR(9) }, /* Korean Daylight */ - { "cast", tZONE, -(HOUR(9)+30) }, /* Central Australian Standard */ - { "cadt", tDAYZONE, -(HOUR(9)+30) }, /* Central Australian Daylight */ - { "east", tZONE, -HOUR(10) }, /* Eastern Australian Standard */ - { "eadt", tDAYZONE, -HOUR(10) }, /* Eastern Australian Daylight */ - { "nzst", tZONE, -HOUR(12) }, /* New Zealand Standard */ - { "nzdt", tDAYZONE, -HOUR(12) }, /* New Zealand Daylight */ - - /* For completeness we include the following entries. */ -#if 0 - - /* Duplicate names. Either they conflict with a zone listed above - * (which is either more likely to be seen or just been in circulation - * longer), or they conflict with another zone in this section and - * we could not reasonably choose one over the other. */ - { "fst", tZONE, HOUR( 2) }, /* Fernando De Noronha Standard */ - { "fdt", tDAYZONE, HOUR( 2) }, /* Fernando De Noronha Daylight */ - { "bst", tZONE, HOUR( 3) }, /* Brazil Standard */ - { "est", tZONE, HOUR( 3) }, /* Eastern Standard (Brazil) */ - { "edt", tDAYZONE, HOUR( 3) }, /* Eastern Daylight (Brazil) */ - { "wst", tZONE, HOUR( 4) }, /* Western Standard (Brazil) */ - { "wdt", tDAYZONE, HOUR( 4) }, /* Western Daylight (Brazil) */ - { "cst", tZONE, HOUR( 5) }, /* Chile Standard */ - { "cdt", tDAYZONE, HOUR( 5) }, /* Chile Daylight */ - { "ast", tZONE, HOUR( 5) }, /* Acre Standard */ - { "adt", tDAYZONE, HOUR( 5) }, /* Acre Daylight */ - { "cst", tZONE, HOUR( 5) }, /* Cuba Standard */ - { "cdt", tDAYZONE, HOUR( 5) }, /* Cuba Daylight */ - { "est", tZONE, HOUR( 6) }, /* Easter Island Standard */ - { "edt", tDAYZONE, HOUR( 6) }, /* Easter Island Daylight */ - { "sst", tZONE, HOUR(11) }, /* Samoa Standard */ - { "ist", tZONE, -HOUR(2) }, /* Israel Standard */ - { "idt", tDAYZONE, -HOUR(2) }, /* Israel Daylight */ - { "idt", tDAYZONE, -(HOUR(3)+30) }, /* Iran Daylight */ - { "ist", tZONE, -(HOUR(3)+30) }, /* Iran Standard */ - { "cst", tZONE, -HOUR(8) }, /* China Standard */ - { "cdt", tDAYZONE, -HOUR(8) }, /* China Daylight */ - { "sst", tZONE, -HOUR(8) }, /* Singapore Standard */ - - /* Dubious (e.g., not in Olson's TIMEZONE package) or obsolete. */ - { "gst", tZONE, HOUR( 3) }, /* Greenland Standard */ - { "wat", tZONE, -HOUR(1) }, /* West Africa */ - { "at", tZONE, HOUR( 2) }, /* Azores */ - { "gst", tZONE, -HOUR(10) }, /* Guam Standard */ - { "nft", tZONE, HOUR(3)+30 }, /* Newfoundland */ - { "idlw", tZONE, HOUR(12) }, /* International Date Line West */ - { "mewt", tZONE, -HOUR(1) }, /* Middle European Winter */ - { "mest", tDAYZONE, -HOUR(1) }, /* Middle European Summer */ - { "swt", tZONE, -HOUR(1) }, /* Swedish Winter */ - { "sst", tDAYZONE, -HOUR(1) }, /* Swedish Summer */ - { "fwt", tZONE, -HOUR(1) }, /* French Winter */ - { "fst", tDAYZONE, -HOUR(1) }, /* French Summer */ - { "bt", tZONE, -HOUR(3) }, /* Baghdad */ - { "it", tZONE, -(HOUR(3)+30) }, /* Iran */ - { "zp4", tZONE, -HOUR(4) }, /* USSR Zone 3 */ - { "zp5", tZONE, -HOUR(5) }, /* USSR Zone 4 */ - { "ist", tZONE, -(HOUR(5)+30) }, /* Indian Standard */ - { "zp6", tZONE, -HOUR(6) }, /* USSR Zone 5 */ - { "nst", tZONE, -HOUR(7) }, /* North Sumatra */ - { "sst", tZONE, -HOUR(7) }, /* South Sumatra */ - { "jt", tZONE, -(HOUR(7)+30) }, /* Java (3pm in Cronusland!) */ - { "nzt", tZONE, -HOUR(12) }, /* New Zealand */ - { "idle", tZONE, -HOUR(12) }, /* International Date Line East */ - { "cat", tZONE, HOUR(10) }, /* -- expired 1967 */ - { "nt", tZONE, HOUR(11) }, /* -- expired 1967 */ - { "ahst", tZONE, HOUR(10) }, /* -- expired 1983 */ - { "hdt", tDAYZONE, HOUR(10) }, /* -- expired 1986 */ -#endif /* 0 */ -}; - - - -static int -GetTimeInfo(TIMEINFO *Now) -{ - static time_t NextHour; - static long LastTzone; - struct tm *tm; - int secondsUntilNextHour; - struct timeval tv; - - /* Get the basic time. */ - if (gettimeofday(&tv, (struct timezone *) 0) == -1) - return -1; - Now->time = tv.tv_sec; - Now->millitm = tv.tv_usec; - - /* Now get the timezone if the last time < HH:00:00 <= now for some HH. */ - if (NextHour <= Now->time) { - tm = localtime(&Now->time); - if (tm == NULL) - return -1; - secondsUntilNextHour = 60 * (60 - tm->tm_min) - tm->tm_sec; - LastTzone = (0 - tm->tm_gmtoff) / 60; - NextHour = Now->time + secondsUntilNextHour; - } - Now->timezone = LastTzone; - return 0; -} - - -/* ARGSUSED */ -static void -date_error(const char *s __unused) -{ - /* NOTREACHED */ -} - - -static time_t -ToSeconds(time_t Hours, time_t Minutes, time_t Seconds, MERIDIAN Meridian) -{ - if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 61) - return -1; - if (Meridian == MER24) { - if (Hours < 0 || Hours > 23) - return -1; - } - else { - if (Hours < 1 || Hours > 12) - return -1; - if (Hours == 12) - Hours = 0; - if (Meridian == MERpm) - Hours += 12; - } - return (Hours * 60L + Minutes) * 60L + Seconds; -} - - -static time_t -Convert(time_t Month, time_t Day, time_t Year, time_t Hours, time_t Minutes, time_t Seconds, MERIDIAN Meridian, DSTMODE dst) -{ - static int DaysNormal[13] = { - 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 - }; - static int DaysLeap[13] = { - 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 - }; - static int LeapYears[] = { - 1972, 1976, 1980, 1984, 1988, 1992, 1996, - 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036 - }; - int *yp; - int *mp; - time_t Julian; - int i; - time_t tod; - - /* Year should not be passed as a relative value, but absolute one. - so this should not happen, but just ensure it */ - if (Year < 0) - Year = -Year; - if (Year < 100) { - Year += 1900; - if (Year < EPOCH) - Year += 100; - } - for (mp = DaysNormal, yp = LeapYears; yp < ENDOF(LeapYears); yp++) - if (Year == *yp) { - mp = DaysLeap; - break; - } - if (Year < EPOCH || Year > END_OF_TIME - || Month < 1 || Month > 12 - /* NOSTRICT *//* conversion from long may lose accuracy */ - || Day < 1 || Day > mp[(int)Month]) - return -1; - - Julian = Day - 1 + (Year - EPOCH) * 365; - for (yp = LeapYears; yp < ENDOF(LeapYears); yp++, Julian++) - if (Year <= *yp) - break; - for (i = 1; i < Month; i++) - Julian += *++mp; - Julian *= SECSPERDAY; - Julian += yyTimezone * 60L; - if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0) - return -1; - Julian += tod; - tod = Julian; - if (dst == DSTon || (dst == DSTmaybe && localtime(&tod)->tm_isdst)) - Julian -= DST_OFFSET * 60 * 60; - return Julian; -} - - -static time_t -DSTcorrect(time_t Start, time_t Future) -{ - time_t StartDay; - time_t FutureDay; - - StartDay = (localtime(&Start)->tm_hour + 1) % 24; - FutureDay = (localtime(&Future)->tm_hour + 1) % 24; - return (Future - Start) + (StartDay - FutureDay) * DST_OFFSET * 60 * 60; -} - - -static time_t -RelativeMonth(time_t Start, time_t RelMonth) -{ - struct tm *tm; - time_t Month; - time_t Year; - - tm = localtime(&Start); - Month = 12 * tm->tm_year + tm->tm_mon + RelMonth; - Year = Month / 12; - Year += 1900; - Month = Month % 12 + 1; - return DSTcorrect(Start, - Convert(Month, (time_t)tm->tm_mday, Year, - (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec, - MER24, DSTmaybe)); -} - - -static int LookupWord(char *buff, int length) -{ - char *p; - STRING q; - TABLE *tp; - int c; - - p = buff; - c = p[0]; - - /* See if we have an abbreviation for a month. */ - if (length == 3 || (length == 4 && p[3] == '.')) - for (tp = MonthDayTable; tp < ENDOF(MonthDayTable); tp++) { - q = tp->name; - if (c == q[0] && p[1] == q[1] && p[2] == q[2]) { - yylval.Number = tp->value; - return tp->type; - } - } - else - for (tp = MonthDayTable; tp < ENDOF(MonthDayTable); tp++) - if (c == tp->name[0] && strcmp(p, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - - /* Try for a timezone. */ - for (tp = TimezoneTable; tp < ENDOF(TimezoneTable); tp++) - if (c == tp->name[0] && p[1] == tp->name[1] - && strcmp(p, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - - /* Try the units table. */ - for (tp = UnitsTable; tp < ENDOF(UnitsTable); tp++) - if (c == tp->name[0] && strcmp(p, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - - /* Strip off any plural and try the units table again. */ - if (--length > 0 && p[length] == 's') { - p[length] = '\0'; - for (tp = UnitsTable; tp < ENDOF(UnitsTable); tp++) - if (c == tp->name[0] && strcmp(p, tp->name) == 0) { - p[length] = 's'; - yylval.Number = tp->value; - return tp->type; - } - p[length] = 's'; - } - length++; - - /* Drop out any periods. */ - for (p = buff, q = (STRING)buff; *q; q++) - if (*q != '.') - *p++ = *q; - *p = '\0'; - - /* Try the meridians. */ - if (buff[1] == 'm' && buff[2] == '\0') { - if (buff[0] == 'a') { - yylval.Meridian = MERam; - return tMERIDIAN; - } - if (buff[0] == 'p') { - yylval.Meridian = MERpm; - return tMERIDIAN; - } - } - - /* If we saw any periods, try the timezones again. */ - if (p - buff != length) { - c = buff[0]; - for (p = buff, tp = TimezoneTable; tp < ENDOF(TimezoneTable); tp++) - if (c == tp->name[0] && p[1] == tp->name[1] - && strcmp(p, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - } - - /* Unknown word -- assume GMT timezone. */ - yylval.Number = 0; - return tZONE; -} - - -static int date_lex(void) -{ - char c; - char *p; - char buff[20]; - int sign; - int i; - int nesting; - - for ( ; ; ) { - /* Get first character after the whitespace. */ - for ( ; ; ) { - while (CTYPE(isspace, (int)*yyInput)) - yyInput++; - c = *yyInput; - - /* Ignore RFC 822 comments, typically time zone names. */ - if (c != LPAREN) - break; - for (nesting = 1; (c = *++yyInput) != RPAREN || --nesting; ) - if (c == LPAREN) - nesting++; - else if (!IS7BIT(c) || c == '\0' || c == '\r' - || (c == '\\' && ((c = *++yyInput) == '\0' || !IS7BIT(c)))) - /* Lexical error: bad comment. */ - return '?'; - yyInput++; - } - - /* A number? */ - if (CTYPE(isdigit, (int)c) || c == '-' || c == '+') { - if (c == '-' || c == '+') { - sign = c == '-' ? -1 : 1; - yyInput++; - if (!CTYPE(isdigit, (int)*yyInput)) - /* Skip the plus or minus sign. */ - continue; - } - else - sign = 0; - for (i = 0; (c = *yyInput++) != '\0' && CTYPE(isdigit, (int)c); ) - i = 10 * i + c - '0'; - yyInput--; - yylval.Number = sign < 0 ? -i : i; - return sign ? tSNUMBER : tUNUMBER; - } - - /* A word? */ - if (CTYPE(isalpha, (int)c)) { - for (p = buff; (c = *yyInput++) == '.' || CTYPE(isalpha, (int)c); ) - if (p < &buff[sizeof buff - 1]) - *p++ = CTYPE(isupper, (int)c) ? tolower(c) : c; - *p = '\0'; - yyInput--; - return LookupWord(buff, p - buff); - } - - return *yyInput++; - } -} - - -time_t parsedate(char *p, TIMEINFO *now) -{ - struct tm *tm; - TIMEINFO ti; - time_t Start; - - yyInput = p; - if (now == NULL) { - now = &ti; - (void)GetTimeInfo(&ti); - } - - tm = localtime(&now->time); - yyYear = tm->tm_year + 1900; - yyMonth = tm->tm_mon + 1; - yyDay = tm->tm_mday; - yyTimezone = now->timezone; - yyDSTmode = DSTmaybe; - yyHour = 0; - yyMinutes = 0; - yySeconds = 0; - yyMeridian = MER24; - yyRelSeconds = 0; - yyRelMonth = 0; - yyHaveDate = 0; - yyHaveRel = 0; - yyHaveTime = 0; - - if (date_parse() || yyHaveTime > 1 || yyHaveDate > 1) - return -1; - - if (yyHaveDate || yyHaveTime) { - Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds, - yyMeridian, yyDSTmode); - if (Start < 0) - return -1; - } - else { - Start = now->time; - if (!yyHaveRel) - Start -= (tm->tm_hour * 60L + tm->tm_min) * 60L + tm->tm_sec; - } - - Start += yyRelSeconds; - if (yyRelMonth) - Start += RelativeMonth(Start, yyRelMonth); - - /* Have to do *something* with a legitimate -1 so it's distinguishable - * from the error return value. (Alternately could set errno on error.) */ - return Start == -1 ? 0 : Start; -} - - -#if defined(TEST) - -#if YYDEBUG -extern int yydebug; -#endif /* YYDEBUG */ - -/* ARGSUSED */ -int -main(ac, av) - int ac; - char *av[]; -{ - char buff[128]; - time_t d; - -#if YYDEBUG - yydebug = 1; -#endif /* YYDEBUG */ - - (void)printf("Enter date, or blank line to exit.\n\t> "); - for ( ; ; ) { - (void)printf("\t> "); - (void)fflush(stdout); - if (gets(buff) == NULL || buff[0] == '\n') - break; -#if YYDEBUG - if (strcmp(buff, "yydebug") == 0) { - yydebug = !yydebug; - printf("yydebug = %s\n", yydebug ? "on" : "off"); - continue; - } -#endif /* YYDEBUG */ - d = parsedate(buff, (TIMEINFO *)NULL); - if (d == -1) - (void)printf("Bad format - couldn't convert.\n"); - else - (void)printf("%s", ctime(&d)); - } - - exit(0); - /* NOTREACHED */ -} -#endif /* defined(TEST) */ -- cgit v1.1