]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/calendar/calendar.h
MFV r336851:
[FreeBSD/FreeBSD.git] / usr.bin / calendar / calendar.h
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1989, 1993, 1994
5  *      The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the University nor the names of its contributors
16  *    may be used to endorse or promote products derived from this software
17  *    without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  * $FreeBSD$
32  */
33
34 #include <sys/types.h>
35 #include <sys/uio.h>
36
37 #define SECSPERDAY      (24 * 60 * 60)
38 #define SECSPERHOUR     (60 * 60)
39 #define SECSPERMINUTE   (60)
40 #define MINSPERHOUR     (60)
41 #define HOURSPERDAY     (24)
42 #define FSECSPERDAY     (24.0 * 60.0 * 60.0)
43 #define FSECSPERHOUR    (60.0 * 60.0)
44 #define FSECSPERMINUTE  (60.0)
45 #define FMINSPERHOUR    (60.0)
46 #define FHOURSPERDAY    (24.0)
47
48 #define DAYSPERYEAR     365
49 #define DAYSPERLEAPYEAR 366
50
51 /* Not yet categorized */
52
53 extern struct passwd *pw;
54 extern int doall;
55 extern time_t t1, t2;
56 extern const char *calendarFile;
57 extern int yrdays;
58 extern struct fixs neaster, npaskha, ncny, nfullmoon, nnewmoon;
59 extern struct fixs nmarequinox, nsepequinox, njunsolstice, ndecsolstice;
60 extern double UTCOffset;
61 extern int EastLongitude;
62
63 #define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
64
65 /* Flags to determine the returned values by determinestyle() in parsedata.c */
66 #define F_NONE                  0x00000
67 #define F_MONTH                 0x00001
68 #define F_DAYOFWEEK             0x00002
69 #define F_DAYOFMONTH            0x00004
70 #define F_MODIFIERINDEX         0x00008
71 #define F_MODIFIEROFFSET        0x00010
72 #define F_SPECIALDAY            0x00020
73 #define F_ALLMONTH              0x00040
74 #define F_ALLDAY                0x00080
75 #define F_VARIABLE              0x00100
76 #define F_EASTER                0x00200
77 #define F_CNY                   0x00400
78 #define F_PASKHA                0x00800
79 #define F_NEWMOON               0x01000
80 #define F_FULLMOON              0x02000
81 #define F_MAREQUINOX            0x04000
82 #define F_SEPEQUINOX            0x08000
83 #define F_JUNSOLSTICE           0x10000
84 #define F_DECSOLSTICE           0x20000
85 #define F_YEAR                  0x40000
86
87 #define STRING_EASTER           "Easter"
88 #define STRING_PASKHA           "Paskha"
89 #define STRING_CNY              "ChineseNewYear"
90 #define STRING_NEWMOON          "NewMoon"
91 #define STRING_FULLMOON         "FullMoon"
92 #define STRING_MAREQUINOX       "MarEquinox"
93 #define STRING_SEPEQUINOX       "SepEquinox"
94 #define STRING_JUNSOLSTICE      "JunSolstice"
95 #define STRING_DECSOLSTICE      "DecSolstice"
96
97 #define MAXCOUNT                125     /* Random number of maximum number of
98                                          * repeats of an event. Should be 52
99                                          * (number of weeks per year), if you
100                                          * want to show two years then it
101                                          * should be 104. If you are seeing
102                                          * more than this you are using this
103                                          * program wrong.
104                                          */
105
106 /*
107  * All the astronomical calculations are carried out for the meridian 120
108  * degrees east of Greenwich.
109  */
110 #define UTCOFFSET_CNY           8.0
111
112 extern int      debug;          /* show parsing of the input */
113 extern int      year1, year2;
114
115 /* events.c */
116 /*
117  * Event sorting related functions:
118  * - Use event_add() to create a new event
119  * - Use event_continue() to add more text to the last added event
120  * - Use event_print_all() to display them in time chronological order
121  */
122 struct event *event_add(int, int, int, char *, int, char *, char *);
123 void    event_continue(struct event *events, char *txt);
124 void    event_print_all(FILE *fp);
125 struct event {
126         int     year;
127         int     month;
128         int     day;
129         int     var;
130         char    *date;
131         char    *text;
132         char    *extra;
133         struct event *next;
134 };
135
136 /* locale.c */
137
138 struct fixs {
139         char    *name;
140         size_t  len;
141 };
142
143 extern const char *days[];
144 extern const char *fdays[];
145 extern const char *fmonths[];
146 extern const char *months[];
147 extern const char *sequences[];
148 extern struct fixs fndays[8];           /* full national days names */
149 extern struct fixs fnmonths[13];        /* full national months names */
150 extern struct fixs ndays[8];            /* short national days names */
151 extern struct fixs nmonths[13];         /* short national month names */
152 extern struct fixs nsequences[10];
153
154 void    setnnames(void);
155 void    setnsequences(char *);
156
157 /* day.c */
158 extern const struct tm tm0;
159 extern char dayname[];
160 void    settimes(time_t,int before, int after, int friday, struct tm *tp1, struct tm *tp2);
161 time_t  Mktime(char *);
162
163 /* parsedata.c */
164 int     parsedaymonth(char *, int *, int *, int *, int *, char **);
165 void    dodebug(char *type);
166
167 /* io.c */
168 void    cal(void);
169 void    closecal(FILE *);
170 FILE    *opencalin(void);
171 FILE    *opencalout(void);
172
173 /* ostern.c / paskha.c */
174 int     paskha(int);
175 int     easter(int);
176 int     j2g(int);
177
178 /* dates.c */
179 extern int cumdaytab[][14];
180 extern int monthdaytab[][14];
181 extern int debug_remember;
182 void    generatedates(struct tm *tp1, struct tm *tp2);
183 void    dumpdates(void);
184 int     remember_ymd(int y, int m, int d);
185 int     remember_yd(int y, int d, int *rm, int *rd);
186 int     first_dayofweek_of_year(int y);
187 int     first_dayofweek_of_month(int y, int m);
188 int     walkthrough_dates(struct event **e);
189 void    addtodate(struct event *e, int year, int month, int day);
190
191 /* pom.c */
192 #define MAXMOONS        18
193 void    pom(int year, double UTCoffset, int *fms, int *nms);
194 void    fpom(int year, double utcoffset, double *ffms, double *fnms);
195
196 /* sunpos.c */
197 void    equinoxsolstice(int year, double UTCoffset, int *equinoxdays, int *solsticedays);
198 void    fequinoxsolstice(int year, double UTCoffset, double *equinoxdays, double *solsticedays);
199 int     calculatesunlongitude30(int year, int degreeGMToffset, int *ichinesemonths);