rh

Check-in [c584edc078]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix up f*cked up time treatment; use system one
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256:c584edc078f8c4ef47f72c3947bf550589a597146e726013ef3dd0aa8b50659a
User & Date: ajv-899-334-8894@vsta.org 2014-07-31 21:58:09
Context
2016-08-10
20:58
Bring rest of changes into git check-in: 74a2587607 user: ajv-899-334-8894@vsta.org tags: master, trunk
2014-07-31
21:58
Fix up f*cked up time treatment; use system one check-in: c584edc078 user: ajv-899-334-8894@vsta.org tags: master, trunk
2013-03-14
22:40
y2k. TBD if those time_t calculations are still correct! check-in: 7d55a1618f user: ajv-899-334-8894@vsta.org tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to getdate.c.

101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
...
382
383
384
385
386
387
388
389
390
391
392
393

394
395
396
397
398
399
400
401




402
403
404
405


406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
...
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
...
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
...
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
....
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
	/*							*/
	/* 	Steven M. Bellovin (unc!smb)			*/
	/*	Dept. of Computer Science			*/
	/*	University of North Carolina at Chapel Hill	*/
	/*	@(#)getdate.y	2.13	9/16/86			*/

#if !defined(lint)
static char rcsid[] = "$Id: getdate.y,v 1.1 2008/12/27 00:56:03 vandys Exp vandys $";
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
................................................................................
#define AM 1
#define PM 2
#define DAYLIGHT 1
#define STANDARD 2
#define MAYBE    3

static int gd_lex(), lookup();
static time_t timeconv(), daylcorr(), dateconv(), daylcorr();

#line 141 "y.tab.c"

#ifndef YYSTYPE
typedef int YYSTYPE;
#endif

................................................................................
	{31, 0, 31,  30, 31, 30,  31, 31, 30,  31, 30, 31};
#define epoch 1970

extern struct tm *localtime();

static time_t
dateconv(mm, dd, yy, h, m, s, mer, zone, dayflag)
int mm, dd, yy, h, m, s, mer, zone, dayflag;
{
	time_t tod, jdate;
	register int i;


	if (yy < 0) yy = -yy;
	if (yy < 200) yy += 1900;
	mdays[1] =
	    28 + ((yy % 4 == 0 && (yy % 100 != 0 || yy % 400 == 0)) ? 1 : 0);
	if ((yy < epoch) || (yy > 2099) || (mm < 1) || (mm > 12) ||
		(dd < 1) || (dd > mdays[--mm])) {
	    return (-1);
	}




	jdate = dd-1;
        for (i=0; i<mm; i++) jdate += mdays[i];
	for (i = epoch; i < yy; i++) {
	    jdate += 365 + ((i % 4 == 0 && (i % 100 != 0 || i % 400 == 0)) ? 1 : 0);


	}
	jdate *= daysec;
	jdate += zone * 60L;
	if ((tod = timeconv(h, m, s, mer)) < 0) return (-1);
	jdate += tod;
	if (dayflag == DAYLIGHT
	    || (dayflag == MAYBE && localtime(&jdate)->tm_isdst)) {
	    jdate += -1*60*60;
	}
	return (jdate);
}

static time_t
dayconv(ord, day, now)
int ord, day; time_t now;
{
	register struct tm *loctime;
	time_t tod;

	tod = now;
	loctime = localtime(&tod);
	tod += daysec * ((day - loctime->tm_wday + 7) % 7);
	tod += 7 * daysec * ((ord <= 0) ? ord : (ord - 1));
	return daylcorr(tod, now);
}

