summaryrefslogtreecommitdiffstats
path: root/usr.bin/find
diff options
context:
space:
mode:
authormarkm <markm@FreeBSD.org>2002-03-21 21:56:05 +0000
committermarkm <markm@FreeBSD.org>2002-03-21 21:56:05 +0000
commit5da7065f3d4fe05102865926b09192cffa03a251 (patch)
treee3d885c77e6bf6e7ca5fd176e325c34b01874abc /usr.bin/find
parent00281942195721d9e90e5686c6d91bac28798cfd (diff)
downloadFreeBSD-src-5da7065f3d4fe05102865926b09192cffa03a251.zip
FreeBSD-src-5da7065f3d4fe05102865926b09192cffa03a251.tar.gz
Restructure for own parsedate (replacement for get_date from CVS).
Fix up parsedate.y for WARNS=4. Reviewd by: bde (except for parsedate.y diffs)
Diffstat (limited to 'usr.bin/find')
-rw-r--r--usr.bin/find/Makefile6
-rw-r--r--usr.bin/find/extern.h2
-rw-r--r--usr.bin/find/function.c3
-rw-r--r--usr.bin/find/parsedate.y91
4 files changed, 54 insertions, 48 deletions
diff --git a/usr.bin/find/Makefile b/usr.bin/find/Makefile
index 3553c1e..0fbcb91 100644
--- a/usr.bin/find/Makefile
+++ b/usr.bin/find/Makefile
@@ -2,9 +2,7 @@
# $FreeBSD$
PROG= find
-SRCS= find.c function.c ls.c main.c misc.c operator.c option.c getdate.y
-CLEANFILES+= getdate.c y.tab.h
-CFLAGS+= -I${.CURDIR}/../../gnu/usr.bin/cvs/lib -DHAVE_CONFIG_H
-.PATH: ${.CURDIR}/../../contrib/cvs/lib
+SRCS= find.c function.c ls.c main.c misc.c operator.c option.c parsedate.y
+YFLAGS=
.include <bsd.prog.mk>
diff --git a/usr.bin/find/extern.h b/usr.bin/find/extern.h
index 8740b0a..0bab1e3 100644
--- a/usr.bin/find/extern.h
+++ b/usr.bin/find/extern.h
@@ -43,6 +43,8 @@ PLAN *find_formplan(char **);
PLAN *not_squish(PLAN *);
PLAN *or_squish(PLAN *);
PLAN *paren_squish(PLAN *);
+struct timeb;
+time_t parsedate(char *, struct timeb *);
struct stat;
void printlong(char *, char *, struct stat *);
int queryuser(char **);
diff --git a/usr.bin/find/function.c b/usr.bin/find/function.c
index 34e12c1..78a93ce 100644
--- a/usr.bin/find/function.c
+++ b/usr.bin/find/function.c
@@ -69,7 +69,6 @@ static PLAN *palloc(OPTION *);
static long long find_parsenum(PLAN *, const char *, char *, char *);
static long long find_parsetime(PLAN *, const char *, char *);
static char *nextarg(OPTION *, char ***);
-time_t get_date(char *, struct timeb *);
#define COMPARE(a, b) do { \
switch (plan->flags & F_ELG_MASK) { \
@@ -999,7 +998,7 @@ c_newer(option, argvp)
new = palloc(option);
/* compare against what */
if (option->flags & F_TIME2_T) {
- new->t_data = get_date(fn_or_tspec, (struct timeb *) 0);
+ new->t_data = parsedate(fn_or_tspec, (struct timeb *) 0);
if (new->t_data == (time_t) -1)
errx(1, "Can't parse date/time: %s", fn_or_tspec);
} else {
diff --git a/usr.bin/find/parsedate.y b/usr.bin/find/parsedate.y
index 15c69d7..e954a0e 100644
--- a/usr.bin/find/parsedate.y
+++ b/usr.bin/find/parsedate.y
@@ -18,23 +18,22 @@
/* 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 "config.h"
-#include "clibrary.h"
-#include <ctype.h>
-#if defined(_HPUX_SOURCE)
-# include <alloca.h>
-#endif
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/timeb.h>
+#include <ctype.h>
+#include <fts.h>
+#include <time.h>
-#ifdef TM_IN_SYS_TIME
-# include <sys/time.h>
-#else
-# include <time.h>
-#endif
+#include "find.h"
-#include "libinn.h"
-#include "macros.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
@@ -51,7 +50,7 @@
static int date_lex(void);
-
+int yyparse(void);
/* See the LeapYears table in Convert. */
#define EPOCH 1970
@@ -112,10 +111,7 @@ static MERIDIAN yyMeridian;
static time_t yyRelMonth;
static time_t yyRelSeconds;
-
-extern struct tm *localtime();
-
-static void date_error();
+static void date_error(const char *);
%}
%union {
@@ -496,21 +492,45 @@ static TABLE TimezoneTable[] = {
+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(s)
- char *s;
+date_error(const char *s __unused)
{
/* NOTREACHED */
}
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 > 61)
return -1;
@@ -531,15 +551,7 @@ ToSeconds(Hours, Minutes, Seconds, Meridian)
static time_t
-Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, dst)
- time_t Month;
- time_t Day;
- time_t Year;
- time_t Hours;
- time_t Minutes;
- time_t Seconds;
- MERIDIAN Meridian;
- DSTMODE dst;
+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
@@ -596,9 +608,7 @@ Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, dst)
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;
@@ -610,9 +620,7 @@ DSTcorrect(Start, Future)
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;
@@ -783,7 +791,6 @@ static int date_lex(void)
time_t parsedate(char *p, TIMEINFO *now)
{
- extern int date_parse();
struct tm *tm;
TIMEINFO ti;
time_t Start;
@@ -798,7 +805,7 @@ time_t parsedate(char *p, TIMEINFO *now)
yyYear = tm->tm_year + 1900;
yyMonth = tm->tm_mon + 1;
yyDay = tm->tm_mday;
- yyTimezone = now->tzone;
+ yyTimezone = now->timezone;
yyDSTmode = DSTmaybe;
yyHour = 0;
yyMinutes = 0;
OpenPOWER on IntegriCloud