10Sstevel@tonic-gate %{
20Sstevel@tonic-gate /*
3*1053Smaheshvs * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
4*1053Smaheshvs * Use is subject to license terms.
50Sstevel@tonic-gate */
60Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
70Sstevel@tonic-gate
80Sstevel@tonic-gate /* $OrigRevision: 2.1 $
90Sstevel@tonic-gate **
100Sstevel@tonic-gate ** Originally written by Steven M. Bellovin <smb@research.att.com> while
110Sstevel@tonic-gate ** at the University of North Carolina at Chapel Hill. Later tweaked by
120Sstevel@tonic-gate ** a couple of people on Usenet. Completely overhauled by Rich $alz
130Sstevel@tonic-gate ** <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
140Sstevel@tonic-gate ** send any email to Rich.
150Sstevel@tonic-gate **
160Sstevel@tonic-gate ** This grammar has eight shift/reduce conflicts.
170Sstevel@tonic-gate **
180Sstevel@tonic-gate ** This code is in the public domain and has no copyright.
190Sstevel@tonic-gate */
200Sstevel@tonic-gate /* SUPPRESS 287 on yaccpar_sccsid *//* Unusd static variable */
210Sstevel@tonic-gate /* SUPPRESS 288 on yyerrlab *//* Label unused */
220Sstevel@tonic-gate #include <stdio.h>
230Sstevel@tonic-gate #include <ctype.h>
240Sstevel@tonic-gate
250Sstevel@tonic-gate #include <sys/types.h>
260Sstevel@tonic-gate #define NEED_TZSET
270Sstevel@tonic-gate struct timeb {
280Sstevel@tonic-gate time_t time; /* Seconds since the epoch */
290Sstevel@tonic-gate unsigned short millitm; /* Field not used */
300Sstevel@tonic-gate short timezone;
310Sstevel@tonic-gate short dstflag; /* Field not used */
320Sstevel@tonic-gate };
330Sstevel@tonic-gate #include <time.h>
340Sstevel@tonic-gate
350Sstevel@tonic-gate #include <locale.h>
360Sstevel@tonic-gate #include <string.h>
370Sstevel@tonic-gate #include <stdlib.h>
380Sstevel@tonic-gate #include <note.h>
390Sstevel@tonic-gate #include <libintl.h>
400Sstevel@tonic-gate
410Sstevel@tonic-gate #if !defined(lint) && !defined(SABER)
420Sstevel@tonic-gate static char RCS[] =
430Sstevel@tonic-gate "$Header: /home/laramie/berliner/ws/backup/usr/src/cmd/backup/lib/getdate.y,v 1.5 1992/06/09 21:46:21 sam Exp $";
440Sstevel@tonic-gate #endif /* !defined(lint) && !defined(SABER) */
450Sstevel@tonic-gate
460Sstevel@tonic-gate
470Sstevel@tonic-gate #define EPOCH 1970
480Sstevel@tonic-gate #define HOURN(x) (x * 60)
490Sstevel@tonic-gate #define SECSPERDAY (24L * 60L * 60L)
500Sstevel@tonic-gate
510Sstevel@tonic-gate #define CHECK_TM(y) (((y) % 100) < 70 ? (y) + 2000 : (y) + 1900)
520Sstevel@tonic-gate
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate ** An entry in the lexical lookup table.
550Sstevel@tonic-gate */
560Sstevel@tonic-gate typedef struct _TABLE {
570Sstevel@tonic-gate char *name;
580Sstevel@tonic-gate int type;
590Sstevel@tonic-gate time_t value;
600Sstevel@tonic-gate } TABLE;
610Sstevel@tonic-gate
620Sstevel@tonic-gate
630Sstevel@tonic-gate /*
640Sstevel@tonic-gate ** Daylight-savings mode: on, off, or not yet known.
650Sstevel@tonic-gate */
660Sstevel@tonic-gate typedef enum _DSTMODE {
670Sstevel@tonic-gate DSTon, DSToff, DSTmaybe
680Sstevel@tonic-gate } DSTMODE;
690Sstevel@tonic-gate
700Sstevel@tonic-gate /*
710Sstevel@tonic-gate ** Meridian: am, pm, or 24-hour style.
720Sstevel@tonic-gate */
730Sstevel@tonic-gate typedef enum _MERIDIAN {
740Sstevel@tonic-gate MERam, MERpm, MER24
750Sstevel@tonic-gate } MERIDIAN;
760Sstevel@tonic-gate
770Sstevel@tonic-gate
780Sstevel@tonic-gate /*
790Sstevel@tonic-gate ** Global variables. We could get rid of most of these by using a good
800Sstevel@tonic-gate ** union as the yacc stack. (This routine was originally written before
810Sstevel@tonic-gate ** yacc had the %union construct.) Maybe someday; right now we only use
820Sstevel@tonic-gate ** the %union very rarely.
830Sstevel@tonic-gate */
840Sstevel@tonic-gate static char *yyInput;
850Sstevel@tonic-gate static DSTMODE yyDSTmode;
860Sstevel@tonic-gate static time_t yyDayOrdinal;
870Sstevel@tonic-gate static time_t yyDayNumber;
880Sstevel@tonic-gate static int yyHaveDate;
890Sstevel@tonic-gate static int yyHaveDay;
900Sstevel@tonic-gate static int yyHaveRel;
910Sstevel@tonic-gate static int yyHaveTime;
920Sstevel@tonic-gate static int yyHaveZone;
930Sstevel@tonic-gate static time_t yyTimezone;
940Sstevel@tonic-gate static time_t yyDay;
950Sstevel@tonic-gate static time_t yyHour;
960Sstevel@tonic-gate static time_t yyMinutes;
970Sstevel@tonic-gate static time_t yyMonth;
980Sstevel@tonic-gate static time_t yySeconds;
990Sstevel@tonic-gate static time_t yyYear;
1000Sstevel@tonic-gate static MERIDIAN yyMeridian;
1010Sstevel@tonic-gate static time_t yyRelMonth;
1020Sstevel@tonic-gate static time_t yyRelSeconds;
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate static char *domainname = "hsm_libdump"; /* for dgettext() */
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate #define yylex 1 /* suppress yacc's definition */
1070Sstevel@tonic-gate %}
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate %union {
1100Sstevel@tonic-gate time_t Number;
1110Sstevel@tonic-gate enum _MERIDIAN Meridian;
1120Sstevel@tonic-gate }
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate %token tAGO tDAY tDAYZONE tID tMERIDIAN tMINUTE_UNIT tMONTH tMONTH_UNIT
1150Sstevel@tonic-gate %token tSEC_UNIT tSNUMBER tUNUMBER tZONE
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate %type <Number> tDAY tDAYZONE tMINUTE_UNIT tMONTH tMONTH_UNIT
1180Sstevel@tonic-gate %type <Number> tSEC_UNIT tSNUMBER tUNUMBER tZONE
1190Sstevel@tonic-gate %type <Meridian> tMERIDIAN o_merid
1200Sstevel@tonic-gate
1210Sstevel@tonic-gate %%
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate spec : /* NULL */
1240Sstevel@tonic-gate | spec item
1250Sstevel@tonic-gate ;
1260Sstevel@tonic-gate
1270Sstevel@tonic-gate item : time {
1280Sstevel@tonic-gate yyHaveTime++;
1290Sstevel@tonic-gate }
1300Sstevel@tonic-gate | zone {
1310Sstevel@tonic-gate yyHaveZone++;
1320Sstevel@tonic-gate }
1330Sstevel@tonic-gate | date {
1340Sstevel@tonic-gate yyHaveDate++;
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate | day {
1370Sstevel@tonic-gate yyHaveDay++;
1380Sstevel@tonic-gate }
1390Sstevel@tonic-gate | rel {
1400Sstevel@tonic-gate yyHaveRel++;
1410Sstevel@tonic-gate }
1420Sstevel@tonic-gate | number
1430Sstevel@tonic-gate ;
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate time : tUNUMBER tMERIDIAN {
1460Sstevel@tonic-gate yyHour = $1;
1470Sstevel@tonic-gate yyMinutes = 0;
1480Sstevel@tonic-gate yySeconds = 0;
1490Sstevel@tonic-gate yyMeridian = $2;
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate | tUNUMBER ':' tUNUMBER o_merid {
1520Sstevel@tonic-gate yyHour = $1;
1530Sstevel@tonic-gate yyMinutes = $3;
1540Sstevel@tonic-gate yySeconds = 0;
1550Sstevel@tonic-gate yyMeridian = $4;
1560Sstevel@tonic-gate }
1570Sstevel@tonic-gate | tUNUMBER ':' tUNUMBER tSNUMBER {
1580Sstevel@tonic-gate yyHour = $1;
1590Sstevel@tonic-gate yyMinutes = $3;
1600Sstevel@tonic-gate yyMeridian = MER24;
1610Sstevel@tonic-gate yyDSTmode = DSToff;
1620Sstevel@tonic-gate yyTimezone = - ($4 % 100 + ($4 / 100) * 60);
1630Sstevel@tonic-gate }
1640Sstevel@tonic-gate | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid {
1650Sstevel@tonic-gate yyHour = $1;
1660Sstevel@tonic-gate yyMinutes = $3;
1670Sstevel@tonic-gate yySeconds = $5;
1680Sstevel@tonic-gate yyMeridian = $6;
1690Sstevel@tonic-gate }
1700Sstevel@tonic-gate | tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER {
1710Sstevel@tonic-gate yyHour = $1;
1720Sstevel@tonic-gate yyMinutes = $3;
1730Sstevel@tonic-gate yySeconds = $5;
1740Sstevel@tonic-gate yyMeridian = MER24;
1750Sstevel@tonic-gate yyDSTmode = DSToff;
1760Sstevel@tonic-gate yyTimezone = - ($6 % 100 + ($6 / 100) * 60);
1770Sstevel@tonic-gate }
1780Sstevel@tonic-gate ;
1790Sstevel@tonic-gate
1800Sstevel@tonic-gate zone : tZONE {
1810Sstevel@tonic-gate yyTimezone = $1;
1820Sstevel@tonic-gate yyDSTmode = DSToff;
1830Sstevel@tonic-gate }
1840Sstevel@tonic-gate | tDAYZONE {
1850Sstevel@tonic-gate yyTimezone = $1;
1860Sstevel@tonic-gate yyDSTmode = DSTon;
1870Sstevel@tonic-gate }
1880Sstevel@tonic-gate ;
1890Sstevel@tonic-gate
1900Sstevel@tonic-gate day : tDAY {
1910Sstevel@tonic-gate yyDayOrdinal = 1;
1920Sstevel@tonic-gate yyDayNumber = $1;
1930Sstevel@tonic-gate }
1940Sstevel@tonic-gate | tDAY ',' {
1950Sstevel@tonic-gate yyDayOrdinal = 1;
1960Sstevel@tonic-gate yyDayNumber = $1;
1970Sstevel@tonic-gate }
1980Sstevel@tonic-gate | tUNUMBER tDAY {
1990Sstevel@tonic-gate yyDayOrdinal = $1;
2000Sstevel@tonic-gate yyDayNumber = $2;
2010Sstevel@tonic-gate }
2020Sstevel@tonic-gate ;
2030Sstevel@tonic-gate
2040Sstevel@tonic-gate date : tUNUMBER '/' tUNUMBER {
2050Sstevel@tonic-gate yyMonth = $1;
2060Sstevel@tonic-gate yyDay = $3;
2070Sstevel@tonic-gate }
2080Sstevel@tonic-gate | tUNUMBER '/' tUNUMBER '/' tUNUMBER {
2090Sstevel@tonic-gate yyMonth = $1;
2100Sstevel@tonic-gate yyDay = $3;
2110Sstevel@tonic-gate yyYear = $5;
2120Sstevel@tonic-gate }
2130Sstevel@tonic-gate | tMONTH tUNUMBER {
2140Sstevel@tonic-gate yyMonth = $1;
2150Sstevel@tonic-gate yyDay = $2;
2160Sstevel@tonic-gate }
2170Sstevel@tonic-gate | tMONTH tUNUMBER ',' tUNUMBER {
2180Sstevel@tonic-gate yyMonth = $1;
2190Sstevel@tonic-gate yyDay = $2;
2200Sstevel@tonic-gate yyYear = $4;
2210Sstevel@tonic-gate }
2220Sstevel@tonic-gate | tUNUMBER tMONTH {
2230Sstevel@tonic-gate yyMonth = $2;
2240Sstevel@tonic-gate yyDay = $1;
2250Sstevel@tonic-gate }
2260Sstevel@tonic-gate | tUNUMBER tMONTH tUNUMBER {
2270Sstevel@tonic-gate yyMonth = $2;
2280Sstevel@tonic-gate yyDay = $1;
2290Sstevel@tonic-gate yyYear = $3;
2300Sstevel@tonic-gate }
2310Sstevel@tonic-gate ;
2320Sstevel@tonic-gate
2330Sstevel@tonic-gate rel : relunit tAGO {
2340Sstevel@tonic-gate yyRelSeconds = -yyRelSeconds;
2350Sstevel@tonic-gate yyRelMonth = -yyRelMonth;
2360Sstevel@tonic-gate }
2370Sstevel@tonic-gate | relunit
2380Sstevel@tonic-gate ;
2390Sstevel@tonic-gate
2400Sstevel@tonic-gate relunit : tUNUMBER tMINUTE_UNIT {
2410Sstevel@tonic-gate yyRelSeconds += $1 * $2 * 60L;
2420Sstevel@tonic-gate }
2430Sstevel@tonic-gate | tSNUMBER tMINUTE_UNIT {
2440Sstevel@tonic-gate yyRelSeconds += $1 * $2 * 60L;
2450Sstevel@tonic-gate }
2460Sstevel@tonic-gate | tMINUTE_UNIT {
2470Sstevel@tonic-gate yyRelSeconds += $1 * 60L;
2480Sstevel@tonic-gate }
2490Sstevel@tonic-gate | tSNUMBER tSEC_UNIT {
2500Sstevel@tonic-gate yyRelSeconds += $1;
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate | tUNUMBER tSEC_UNIT {
2530Sstevel@tonic-gate yyRelSeconds += $1;
2540Sstevel@tonic-gate }
2550Sstevel@tonic-gate | tSEC_UNIT {
2560Sstevel@tonic-gate yyRelSeconds++;
2570Sstevel@tonic-gate }
2580Sstevel@tonic-gate | tSNUMBER tMONTH_UNIT {
2590Sstevel@tonic-gate yyRelMonth += $1 * $2;
2600Sstevel@tonic-gate }
2610Sstevel@tonic-gate | tUNUMBER tMONTH_UNIT {
2620Sstevel@tonic-gate yyRelMonth += $1 * $2;
2630Sstevel@tonic-gate }
2640Sstevel@tonic-gate | tMONTH_UNIT {
2650Sstevel@tonic-gate yyRelMonth += $1;
2660Sstevel@tonic-gate }
2670Sstevel@tonic-gate ;
2680Sstevel@tonic-gate
2690Sstevel@tonic-gate number : tUNUMBER {
2700Sstevel@tonic-gate if (yyHaveTime && yyHaveDate && !yyHaveRel)
2710Sstevel@tonic-gate yyYear = $1;
2720Sstevel@tonic-gate else {
2730Sstevel@tonic-gate yyHaveTime++;
2740Sstevel@tonic-gate if ($1 < 100) {
2750Sstevel@tonic-gate yyHour = $1;
2760Sstevel@tonic-gate yyMinutes = 0;
2770Sstevel@tonic-gate }
2780Sstevel@tonic-gate else {
2790Sstevel@tonic-gate yyHour = $1 / 100;
2800Sstevel@tonic-gate yyMinutes = $1 % 100;
2810Sstevel@tonic-gate }
2820Sstevel@tonic-gate yySeconds = 0;
2830Sstevel@tonic-gate yyMeridian = MER24;
2840Sstevel@tonic-gate }
2850Sstevel@tonic-gate }
2860Sstevel@tonic-gate ;
2870Sstevel@tonic-gate
2880Sstevel@tonic-gate o_merid : /* NULL */ {
2890Sstevel@tonic-gate $$ = MER24;
2900Sstevel@tonic-gate }
2910Sstevel@tonic-gate | tMERIDIAN {
2920Sstevel@tonic-gate $$ = $1;
2930Sstevel@tonic-gate }
2940Sstevel@tonic-gate ;
2950Sstevel@tonic-gate
2960Sstevel@tonic-gate %%
2970Sstevel@tonic-gate
2980Sstevel@tonic-gate /* Month and day table. */
2990Sstevel@tonic-gate static TABLE MonthDayTable[] = {
3000Sstevel@tonic-gate { "january", tMONTH, 1 },
3010Sstevel@tonic-gate { "february", tMONTH, 2 },
3020Sstevel@tonic-gate { "march", tMONTH, 3 },
3030Sstevel@tonic-gate { "april", tMONTH, 4 },
3040Sstevel@tonic-gate { "may", tMONTH, 5 },
3050Sstevel@tonic-gate { "june", tMONTH, 6 },
3060Sstevel@tonic-gate { "july", tMONTH, 7 },
3070Sstevel@tonic-gate { "august", tMONTH, 8 },
3080Sstevel@tonic-gate { "september", tMONTH, 9 },
3090Sstevel@tonic-gate { "sept", tMONTH, 9 },
3100Sstevel@tonic-gate { "october", tMONTH, 10 },
3110Sstevel@tonic-gate { "november", tMONTH, 11 },
3120Sstevel@tonic-gate { "december", tMONTH, 12 },
3130Sstevel@tonic-gate { "sunday", tDAY, 0 },
3140Sstevel@tonic-gate { "monday", tDAY, 1 },
3150Sstevel@tonic-gate { "tuesday", tDAY, 2 },
3160Sstevel@tonic-gate { "tues", tDAY, 2 },
3170Sstevel@tonic-gate { "wednesday", tDAY, 3 },
3180Sstevel@tonic-gate { "wednes", tDAY, 3 },
3190Sstevel@tonic-gate { "thursday", tDAY, 4 },
3200Sstevel@tonic-gate { "thur", tDAY, 4 },
3210Sstevel@tonic-gate { "thurs", tDAY, 4 },
3220Sstevel@tonic-gate { "friday", tDAY, 5 },
3230Sstevel@tonic-gate { "saturday", tDAY, 6 },
3240Sstevel@tonic-gate { NULL }
3250Sstevel@tonic-gate };
3260Sstevel@tonic-gate
3270Sstevel@tonic-gate /* Time units table. */
3280Sstevel@tonic-gate static TABLE UnitsTable[] = {
3290Sstevel@tonic-gate { "year", tMONTH_UNIT, 12 },
3300Sstevel@tonic-gate { "month", tMONTH_UNIT, 1 },
3310Sstevel@tonic-gate { "fortnight", tMINUTE_UNIT, 14 * 24 * 60 },
3320Sstevel@tonic-gate { "week", tMINUTE_UNIT, 7 * 24 * 60 },
3330Sstevel@tonic-gate { "day", tMINUTE_UNIT, 1 * 24 * 60 },
3340Sstevel@tonic-gate { "hour", tMINUTE_UNIT, 60 },
3350Sstevel@tonic-gate { "minute", tMINUTE_UNIT, 1 },
3360Sstevel@tonic-gate { "min", tMINUTE_UNIT, 1 },
3370Sstevel@tonic-gate { "second", tSEC_UNIT, 1 },
3380Sstevel@tonic-gate { "sec", tSEC_UNIT, 1 },
3390Sstevel@tonic-gate { NULL }
3400Sstevel@tonic-gate };
3410Sstevel@tonic-gate
3420Sstevel@tonic-gate /* Assorted relative-time words. */
3430Sstevel@tonic-gate static TABLE OtherTable[] = {
3440Sstevel@tonic-gate { "tomorrow", tMINUTE_UNIT, 1 * 24 * 60 },
3450Sstevel@tonic-gate { "yesterday", tMINUTE_UNIT, -1 * 24 * 60 },
3460Sstevel@tonic-gate { "today", tMINUTE_UNIT, 0 },
3470Sstevel@tonic-gate { "now", tMINUTE_UNIT, 0 },
3480Sstevel@tonic-gate { "last", tUNUMBER, -1 },
3490Sstevel@tonic-gate { "this", tMINUTE_UNIT, 0 },
3500Sstevel@tonic-gate { "next", tUNUMBER, 2 },
3510Sstevel@tonic-gate { "first", tUNUMBER, 1 },
3520Sstevel@tonic-gate /* { "second", tUNUMBER, 2 }, */
3530Sstevel@tonic-gate { "third", tUNUMBER, 3 },
3540Sstevel@tonic-gate { "fourth", tUNUMBER, 4 },
3550Sstevel@tonic-gate { "fifth", tUNUMBER, 5 },
3560Sstevel@tonic-gate { "sixth", tUNUMBER, 6 },
3570Sstevel@tonic-gate { "seventh", tUNUMBER, 7 },
3580Sstevel@tonic-gate { "eighth", tUNUMBER, 8 },
3590Sstevel@tonic-gate { "ninth", tUNUMBER, 9 },
3600Sstevel@tonic-gate { "tenth", tUNUMBER, 10 },
3610Sstevel@tonic-gate { "eleventh", tUNUMBER, 11 },
3620Sstevel@tonic-gate { "twelfth", tUNUMBER, 12 },
3630Sstevel@tonic-gate { "ago", tAGO, 1 },
3640Sstevel@tonic-gate { NULL }
3650Sstevel@tonic-gate };
3660Sstevel@tonic-gate
3670Sstevel@tonic-gate /* The timezone table. */
3680Sstevel@tonic-gate static TABLE TimezoneTable[] = {
3690Sstevel@tonic-gate { "gmt", tZONE, HOURN( 0) }, /* Greenwich Mean */
3700Sstevel@tonic-gate { "ut", tZONE, HOURN( 0) }, /* Universal (Coordinated) */
3710Sstevel@tonic-gate { "utc", tZONE, HOURN( 0) },
3720Sstevel@tonic-gate { "wet", tZONE, HOURN( 0) }, /* Western European */
3730Sstevel@tonic-gate { "bst", tDAYZONE, HOURN( 0) }, /* British Summer */
3740Sstevel@tonic-gate { "wat", tZONE, HOURN( 1) }, /* West Africa */
3750Sstevel@tonic-gate { "at", tZONE, HOURN( 2) }, /* Azores */
3760Sstevel@tonic-gate #if 0
3770Sstevel@tonic-gate /* For completeness. BST is also British Summer, and GST is
3780Sstevel@tonic-gate * also Guam Standard. */
3790Sstevel@tonic-gate { "bst", tZONE, HOURN( 3) }, /* Brazil Standard */
3800Sstevel@tonic-gate { "gst", tZONE, HOURN( 3) }, /* Greenland Standard */
3810Sstevel@tonic-gate #endif
3820Sstevel@tonic-gate { "nft", tZONE, HOURN(3.5) }, /* Newfoundland */
3830Sstevel@tonic-gate { "nst", tZONE, HOURN(3.5) }, /* Newfoundland Standard */
3840Sstevel@tonic-gate { "ndt", tDAYZONE, HOURN(3.5) }, /* Newfoundland Daylight */
3850Sstevel@tonic-gate { "ast", tZONE, HOURN( 4) }, /* Atlantic Standard */
3860Sstevel@tonic-gate { "adt", tDAYZONE, HOURN( 4) }, /* Atlantic Daylight */
3870Sstevel@tonic-gate { "est", tZONE, HOURN( 5) }, /* Eastern Standard */
3880Sstevel@tonic-gate { "edt", tDAYZONE, HOURN( 5) }, /* Eastern Daylight */
3890Sstevel@tonic-gate { "cst", tZONE, HOURN( 6) }, /* Central Standard */
3900Sstevel@tonic-gate { "cdt", tDAYZONE, HOURN( 6) }, /* Central Daylight */
3910Sstevel@tonic-gate { "mst", tZONE, HOURN( 7) }, /* Mountain Standard */
3920Sstevel@tonic-gate { "mdt", tDAYZONE, HOURN( 7) }, /* Mountain Daylight */
3930Sstevel@tonic-gate { "pst", tZONE, HOURN( 8) }, /* Pacific Standard */
3940Sstevel@tonic-gate { "pdt", tDAYZONE, HOURN( 8) }, /* Pacific Daylight */
3950Sstevel@tonic-gate { "yst", tZONE, HOURN( 9) }, /* Yukon Standard */
3960Sstevel@tonic-gate { "ydt", tDAYZONE, HOURN( 9) }, /* Yukon Daylight */
3970Sstevel@tonic-gate { "hst", tZONE, HOURN(10) }, /* Hawaii Standard */
3980Sstevel@tonic-gate { "hdt", tDAYZONE, HOURN(10) }, /* Hawaii Daylight */
3990Sstevel@tonic-gate { "cat", tZONE, HOURN(10) }, /* Central Alaska */
4000Sstevel@tonic-gate { "ahst", tZONE, HOURN(10) }, /* Alaska-Hawaii Standard */
4010Sstevel@tonic-gate { "nt", tZONE, HOURN(11) }, /* Nome */
4020Sstevel@tonic-gate { "idlw", tZONE, HOURN(12) }, /* International Date Line West */
4030Sstevel@tonic-gate { "cet", tZONE, -HOURN(1) }, /* Central European */
4040Sstevel@tonic-gate { "met", tZONE, -HOURN(1) }, /* Middle European */
4050Sstevel@tonic-gate { "mewt", tZONE, -HOURN(1) }, /* Middle European Winter */
4060Sstevel@tonic-gate { "mest", tDAYZONE, -HOURN(1) }, /* Middle European Summer */
4070Sstevel@tonic-gate { "swt", tZONE, -HOURN(1) }, /* Swedish Winter */
4080Sstevel@tonic-gate { "sst", tDAYZONE, -HOURN(1) }, /* Swedish Summer */
4090Sstevel@tonic-gate { "fwt", tZONE, -HOURN(1) }, /* French Winter */
4100Sstevel@tonic-gate { "fst", tDAYZONE, -HOURN(1) }, /* French Summer */
4110Sstevel@tonic-gate { "eet", tZONE, -HOURN(2) }, /* Eastern Europe, USSR Zone 1 */
4120Sstevel@tonic-gate { "bt", tZONE, -HOURN(3) }, /* Baghdad, USSR Zone 2 */
4130Sstevel@tonic-gate { "it", tZONE, -HOURN(3.5) },/* Iran */
4140Sstevel@tonic-gate { "zp4", tZONE, -HOURN(4) }, /* USSR Zone 3 */
4150Sstevel@tonic-gate { "zp5", tZONE, -HOURN(5) }, /* USSR Zone 4 */
4160Sstevel@tonic-gate { "ist", tZONE, -HOURN(5.5) },/* Indian Standard */
4170Sstevel@tonic-gate { "zp6", tZONE, -HOURN(6) }, /* USSR Zone 5 */
4180Sstevel@tonic-gate #if 0
4190Sstevel@tonic-gate /* For completeness. NST is also Newfoundland Stanard, nad SST is
4200Sstevel@tonic-gate * also Swedish Summer. */
4210Sstevel@tonic-gate { "nst", tZONE, -HOURN(6.5) },/* North Sumatra */
4220Sstevel@tonic-gate { "sst", tZONE, -HOURN(7) }, /* South Sumatra, USSR Zone 6 */
4230Sstevel@tonic-gate #endif /* 0 */
4240Sstevel@tonic-gate { "wast", tZONE, -HOURN(7) }, /* West Australian Standard */
4250Sstevel@tonic-gate { "wadt", tDAYZONE, -HOURN(7) }, /* West Australian Daylight */
4260Sstevel@tonic-gate { "jt", tZONE, -HOURN(7.5) },/* Java (3pm in Cronusland!) */
4270Sstevel@tonic-gate { "cct", tZONE, -HOURN(8) }, /* China Coast, USSR Zone 7 */
4280Sstevel@tonic-gate { "jst", tZONE, -HOURN(9) }, /* Japan Standard, USSR Zone 8 */
4290Sstevel@tonic-gate { "cast", tZONE, -HOURN(9.5) },/* Central Australian Standard */
4300Sstevel@tonic-gate { "cadt", tDAYZONE, -HOURN(9.5) },/* Central Australian Daylight */
4310Sstevel@tonic-gate { "east", tZONE, -HOURN(10) }, /* Eastern Australian Standard */
4320Sstevel@tonic-gate { "eadt", tDAYZONE, -HOURN(10) }, /* Eastern Australian Daylight */
4330Sstevel@tonic-gate { "gst", tZONE, -HOURN(10) }, /* Guam Standard, USSR Zone 9 */
4340Sstevel@tonic-gate { "nzt", tZONE, -HOURN(12) }, /* New Zealand */
4350Sstevel@tonic-gate { "nzst", tZONE, -HOURN(12) }, /* New Zealand Standard */
4360Sstevel@tonic-gate { "nzdt", tDAYZONE, -HOURN(12) }, /* New Zealand Daylight */
4370Sstevel@tonic-gate { "idle", tZONE, -HOURN(12) }, /* International Date Line East */
4380Sstevel@tonic-gate { NULL }
4390Sstevel@tonic-gate };
4400Sstevel@tonic-gate
4410Sstevel@tonic-gate /* Military timezone table. */
4420Sstevel@tonic-gate static TABLE MilitaryTable[] = {
4430Sstevel@tonic-gate { "a", tZONE, HOURN( 1) },
4440Sstevel@tonic-gate { "b", tZONE, HOURN( 2) },
4450Sstevel@tonic-gate { "c", tZONE, HOURN( 3) },
4460Sstevel@tonic-gate { "d", tZONE, HOURN( 4) },
4470Sstevel@tonic-gate { "e", tZONE, HOURN( 5) },
4480Sstevel@tonic-gate { "f", tZONE, HOURN( 6) },
4490Sstevel@tonic-gate { "g", tZONE, HOURN( 7) },
4500Sstevel@tonic-gate { "h", tZONE, HOURN( 8) },
4510Sstevel@tonic-gate { "i", tZONE, HOURN( 9) },
4520Sstevel@tonic-gate { "k", tZONE, HOURN( 10) },
4530Sstevel@tonic-gate { "l", tZONE, HOURN( 11) },
4540Sstevel@tonic-gate { "m", tZONE, HOURN( 12) },
4550Sstevel@tonic-gate { "n", tZONE, HOURN(- 1) },
4560Sstevel@tonic-gate { "o", tZONE, HOURN(- 2) },
4570Sstevel@tonic-gate { "p", tZONE, HOURN(- 3) },
4580Sstevel@tonic-gate { "q", tZONE, HOURN(- 4) },
4590Sstevel@tonic-gate { "r", tZONE, HOURN(- 5) },
4600Sstevel@tonic-gate { "s", tZONE, HOURN(- 6) },
4610Sstevel@tonic-gate { "t", tZONE, HOURN(- 7) },
4620Sstevel@tonic-gate { "u", tZONE, HOURN(- 8) },
4630Sstevel@tonic-gate { "v", tZONE, HOURN(- 9) },
4640Sstevel@tonic-gate { "w", tZONE, HOURN(-10) },
4650Sstevel@tonic-gate { "x", tZONE, HOURN(-11) },
4660Sstevel@tonic-gate { "y", tZONE, HOURN(-12) },
4670Sstevel@tonic-gate { "z", tZONE, HOURN( 0) },
4680Sstevel@tonic-gate { NULL }
4690Sstevel@tonic-gate };
4700Sstevel@tonic-gate
4710Sstevel@tonic-gate
4720Sstevel@tonic-gate
4730Sstevel@tonic-gate
4740Sstevel@tonic-gate /* ARGSUSED */
4750Sstevel@tonic-gate static void
yyerror(s)4760Sstevel@tonic-gate yyerror(s)
4770Sstevel@tonic-gate char *s;
4780Sstevel@tonic-gate {
4790Sstevel@tonic-gate }
4800Sstevel@tonic-gate
4810Sstevel@tonic-gate
4820Sstevel@tonic-gate static time_t
ToSeconds(Hours,Minutes,Seconds,Meridian)4830Sstevel@tonic-gate ToSeconds(Hours, Minutes, Seconds, Meridian)
4840Sstevel@tonic-gate time_t Hours;
4850Sstevel@tonic-gate time_t Minutes;
4860Sstevel@tonic-gate time_t Seconds;
4870Sstevel@tonic-gate MERIDIAN Meridian;
4880Sstevel@tonic-gate {
4890Sstevel@tonic-gate if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59)
4900Sstevel@tonic-gate return -1;
4910Sstevel@tonic-gate switch (Meridian) {
4920Sstevel@tonic-gate case MER24:
4930Sstevel@tonic-gate if (Hours < 0 || Hours > 23)
4940Sstevel@tonic-gate return -1;
4950Sstevel@tonic-gate return (Hours * 60L + Minutes) * 60L + Seconds;
4960Sstevel@tonic-gate case MERam:
4970Sstevel@tonic-gate if (Hours < 1 || Hours > 12)
4980Sstevel@tonic-gate return -1;
4990Sstevel@tonic-gate if (Hours != 12)
5000Sstevel@tonic-gate return (Hours * 60L + Minutes) * 60L + Seconds;
5010Sstevel@tonic-gate else
5020Sstevel@tonic-gate return Minutes * 60L + Seconds;
5030Sstevel@tonic-gate case MERpm:
5040Sstevel@tonic-gate if (Hours < 1 || Hours > 12)
5050Sstevel@tonic-gate return -1;
5060Sstevel@tonic-gate if (Hours != 12)
5070Sstevel@tonic-gate return ((Hours + 12) * 60L + Minutes) * 60L + Seconds;
5080Sstevel@tonic-gate else
5090Sstevel@tonic-gate return (720L + Minutes) * 60L + Seconds;
5100Sstevel@tonic-gate }
5110Sstevel@tonic-gate /* NOTREACHED */
512*1053Smaheshvs return (-1);
5130Sstevel@tonic-gate }
5140Sstevel@tonic-gate
5150Sstevel@tonic-gate
5160Sstevel@tonic-gate static time_t
Convert(Month,Day,Year,Hours,Minutes,Seconds,Meridian,DSTmode)5170Sstevel@tonic-gate Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode)
5180Sstevel@tonic-gate time_t Month;
5190Sstevel@tonic-gate time_t Day;
5200Sstevel@tonic-gate time_t Year;
5210Sstevel@tonic-gate time_t Hours;
5220Sstevel@tonic-gate time_t Minutes;
5230Sstevel@tonic-gate time_t Seconds;
5240Sstevel@tonic-gate MERIDIAN Meridian;
5250Sstevel@tonic-gate DSTMODE DSTmode;
5260Sstevel@tonic-gate {
5270Sstevel@tonic-gate static int DaysInMonth[12] = {
5280Sstevel@tonic-gate 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
5290Sstevel@tonic-gate };
5300Sstevel@tonic-gate time_t tod;
5310Sstevel@tonic-gate time_t Julian;
5320Sstevel@tonic-gate time_t i;
5330Sstevel@tonic-gate
5340Sstevel@tonic-gate if (Year < 0)
5350Sstevel@tonic-gate Year = -Year;
5360Sstevel@tonic-gate if (Year < 138)
5370Sstevel@tonic-gate Year += 1900;
5380Sstevel@tonic-gate DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0)
5390Sstevel@tonic-gate ? 29 : 28;
5400Sstevel@tonic-gate if (Year < EPOCH || Year > 2037
5410Sstevel@tonic-gate || Month < 1 || Month > 12
5420Sstevel@tonic-gate /* LINTED Month is a time_t so intermediate results aren't truncated */
5430Sstevel@tonic-gate || Day < 1 || Day > DaysInMonth[(int)--Month])
5440Sstevel@tonic-gate return -1;
5450Sstevel@tonic-gate
5460Sstevel@tonic-gate for (Julian = Day - 1, i = 0; i < Month; i++)
5470Sstevel@tonic-gate Julian += DaysInMonth[i];
5480Sstevel@tonic-gate for (i = EPOCH; i < Year; i++)
5490Sstevel@tonic-gate Julian += 365 + (i % 4 == 0);
5500Sstevel@tonic-gate Julian *= SECSPERDAY;
5510Sstevel@tonic-gate Julian += yyTimezone * 60L;
5520Sstevel@tonic-gate if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0)
5530Sstevel@tonic-gate return -1;
5540Sstevel@tonic-gate Julian += tod;
5550Sstevel@tonic-gate if (DSTmode == DSTon
5560Sstevel@tonic-gate || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst))
5570Sstevel@tonic-gate Julian -= 60 * 60;
5580Sstevel@tonic-gate return Julian;
5590Sstevel@tonic-gate }
5600Sstevel@tonic-gate
5610Sstevel@tonic-gate
5620Sstevel@tonic-gate static time_t
DSTcorrect(Start,Future)5630Sstevel@tonic-gate DSTcorrect(Start, Future)
5640Sstevel@tonic-gate time_t Start;
5650Sstevel@tonic-gate time_t Future;
5660Sstevel@tonic-gate {
5670Sstevel@tonic-gate time_t StartDay;
5680Sstevel@tonic-gate time_t FutureDay;
5690Sstevel@tonic-gate
5700Sstevel@tonic-gate StartDay = (localtime(&Start)->tm_hour + 1) % 24;
5710Sstevel@tonic-gate FutureDay = (localtime(&Future)->tm_hour + 1) % 24;
5720Sstevel@tonic-gate return (Future - Start) + (StartDay - FutureDay) * 60L * 60L;
5730Sstevel@tonic-gate }
5740Sstevel@tonic-gate
5750Sstevel@tonic-gate
5760Sstevel@tonic-gate static time_t
RelativeDate(Start,DayOrdinal,DayNumber)5770Sstevel@tonic-gate RelativeDate(Start, DayOrdinal, DayNumber)
5780Sstevel@tonic-gate time_t Start;
5790Sstevel@tonic-gate time_t DayOrdinal;
5800Sstevel@tonic-gate time_t DayNumber;
5810Sstevel@tonic-gate {
5820Sstevel@tonic-gate struct tm *tm;
5830Sstevel@tonic-gate time_t now;
5840Sstevel@tonic-gate
5850Sstevel@tonic-gate now = Start;
5860Sstevel@tonic-gate tm = localtime(&now);
5870Sstevel@tonic-gate now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7);
5880Sstevel@tonic-gate now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1);
5890Sstevel@tonic-gate return DSTcorrect(Start, now);
5900Sstevel@tonic-gate }
5910Sstevel@tonic-gate
5920Sstevel@tonic-gate
5930Sstevel@tonic-gate static time_t
RelativeMonth(Start,RelMonth)5940Sstevel@tonic-gate RelativeMonth(Start, RelMonth)
5950Sstevel@tonic-gate time_t Start;
5960Sstevel@tonic-gate time_t RelMonth;
5970Sstevel@tonic-gate {
5980Sstevel@tonic-gate struct tm *tm;
5990Sstevel@tonic-gate time_t Month;
6000Sstevel@tonic-gate time_t Year;
6010Sstevel@tonic-gate
6020Sstevel@tonic-gate if (RelMonth == 0)
6030Sstevel@tonic-gate return 0;
6040Sstevel@tonic-gate tm = localtime(&Start);
6050Sstevel@tonic-gate Month = 12 * tm->tm_year + tm->tm_mon + RelMonth;
6060Sstevel@tonic-gate Year = Month / 12;
6070Sstevel@tonic-gate Month = Month % 12 + 1;
6080Sstevel@tonic-gate return DSTcorrect(Start,
6090Sstevel@tonic-gate Convert(Month, (time_t)tm->tm_mday, Year,
6100Sstevel@tonic-gate (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec,
6110Sstevel@tonic-gate MER24, DSTmaybe));
6120Sstevel@tonic-gate }
6130Sstevel@tonic-gate
6140Sstevel@tonic-gate
6150Sstevel@tonic-gate static int
LookupWord(buff)6160Sstevel@tonic-gate LookupWord(buff)
6170Sstevel@tonic-gate char *buff;
6180Sstevel@tonic-gate {
6190Sstevel@tonic-gate char *p;
6200Sstevel@tonic-gate char *q;
6210Sstevel@tonic-gate TABLE *tp;
6220Sstevel@tonic-gate uint_t i;
6230Sstevel@tonic-gate int abbrev;
6240Sstevel@tonic-gate
6250Sstevel@tonic-gate /* Make it lowercase. */
6260Sstevel@tonic-gate for (p = buff; *p; p++)
6270Sstevel@tonic-gate if (isupper((u_char)*p))
6280Sstevel@tonic-gate *p = tolower(*p);
6290Sstevel@tonic-gate
6300Sstevel@tonic-gate if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) {
6310Sstevel@tonic-gate yylval.Meridian = MERam;
6320Sstevel@tonic-gate return tMERIDIAN;
6330Sstevel@tonic-gate }
6340Sstevel@tonic-gate if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) {
6350Sstevel@tonic-gate yylval.Meridian = MERpm;
6360Sstevel@tonic-gate return tMERIDIAN;
6370Sstevel@tonic-gate }
6380Sstevel@tonic-gate
6390Sstevel@tonic-gate /* See if we have an abbreviation for a month. */
6400Sstevel@tonic-gate if (strlen(buff) == 3)
6410Sstevel@tonic-gate abbrev = 1;
6420Sstevel@tonic-gate else if (strlen(buff) == 4 && buff[3] == '.') {
6430Sstevel@tonic-gate abbrev = 1;
6440Sstevel@tonic-gate buff[3] = '\0';
6450Sstevel@tonic-gate }
6460Sstevel@tonic-gate else
6470Sstevel@tonic-gate abbrev = 0;
6480Sstevel@tonic-gate
6490Sstevel@tonic-gate for (tp = MonthDayTable; tp->name; tp++) {
6500Sstevel@tonic-gate if (abbrev) {
6510Sstevel@tonic-gate if (strncmp(buff, tp->name, 3) == 0) {
6520Sstevel@tonic-gate yylval.Number = tp->value;
6530Sstevel@tonic-gate return tp->type;
6540Sstevel@tonic-gate }
6550Sstevel@tonic-gate }
6560Sstevel@tonic-gate else if (strcmp(buff, tp->name) == 0) {
6570Sstevel@tonic-gate yylval.Number = tp->value;
6580Sstevel@tonic-gate return tp->type;
6590Sstevel@tonic-gate }
6600Sstevel@tonic-gate }
6610Sstevel@tonic-gate
6620Sstevel@tonic-gate for (tp = TimezoneTable; tp->name; tp++)
6630Sstevel@tonic-gate if (strcmp(buff, tp->name) == 0) {
6640Sstevel@tonic-gate yylval.Number = tp->value;
6650Sstevel@tonic-gate return tp->type;
6660Sstevel@tonic-gate }
6670Sstevel@tonic-gate
6680Sstevel@tonic-gate for (tp = UnitsTable; tp->name; tp++)
6690Sstevel@tonic-gate if (strcmp(buff, tp->name) == 0) {
6700Sstevel@tonic-gate yylval.Number = tp->value;
6710Sstevel@tonic-gate return tp->type;
6720Sstevel@tonic-gate }
6730Sstevel@tonic-gate
6740Sstevel@tonic-gate /* Strip off any plural and try the units table again. */
6750Sstevel@tonic-gate i = strlen(buff) - 1;
6760Sstevel@tonic-gate if (buff[i] == 's') {
6770Sstevel@tonic-gate buff[i] = '\0';
6780Sstevel@tonic-gate for (tp = UnitsTable; tp->name; tp++)
6790Sstevel@tonic-gate if (strcmp(buff, tp->name) == 0) {
6800Sstevel@tonic-gate yylval.Number = tp->value;
6810Sstevel@tonic-gate return tp->type;
6820Sstevel@tonic-gate }
6830Sstevel@tonic-gate }
6840Sstevel@tonic-gate
6850Sstevel@tonic-gate for (tp = OtherTable; tp->name; tp++)
6860Sstevel@tonic-gate if (strcmp(buff, tp->name) == 0) {
6870Sstevel@tonic-gate yylval.Number = tp->value;
6880Sstevel@tonic-gate return tp->type;
6890Sstevel@tonic-gate }
6900Sstevel@tonic-gate
6910Sstevel@tonic-gate /* Military timezones. */
6920Sstevel@tonic-gate if (buff[1] == '\0' && isalpha((u_char)*buff)) {
6930Sstevel@tonic-gate for (tp = MilitaryTable; tp->name; tp++)
6940Sstevel@tonic-gate if (strcmp(buff, tp->name) == 0) {
6950Sstevel@tonic-gate yylval.Number = tp->value;
6960Sstevel@tonic-gate return tp->type;
6970Sstevel@tonic-gate }
6980Sstevel@tonic-gate }
6990Sstevel@tonic-gate
7000Sstevel@tonic-gate /* Drop out any periods and try the timezone table again. */
7010Sstevel@tonic-gate for (i = 0, p = q = buff; *q; q++)
7020Sstevel@tonic-gate if (*q != '.')
7030Sstevel@tonic-gate *p++ = *q;
7040Sstevel@tonic-gate else
7050Sstevel@tonic-gate i++;
7060Sstevel@tonic-gate *p = '\0';
7070Sstevel@tonic-gate if (i)
7080Sstevel@tonic-gate for (tp = TimezoneTable; tp->name; tp++)
7090Sstevel@tonic-gate if (strcmp(buff, tp->name) == 0) {
7100Sstevel@tonic-gate yylval.Number = tp->value;
7110Sstevel@tonic-gate return tp->type;
7120Sstevel@tonic-gate }
7130Sstevel@tonic-gate
7140Sstevel@tonic-gate return tID;
7150Sstevel@tonic-gate }
7160Sstevel@tonic-gate
7170Sstevel@tonic-gate void
pdateerr(p)7180Sstevel@tonic-gate pdateerr(p)
7190Sstevel@tonic-gate char *p;
7200Sstevel@tonic-gate {
7210Sstevel@tonic-gate char *name = "DATEMSK"; /* env variable for date format */
7220Sstevel@tonic-gate char *value;
7230Sstevel@tonic-gate char fmt[256], line[256];
7240Sstevel@tonic-gate FILE *fp;
7250Sstevel@tonic-gate time_t now;
7260Sstevel@tonic-gate struct tm *tm;
7270Sstevel@tonic-gate
7280Sstevel@tonic-gate value = getenv(name);
7290Sstevel@tonic-gate if (value == (char *)0) {
7300Sstevel@tonic-gate fprintf(stderr,
7310Sstevel@tonic-gate dgettext(domainname, "%s: Environment variable %s not set\n"),
7320Sstevel@tonic-gate p, name);
7330Sstevel@tonic-gate return;
7340Sstevel@tonic-gate }
7350Sstevel@tonic-gate switch (getdate_err) {
7360Sstevel@tonic-gate case 0:
7370Sstevel@tonic-gate default:
7380Sstevel@tonic-gate fprintf(stderr,
7390Sstevel@tonic-gate dgettext(domainname, "%s: Unkown getdate() error\n"), p);
7400Sstevel@tonic-gate break;
7410Sstevel@tonic-gate case 1:
7420Sstevel@tonic-gate fprintf(stderr,
7430Sstevel@tonic-gate dgettext(domainname, "%s: %s null or undefined\n"), p, name);
7440Sstevel@tonic-gate break;
7450Sstevel@tonic-gate case 2:
7460Sstevel@tonic-gate fprintf(stderr, dgettext(domainname,
7470Sstevel@tonic-gate "%s: Cannot read template file %s\n"), p, value);
7480Sstevel@tonic-gate break;
7490Sstevel@tonic-gate case 3:
7500Sstevel@tonic-gate fprintf(stderr, dgettext(domainname,
7510Sstevel@tonic-gate "%s: Failed to get file status information\n"), p);
7520Sstevel@tonic-gate break;
7530Sstevel@tonic-gate case 4:
7540Sstevel@tonic-gate fprintf(stderr, dgettext(domainname,
7550Sstevel@tonic-gate "%s: Template file %s not a regular file\n"), p, value);
7560Sstevel@tonic-gate break;
7570Sstevel@tonic-gate case 5:
7580Sstevel@tonic-gate fprintf(stderr, dgettext(domainname,
7590Sstevel@tonic-gate "%s: Error reading template file %s\n"), p, value);
7600Sstevel@tonic-gate break;
7610Sstevel@tonic-gate case 6:
7620Sstevel@tonic-gate fprintf(stderr, dgettext(domainname,
7630Sstevel@tonic-gate "%s: %s failed\n"), p, "malloc()");
7640Sstevel@tonic-gate break;
7650Sstevel@tonic-gate case 7:
7660Sstevel@tonic-gate fprintf(stderr, dgettext(domainname,
7670Sstevel@tonic-gate "%s: Bad date/time format\n"), p);
7680Sstevel@tonic-gate fp = fopen(value, "r");
7690Sstevel@tonic-gate if (fp == (FILE *)0)
7700Sstevel@tonic-gate break;
7710Sstevel@tonic-gate now = time((time_t *)0);
7720Sstevel@tonic-gate tm = localtime(&now);
7730Sstevel@tonic-gate fprintf(stderr, dgettext(domainname,
7740Sstevel@tonic-gate "The following are examples of valid formats:\n"));
7750Sstevel@tonic-gate while (fgets(fmt, sizeof (fmt), fp)) {
7760Sstevel@tonic-gate if (strchr(fmt, '%') == (char *)0)
7770Sstevel@tonic-gate continue;
7780Sstevel@tonic-gate fprintf(stderr, " ");
7790Sstevel@tonic-gate (void) strftime(line, sizeof (line), fmt, tm);
7800Sstevel@tonic-gate fprintf(stderr, "%s", line);
7810Sstevel@tonic-gate }
7820Sstevel@tonic-gate (void) fclose(fp);
7830Sstevel@tonic-gate break;
7840Sstevel@tonic-gate case 8:
7850Sstevel@tonic-gate (void) fprintf(stderr, dgettext(domainname,
7860Sstevel@tonic-gate "%s: Invalid date specification\n"), p);
7870Sstevel@tonic-gate break;
7880Sstevel@tonic-gate }
7890Sstevel@tonic-gate }
7900Sstevel@tonic-gate
7910Sstevel@tonic-gate #undef yylex
7920Sstevel@tonic-gate static int
yylex()7930Sstevel@tonic-gate yylex()
7940Sstevel@tonic-gate {
7950Sstevel@tonic-gate char c;
7960Sstevel@tonic-gate char *p;
7970Sstevel@tonic-gate char buff[20];
7980Sstevel@tonic-gate int Count;
7990Sstevel@tonic-gate int sign;
8000Sstevel@tonic-gate
8010Sstevel@tonic-gate for ( ; ; ) {
8020Sstevel@tonic-gate while (isspace((u_char)*yyInput))
8030Sstevel@tonic-gate yyInput++;
8040Sstevel@tonic-gate
8050Sstevel@tonic-gate if (isdigit((u_char)(c = *yyInput)) || c == '-' || c == '+') {
8060Sstevel@tonic-gate if (c == '-' || c == '+') {
8070Sstevel@tonic-gate sign = c == '-' ? -1 : 1;
8080Sstevel@tonic-gate if (!isdigit((u_char)*++yyInput))
8090Sstevel@tonic-gate /* skip the '-' sign */
8100Sstevel@tonic-gate continue;
8110Sstevel@tonic-gate }
8120Sstevel@tonic-gate else
8130Sstevel@tonic-gate sign = 0;
8140Sstevel@tonic-gate yylval.Number = 0;
8150Sstevel@tonic-gate while (isdigit((u_char)(c = *yyInput++))) {
8160Sstevel@tonic-gate int n;
8170Sstevel@tonic-gate char digit = c;
8180Sstevel@tonic-gate (void) sscanf(&digit, "%1d", &n);
8190Sstevel@tonic-gate yylval.Number = 10 * yylval.Number + n;
8200Sstevel@tonic-gate }
8210Sstevel@tonic-gate yyInput--;
8220Sstevel@tonic-gate if (sign < 0)
8230Sstevel@tonic-gate yylval.Number = -yylval.Number;
8240Sstevel@tonic-gate return sign ? tSNUMBER : tUNUMBER;
8250Sstevel@tonic-gate }
8260Sstevel@tonic-gate if (isalpha((u_char)c)) {
8270Sstevel@tonic-gate for (p = buff; isalpha((u_char)(c = *yyInput++)) || c == '.'; )
8280Sstevel@tonic-gate if (p < &buff[sizeof (buff) - 1])
8290Sstevel@tonic-gate *p++ = c;
8300Sstevel@tonic-gate *p = '\0';
8310Sstevel@tonic-gate yyInput--;
8320Sstevel@tonic-gate return LookupWord(buff);
8330Sstevel@tonic-gate }
8340Sstevel@tonic-gate if (c != '(')
8350Sstevel@tonic-gate return *yyInput++;
8360Sstevel@tonic-gate Count = 0;
8370Sstevel@tonic-gate do {
8380Sstevel@tonic-gate c = *yyInput++;
8390Sstevel@tonic-gate if (c == '\0')
8400Sstevel@tonic-gate return c;
8410Sstevel@tonic-gate if (c == '(')
8420Sstevel@tonic-gate Count++;
8430Sstevel@tonic-gate else if (c == ')')
8440Sstevel@tonic-gate Count--;
8450Sstevel@tonic-gate } while (Count > 0);
8460Sstevel@tonic-gate }
8470Sstevel@tonic-gate }
8480Sstevel@tonic-gate
8490Sstevel@tonic-gate
8500Sstevel@tonic-gate time_t
getreldate(p,now)8510Sstevel@tonic-gate getreldate(p, now)
8520Sstevel@tonic-gate char *p;
8530Sstevel@tonic-gate struct timeb *now;
8540Sstevel@tonic-gate {
8550Sstevel@tonic-gate struct tm *tm;
8560Sstevel@tonic-gate struct timeb ftz;
8570Sstevel@tonic-gate time_t Start;
8580Sstevel@tonic-gate time_t tod;
8590Sstevel@tonic-gate
8600Sstevel@tonic-gate if (strcmp(setlocale(LC_TIME, NULL), "C")) {
8610Sstevel@tonic-gate static char localedate[24];
8620Sstevel@tonic-gate struct tm ltm;
8630Sstevel@tonic-gate
8640Sstevel@tonic-gate tm = getdate(p);
8650Sstevel@tonic-gate if (getdate_err == 1 /* NODATEMASK */) {
8660Sstevel@tonic-gate char buffy[BUFSIZ];
8670Sstevel@tonic-gate time_t current;
8680Sstevel@tonic-gate
8690Sstevel@tonic-gate printf(gettext("environment variable %s not set\n"), "DATEMSK");
8700Sstevel@tonic-gate do {
8710Sstevel@tonic-gate time(¤t);
8720Sstevel@tonic-gate tm = localtime(¤t);
8730Sstevel@tonic-gate memcpy(<m, tm, sizeof(ltm));
8740Sstevel@tonic-gate tm = <m;
8750Sstevel@tonic-gate
8760Sstevel@tonic-gate (void) fputs(gettext("Enter date as mmddhhmm[yy]: "), stdout);
8770Sstevel@tonic-gate (void) fflush(stdout);
8780Sstevel@tonic-gate if (fgets(buffy, sizeof (buffy), stdin) == NULL) {
8790Sstevel@tonic-gate (void) printf(gettext("Encountered EOF on stdin\n"));
8800Sstevel@tonic-gate return(-1);
8810Sstevel@tonic-gate }
8820Sstevel@tonic-gate } while (sscanf(buffy, "%2d%2d%2d%2d%2d",
8830Sstevel@tonic-gate &(tm->tm_mon), &(tm->tm_mday), &(tm->tm_hour),
8840Sstevel@tonic-gate &(tm->tm_min), &(tm->tm_year)) < 4);
8850Sstevel@tonic-gate
8860Sstevel@tonic-gate (tm->tm_mon)--;
8870Sstevel@tonic-gate } else if (tm == NULL)
8880Sstevel@tonic-gate return(-1);
8890Sstevel@tonic-gate
8900Sstevel@tonic-gate (void)sprintf(localedate, "%d:%2.2d %d/%d %d",
8910Sstevel@tonic-gate tm->tm_hour, tm->tm_min, tm->tm_mon + 1,
8920Sstevel@tonic-gate tm->tm_mday, CHECK_TM(tm->tm_year));
8930Sstevel@tonic-gate p = localedate;
8940Sstevel@tonic-gate }
8950Sstevel@tonic-gate
8960Sstevel@tonic-gate yyInput = p;
8970Sstevel@tonic-gate if (now == NULL) {
8980Sstevel@tonic-gate now = &ftz;
8990Sstevel@tonic-gate (void) time(&ftz.time);
9000Sstevel@tonic-gate /* Set the timezone global. */
9010Sstevel@tonic-gate tzset();
9020Sstevel@tonic-gate /* LINTED timezone is time_t so intermediate results aren't truncated */
9030Sstevel@tonic-gate ftz.timezone = (int) timezone / 60;
9040Sstevel@tonic-gate }
9050Sstevel@tonic-gate
9060Sstevel@tonic-gate tm = localtime(&now->time);
9070Sstevel@tonic-gate yyYear = tm->tm_year;
9080Sstevel@tonic-gate yyMonth = tm->tm_mon + 1;
9090Sstevel@tonic-gate yyDay = tm->tm_mday;
9100Sstevel@tonic-gate yyTimezone = now->timezone;
9110Sstevel@tonic-gate yyDSTmode = DSTmaybe;
9120Sstevel@tonic-gate yyHour = tm->tm_hour;
9130Sstevel@tonic-gate yyMinutes = tm->tm_min;
9140Sstevel@tonic-gate yySeconds = tm->tm_sec;
9150Sstevel@tonic-gate yyMeridian = MER24;
9160Sstevel@tonic-gate yyRelSeconds = 0;
9170Sstevel@tonic-gate yyRelMonth = 0;
9180Sstevel@tonic-gate yyHaveDate = 0;
9190Sstevel@tonic-gate yyHaveDay = 0;
9200Sstevel@tonic-gate yyHaveRel = 0;
9210Sstevel@tonic-gate yyHaveTime = 0;
9220Sstevel@tonic-gate yyHaveZone = 0;
9230Sstevel@tonic-gate
9240Sstevel@tonic-gate if (yyparse()
9250Sstevel@tonic-gate || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1)
9260Sstevel@tonic-gate return -1;
9270Sstevel@tonic-gate
9280Sstevel@tonic-gate if (yyHaveDate || yyHaveTime || yyHaveDay) {
9290Sstevel@tonic-gate Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds,
9300Sstevel@tonic-gate yyMeridian, yyDSTmode);
9310Sstevel@tonic-gate if (Start < 0)
9320Sstevel@tonic-gate return -1;
9330Sstevel@tonic-gate }
9340Sstevel@tonic-gate else {
9350Sstevel@tonic-gate Start = now->time;
9360Sstevel@tonic-gate if (!yyHaveRel)
9370Sstevel@tonic-gate Start -= ((tm->tm_hour * 60L) + tm->tm_min * 60L) + tm->tm_sec;
9380Sstevel@tonic-gate }
9390Sstevel@tonic-gate
9400Sstevel@tonic-gate Start += yyRelSeconds;
9410Sstevel@tonic-gate Start += RelativeMonth(Start, yyRelMonth);
9420Sstevel@tonic-gate
9430Sstevel@tonic-gate if (yyHaveDay && !yyHaveDate) {
9440Sstevel@tonic-gate tod = RelativeDate(Start, yyDayOrdinal, yyDayNumber);
9450Sstevel@tonic-gate Start += tod;
9460Sstevel@tonic-gate }
9470Sstevel@tonic-gate
9480Sstevel@tonic-gate /* Have to do *something* with a legitimate -1 so it's distinguishable
9490Sstevel@tonic-gate * from the error return value. (Alternately could set errno on error.) */
9500Sstevel@tonic-gate return Start == -1 ? 0 : Start;
9510Sstevel@tonic-gate }
9520Sstevel@tonic-gate
9530Sstevel@tonic-gate #if defined(TEST)
9540Sstevel@tonic-gate
9550Sstevel@tonic-gate /* ARGSUSED */
main(ac,av)9560Sstevel@tonic-gate main(ac, av)
9570Sstevel@tonic-gate int ac;
9580Sstevel@tonic-gate char *av[];
9590Sstevel@tonic-gate {
9600Sstevel@tonic-gate char buff[128];
9610Sstevel@tonic-gate time_t d;
9620Sstevel@tonic-gate
9630Sstevel@tonic-gate (void) setlocale(LC_ALL, "");
9640Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
9650Sstevel@tonic-gate #define TEXT_DOMAIN "SYS_TEST"
9660Sstevel@tonic-gate #endif
9670Sstevel@tonic-gate (void) textdomain(TEXT_DOMAIN);
9680Sstevel@tonic-gate
9690Sstevel@tonic-gate (void) printf(gettext("Enter date, or blank line to exit.\n\t> "));
9700Sstevel@tonic-gate (void) fflush(stdout);
9710Sstevel@tonic-gate while (gets(buff) && buff[0]) {
9720Sstevel@tonic-gate d = getreldate(buff, (struct timeb *)NULL);
9730Sstevel@tonic-gate if (d == -1)
9740Sstevel@tonic-gate (void) printf(gettext("Bad format - couldn't convert.\n"));
9750Sstevel@tonic-gate else {
9760Sstevel@tonic-gate (void) cftime(buff, "%c\n", &d);
9770Sstevel@tonic-gate (void) printf("%s", buff);
9780Sstevel@tonic-gate }
9790Sstevel@tonic-gate (void) printf("\t> ");
9800Sstevel@tonic-gate (void) fflush(stdout);
9810Sstevel@tonic-gate }
9820Sstevel@tonic-gate exit(0);
9830Sstevel@tonic-gate /* NOTREACHED */
9840Sstevel@tonic-gate }
9850Sstevel@tonic-gate #endif /* defined(TEST) */
986