summaryrefslogtreecommitdiff
path: root/bin/pax
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2002-10-16 15:56:43 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2002-10-16 15:56:43 +0000
commitfe83cf65234b817450b4b23fcb27269821db2a84 (patch)
treede079d9c5a7afd466f78a756d088c408659a6178 /bin/pax
parentb49c1b858b161388b716dea0cb718f97b320380f (diff)
Sync date parsing code with that in date(1) (which is obviously what pax's
date code was based on). It is now possible to specify 4 digit years.
Diffstat (limited to 'bin/pax')
-rw-r--r--bin/pax/pax.119
-rw-r--r--bin/pax/sel_subs.c111
-rw-r--r--bin/pax/sel_subs.h4
3 files changed, 71 insertions, 63 deletions
diff --git a/bin/pax/pax.1 b/bin/pax/pax.1
index e21a2f31a56..ccebc4fc996 100644
--- a/bin/pax/pax.1
+++ b/bin/pax/pax.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: pax.1,v 1.32 2002/10/15 21:25:31 millert Exp $
+.\" $OpenBSD: pax.1,v 1.33 2002/10/16 15:56:42 millert Exp $
.\" $NetBSD: pax.1,v 1.3 1995/03/21 09:07:37 cgd Exp $
.\"
.\" Copyright (c) 1992 Keith Muller.
@@ -896,8 +896,10 @@ changed during a specified time range will be archived).
A time range is made up of six different fields and each field must contain two
digits.
The format is:
-.Dl [[[[yy]mm]dd]hh]mm[.ss]
+.Dl [[[[[cc]yy]mm]dd]HH]MM[.SS]
Where
+.Cm cc
+is the first two digits of the year (the century),
.Cm yy
is the last two digits of the year,
the first
@@ -905,21 +907,20 @@ the first
is the month (from 01 to 12),
.Cm dd
is the day of the month (from 01 to 31),
-.Cm hh
+.Cm HH
is the hour of the day (from 00 to 23),
-the second
-.Cm mm
+.Cm MM
is the minute (from 00 to 59),
and
-.Cm ss
+.Cm SS
is the seconds (from 00 to 59).
The minute field
-.Cm mm
+.Cm MM
is required, while the other fields are optional and must be added in the
following order:
-.Dl Cm hh , dd , mm , yy .
+.Dl Cm HH , dd , mm , yy , cc .
The
-.Cm ss
+.Cm SS
field may be added independently of the other fields.
Time ranges are relative to the current time, so
.Dl Fl T Ar 1234/cm
diff --git a/bin/pax/sel_subs.c b/bin/pax/sel_subs.c
index e111d2bfe97..098cc939ec4 100644
--- a/bin/pax/sel_subs.c
+++ b/bin/pax/sel_subs.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sel_subs.c,v 1.11 2002/10/15 21:25:31 millert Exp $ */
+/* $OpenBSD: sel_subs.c,v 1.12 2002/10/16 15:56:42 millert Exp $ */
/* $NetBSD: sel_subs.c,v 1.5 1995/03/21 09:07:42 cgd Exp $ */
/*-
@@ -42,7 +42,7 @@
#if 0
static char sccsid[] = "@(#)sel_subs.c 8.1 (Berkeley) 5/31/93";
#else
-static char rcsid[] = "$OpenBSD: sel_subs.c,v 1.11 2002/10/15 21:25:31 millert Exp $";
+static char rcsid[] = "$OpenBSD: sel_subs.c,v 1.12 2002/10/16 15:56:42 millert Exp $";
#endif
#endif /* not lint */
@@ -50,12 +50,14 @@ static char rcsid[] = "$OpenBSD: sel_subs.c,v 1.11 2002/10/15 21:25:31 millert E
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/param.h>
-#include <pwd.h>
+#include <ctype.h>
#include <grp.h>
+#include <pwd.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include <tzfile.h>
#include <unistd.h>
-#include <stdlib.h>
#include "pax.h"
#include "sel_subs.h"
#include "extern.h"
@@ -315,7 +317,7 @@ grp_match(register ARCHD *arcn)
* trng_add()
* add a time range match to the time range list.
* This is a non-standard pax option. Lower and upper ranges are in the
- * format: [[[[yy]mm]dd]hh]mm[.ss] and are comma separated.
+ * format: [[[[[cc]yy]mm]dd]HH]MM[.SS] and are comma separated.
* Time ranges are based on current time, so 1234 would specify a time of
* 12:34 today.
* Return:
@@ -451,7 +453,7 @@ trng_add(register char *str)
return(0);
out:
- paxwarn(1, "Time range format is: [[[[yy]mm]dd]hh]mm[.ss][/[c][m]]");
+ paxwarn(1, "Time range format is: [[[[[cc]yy]mm]dd]HH]MM[.SS][/[c][m]]");
return(-1);
}
@@ -525,80 +527,85 @@ trng_match(register ARCHD *arcn)
/*
* str_sec()
- * Convert a time string in the format of [[[[yy]mm]dd]hh]mm[.ss] to gmt
- * seconds. Tval already has current time loaded into it at entry.
+ * Convert a time string in the format of [[[[[cc]yy]mm]dd]HH]MM[.SS] to
+ * UTC seconds. Tval already has current time loaded into it at entry.
* Return:
* 0 if converted ok, -1 otherwise
*/
static int
-str_sec(register char *str, time_t *tval)
+str_sec(register char *p, time_t *tval)
{
register struct tm *lt;
- register char *dot = NULL;
+ register char *dot, *t;
+ int bigyear;
+ int yearset = 0;
+
+ for (t = p, dot = NULL; *t; ++t) {
+ if (isdigit(*t))
+ continue;
+ if (*t == '.' && dot == NULL) {
+ dot = t;
+ continue;
+ }
+ return(-1);
+ }
lt = localtime(tval);
- if ((dot = strchr(str, '.')) != NULL) {
- /*
- * seconds (.ss)
- */
+
+ if (dot != NULL) { /* .SS */
*dot++ = '\0';
if (strlen(dot) != 2)
return(-1);
- if ((lt->tm_sec = ATOI2(dot)) > 61)
+ lt->tm_sec = ATOI2(dot);
+ if (lt->tm_sec > 61)
return(-1);
} else
lt->tm_sec = 0;
- switch (strlen(str)) {
- case 10:
- /*
- * year (yy)
- * watch out for year 2000
- */
- if ((lt->tm_year = ATOI2(str)) < 69)
- lt->tm_year += 100;
- str += 2;
+ switch (strlen(p)) {
+ case 12: /* cc */
+ bigyear = ATOI2(p);
+ lt->tm_year = (bigyear * 100) - TM_YEAR_BASE;
+ yearset = 1;
/* FALLTHROUGH */
- case 8:
- /*
- * month (mm)
- * watch out months are from 0 - 11 internally
- */
- if ((lt->tm_mon = ATOI2(str)) > 12)
+ case 10: /* yy */
+ if (yearset) {
+ lt->tm_year += ATOI2(p);
+ } else {
+ lt->tm_year = ATOI2(p);
+ if (lt->tm_year < 69) /* hack for 2000 ;-} */
+ lt->tm_year += (2000 - TM_YEAR_BASE);
+ else
+ lt->tm_year += (1900 - TM_YEAR_BASE);
+ }
+ /* FALLTHROUGH */
+ case 8: /* mm */
+ lt->tm_mon = ATOI2(p);
+ if ((lt->tm_mon > 12) || !lt->tm_mon)
return(-1);
- --lt->tm_mon;
- str += 2;
+ --lt->tm_mon; /* time struct is 0 - 11 */
/* FALLTHROUGH */
- case 6:
- /*
- * day (dd)
- */
- if ((lt->tm_mday = ATOI2(str)) > 31)
+ case 6: /* dd */
+ lt->tm_mday = ATOI2(p);
+ if ((lt->tm_mday > 31) || !lt->tm_mday)
return(-1);
- str += 2;
/* FALLTHROUGH */
- case 4:
- /*
- * hour (hh)
- */
- if ((lt->tm_hour = ATOI2(str)) > 23)
+ case 4: /* HH */
+ lt->tm_hour = ATOI2(p);
+ if (lt->tm_hour > 23)
return(-1);
- str += 2;
/* FALLTHROUGH */
- case 2:
- /*
- * minute (mm)
- */
- if ((lt->tm_min = ATOI2(str)) > 59)
+ case 2: /* MM */
+ lt->tm_min = ATOI2(p);
+ if (lt->tm_min > 59)
return(-1);
break;
default:
return(-1);
}
- /*
- * convert broken-down time to GMT clock time seconds
- */
+
+ /* convert broken-down time to UTC clock time seconds */
if ((*tval = mktime(lt)) == -1)
return(-1);
return(0);
diff --git a/bin/pax/sel_subs.h b/bin/pax/sel_subs.h
index fc86e9dfa23..4caaefd6d7e 100644
--- a/bin/pax/sel_subs.h
+++ b/bin/pax/sel_subs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sel_subs.h,v 1.2 1996/06/23 14:20:41 deraadt Exp $ */
+/* $OpenBSD: sel_subs.h,v 1.3 2002/10/16 15:56:42 millert Exp $ */
/* $NetBSD: sel_subs.h,v 1.3 1995/03/21 09:07:44 cgd Exp $ */
/*-
@@ -61,7 +61,7 @@ typedef struct grpt {
* data structure for storing user supplied time ranges (-T option)
*/
-#define ATOI2(s) ((((s)[0] - '0') * 10) + ((s)[1] - '0'))
+#define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2;
typedef struct time_rng {
time_t low_time; /* lower inclusive time limit */