calendar.h revision 205821
1205821Sedwin/*-
213877Swosch * Copyright (c) 1989, 1993, 1994
313877Swosch *	The Regents of the University of California.  All rights reserved.
413877Swosch *
513877Swosch * Redistribution and use in source and binary forms, with or without
613877Swosch * modification, are permitted provided that the following conditions
713877Swosch * are met:
813877Swosch * 1. Redistributions of source code must retain the above copyright
913877Swosch *    notice, this list of conditions and the following disclaimer.
1013877Swosch * 2. Redistributions in binary form must reproduce the above copyright
1113877Swosch *    notice, this list of conditions and the following disclaimer in the
1213877Swosch *    documentation and/or other materials provided with the distribution.
1313877Swosch * 3. All advertising materials mentioning features or use of this software
1413877Swosch *    must display the following acknowledgement:
1513877Swosch *	This product includes software developed by the University of
1613877Swosch *	California, Berkeley and its contributors.
1713877Swosch * 4. Neither the name of the University nor the names of its contributors
1813877Swosch *    may be used to endorse or promote products derived from this software
1913877Swosch *    without specific prior written permission.
2013877Swosch *
2113877Swosch * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2213877Swosch * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2313877Swosch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2413877Swosch * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2513877Swosch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2613877Swosch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2713877Swosch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2813877Swosch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2913877Swosch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3013877Swosch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3113877Swosch * SUCH DAMAGE.
3259945Sphantom *
3359945Sphantom * $FreeBSD: head/usr.bin/calendar/calendar.h 205821 2010-03-29 06:49:20Z edwin $
3413877Swosch */
3513877Swosch
36129814Sstefanf#include <sys/types.h>
37129814Sstefanf#include <sys/uio.h>
3813877Swosch
39205821Sedwin#define	SECSPERDAY	(24 * 60 * 60)
40205821Sedwin#define	SECSPERHOUR	(60 * 60)
41205821Sedwin#define	SECSPERMINUTE	(60)
42205821Sedwin#define	MINSPERHOUR	(60)
43205821Sedwin#define	HOURSPERDAY	(24)
44205821Sedwin#define	FSECSPERDAY	(24.0 * 60.0 * 60.0)
45205821Sedwin#define	FSECSPERHOUR	(60.0 * 60.0)
46205821Sedwin#define	FSECSPERMINUTE	(60.0)
47205821Sedwin#define	FMINSPERHOUR	(60.0)
48205821Sedwin#define	FHOURSPERDAY	(24.0)
49205821Sedwin
50205821Sedwin#define	DAYSPERYEAR	365
51205821Sedwin#define	DAYSPERLEAPYEAR	366
52205821Sedwin
53205821Sedwin/* Not yet categorized */
54205821Sedwin
5513877Swoschextern struct passwd *pw;
5613877Swoschextern int doall;
57205821Sedwinextern time_t t1, t2;
5887235Smarkmextern const char *calendarFile;
59170447Sgrogextern int yrdays;
60205821Sedwinextern struct fixs neaster, npaskha, ncny, nfullmoon, nnewmoon;
61205821Sedwinextern struct fixs nmarequinox, nsepequinox, njunsolstice, ndecsolstice;
62205821Sedwinextern double UTCOffset;
63205821Sedwinextern int EastLongitude;
6413877Swosch
65205821Sedwin#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
66205821Sedwin
67205821Sedwin/* Flags to determine the returned values by determinestyle() in parsedata.c */
68205821Sedwin#define	F_NONE			0x00000
69205821Sedwin#define	F_MONTH			0x00001
70205821Sedwin#define	F_DAYOFWEEK		0x00002
71205821Sedwin#define	F_DAYOFMONTH		0x00004
72205821Sedwin#define	F_MODIFIERINDEX		0x00008
73205821Sedwin#define	F_MODIFIEROFFSET	0x00010
74205821Sedwin#define	F_SPECIALDAY		0x00020
75205821Sedwin#define	F_ALLMONTH		0x00040
76205821Sedwin#define	F_ALLDAY		0x00080
77205821Sedwin#define	F_VARIABLE		0x00100
78205821Sedwin#define	F_EASTER		0x00200
79205821Sedwin#define	F_CNY			0x00400
80205821Sedwin#define	F_PASKHA		0x00800
81205821Sedwin#define	F_NEWMOON		0x01000
82205821Sedwin#define	F_FULLMOON		0x02000
83205821Sedwin#define	F_MAREQUINOX		0x04000
84205821Sedwin#define	F_SEPEQUINOX		0x08000
85205821Sedwin#define	F_JUNSOLSTICE		0x10000
86205821Sedwin#define	F_DECSOLSTICE		0x20000
87205821Sedwin
88205821Sedwin#define	STRING_EASTER		"Easter"
89205821Sedwin#define	STRING_PASKHA		"Paskha"
90205821Sedwin#define	STRING_CNY		"ChineseNewYear"
91205821Sedwin#define STRING_NEWMOON		"NewMoon"
92205821Sedwin#define STRING_FULLMOON		"FullMoon"
93205821Sedwin#define STRING_MAREQUINOX	"MarEquinox"
94205821Sedwin#define STRING_SEPEQUINOX	"SepEquinox"
95205821Sedwin#define STRING_JUNSOLSTICE	"JunSolstice"
96205821Sedwin#define STRING_DECSOLSTICE	"DecSolstice"
97205821Sedwin
98205821Sedwin#define	MAXCOUNT		125	/* Random number of maximum number of
99205821Sedwin					 * repeats of an event. Should be 52
100205821Sedwin					 * (number of weeks per year), if you
101205821Sedwin					 * want to show two years then it
102205821Sedwin					 * should be 104. If you are seeing
103205821Sedwin					 * more than this you are using this
104205821Sedwin					 * program wrong.
105205821Sedwin					 */
106205821Sedwin
107205821Sedwin/*
108205821Sedwin * All the astronomical calculations are carried out for the meridian 120
109205821Sedwin * degrees east of Greenwich.
110205821Sedwin */
111205821Sedwin#define UTCOFFSET_CNY		8.0
112205821Sedwin
113205821Sedwinextern int	debug;		/* show parsing of the input */
114205821Sedwinextern int	year1, year2;
115205821Sedwin
116205821Sedwin/* events.c */
117205821Sedwin/*
118205821Sedwin * Event sorting related functions:
119205821Sedwin * - Use event_add() to create a new event
120205821Sedwin * - Use event_continue() to add more text to the last added event
121205821Sedwin * - Use event_print_all() to display them in time chronological order
122205821Sedwin */
123205821Sedwinstruct event *event_add(int, int, int, char *, int, char *, char *);
124205821Sedwinvoid	event_continue(struct event *events, char *txt);
125205821Sedwinvoid	event_print_all(FILE *fp);
126205821Sedwinstruct event {
127205821Sedwin	int	year;
128205821Sedwin	int	month;
129205821Sedwin	int	day;
130205821Sedwin	int	var;
131205821Sedwin	char	*date;
132205821Sedwin	char	*text;
133205821Sedwin	char	*extra;
134205821Sedwin	struct event *next;
135205821Sedwin};
136205821Sedwin
137205821Sedwin/* locale.c */
138205821Sedwin
139205821Sedwinstruct fixs {
140205821Sedwin	char	*name;
141205821Sedwin	size_t	len;
142205821Sedwin};
143205821Sedwin
144205821Sedwinextern const char *days[];
145205821Sedwinextern const char *fdays[];
146205821Sedwinextern const char *fmonths[];
147205821Sedwinextern const char *months[];
148205821Sedwinextern const char *sequences[];
149205821Sedwinextern struct fixs fndays[8];		/* full national days names */
150205821Sedwinextern struct fixs fnmonths[13];	/* full national months names */
151205821Sedwinextern struct fixs ndays[8];		/* short national days names */
152205821Sedwinextern struct fixs nmonths[13];		/* short national month names */
153205821Sedwinextern struct fixs nsequences[10];
154205821Sedwin
155205821Sedwinvoid	setnnames(void);
156205821Sedwinvoid	setnsequences(char *);
157205821Sedwin
158205821Sedwin/* day.c */
159205821Sedwinextern const struct tm tm0;
160205821Sedwinextern char dayname[];
161205821Sedwinvoid	settimes(time_t,int before, int after, int friday, struct tm *tp1, struct tm *tp2);
162205821Sedwintime_t	Mktime(char *);
163205821Sedwin
164205821Sedwin/* parsedata.c */
165205821Sedwinint	parsedaymonth(char *, int *, int *, int *, int *, char **);
166205821Sedwinvoid	dodebug(char *type);
167205821Sedwin
168205821Sedwin/* io.c */
169181322Sedwinvoid	cal(void);
170181322Sedwinvoid	closecal(FILE *);
17192920SimpFILE	*opencal(void);
17213877Swosch
173205821Sedwin/* ostern.c / pashka.c */
174205821Sedwinint	paskha(int);
175205821Sedwinint	easter(int);
17613877Swosch
177205821Sedwin/* dates.c */
178205821Sedwinextern int cumdaytab[][14];
179205821Sedwinextern int mondaytab[][14];
180205821Sedwinextern int debug_remember;
181205821Sedwinvoid	generatedates(struct tm *tp1, struct tm *tp2);
182205821Sedwinvoid	dumpdates(void);
183205821Sedwinint	remember_ymd(int y, int m, int d);
184205821Sedwinint	remember_yd(int y, int d, int *rm, int *rd);
185205821Sedwinint	first_dayofweek_of_year(int y);
186205821Sedwinint	first_dayofweek_of_month(int y, int m);
187205821Sedwinint	walkthrough_dates(struct event **e);
188205821Sedwinvoid	addtodate(struct event *e, int year, int month, int day);
18913877Swosch
190205821Sedwin/* pom.c */
191205821Sedwin#define	MAXMOONS	18
192205821Sedwinvoid	pom(int year, double UTCoffset, int *fms, int *nms);
193205821Sedwinvoid	fpom(int year, double utcoffset, double *ffms, double *fnms);
19415720Sache
195205821Sedwin/* sunpos.c */
196205821Sedwinvoid	equinoxsolstice(int year, double UTCoffset, int *equinoxdays, int *solsticedays);
197205821Sedwinvoid	fequinoxsolstice(int year, double UTCoffset, double *equinoxdays, double *solsticedays);
198205821Sedwinint	calculatesunlongitude30(int year, int degreeGMToffset, int *ichinesemonths);
199