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