version 1.1.1.2, 2012/05/29 12:26:49
|
version 1.1.1.5, 2014/06/15 16:12:54
|
Line 46
|
Line 46
|
#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 110 static MERIDIAN yyMeridian;
|
Line 110 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 389 YYSTYPE yylval;
|
Line 389 YYSTYPE yylval;
|
short *yyss; |
short *yyss; |
short *yysslim; |
short *yysslim; |
YYSTYPE *yyvs; |
YYSTYPE *yyvs; |
int yystacksize; | unsigned int yystacksize; |
#line 326 "getdate.y" |
#line 326 "getdate.y" |
|
|
/* Month and day table. */ |
/* Month and day table. */ |
Line 443 static TABLE const OtherTable[] = {
|
Line 443 static TABLE const OtherTable[] = {
|
{ "today", tMINUTE_UNIT, 0 }, |
{ "today", tMINUTE_UNIT, 0 }, |
{ "now", tMINUTE_UNIT, 0 }, |
{ "now", tMINUTE_UNIT, 0 }, |
{ "last", tUNUMBER, -1 }, |
{ "last", tUNUMBER, -1 }, |
{ "this", tMINUTE_UNIT, 0 }, | { "this", tUNUMBER, 0 }, |
{ "next", tUNUMBER, 2 }, |
{ "next", tUNUMBER, 2 }, |
{ "first", tUNUMBER, 1 }, |
{ "first", tUNUMBER, 1 }, |
/* { "second", tUNUMBER, 2 }, */ |
/* { "second", tUNUMBER, 2 }, */ |
Line 581 static TABLE const MilitaryTable[] = {
|
Line 581 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 626 ToSeconds(Hours, Minutes, Seconds, Meridian)
|
Line 621 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 654 Convert(Month, Day, Year, Hours, Minutes, Seconds, Mer
|
Line 643 Convert(Month, Day, Year, Hours, Minutes, Seconds, Mer
|
} |
} |
DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) |
DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) |
? 29 : 28; |
? 29 : 28; |
/* Checking for 2038 bogusly assumes that time_t is 32 bits. But | /* 32-bit time_t cannot represent years past 2038 */ |
I'm too lazy to try to check for time_t overflow in another way. */ | if (Year < EPOCH || (sizeof(time_t) == sizeof(int) && Year > 2038) |
if (Year < EPOCH || Year > 2038 | |
|| Month < 1 || Month > 12 |
|| Month < 1 || Month > 12 |
/* Lint fluff: "conversion from long may lose accuracy" */ |
/* Lint fluff: "conversion from long may lose accuracy" */ |
|| Day < 1 || Day > DaysInMonth[(int)--Month]) |
|| Day < 1 || Day > DaysInMonth[(int)--Month]) |
Line 672 Convert(Month, Day, Year, Hours, Minutes, Seconds, Mer
|
Line 660 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 710 RelativeDate(Start, DayOrdinal, DayNumber)
|
Line 701 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 720 RelativeMonth(Start, RelMonth)
|
Line 709 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 732 RelativeMonth(Start, RelMonth)
|
Line 722 RelativeMonth(Start, RelMonth)
|
|
|
|
|
static int |
static int |
LookupWord(buff) | LookupWord(char *buff) |
char *buff; | |
{ |
{ |
char *p; |
char *p; |
char *q; |
char *q; |
Line 839 LookupWord(buff)
|
Line 828 LookupWord(buff)
|
|
|
|
|
static int |
static int |
yylex() | yylex(void) |
{ |
{ |
char c; |
char c; |
char *p; |
char *p; |
Line 894 yylex()
|
Line 883 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 915 difftm (a, b)
|
Line 903 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 954 get_date(p)
|
Line 941 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 1002 get_date(p)
|
Line 988 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 1027 main(ac, av)
|
Line 1011 main(ac, av)
|
exit(0); |
exit(0); |
/* NOTREACHED */ |
/* NOTREACHED */ |
} |
} |
#endif /* defined(TEST) */ | #endif /* TEST */ |
#line 979 "getdate.c" | #line 963 "getdate.c" |
/* allocate initial stack or double stack size, up to YYMAXDEPTH */ |
/* allocate initial stack or double stack size, up to YYMAXDEPTH */ |
#if defined(__cplusplus) || defined(__STDC__) |
#if defined(__cplusplus) || defined(__STDC__) |
static int yygrowstack(void) |
static int yygrowstack(void) |
Line 1036 static int yygrowstack(void)
|
Line 1020 static int yygrowstack(void)
|
static int yygrowstack() |
static int yygrowstack() |
#endif |
#endif |
{ |
{ |
int newsize, i; | unsigned int newsize; |
| long sslen; |
short *newss; |
short *newss; |
YYSTYPE *newvs; |
YYSTYPE *newvs; |
|
|
Line 1046 static int yygrowstack()
|
Line 1031 static int yygrowstack()
|
return -1; |
return -1; |
else if ((newsize *= 2) > YYMAXDEPTH) |
else if ((newsize *= 2) > YYMAXDEPTH) |
newsize = YYMAXDEPTH; |
newsize = YYMAXDEPTH; |
i = yyssp - yyss; |
|
#ifdef SIZE_MAX |
#ifdef SIZE_MAX |
#define YY_SIZE_MAX SIZE_MAX |
#define YY_SIZE_MAX SIZE_MAX |
#else |
#else |
#define YY_SIZE_MAX 0x7fffffff | #ifdef __STDC__ |
| #define YY_SIZE_MAX 0xffffffffU |
| #else |
| #define YY_SIZE_MAX (unsigned int)0xffffffff |
#endif |
#endif |
if (!newsize || YY_SIZE_MAX / newsize < sizeof *newss) | #endif |
| if (YY_SIZE_MAX / newsize < sizeof *newss) |
goto bail; |
goto bail; |
|
sslen = yyssp - yyss; |
newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) : |
newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) : |
(short *)malloc(newsize * sizeof *newss); /* overflow check above */ |
(short *)malloc(newsize * sizeof *newss); /* overflow check above */ |
if (newss == NULL) |
if (newss == NULL) |
goto bail; |
goto bail; |
yyss = newss; |
yyss = newss; |
yyssp = newss + i; | yyssp = newss + sslen; |
if (!newsize || YY_SIZE_MAX / newsize < sizeof *newvs) | |
goto bail; | |
newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) : |
newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) : |
(YYSTYPE *)malloc(newsize * sizeof *newvs); /* overflow check above */ |
(YYSTYPE *)malloc(newsize * sizeof *newvs); /* overflow check above */ |
if (newvs == NULL) |
if (newvs == NULL) |
goto bail; |
goto bail; |
yyvs = newvs; |
yyvs = newvs; |
yyvsp = newvs + i; | yyvsp = newvs + sslen; |
yystacksize = newsize; |
yystacksize = newsize; |
yysslim = yyss + newsize - 1; |
yysslim = yyss + newsize - 1; |
return 0; |
return 0; |
Line 1523 case 41:
|
Line 1510 case 41:
|
yyval.Meridian = yyvsp[0].Meridian; |
yyval.Meridian = yyvsp[0].Meridian; |
} |
} |
break; |
break; |
#line 1474 "getdate.c" | #line 1461 "getdate.c" |
} |
} |
yyssp -= yym; |
yyssp -= yym; |
yystate = *yyssp; |
yystate = *yyssp; |