static time_t
timeconv(hh, mm, ss, mer)
register int hh, mm, ss, mer;
{
	if (mm < 0 || mm > 59 || ss < 0 || ss > 59) return (-1);
	switch (mer) {
		case AM: if (hh < 1 || hh > 12) return(-1);
			 return (60L * ((hh%12)*60L + mm)+ss);
		case PM: if (hh < 1 || hh > 12) return(-1);
			 return (60L * ((hh%12 +12)*60L + mm)+ss);
................................................................................

static char *lptr;

static int gd_lex()
{
	extern int gd_lval;
	int sign;
	register char c;
	register char *p;
	char idbuf[20];
	int pcnt;

	for (;;) {
		while (isspace(*lptr)) lptr++;

		if (isdigit(c = *lptr) || c == '-' || c == '+') {
................................................................................
static int lookup(id)
char *id;
{
#define gotit (gd_lval = i->value , i->type)
#define getid for(j = idvar, k = id; (*j++ = *k++) != '\0'; /* void */)

	char idvar[20];
	register char *j, *k;
	register struct table *i;
	int abbrev;

	getid;
	if (strlen(idvar) == 3) {
	    abbrev = 1;
	}
	else if (strlen(idvar) == 4 && idvar[3] == '.') {
................................................................................
}

/*ARGSUSED*/
void gd_error(char *s)
{
    return;
}
#line 842 "y.tab.c"

#if YYDEBUG
#include <stdio.h>		/* needed for printf */
#endif

#include <stdlib.h>	/* needed for malloc, etc */
#include <string.h>	/* needed for memset */
................................................................................
		{relsec++;}
break;
case 34:
#line 135 "getdate.y"

		{relsec = -relsec; relmonth = -relmonth;}
break;
#line 1224 "y.tab.c"
    }
    yystack.s_mark -= yym;
    yystate = *yystack.s_mark;
    yystack.l_mark -= yym;
    yym = yylhs[yyn];
    if (yystate == 0 && yym == 0)
    {







|







 







|







 







|

|
|

>
|
<
|
<
<
<
<
|
>
>
>
>
|
|
|
|
>
>
|
<
<
|
|
<
<
<
|
|






|











|







 







|
|







 







|
|







 







|







 







|







101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
...
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
...
382
383
384
385
386
387
388
389
390
391
392
393
394
395

396




397
398
399
400
401
402
403
404
405
406
407
408


409
410



411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
...
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
...
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
...
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
....
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
	/*							*/
	/* 	Steven M. Bellovin (unc!smb)			*/
	/*	Dept. of Computer Science			*/
	/*	University of North Carolina at Chapel Hill	*/
	/*	@(#)getdate.y	2.13	9/16/86			*/

#if !defined(lint)
static char rcsid[] = "$Id: getdate.y,v 1.2 2013/03/14 22:40:31 vandys Exp vandys $";
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
................................................................................
#define AM 1
#define PM 2
#define DAYLIGHT 1
#define STANDARD 2
#define MAYBE    3

static int gd_lex(), lookup();
static time_t timeconv(), daylcorr(), dateconv();

#line 141 "y.tab.c"

#ifndef YYSTYPE
typedef int YYSTYPE;
#endif

................................................................................
	{31, 0, 31,  30, 31, 30,  31, 31, 30,  31, 30, 31};
#define epoch 1970

extern struct tm *localtime();

static time_t
dateconv(mm, dd, yy, h, m, s, mer, zone, dayflag)
    int mm, dd, yy, h, m, s, mer, zone, dayflag;
{
    time_t t;
    struct tm tm;

    /* Negative year?  WTF? */
    if (yy < 0) {

	yy = -yy;




    }

    /* Initialize exploded time, then fill in */
    time(&t);
    tm = *localtime(&t);
    tm.tm_year = yy;
    tm.tm_mon = mm-1;
    tm.tm_mday = dd;
    tm.tm_hour = h;
    tm.tm_min = m;
    tm.tm_sec = s;



    /* Convert */
    t = mktime(&tm);




    return (t);
}

static time_t
dayconv(ord, day, now)
int ord, day; time_t now;
{
	struct tm *loctime;
	time_t tod;

	tod = now;
	loctime = localtime(&tod);
	tod += daysec * ((day - loctime->tm_wday + 7) % 7);
	tod += 7 * daysec * ((ord <= 0) ? ord : (ord - 1));
	return daylcorr(tod, now);
}

static time_t
timeconv(hh, mm, ss, mer)
int hh, mm, ss, mer;
{
	if (mm < 0 || mm > 59 || ss < 0 || ss > 59) return (-1);
	switch (mer) {
		case AM: if (hh < 1 || hh > 12) return(-1);
			 return (60L * ((hh%12)*60L + mm)+ss);
		case PM: if (hh < 1 || hh > 12) return(-1);
			 return (60L * ((hh%12 +12)*60L + mm)+ss);
................................................................................

static char *lptr;

static int gd_lex()
{
	extern int gd_lval;
	int sign;
	char c;
	char *p;
	char idbuf[20];
	int pcnt;

	for (;;) {
		while (isspace(*lptr)) lptr++;

		if (isdigit(c = *lptr) || c == '-' || c == '+') {
................................................................................
static int lookup(id)
char *id;
{
#define gotit (gd_lval = i->value , i->type)
#define getid for(j = idvar, k = id; (*j++ = *k++) != '\0'; /* void */)

	char idvar[20];
	char *j, *k;
	struct table *i;
	int abbrev;

	getid;
	if (strlen(idvar) == 3) {
	    abbrev = 1;
	}
	else if (strlen(idvar) == 4 && idvar[3] == '.') {
................................................................................
}

/*ARGSUSED*/
void gd_error(char *s)
{
    return;
}
#line 839 "y.tab.c"

#if YYDEBUG
#include <stdio.h>		/* needed for printf */
#endif

#include <stdlib.h>	/* needed for malloc, etc */
#include <string.h>	/* needed for memset */
................................................................................
		{relsec++;}
break;
case 34:
#line 135 "getdate.y"

		{relsec = -relsec; relmonth = -relmonth;}
break;
#line 1221 "y.tab.c"
    }
    yystack.s_mark -= yym;
    yystate = *yystack.s_mark;
    yystack.l_mark -= yym;
    yym = yylhs[yyn];
    if (yystate == 0 && yym == 0)
    {

Changes to getdate.y.

4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
..
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
...
140
141
142
143
144
145
146
147
148
149
150
151

152
153
154
155
156
157
158
159




160
161
162
163


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
...
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
	/*							*/
	/* 	Steven M. Bellovin (unc!smb)			*/
	/*	Dept. of Computer Science			*/
	/*	University of North Carolina at Chapel Hill	*/
	/*	@(#)getdate.y	2.13	9/16/86			*/

#if !defined(lint)
static char rcsid[] = "$Id: getdate.y,v 1.1 2008/12/27 00:56:03 vandys Exp vandys $";
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
................................................................................
#define AM 1
#define PM 2
#define DAYLIGHT 1
#define STANDARD 2
#define MAYBE    3

static int gd_lex(), lookup();
static time_t timeconv(), daylcorr(), dateconv(), daylcorr();

%}

%%
timedate: 		/* empty */
	| timedate item;

................................................................................
	{31, 0, 31,  30, 31, 30,  31, 31, 30,  31, 30, 31};
#define epoch 1970

extern struct tm *localtime();

static time_t
dateconv(mm, dd, yy, h, m, s, mer, zone, dayflag)
int mm, dd, yy, h, m, s, mer, zone, dayflag;
{
	time_t tod, jdate;
	register int i;


	if (yy < 0) yy = -yy;
	if (yy < 200) yy += 1900;
	mdays[1] =
	    28 + ((yy % 4 == 0 && (yy % 100 != 0 || yy % 400 == 0)) ? 1 : 0);
	if ((yy < epoch) || (yy > 2099) || (mm < 1) || (mm > 12) ||
		(dd < 1) || (dd > mdays[--mm])) {
	    return (-1);
	}




	jdate = dd-1;
        for (i=0; i<mm; i++) jdate += mdays[i];
	for (i = epoch; i < yy; i++) {
	    jdate += 365 + ((i % 4 == 0 && (i % 100 != 0 || i % 400 == 0)) ? 1 : 0);


	}
	jdate *= daysec;
	jdate += zone * 60L;
	if ((tod = timeconv(h, m, s, mer)) < 0) return (-1);
	jdate += tod;
	if (dayflag == DAYLIGHT
	    || (dayflag == MAYBE && localtime(&jdate)->tm_isdst)) {
	    jdate += -1*60*60;
	}
	return (jdate);
}

static time_t
dayconv(ord, day, now)
int ord, day; time_t now;
{
	register struct tm *loctime;
	time_t tod;

	tod = now;
	loctime = localtime(&tod);
	tod += daysec * ((day - loctime->tm_wday + 7) % 7);
	tod += 7 * daysec * ((ord <= 0) ? ord : (ord - 1));
	return daylcorr(tod, now);
}

static time_t
timeconv(hh, mm, ss, mer)
register int hh, mm, ss, mer;
{
	if (mm < 0 || mm > 59 || ss < 0 || ss > 59) return (-1);
	switch (mer) {
		case AM: if (hh < 1 || hh > 12) return(-1);
			 return (60L * ((hh%12)*60L + mm)+ss);
		case PM: if (hh < 1 || hh > 12) return(-1);
			 return (60L * ((hh%12 +12)*60L + mm)+ss);
................................................................................

static char *lptr;

static int gd_lex()
{
	extern int gd_lval;
	int sign;
	register char c;
	register char *p;
	char idbuf[20];
	int pcnt;

	for (;;) {
		while (isspace(*lptr)) lptr++;

		if (isdigit(c = *lptr) || c == '-' || c == '+') {
................................................................................
static int lookup(id)
char *id;
{
#define gotit (gd_lval = i->value , i->type)
#define getid for(j = idvar, k = id; (*j++ = *k++) != '\0'; /* void */)

	char idvar[20];
	register char *j, *k;
	register struct table *i;
	int abbrev;

	getid;
	if (strlen(idvar) == 3) {
	    abbrev = 1;
	}
	else if (strlen(idvar) == 4 && idvar[3] == '.') {







|







 







|







 







|

|
|

>
|
<
|
<
<
<
<
|
>
>
>
>
|
|
|
|
>
>
|
<
<
|
|
<
<
<
|
|






|











|







 







|
|







 







|
|







4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
..
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
...
140
141
142
143
144
145
146
147
148
149
150
151
152
153

154




155
156
157
158
159
160
161
162
163
164
165
166


167
168



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
...
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
...
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
	/*							*/
	/* 	Steven M. Bellovin (unc!smb)			*/
	/*	Dept. of Computer Science			*/
	/*	University of North Carolina at Chapel Hill	*/
	/*	@(#)getdate.y	2.13	9/16/86			*/

#if !defined(lint)
static char rcsid[] = "$Id: getdate.y,v 1.2 2013/03/14 22:40:31 vandys Exp vandys $";
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <sys/types.h>
................................................................................
#define AM 1
#define PM 2
#define DAYLIGHT 1
#define STANDARD 2
#define MAYBE    3

static int gd_lex(), lookup();
static time_t timeconv(), daylcorr(), dateconv();

%}

%%
timedate: 		/* empty */
	| timedate item;

................................................................................
	{31, 0, 31,  30, 31, 30,  31, 31, 30,  31, 30, 31};
#define epoch 1970

extern struct tm *localtime();

static time_t
dateconv(mm, dd, yy, h, m, s, mer, zone, dayflag)
    int mm, dd, yy, h, m, s, mer, zone, dayflag;
{
    time_t t;
    struct tm tm;

    /* Negative year?  WTF? */
    if (yy < 0) {

	yy = -yy;




    }

    /* Initialize exploded time, then fill in */
    time(&t);
    tm = *localtime(&t);
    tm.tm_year = yy;
    tm.tm_mon = mm-1;
    tm.tm_mday = dd;
    tm.tm_hour = h;
    tm.tm_min = m;
    tm.tm_sec = s;



    /* Convert */
    t = mktime(&tm);




    return (t);
}

static time_t
dayconv(ord, day, now)
int ord, day; time_t now;
{
	struct tm *loctime;
	time_t tod;

	tod = now;
	loctime = localtime(&tod);
	tod += daysec * ((day - loctime->tm_wday + 7) % 7);
	tod += 7 * daysec * ((ord <= 0) ? ord : (ord - 1));
	return daylcorr(tod, now);
}

static time_t
timeconv(hh, mm, ss, mer)
int hh, mm, ss, mer;
{
	if (mm < 0 || mm > 59 || ss < 0 || ss > 59) return (-1);
	switch (mer) {
		case AM: if (hh < 1 || hh > 12) return(-1);
			 return (60L * ((hh%12)*60L + mm)+ss);
		case PM: if (hh < 1 || hh > 12) return(-1);
			 return (60L * ((hh%12 +12)*60L + mm)+ss);
................................................................................

static char *lptr;

static int gd_lex()
{
	extern int gd_lval;
	int sign;
	char c;
	char *p;
	char idbuf[20];
	int pcnt;

	for (;;) {
		while (isspace(*lptr)) lptr++;

		if (isdigit(c = *lptr) || c == '-' || c == '+') {
................................................................................
static int lookup(id)
char *id;
{
#define gotit (gd_lval = i->value , i->type)
#define getid for(j = idvar, k = id; (*j++ = *k++) != '\0'; /* void */)

	char idvar[20];
	char *j, *k;
	struct table *i;
	int abbrev;

	getid;
	if (strlen(idvar) == 3) {
	    abbrev = 1;
	}
	else if (strlen(idvar) == 4 && idvar[3] == '.') {