version 1.1.1.3, 2013/10/14 07:56:34
|
version 1.1.1.4, 2014/06/15 16:12:54
|
Line 34
|
Line 34
|
#ifdef HAVE_STRINGS_H |
#ifdef HAVE_STRINGS_H |
# include <strings.h> |
# include <strings.h> |
#endif /* HAVE_STRINGS_H */ |
#endif /* HAVE_STRINGS_H */ |
#if TIME_WITH_SYS_TIME | #ifdef TIME_WITH_SYS_TIME |
# include <time.h> |
# include <time.h> |
#endif |
#endif |
#include <ctype.h> |
#include <ctype.h> |
Line 98 static MERIDIAN yyMeridian;
|
Line 98 static MERIDIAN yyMeridian;
|
static time_t yyRelMonth; |
static time_t yyRelMonth; |
static time_t yyRelSeconds; |
static time_t yyRelSeconds; |
|
|
static int yyerror(char *s); | static int yyerror(const char *s); |
static int yylex(void); |
static int yylex(void); |
int yyparse(void); |
int yyparse(void); |
|
|
Line 513 static TABLE const MilitaryTable[] = {
|
Line 513 static TABLE const MilitaryTable[] = {
|
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
static int |
static int |
yyerror(s) | yyerror(const char *s) |
char *s; | |
{ |
{ |
return 0; |
return 0; |
} |
} |
|
|
|
|
static time_t |
static time_t |
ToSeconds(Hours, Minutes, Seconds, Meridian) | ToSeconds(time_t Hours, time_t Minutes, time_t Seconds, MERIDIAN Meridian) |
time_t Hours; | |
time_t Minutes; | |
time_t Seconds; | |
MERIDIAN Meridian; | |
{ |
{ |
if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) |
if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) |
return -1; |
return -1; |
Line 558 ToSeconds(Hours, Minutes, Seconds, Meridian)
|
Line 553 ToSeconds(Hours, Minutes, Seconds, Meridian)
|
* A number from 0 to 99, which means a year from 1900 to 1999, or |
* A number from 0 to 99, which means a year from 1900 to 1999, or |
* The actual year (>=100). */ |
* The actual year (>=100). */ |
static time_t |
static time_t |
Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode) | Convert(time_t Month, time_t Day, time_t Year, time_t Hours, time_t Minutes, |
time_t Month; | time_t Seconds, MERIDIAN Meridian, DSTMODE DSTmode) |
time_t Day; | |
time_t Year; | |
time_t Hours; | |
time_t Minutes; | |
time_t Seconds; | |
MERIDIAN Meridian; | |
DSTMODE DSTmode; | |
{ |
{ |
static int DaysInMonth[12] = { |
static int DaysInMonth[12] = { |
31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 |
31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 |
}; |
}; |
|
struct tm *tm; |
time_t tod; |
time_t tod; |
time_t Julian; |
time_t Julian; |
int i; |
int i; |
Line 603 Convert(Month, Day, Year, Hours, Minutes, Seconds, Mer
|
Line 592 Convert(Month, Day, Year, Hours, Minutes, Seconds, Mer
|
return -1; |
return -1; |
Julian += tod; |
Julian += tod; |
if (DSTmode == DSTon |
if (DSTmode == DSTon |
|| (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst)) | || (DSTmode == DSTmaybe && (tm = localtime(&Julian)) && tm->tm_isdst)) |
Julian -= 60 * 60; |
Julian -= 60 * 60; |
return Julian; |
return Julian; |
} |
} |
|
|
|
|
static time_t |
static time_t |
DSTcorrect(Start, Future) | DSTcorrect(time_t Start, time_t Future) |
time_t Start; | |
time_t Future; | |
{ |
{ |
|
struct tm *start_tm; |
|
struct tm *future_tm; |
time_t StartDay; |
time_t StartDay; |
time_t FutureDay; |
time_t FutureDay; |
|
|
StartDay = (localtime(&Start)->tm_hour + 1) % 24; | start_tm = localtime(&Start); |
FutureDay = (localtime(&Future)->tm_hour + 1) % 24; | future_tm = localtime(&Future); |
| if (!start_tm || !future_tm) |
| return -1; |
| |
| StartDay = (start_tm->tm_hour + 1) % 24; |
| FutureDay = (future_tm->tm_hour + 1) % 24; |
return (Future - Start) + (StartDay - FutureDay) * 60L * 60L; |
return (Future - Start) + (StartDay - FutureDay) * 60L * 60L; |
} |
} |
|
|
|
|
static time_t |
static time_t |
RelativeDate(Start, DayOrdinal, DayNumber) | RelativeDate(time_t Start, time_t DayOrdinal, time_t DayNumber) |
time_t Start; | |
time_t DayOrdinal; | |
time_t DayNumber; | |
{ |
{ |
struct tm *tm; |
struct tm *tm; |
time_t now; |
time_t now; |
|
|
now = Start; |
now = Start; |
tm = localtime(&now); | if (!(tm = localtime(&now))) |
| return -1; |
now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7); |
now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7); |
now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1); |
now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1); |
return DSTcorrect(Start, now); |
return DSTcorrect(Start, now); |
Line 641 RelativeDate(Start, DayOrdinal, DayNumber)
|
Line 633 RelativeDate(Start, DayOrdinal, DayNumber)
|
|
|
|
|
static time_t |
static time_t |
RelativeMonth(Start, RelMonth) | RelativeMonth(time_t Start, time_t RelMonth) |
time_t Start; | |
time_t RelMonth; | |
{ |
{ |
struct tm *tm; |
struct tm *tm; |
time_t Month; |
time_t Month; |
Line 651 RelativeMonth(Start, RelMonth)
|
Line 641 RelativeMonth(Start, RelMonth)
|
|
|
if (RelMonth == 0) |
if (RelMonth == 0) |
return 0; |
return 0; |
tm = localtime(&Start); | if (!(tm = localtime(&Start))) |
| return -1; |
Month = 12 * (tm->tm_year + 1900) + tm->tm_mon + RelMonth; |
Month = 12 * (tm->tm_year + 1900) + tm->tm_mon + RelMonth; |
Year = Month / 12; |
Year = Month / 12; |
Month = Month % 12 + 1; |
Month = Month % 12 + 1; |
Line 663 RelativeMonth(Start, RelMonth)
|
Line 654 RelativeMonth(Start, RelMonth)
|
|
|
|
|
static int |
static int |
LookupWord(buff) | LookupWord(char *buff) |
char *buff; | |
{ |
{ |
char *p; |
char *p; |
char *q; |
char *q; |
Line 770 LookupWord(buff)
|
Line 760 LookupWord(buff)
|
|
|
|
|
static int |
static int |
yylex() | yylex(void) |
{ |
{ |
char c; |
char c; |
char *p; |
char *p; |
Line 825 yylex()
|
Line 815 yylex()
|
|
|
/* Yield A - B, measured in seconds. */ |
/* Yield A - B, measured in seconds. */ |
static long |
static long |
difftm (a, b) | difftm(struct tm *a, struct tm *b) |
struct tm *a, *b; | |
{ |
{ |
int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); |
int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); |
int by = b->tm_year + (TM_YEAR_ORIGIN - 1); |
int by = b->tm_year + (TM_YEAR_ORIGIN - 1); |
Line 846 difftm (a, b)
|
Line 835 difftm (a, b)
|
} |
} |
|
|
time_t |
time_t |
get_date(p) | get_date(char *p) |
char *p; | |
{ |
{ |
struct tm *tm, *gmt, gmtbuf; |
struct tm *tm, *gmt, gmtbuf; |
time_t Start; |
time_t Start; |
Line 885 get_date(p)
|
Line 873 get_date(p)
|
if(tm->tm_isdst) |
if(tm->tm_isdst) |
timezone += 60; |
timezone += 60; |
|
|
tm = localtime(&now); |
|
yyYear = tm->tm_year + 1900; |
yyYear = tm->tm_year + 1900; |
yyMonth = tm->tm_mon + 1; |
yyMonth = tm->tm_mon + 1; |
yyDay = tm->tm_mday; |
yyDay = tm->tm_mday; |
Line 933 get_date(p)
|
Line 920 get_date(p)
|
} |
} |
|
|
|
|
#if defined(TEST) | #ifdef TEST |
|
|
/* ARGSUSED */ |
/* ARGSUSED */ |
int |
int |
main(ac, av) | main(int argc, char *argv[]) |
int ac; | |
char *av[]; | |
{ |
{ |
char buff[128]; |
char buff[128]; |
time_t d; |
time_t d; |
|
|
(void)printf("Enter date, or blank line to exit.\n\t> "); |
(void)printf("Enter date, or blank line to exit.\n\t> "); |
(void)fflush(stdout); |
(void)fflush(stdout); |
while (gets(buff) && buff[0]) { | while (fgets(buff, sizeof(buff), stdin) && buff[0]) { |
d = get_date(buff); |
d = get_date(buff); |
if (d == -1) |
if (d == -1) |
(void)printf("Bad format - couldn't convert.\n"); |
(void)printf("Bad format - couldn't convert.\n"); |
Line 958 main(ac, av)
|
Line 943 main(ac, av)
|
exit(0); |
exit(0); |
/* NOTREACHED */ |
/* NOTREACHED */ |
} |
} |
#endif /* defined(TEST) */ | #endif /* TEST */ |