3 static char elsieid
[] = "@(#)zic.c 7.62";
4 #endif /* !defined NOID */
5 #endif /* !defined lint */
11 #include "sys/stat.h" /* for umask manifest constants */
12 #endif /* defined unix */
15 ** On some ancient hosts, predicates like `isspace(C)' are defined
16 ** only if isascii(C) || C == EOF. Modern hosts obey the C Standard,
17 ** which says they are defined only if C == ((unsigned char) C) || C == EOF.
18 ** Neither the C Standard nor Posix require that `isascii' exist.
19 ** For portability, we check both ancient and modern requirements.
20 ** If isascii is not defined, the isascii check succeeds trivially.
28 const char * r_filename
;
32 int r_loyear
; /* for example, 1986 */
33 int r_hiyear
; /* for example, 1986 */
34 const char * r_yrtype
;
36 int r_month
; /* 0..11 */
38 int r_dycode
; /* see below */
42 long r_tod
; /* time from midnight */
43 int r_todisstd
; /* above is standard time if TRUE */
44 /* or wall clock time if FALSE */
45 int r_todisgmt
; /* above is GMT if TRUE */
46 /* or local time if FALSE */
47 long r_stdoff
; /* offset from standard time */
48 const char * r_abbrvar
; /* variable part of abbreviation */
50 int r_todo
; /* a rule to do (used in outzone) */
51 time_t r_temp
; /* used in outzone */
55 ** r_dycode r_dayofmonth r_wday
58 #define DC_DOM 0 /* 1..31 */ /* unused */
59 #define DC_DOWGEQ 1 /* 1..31 */ /* 0..6 (Sun..Sat) */
60 #define DC_DOWLEQ 2 /* 1..31 */ /* 0..6 (Sun..Sat) */
63 const char * z_filename
;
69 const char * z_format
;
73 struct rule
* z_rules
;
76 struct rule z_untilrule
;
80 extern int getopt
P((int argc
, char * const argv
[],
81 const char * options
));
82 extern char * icatalloc
P((char * old
, const char * new));
83 extern char * icpyalloc
P((const char * string
));
84 extern void ifree
P((char * p
));
85 extern char * imalloc
P((int n
));
86 extern void * irealloc
P((void * old
, int n
));
87 extern int link
P((const char * fromname
, const char * toname
));
90 extern char * scheck
P((const char * string
, const char * format
));
92 static void addtt
P((time_t starttime
, int type
));
93 static int addtype
P((long gmtoff
, const char * abbr
, int isdst
,
94 int ttisstd
, int ttisgmt
));
95 static void leapadd
P((time_t t
, int positive
, int rolling
, int count
));
96 static void adjleap
P((void));
97 static void associate
P((void));
98 static int ciequal
P((const char * ap
, const char * bp
));
99 static void convert
P((long val
, char * buf
));
100 static void dolink
P((const char * fromfile
, const char * tofile
));
101 static void doabbr
P((char * abbr
, const char * format
,
102 const char * letters
, int isdst
));
103 static void eat
P((const char * name
, int num
));
104 static void eats
P((const char * name
, int num
,
105 const char * rname
, int rnum
));
106 static long eitol
P((int i
));
107 static void error
P((const char * message
));
108 static char ** getfields
P((char * buf
));
109 static long gethms
P((const char * string
, const char * errstrng
,
111 static void infile
P((const char * filename
));
112 static void inleap
P((char ** fields
, int nfields
));
113 static void inlink
P((char ** fields
, int nfields
));
114 static void inrule
P((char ** fields
, int nfields
));
115 static int inzcont
P((char ** fields
, int nfields
));
116 static int inzone
P((char ** fields
, int nfields
));
117 static int inzsub
P((char ** fields
, int nfields
, int iscont
));
118 static int itsabbr
P((const char * abbr
, const char * word
));
119 static int itsdir
P((const char * name
));
120 static int lowerit
P((int c
));
121 static char * memcheck
P((char * tocheck
));
122 static int mkdirs
P((char * filename
));
123 static void newabbr
P((const char * abbr
));
124 static long oadd
P((long t1
, long t2
));
125 static void outzone
P((const struct zone
* zp
, int ntzones
));
126 static void puttzcode
P((long code
, FILE * fp
));
127 static int rcomp
P((const void * leftp
, const void * rightp
));
128 static time_t rpytime
P((const struct rule
* rp
, int wantedy
));
129 static void rulesub
P((struct rule
* rp
,
130 const char * loyearp
, const char * hiyearp
,
131 const char * typep
, const char * monthp
,
132 const char * dayp
, const char * timep
));
133 static void setboundaries
P((void));
134 static time_t tadd
P((time_t t1
, long t2
));
135 static void usage
P((void));
136 static void writezone
P((const char * name
));
137 static int yearistype
P((int year
, const char * type
));
140 static char * strerror
P((int));
141 #endif /* !HAVE_STRERROR */
145 static const char * filename
;
148 static time_t max_time
;
150 static time_t min_time
;
153 static const char * rfilename
;
155 static const char * progname
;
169 ** Which fields are which on a Zone line.
177 #define ZF_TILMONTH 6
180 #define ZONE_MINFIELDS 5
181 #define ZONE_MAXFIELDS 9
184 ** Which fields are which on a Zone continuation line.
190 #define ZFC_TILYEAR 3
191 #define ZFC_TILMONTH 4
193 #define ZFC_TILTIME 6
194 #define ZONEC_MINFIELDS 3
195 #define ZONEC_MAXFIELDS 7
198 ** Which files are which on a Rule line.
210 #define RULE_FIELDS 10
213 ** Which fields are which on a Link line.
218 #define LINK_FIELDS 3
221 ** Which fields are which on a Leap line.
230 #define LEAP_FIELDS 7
240 static struct rule
* rules
;
241 static int nrules
; /* number of rules */
243 static struct zone
* zones
;
244 static int nzones
; /* number of zones */
247 const char * l_filename
;
253 static struct link
* links
;
261 static struct lookup
const * byword
P((const char * string
,
262 const struct lookup
* lp
));
264 static struct lookup
const line_codes
[] = {
272 static struct lookup
const mon_names
[] = {
273 { "January", TM_JANUARY
},
274 { "February", TM_FEBRUARY
},
275 { "March", TM_MARCH
},
276 { "April", TM_APRIL
},
280 { "August", TM_AUGUST
},
281 { "September", TM_SEPTEMBER
},
282 { "October", TM_OCTOBER
},
283 { "November", TM_NOVEMBER
},
284 { "December", TM_DECEMBER
},
288 static struct lookup
const wday_names
[] = {
289 { "Sunday", TM_SUNDAY
},
290 { "Monday", TM_MONDAY
},
291 { "Tuesday", TM_TUESDAY
},
292 { "Wednesday", TM_WEDNESDAY
},
293 { "Thursday", TM_THURSDAY
},
294 { "Friday", TM_FRIDAY
},
295 { "Saturday", TM_SATURDAY
},
299 static struct lookup
const lasts
[] = {
300 { "last-Sunday", TM_SUNDAY
},
301 { "last-Monday", TM_MONDAY
},
302 { "last-Tuesday", TM_TUESDAY
},
303 { "last-Wednesday", TM_WEDNESDAY
},
304 { "last-Thursday", TM_THURSDAY
},
305 { "last-Friday", TM_FRIDAY
},
306 { "last-Saturday", TM_SATURDAY
},
310 static struct lookup
const begin_years
[] = {
311 { "minimum", YR_MINIMUM
},
312 { "maximum", YR_MAXIMUM
},
316 static struct lookup
const end_years
[] = {
317 { "minimum", YR_MINIMUM
},
318 { "maximum", YR_MAXIMUM
},
323 static struct lookup
const leap_types
[] = {
325 { "Stationary", FALSE
},
329 static const int len_months
[2][MONSPERYEAR
] = {
330 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
331 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
334 static const int len_years
[2] = {
335 DAYSPERNYEAR
, DAYSPERLYEAR
338 static time_t ats
[TZ_MAX_TIMES
];
339 static unsigned char types
[TZ_MAX_TIMES
];
340 static long gmtoffs
[TZ_MAX_TYPES
];
341 static char isdsts
[TZ_MAX_TYPES
];
342 static unsigned char abbrinds
[TZ_MAX_TYPES
];
343 static char ttisstds
[TZ_MAX_TYPES
];
344 static char ttisgmts
[TZ_MAX_TYPES
];
345 static char chars
[TZ_MAX_CHARS
];
346 static time_t trans
[TZ_MAX_LEAPS
];
347 static long corr
[TZ_MAX_LEAPS
];
348 static char roll
[TZ_MAX_LEAPS
];
351 ** Memory allocation.
359 const char *e
= strerror(errno
);
360 (void) fprintf(stderr
, _("%s: Memory exhausted: %s\n"),
362 (void) exit(EXIT_FAILURE
);
367 #define emalloc(size) memcheck(imalloc(size))
368 #define erealloc(ptr, size) memcheck(irealloc((ptr), (size)))
369 #define ecpyalloc(ptr) memcheck(icpyalloc(ptr))
370 #define ecatalloc(oldp, newp) memcheck(icatalloc((oldp), (newp)))
381 extern char *sys_errlist
[];
384 if (errnum
> 0 && errnum
<= sys_nerr
)
385 return sys_errlist
[errnum
];
386 return "Unknown system error";
388 #endif /* ! HAVE_STRERROR */
391 eats(name
, num
, rname
, rnum
)
392 const char * const name
;
394 const char * const rname
;
405 const char * const name
;
408 eats(name
, num
, (char *) NULL
, -1);
413 const char * const string
;
416 ** Match the format of "cc" to allow sh users to
417 ** zic ... 2>&1 | error -t "*" -v
420 (void) fprintf(stderr
, _("\"%s\", line %d: %s"),
421 filename
, linenum
, string
);
422 if (rfilename
!= NULL
)
423 (void) fprintf(stderr
, _(" (rule from \"%s\", line %d)"),
424 rfilename
, rlinenum
);
425 (void) fprintf(stderr
, "\n");
432 (void) fprintf(stderr
, _("%s: usage is %s \
433 [ -s ] [ -v ] [ -l localtime ] [ -p posixrules ] [ -d directory ]\n\
434 \t[ -L leapseconds ] [ -y yearistype ] [ filename ... ]\n"),
436 (void) exit(EXIT_FAILURE
);
439 static const char * psxrules
;
440 static const char * lcltime
;
441 static const char * directory
;
442 static const char * leapsec
;
443 static const char * yitcommand
;
444 static int sflag
= FALSE
;
456 (void) umask(umask(S_IWGRP
| S_IWOTH
) | (S_IWGRP
| S_IWOTH
));
457 #endif /* defined unix */
459 (void) setlocale(LC_MESSAGES
, "");
461 (void) bindtextdomain(TZ_DOMAIN
, TZ_DOMAINDIR
);
462 #endif /* defined TEXTDOMAINDIR */
463 (void) textdomain(TZ_DOMAIN
);
464 #endif /* HAVE_GETTEXT - 0 */
466 while ((c
= getopt(argc
, argv
, "d:l:p:L:vsy:")) != EOF
)
471 if (directory
== NULL
)
474 (void) fprintf(stderr
,
475 _("%s: More than one -d option specified\n"),
477 (void) exit(EXIT_FAILURE
);
484 (void) fprintf(stderr
,
485 _("%s: More than one -l option specified\n"),
487 (void) exit(EXIT_FAILURE
);
491 if (psxrules
== NULL
)
494 (void) fprintf(stderr
,
495 _("%s: More than one -p option specified\n"),
497 (void) exit(EXIT_FAILURE
);
501 if (yitcommand
== NULL
)
504 (void) fprintf(stderr
,
505 _("%s: More than one -y option specified\n"),
507 (void) exit(EXIT_FAILURE
);
514 (void) fprintf(stderr
,
515 _("%s: More than one -L option specified\n"),
517 (void) exit(EXIT_FAILURE
);
527 if (optind
== argc
- 1 && strcmp(argv
[optind
], "=") == 0)
528 usage(); /* usage message by request */
529 if (directory
== NULL
)
531 if (yitcommand
== NULL
)
532 yitcommand
= "yearistype";
536 if (optind
< argc
&& leapsec
!= NULL
) {
541 for (i
= optind
; i
< argc
; ++i
)
544 (void) exit(EXIT_FAILURE
);
546 for (i
= 0; i
< nzones
; i
= j
) {
548 ** Find the next non-continuation zone entry.
550 for (j
= i
+ 1; j
< nzones
&& zones
[j
].z_name
== NULL
; ++j
)
552 outzone(&zones
[i
], j
- i
);
557 for (i
= 0; i
< nlinks
; ++i
)
558 dolink(links
[i
].l_from
, links
[i
].l_to
);
560 dolink(lcltime
, TZDEFAULT
);
561 if (psxrules
!= NULL
)
562 dolink(psxrules
, TZDEFRULES
);
563 return (errors
== 0) ? EXIT_SUCCESS
: EXIT_FAILURE
;
567 dolink(fromfile
, tofile
)
568 const char * const fromfile
;
569 const char * const tofile
;
571 register char * fromname
;
572 register char * toname
;
574 if (fromfile
[0] == '/')
575 fromname
= ecpyalloc(fromfile
);
577 fromname
= ecpyalloc(directory
);
578 fromname
= ecatalloc(fromname
, "/");
579 fromname
= ecatalloc(fromname
, fromfile
);
581 if (tofile
[0] == '/')
582 toname
= ecpyalloc(tofile
);
584 toname
= ecpyalloc(directory
);
585 toname
= ecatalloc(toname
, "/");
586 toname
= ecatalloc(toname
, tofile
);
589 ** We get to be careful here since
590 ** there's a fair chance of root running us.
593 (void) remove(toname
);
594 if (link(fromname
, toname
) != 0) {
595 if (mkdirs(toname
) != 0)
596 (void) exit(EXIT_FAILURE
);
597 if (link(fromname
, toname
) != 0) {
598 const char *e
= strerror(errno
);
599 (void) fprintf(stderr
,
600 _("%s: Can't link from %s to %s: %s\n"),
601 progname
, fromname
, toname
, e
);
602 (void) exit(EXIT_FAILURE
);
610 #define INT_MAX ((int) (((unsigned)~0)>>1))
611 #endif /* !defined INT_MAX */
614 #define INT_MIN ((int) ~(((unsigned)~0)>>1))
615 #endif /* !defined INT_MIN */
618 ** The tz file format currently allows at most 32-bit quantities.
619 ** This restriction should be removed before signed 32-bit values
620 ** wrap around in 2038, but unfortunately this will require a
621 ** change to the tz file format.
624 #define MAX_BITS_IN_FILE 32
625 #define TIME_T_BITS_IN_FILE ((TYPE_BIT(time_t) < MAX_BITS_IN_FILE) ? \
626 TYPE_BIT(time_t) : MAX_BITS_IN_FILE)
629 setboundaries
P((void))
631 if (TYPE_SIGNED(time_t)) {
632 min_time
= ~ (time_t) 0;
633 min_time
<<= TIME_T_BITS_IN_FILE
- 1;
634 max_time
= ~ (time_t) 0 - min_time
;
639 max_time
= 2 - sflag
;
640 max_time
<<= TIME_T_BITS_IN_FILE
- 1;
643 min_year
= TM_YEAR_BASE
+ gmtime(&min_time
)->tm_year
;
644 max_year
= TM_YEAR_BASE
+ gmtime(&max_time
)->tm_year
;
649 const char * const name
;
651 register char * myname
;
654 myname
= ecpyalloc(name
);
655 myname
= ecatalloc(myname
, "/.");
656 accres
= access(myname
, F_OK
);
662 ** Associate sets of rules with zones.
666 ** Sort by rule name.
674 return strcmp(((const struct rule
*) cp1
)->r_name
,
675 ((const struct rule
*) cp2
)->r_name
);
681 register struct zone
* zp
;
682 register struct rule
* rp
;
683 register int base
, out
;
687 (void) qsort((void *) rules
, (size_t) nrules
,
688 (size_t) sizeof *rules
, rcomp
);
689 for (i
= 0; i
< nzones
; ++i
) {
694 for (base
= 0; base
< nrules
; base
= out
) {
696 for (out
= base
+ 1; out
< nrules
; ++out
)
697 if (strcmp(rp
->r_name
, rules
[out
].r_name
) != 0)
699 for (i
= 0; i
< nzones
; ++i
) {
701 if (strcmp(zp
->z_rule
, rp
->r_name
) != 0)
704 zp
->z_nrules
= out
- base
;
707 for (i
= 0; i
< nzones
; ++i
) {
709 if (zp
->z_nrules
== 0) {
711 ** Maybe we have a local standard time offset.
713 eat(zp
->z_filename
, zp
->z_linenum
);
714 zp
->z_stdoff
= gethms(zp
->z_rule
, _("unruly zone"),
717 ** Note, though, that if there's no rule,
718 ** a '%s' in the format is a bad thing.
720 if (strchr(zp
->z_format
, '%') != 0)
721 error(_("%s in ruleless zone"));
725 (void) exit(EXIT_FAILURE
);
733 register char ** fields
;
735 register const struct lookup
* lp
;
736 register int nfields
;
737 register int wantcont
;
741 if (strcmp(name
, "-") == 0) {
742 name
= _("standard input");
744 } else if ((fp
= fopen(name
, "r")) == NULL
) {
745 const char *e
= strerror(errno
);
746 (void) fprintf(stderr
, _("%s: Can't open %s: %s\n"),
748 (void) exit(EXIT_FAILURE
);
751 for (num
= 1; ; ++num
) {
753 if (fgets(buf
, (int) sizeof buf
, fp
) != buf
)
755 cp
= strchr(buf
, '\n');
757 error(_("line too long"));
758 (void) exit(EXIT_FAILURE
);
761 fields
= getfields(buf
);
763 while (fields
[nfields
] != NULL
) {
766 if (strcmp(fields
[nfields
], "-") == 0)
767 fields
[nfields
] = &nada
;
772 } else if (wantcont
) {
773 wantcont
= inzcont(fields
, nfields
);
775 lp
= byword(fields
[0], line_codes
);
777 error(_("input line of unknown type"));
778 else switch ((int) (lp
->l_value
)) {
780 inrule(fields
, nfields
);
784 wantcont
= inzone(fields
, nfields
);
787 inlink(fields
, nfields
);
792 (void) fprintf(stderr
,
793 _("%s: Leap line in non leap seconds file %s\n"),
795 else inleap(fields
, nfields
);
798 default: /* "cannot happen" */
799 (void) fprintf(stderr
,
800 _("%s: panic: Invalid l_value %d\n"),
801 progname
, lp
->l_value
);
802 (void) exit(EXIT_FAILURE
);
805 ifree((char *) fields
);
808 (void) fprintf(stderr
, _("%s: Error reading %s\n"),
810 (void) exit(EXIT_FAILURE
);
812 if (fp
!= stdin
&& fclose(fp
)) {
813 const char *e
= strerror(errno
);
814 (void) fprintf(stderr
, _("%s: Error closing %s: %s\n"),
815 progname
, filename
, e
);
816 (void) exit(EXIT_FAILURE
);
819 error(_("expected continuation line not found"));
823 ** Convert a string of one of the forms
824 ** h -h hh:mm -hh:mm hh:mm:ss -hh:mm:ss
825 ** into a number of seconds.
826 ** A null string maps to zero.
827 ** Call error with errstring and return zero on errors.
831 gethms(string
, errstring
, signable
)
833 const char * const errstring
;
836 int hh
, mm
, ss
, sign
;
838 if (string
== NULL
|| *string
== '\0')
842 else if (*string
== '-') {
846 if (sscanf(string
, scheck(string
, "%d"), &hh
) == 1)
848 else if (sscanf(string
, scheck(string
, "%d:%d"), &hh
, &mm
) == 2)
850 else if (sscanf(string
, scheck(string
, "%d:%d:%d"),
851 &hh
, &mm
, &ss
) != 3) {
855 if (hh
< 0 || hh
>= HOURSPERDAY
||
856 mm
< 0 || mm
>= MINSPERHOUR
||
857 ss
< 0 || ss
> SECSPERMIN
) {
862 (eitol(hh
* MINSPERHOUR
+ mm
) *
863 eitol(SECSPERMIN
) + eitol(ss
));
867 inrule(fields
, nfields
)
868 register char ** const fields
;
871 static struct rule r
;
873 if (nfields
!= RULE_FIELDS
) {
874 error(_("wrong number of fields on Rule line"));
877 if (*fields
[RF_NAME
] == '\0') {
878 error(_("nameless rule"));
881 r
.r_filename
= filename
;
882 r
.r_linenum
= linenum
;
883 r
.r_stdoff
= gethms(fields
[RF_STDOFF
], _("invalid saved time"), TRUE
);
884 rulesub(&r
, fields
[RF_LOYEAR
], fields
[RF_HIYEAR
], fields
[RF_COMMAND
],
885 fields
[RF_MONTH
], fields
[RF_DAY
], fields
[RF_TOD
]);
886 r
.r_name
= ecpyalloc(fields
[RF_NAME
]);
887 r
.r_abbrvar
= ecpyalloc(fields
[RF_ABBRVAR
]);
888 rules
= (struct rule
*) (void *) erealloc((char *) rules
,
889 (int) ((nrules
+ 1) * sizeof *rules
));
894 inzone(fields
, nfields
)
895 register char ** const fields
;
901 if (nfields
< ZONE_MINFIELDS
|| nfields
> ZONE_MAXFIELDS
) {
902 error(_("wrong number of fields on Zone line"));
905 if (strcmp(fields
[ZF_NAME
], TZDEFAULT
) == 0 && lcltime
!= NULL
) {
906 buf
= erealloc(buf
, (int) (132 + strlen(TZDEFAULT
)));
908 _("\"Zone %s\" line and -l option are mutually exclusive"),
913 if (strcmp(fields
[ZF_NAME
], TZDEFRULES
) == 0 && psxrules
!= NULL
) {
914 buf
= erealloc(buf
, (int) (132 + strlen(TZDEFRULES
)));
916 _("\"Zone %s\" line and -p option are mutually exclusive"),
921 for (i
= 0; i
< nzones
; ++i
)
922 if (zones
[i
].z_name
!= NULL
&&
923 strcmp(zones
[i
].z_name
, fields
[ZF_NAME
]) == 0) {
924 buf
= erealloc(buf
, (int) (132 +
925 strlen(fields
[ZF_NAME
]) +
926 strlen(zones
[i
].z_filename
)));
928 _("duplicate zone name %s (file \"%s\", line %d)"),
935 return inzsub(fields
, nfields
, FALSE
);
939 inzcont(fields
, nfields
)
940 register char ** const fields
;
943 if (nfields
< ZONEC_MINFIELDS
|| nfields
> ZONEC_MAXFIELDS
) {
944 error(_("wrong number of fields on Zone continuation line"));
947 return inzsub(fields
, nfields
, TRUE
);
951 inzsub(fields
, nfields
, iscont
)
952 register char ** const fields
;
957 static struct zone z
;
958 register int i_gmtoff
, i_rule
, i_format
;
959 register int i_untilyear
, i_untilmonth
;
960 register int i_untilday
, i_untiltime
;
961 register int hasuntil
;
964 i_gmtoff
= ZFC_GMTOFF
;
966 i_format
= ZFC_FORMAT
;
967 i_untilyear
= ZFC_TILYEAR
;
968 i_untilmonth
= ZFC_TILMONTH
;
969 i_untilday
= ZFC_TILDAY
;
970 i_untiltime
= ZFC_TILTIME
;
973 i_gmtoff
= ZF_GMTOFF
;
975 i_format
= ZF_FORMAT
;
976 i_untilyear
= ZF_TILYEAR
;
977 i_untilmonth
= ZF_TILMONTH
;
978 i_untilday
= ZF_TILDAY
;
979 i_untiltime
= ZF_TILTIME
;
980 z
.z_name
= ecpyalloc(fields
[ZF_NAME
]);
982 z
.z_filename
= filename
;
983 z
.z_linenum
= linenum
;
984 z
.z_gmtoff
= gethms(fields
[i_gmtoff
], _("invalid GMT offset"), TRUE
);
985 if ((cp
= strchr(fields
[i_format
], '%')) != 0) {
986 if (*++cp
!= 's' || strchr(cp
, '%') != 0) {
987 error(_("invalid abbreviation format"));
991 z
.z_rule
= ecpyalloc(fields
[i_rule
]);
992 z
.z_format
= ecpyalloc(fields
[i_format
]);
993 hasuntil
= nfields
> i_untilyear
;
995 z
.z_untilrule
.r_filename
= filename
;
996 z
.z_untilrule
.r_linenum
= linenum
;
997 rulesub(&z
.z_untilrule
,
1001 (nfields
> i_untilmonth
) ?
1002 fields
[i_untilmonth
] : "Jan",
1003 (nfields
> i_untilday
) ? fields
[i_untilday
] : "1",
1004 (nfields
> i_untiltime
) ? fields
[i_untiltime
] : "0");
1005 z
.z_untiltime
= rpytime(&z
.z_untilrule
,
1006 z
.z_untilrule
.r_loyear
);
1007 if (iscont
&& nzones
> 0 &&
1008 z
.z_untiltime
> min_time
&&
1009 z
.z_untiltime
< max_time
&&
1010 zones
[nzones
- 1].z_untiltime
> min_time
&&
1011 zones
[nzones
- 1].z_untiltime
< max_time
&&
1012 zones
[nzones
- 1].z_untiltime
>= z
.z_untiltime
) {
1013 error(_("Zone continuation line end time is \
1014 not after end time of previous line"));
1018 zones
= (struct zone
*) (void *) erealloc((char *) zones
,
1019 (int) ((nzones
+ 1) * sizeof *zones
));
1020 zones
[nzones
++] = z
;
1022 ** If there was an UNTIL field on this line,
1023 ** there's more information about the zone on the next line.
1029 inleap(fields
, nfields
)
1030 register char ** const fields
;
1033 register const char * cp
;
1034 register const struct lookup
* lp
;
1036 int year
, month
, day
;
1040 if (nfields
!= LEAP_FIELDS
) {
1041 error(_("wrong number of fields on Leap line"));
1045 cp
= fields
[LP_YEAR
];
1046 if (sscanf(cp
, scheck(cp
, "%d"), &year
) != 1) {
1050 error(_("invalid leaping year"));
1056 i
= len_years
[isleap(j
)];
1060 i
= -len_years
[isleap(j
)];
1062 dayoff
= oadd(dayoff
, eitol(i
));
1064 if ((lp
= byword(fields
[LP_MONTH
], mon_names
)) == NULL
) {
1065 error(_("invalid month name"));
1068 month
= lp
->l_value
;
1070 while (j
!= month
) {
1071 i
= len_months
[isleap(year
)][j
];
1072 dayoff
= oadd(dayoff
, eitol(i
));
1075 cp
= fields
[LP_DAY
];
1076 if (sscanf(cp
, scheck(cp
, "%d"), &day
) != 1 ||
1077 day
<= 0 || day
> len_months
[isleap(year
)][month
]) {
1078 error(_("invalid day of month"));
1081 dayoff
= oadd(dayoff
, eitol(day
- 1));
1082 if (dayoff
< 0 && !TYPE_SIGNED(time_t)) {
1083 error(_("time before zero"));
1086 t
= (time_t) dayoff
* SECSPERDAY
;
1088 ** Cheap overflow check.
1090 if (t
/ SECSPERDAY
!= dayoff
) {
1091 error(_("time overflow"));
1094 tod
= gethms(fields
[LP_TIME
], _("invalid time of day"), FALSE
);
1095 cp
= fields
[LP_CORR
];
1097 register int positive
;
1100 if (strcmp(cp
, "") == 0) { /* infile() turns "-" into "" */
1103 } else if (strcmp(cp
, "--") == 0) {
1106 } else if (strcmp(cp
, "+") == 0) {
1109 } else if (strcmp(cp
, "++") == 0) {
1113 error(_("illegal CORRECTION field on Leap line"));
1116 if ((lp
= byword(fields
[LP_ROLL
], leap_types
)) == NULL
) {
1117 error(_("illegal Rolling/Stationary field on Leap line"));
1120 leapadd(tadd(t
, tod
), positive
, lp
->l_value
, count
);
1125 inlink(fields
, nfields
)
1126 register char ** const fields
;
1131 if (nfields
!= LINK_FIELDS
) {
1132 error(_("wrong number of fields on Link line"));
1135 if (*fields
[LF_FROM
] == '\0') {
1136 error(_("blank FROM field on Link line"));
1139 if (*fields
[LF_TO
] == '\0') {
1140 error(_("blank TO field on Link line"));
1143 l
.l_filename
= filename
;
1144 l
.l_linenum
= linenum
;
1145 l
.l_from
= ecpyalloc(fields
[LF_FROM
]);
1146 l
.l_to
= ecpyalloc(fields
[LF_TO
]);
1147 links
= (struct link
*) (void *) erealloc((char *) links
,
1148 (int) ((nlinks
+ 1) * sizeof *links
));
1149 links
[nlinks
++] = l
;
1153 rulesub(rp
, loyearp
, hiyearp
, typep
, monthp
, dayp
, timep
)
1154 register struct rule
* const rp
;
1155 const char * const loyearp
;
1156 const char * const hiyearp
;
1157 const char * const typep
;
1158 const char * const monthp
;
1159 const char * const dayp
;
1160 const char * const timep
;
1162 register const struct lookup
* lp
;
1163 register const char * cp
;
1167 if ((lp
= byword(monthp
, mon_names
)) == NULL
) {
1168 error(_("invalid month name"));
1171 rp
->r_month
= lp
->l_value
;
1172 rp
->r_todisstd
= FALSE
;
1173 rp
->r_todisgmt
= FALSE
;
1174 dp
= ecpyalloc(timep
);
1176 ep
= dp
+ strlen(dp
) - 1;
1177 switch (lowerit(*ep
)) {
1178 case 's': /* Standard */
1179 rp
->r_todisstd
= TRUE
;
1180 rp
->r_todisgmt
= FALSE
;
1183 case 'w': /* Wall */
1184 rp
->r_todisstd
= FALSE
;
1185 rp
->r_todisgmt
= FALSE
;
1187 case 'g': /* Greenwich */
1188 case 'u': /* Universal */
1189 case 'z': /* Zulu */
1190 rp
->r_todisstd
= TRUE
;
1191 rp
->r_todisgmt
= TRUE
;
1196 rp
->r_tod
= gethms(dp
, _("invalid time of day"), FALSE
);
1202 lp
= byword(cp
, begin_years
);
1203 if (lp
!= NULL
) switch ((int) lp
->l_value
) {
1205 rp
->r_loyear
= INT_MIN
;
1208 rp
->r_loyear
= INT_MAX
;
1210 default: /* "cannot happen" */
1211 (void) fprintf(stderr
,
1212 _("%s: panic: Invalid l_value %d\n"),
1213 progname
, lp
->l_value
);
1214 (void) exit(EXIT_FAILURE
);
1215 } else if (sscanf(cp
, scheck(cp
, "%d"), &rp
->r_loyear
) != 1) {
1216 error(_("invalid starting year"));
1220 if ((lp
= byword(cp
, end_years
)) != NULL
) switch ((int) lp
->l_value
) {
1222 rp
->r_hiyear
= INT_MIN
;
1225 rp
->r_hiyear
= INT_MAX
;
1228 rp
->r_hiyear
= rp
->r_loyear
;
1230 default: /* "cannot happen" */
1231 (void) fprintf(stderr
,
1232 _("%s: panic: Invalid l_value %d\n"),
1233 progname
, lp
->l_value
);
1234 (void) exit(EXIT_FAILURE
);
1235 } else if (sscanf(cp
, scheck(cp
, "%d"), &rp
->r_hiyear
) != 1) {
1236 error(_("invalid ending year"));
1239 if (rp
->r_loyear
> rp
->r_hiyear
) {
1240 error(_("starting year greater than ending year"));
1244 rp
->r_yrtype
= NULL
;
1246 if (rp
->r_loyear
== rp
->r_hiyear
) {
1247 error(_("typed single year"));
1250 rp
->r_yrtype
= ecpyalloc(typep
);
1254 ** Accept things such as:
1260 dp
= ecpyalloc(dayp
);
1261 if ((lp
= byword(dp
, lasts
)) != NULL
) {
1262 rp
->r_dycode
= DC_DOWLEQ
;
1263 rp
->r_wday
= lp
->l_value
;
1264 rp
->r_dayofmonth
= len_months
[1][rp
->r_month
];
1266 if ((ep
= strchr(dp
, '<')) != 0)
1267 rp
->r_dycode
= DC_DOWLEQ
;
1268 else if ((ep
= strchr(dp
, '>')) != 0)
1269 rp
->r_dycode
= DC_DOWGEQ
;
1272 rp
->r_dycode
= DC_DOM
;
1274 if (rp
->r_dycode
!= DC_DOM
) {
1277 error(_("invalid day of month"));
1281 if ((lp
= byword(dp
, wday_names
)) == NULL
) {
1282 error(_("invalid weekday name"));
1286 rp
->r_wday
= lp
->l_value
;
1288 if (sscanf(ep
, scheck(ep
, "%d"), &rp
->r_dayofmonth
) != 1 ||
1289 rp
->r_dayofmonth
<= 0 ||
1290 (rp
->r_dayofmonth
> len_months
[1][rp
->r_month
])) {
1291 error(_("invalid day of month"));
1305 register long shift
;
1307 for (i
= 0, shift
= 24; i
< 4; ++i
, shift
-= 8)
1308 buf
[i
] = val
>> shift
;
1319 (void) fwrite((void *) buf
, (size_t) sizeof buf
, (size_t) 1, fp
);
1324 const char * const name
;
1328 static char * fullname
;
1329 static struct tzhead tzh
;
1331 fullname
= erealloc(fullname
,
1332 (int) (strlen(directory
) + 1 + strlen(name
) + 1));
1333 (void) sprintf(fullname
, "%s/%s", directory
, name
);
1334 if ((fp
= fopen(fullname
, "wb")) == NULL
) {
1335 if (mkdirs(fullname
) != 0)
1336 (void) exit(EXIT_FAILURE
);
1337 if ((fp
= fopen(fullname
, "wb")) == NULL
) {
1338 const char *e
= strerror(errno
);
1339 (void) fprintf(stderr
, _("%s: Can't create %s: %s\n"),
1340 progname
, fullname
, e
);
1341 (void) exit(EXIT_FAILURE
);
1344 convert(eitol(typecnt
), tzh
.tzh_ttisgmtcnt
);
1345 convert(eitol(typecnt
), tzh
.tzh_ttisstdcnt
);
1346 convert(eitol(leapcnt
), tzh
.tzh_leapcnt
);
1347 convert(eitol(timecnt
), tzh
.tzh_timecnt
);
1348 convert(eitol(typecnt
), tzh
.tzh_typecnt
);
1349 convert(eitol(charcnt
), tzh
.tzh_charcnt
);
1350 #define DO(field) (void) fwrite((void *) tzh.field, \
1351 (size_t) sizeof tzh.field, (size_t) 1, fp)
1360 for (i
= 0; i
< timecnt
; ++i
) {
1363 if (ats
[i
] >= trans
[j
]) {
1364 ats
[i
] = tadd(ats
[i
], corr
[j
]);
1367 puttzcode((long) ats
[i
], fp
);
1370 (void) fwrite((void *) types
, (size_t) sizeof types
[0],
1371 (size_t) timecnt
, fp
);
1372 for (i
= 0; i
< typecnt
; ++i
) {
1373 puttzcode((long) gmtoffs
[i
], fp
);
1374 (void) putc(isdsts
[i
], fp
);
1375 (void) putc(abbrinds
[i
], fp
);
1378 (void) fwrite((void *) chars
, (size_t) sizeof chars
[0],
1379 (size_t) charcnt
, fp
);
1380 for (i
= 0; i
< leapcnt
; ++i
) {
1382 if (timecnt
== 0 || trans
[i
] < ats
[0]) {
1385 if (++j
>= typecnt
) {
1391 while (j
< timecnt
&& trans
[i
] >= ats
[j
])
1395 puttzcode((long) tadd(trans
[i
], -gmtoffs
[j
]), fp
);
1396 } else puttzcode((long) trans
[i
], fp
);
1397 puttzcode((long) corr
[i
], fp
);
1399 for (i
= 0; i
< typecnt
; ++i
)
1400 (void) putc(ttisstds
[i
], fp
);
1401 for (i
= 0; i
< typecnt
; ++i
)
1402 (void) putc(ttisgmts
[i
], fp
);
1403 if (ferror(fp
) || fclose(fp
)) {
1404 (void) fprintf(stderr
, _("%s: Error writing %s\n"),
1405 progname
, fullname
);
1406 (void) exit(EXIT_FAILURE
);
1411 doabbr(abbr
, format
, letters
, isdst
)
1413 const char * const format
;
1414 const char * const letters
;
1417 if (strchr(format
, '/') == NULL
) {
1418 if (letters
== NULL
)
1419 (void) strcpy(abbr
, format
);
1420 else (void) sprintf(abbr
, format
, letters
);
1422 (void) strcpy(abbr
, strchr(format
, '/') + 1);
1424 (void) strcpy(abbr
, format
);
1425 *strchr(abbr
, '/') = '\0';
1430 outzone(zpfirst
, zonecount
)
1431 const struct zone
* const zpfirst
;
1432 const int zonecount
;
1434 register const struct zone
* zp
;
1435 register struct rule
* rp
;
1437 register int usestart
, useuntil
;
1438 register time_t starttime
, untiltime
;
1439 register long gmtoff
;
1440 register long stdoff
;
1442 register long startoff
;
1443 register int startisdst
;
1444 register int startttisstd
;
1445 register int startttisgmt
;
1447 char startbuf
[BUFSIZ
];
1449 INITIALIZE(untiltime
);
1450 INITIALIZE(starttime
);
1451 INITIALIZE(startoff
);
1453 ** Now. . .finally. . .generate some useful data!
1459 ** A guess that may well be corrected later.
1463 ** Thanks to Earl Chew (earl@dnd.icp.nec.com.au)
1464 ** for noting the need to unconditionally initialize startttisstd.
1466 startttisstd
= FALSE
;
1467 startttisgmt
= FALSE
;
1468 for (i
= 0; i
< zonecount
; ++i
) {
1470 usestart
= i
> 0 && (zp
- 1)->z_untiltime
> min_time
;
1471 useuntil
= i
< (zonecount
- 1);
1472 if (useuntil
&& zp
->z_untiltime
<= min_time
)
1474 gmtoff
= zp
->z_gmtoff
;
1475 eat(zp
->z_filename
, zp
->z_linenum
);
1477 if (zp
->z_nrules
== 0) {
1478 stdoff
= zp
->z_stdoff
;
1479 doabbr(startbuf
, zp
->z_format
,
1480 (char *) NULL
, stdoff
!= 0);
1481 type
= addtype(oadd(zp
->z_gmtoff
, stdoff
),
1482 startbuf
, stdoff
!= 0, startttisstd
,
1485 addtt(starttime
, type
);
1486 else if (stdoff
!= 0)
1487 addtt(min_time
, type
);
1488 } else for (year
= min_year
; year
<= max_year
; ++year
) {
1489 if (useuntil
&& year
> zp
->z_untilrule
.r_hiyear
)
1492 ** Mark which rules to do in the current year.
1493 ** For those to do, calculate rpytime(rp, year);
1495 for (j
= 0; j
< zp
->z_nrules
; ++j
) {
1496 rp
= &zp
->z_rules
[j
];
1497 eats(zp
->z_filename
, zp
->z_linenum
,
1498 rp
->r_filename
, rp
->r_linenum
);
1499 rp
->r_todo
= year
>= rp
->r_loyear
&&
1500 year
<= rp
->r_hiyear
&&
1501 yearistype(year
, rp
->r_yrtype
);
1503 rp
->r_temp
= rpytime(rp
, year
);
1507 register time_t jtime
, ktime
;
1508 register long offset
;
1514 ** Turn untiltime into GMT
1515 ** assuming the current gmtoff and
1518 untiltime
= zp
->z_untiltime
;
1519 if (!zp
->z_untilrule
.r_todisgmt
)
1520 untiltime
= tadd(untiltime
,
1522 if (!zp
->z_untilrule
.r_todisstd
)
1523 untiltime
= tadd(untiltime
,
1527 ** Find the rule (of those to do, if any)
1528 ** that takes effect earliest in the year.
1531 for (j
= 0; j
< zp
->z_nrules
; ++j
) {
1532 rp
= &zp
->z_rules
[j
];
1535 eats(zp
->z_filename
, zp
->z_linenum
,
1536 rp
->r_filename
, rp
->r_linenum
);
1537 offset
= rp
->r_todisgmt
? 0 : gmtoff
;
1538 if (!rp
->r_todisstd
)
1539 offset
= oadd(offset
, stdoff
);
1541 if (jtime
== min_time
||
1544 jtime
= tadd(jtime
, -offset
);
1545 if (k
< 0 || jtime
< ktime
) {
1551 break; /* go on to next year */
1552 rp
= &zp
->z_rules
[k
];
1554 if (useuntil
&& ktime
>= untiltime
)
1557 if (ktime
< starttime
) {
1558 stdoff
= rp
->r_stdoff
;
1559 startoff
= oadd(zp
->z_gmtoff
,
1561 doabbr(startbuf
, zp
->z_format
,
1564 startisdst
= rp
->r_stdoff
!= 0;
1568 if (ktime
!= starttime
) {
1569 if (startisdst
< 0 &&
1571 (zp
- 1)->z_gmtoff
) {
1572 type
= (timecnt
== 0) ? 0 :
1574 startoff
= oadd(gmtoffs
[type
],
1575 -(zp
- 1)->z_gmtoff
);
1576 startisdst
= startoff
!= 0;
1577 startoff
= oadd(startoff
,
1579 (void) strcpy(startbuf
,
1580 &chars
[abbrinds
[type
]]);
1582 if (startisdst
>= 0)
1583 addtt(starttime
, addtype(startoff
, startbuf
, startisdst
, startttisstd
,
1587 eats(zp
->z_filename
, zp
->z_linenum
,
1588 rp
->r_filename
, rp
->r_linenum
);
1589 doabbr(buf
, zp
->z_format
, rp
->r_abbrvar
,
1591 offset
= oadd(zp
->z_gmtoff
, rp
->r_stdoff
);
1592 type
= addtype(offset
, buf
, rp
->r_stdoff
!= 0,
1593 rp
->r_todisstd
, rp
->r_todisgmt
);
1595 stdoff
= rp
->r_stdoff
;
1599 ** Now we may get to set starttime for the next zone line.
1602 starttime
= tadd(zp
->z_untiltime
, -gmtoff
);
1603 startttisstd
= zp
->z_untilrule
.r_todisstd
;
1604 startttisgmt
= zp
->z_untilrule
.r_todisgmt
;
1606 starttime
= tadd(starttime
, -stdoff
);
1609 writezone(zpfirst
->z_name
);
1613 addtt(starttime
, type
)
1614 const time_t starttime
;
1617 if (timecnt
!= 0 && type
== types
[timecnt
- 1])
1618 return; /* easy enough! */
1619 if (timecnt
== 0 && type
== 0 && isdsts
[0] == 0)
1620 return; /* handled by default rule */
1621 if (timecnt
>= TZ_MAX_TIMES
) {
1622 error(_("too many transitions?!"));
1623 (void) exit(EXIT_FAILURE
);
1625 ats
[timecnt
] = starttime
;
1626 types
[timecnt
] = type
;
1631 addtype(gmtoff
, abbr
, isdst
, ttisstd
, ttisgmt
)
1633 const char * const abbr
;
1641 ** See if there's already an entry for this zone type.
1642 ** If so, just return its index.
1644 for (i
= 0; i
< typecnt
; ++i
) {
1645 if (gmtoff
== gmtoffs
[i
] && isdst
== isdsts
[i
] &&
1646 strcmp(abbr
, &chars
[abbrinds
[i
]]) == 0 &&
1647 ttisstd
== ttisstds
[i
] &&
1648 ttisgmt
== ttisgmts
[i
])
1652 ** There isn't one; add a new one, unless there are already too
1655 if (typecnt
>= TZ_MAX_TYPES
) {
1656 error(_("too many local time types"));
1657 (void) exit(EXIT_FAILURE
);
1659 gmtoffs
[i
] = gmtoff
;
1661 ttisstds
[i
] = ttisstd
;
1662 ttisgmts
[i
] = ttisgmt
;
1664 for (j
= 0; j
< charcnt
; ++j
)
1665 if (strcmp(&chars
[j
], abbr
) == 0)
1675 leapadd(t
, positive
, rolling
, count
)
1683 if (leapcnt
+ (positive
? count
: 1) > TZ_MAX_LEAPS
) {
1684 error(_("too many leap seconds"));
1685 (void) exit(EXIT_FAILURE
);
1687 for (i
= 0; i
< leapcnt
; ++i
)
1688 if (t
<= trans
[i
]) {
1689 if (t
== trans
[i
]) {
1690 error(_("repeated leap second moment"));
1691 (void) exit(EXIT_FAILURE
);
1696 for (j
= leapcnt
; j
> i
; --j
) {
1697 trans
[j
] = trans
[j
- 1];
1698 corr
[j
] = corr
[j
- 1];
1699 roll
[j
] = roll
[j
- 1];
1702 corr
[i
] = positive
? 1L : eitol(-count
);
1705 } while (positive
&& --count
!= 0);
1712 register long last
= 0;
1715 ** propagate leap seconds forward
1717 for (i
= 0; i
< leapcnt
; ++i
) {
1718 trans
[i
] = tadd(trans
[i
], last
);
1719 last
= corr
[i
] += last
;
1724 yearistype(year
, type
)
1726 const char * const type
;
1731 if (type
== NULL
|| *type
== '\0')
1733 buf
= erealloc(buf
, (int) (132 + strlen(yitcommand
) + strlen(type
)));
1734 (void) sprintf(buf
, "%s %d %s", yitcommand
, year
, type
);
1735 result
= system(buf
);
1738 if (result
== (1 << 8))
1740 error(_("Wild result from command execution"));
1741 (void) fprintf(stderr
, _("%s: command was '%s', result was %d\n"),
1742 progname
, buf
, result
);
1744 (void) exit(EXIT_FAILURE
);
1751 a
= (unsigned char) a
;
1752 return (isascii(a
) && isupper(a
)) ? tolower(a
) : a
;
1756 ciequal(ap
, bp
) /* case-insensitive equality */
1757 register const char * ap
;
1758 register const char * bp
;
1760 while (lowerit(*ap
) == lowerit(*bp
++))
1768 register const char * abbr
;
1769 register const char * word
;
1771 if (lowerit(*abbr
) != lowerit(*word
))
1774 while (*++abbr
!= '\0')
1778 } while (lowerit(*word
++) != lowerit(*abbr
));
1782 static const struct lookup
*
1784 register const char * const word
;
1785 register const struct lookup
* const table
;
1787 register const struct lookup
* foundlp
;
1788 register const struct lookup
* lp
;
1790 if (word
== NULL
|| table
== NULL
)
1793 ** Look for exact match.
1795 for (lp
= table
; lp
->l_word
!= NULL
; ++lp
)
1796 if (ciequal(word
, lp
->l_word
))
1799 ** Look for inexact match.
1802 for (lp
= table
; lp
->l_word
!= NULL
; ++lp
)
1803 if (itsabbr(word
, lp
->l_word
))
1804 if (foundlp
== NULL
)
1806 else return NULL
; /* multiple inexact matches */
1815 register char ** array
;
1820 array
= (char **) (void *)
1821 emalloc((int) ((strlen(cp
) + 1) * sizeof *array
));
1824 while (isascii(*cp
) && isspace((unsigned char) *cp
))
1826 if (*cp
== '\0' || *cp
== '#')
1828 array
[nsubs
++] = dp
= cp
;
1830 if ((*dp
= *cp
++) != '"')
1832 else while ((*dp
= *cp
++) != '"')
1835 else error(_("Odd number of quotation marks"));
1836 } while (*cp
!= '\0' && *cp
!= '#' &&
1837 (!isascii(*cp
) || !isspace((unsigned char) *cp
)));
1838 if (isascii(*cp
) && isspace((unsigned char) *cp
))
1842 array
[nsubs
] = NULL
;
1854 if ((t2
> 0 && t
<= t1
) || (t2
< 0 && t
>= t1
)) {
1855 error(_("time overflow"));
1856 (void) exit(EXIT_FAILURE
);
1868 if (t1
== max_time
&& t2
> 0)
1870 if (t1
== min_time
&& t2
< 0)
1873 if ((t2
> 0 && t
<= t1
) || (t2
< 0 && t
>= t1
)) {
1874 error(_("time overflow"));
1875 (void) exit(EXIT_FAILURE
);
1881 ** Given a rule, and a year, compute the date - in seconds since January 1,
1882 ** 1970, 00:00 LOCAL time - in that year that the rule refers to.
1886 rpytime(rp
, wantedy
)
1887 register const struct rule
* const rp
;
1888 register const int wantedy
;
1890 register int y
, m
, i
;
1891 register long dayoff
; /* with a nod to Margaret O. */
1894 if (wantedy
== INT_MIN
)
1896 if (wantedy
== INT_MAX
)
1901 while (wantedy
!= y
) {
1903 i
= len_years
[isleap(y
)];
1907 i
= -len_years
[isleap(y
)];
1909 dayoff
= oadd(dayoff
, eitol(i
));
1911 while (m
!= rp
->r_month
) {
1912 i
= len_months
[isleap(y
)][m
];
1913 dayoff
= oadd(dayoff
, eitol(i
));
1916 i
= rp
->r_dayofmonth
;
1917 if (m
== TM_FEBRUARY
&& i
== 29 && !isleap(y
)) {
1918 if (rp
->r_dycode
== DC_DOWLEQ
)
1921 error(_("use of 2/29 in non leap-year"));
1922 (void) exit(EXIT_FAILURE
);
1926 dayoff
= oadd(dayoff
, eitol(i
));
1927 if (rp
->r_dycode
== DC_DOWGEQ
|| rp
->r_dycode
== DC_DOWLEQ
) {
1930 #define LDAYSPERWEEK ((long) DAYSPERWEEK)
1931 wday
= eitol(EPOCH_WDAY
);
1933 ** Don't trust mod of negative numbers.
1936 wday
= (wday
+ dayoff
) % LDAYSPERWEEK
;
1938 wday
-= ((-dayoff
) % LDAYSPERWEEK
);
1940 wday
+= LDAYSPERWEEK
;
1942 while (wday
!= eitol(rp
->r_wday
))
1943 if (rp
->r_dycode
== DC_DOWGEQ
) {
1944 dayoff
= oadd(dayoff
, (long) 1);
1945 if (++wday
>= LDAYSPERWEEK
)
1949 dayoff
= oadd(dayoff
, (long) -1);
1951 wday
= LDAYSPERWEEK
- 1;
1954 if (i
< 0 || i
>= len_months
[isleap(y
)][m
]) {
1955 error(_("no day in month matches rule"));
1956 (void) exit(EXIT_FAILURE
);
1959 if (dayoff
< 0 && !TYPE_SIGNED(time_t))
1961 t
= (time_t) dayoff
* SECSPERDAY
;
1963 ** Cheap overflow check.
1965 if (t
/ SECSPERDAY
!= dayoff
)
1966 return (dayoff
> 0) ? max_time
: min_time
;
1967 return tadd(t
, rp
->r_tod
);
1972 const char * const string
;
1976 i
= strlen(string
) + 1;
1977 if (charcnt
+ i
> TZ_MAX_CHARS
) {
1978 error(_("too many, or too long, time zone abbreviations"));
1979 (void) exit(EXIT_FAILURE
);
1981 (void) strcpy(&chars
[charcnt
], string
);
1982 charcnt
+= eitol(i
);
1987 char * const argname
;
1989 register char * name
;
1992 if (argname
== NULL
|| *argname
== '\0')
1994 cp
= name
= ecpyalloc(argname
);
1995 while ((cp
= strchr(cp
+ 1, '/')) != 0) {
1999 ** DOS drive specifier?
2001 if (isalpha((unsigned char) name
[0]) &&
2002 name
[1] == ':' && name
[2] == '\0') {
2006 #endif /* !defined unix */
2007 if (!itsdir(name
)) {
2009 ** It doesn't seem to exist, so we try to create it.
2011 if (mkdir(name
, 0755) != 0) {
2012 const char *e
= strerror(errno
);
2013 (void) fprintf(stderr
,
2014 _("%s: Can't create directory %s: %s\n"),
2033 if ((i
< 0 && l
>= 0) || (i
== 0 && l
!= 0) || (i
> 0 && l
<= 0)) {
2034 (void) fprintf(stderr
,
2035 _("%s: %d did not sign extend correctly\n"),
2037 (void) exit(EXIT_FAILURE
);
2043 ** UNIX was a registered trademark of UNIX System Laboratories in 1993.