calendar.h revision 212035
1249259Sdim/*-
2249259Sdim * Copyright (c) 1989, 1993, 1994
3249259Sdim *	The Regents of the University of California.  All rights reserved.
4249259Sdim *
5249259Sdim * Redistribution and use in source and binary forms, with or without
6249259Sdim * modification, are permitted provided that the following conditions
7249259Sdim * are met:
8249259Sdim * 1. Redistributions of source code must retain the above copyright
9249259Sdim *    notice, this list of conditions and the following disclaimer.
10249259Sdim * 2. Redistributions in binary form must reproduce the above copyright
11249259Sdim *    notice, this list of conditions and the following disclaimer in the
12249259Sdim *    documentation and/or other materials provided with the distribution.
13249259Sdim * 4. Neither the name of the University nor the names of its contributors
14249259Sdim *    may be used to endorse or promote products derived from this software
15249259Sdim *    without specific prior written permission.
16249259Sdim *
17249259Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18249259Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19249259Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20249259Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21249259Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22249259Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23249259Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24249259Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25249259Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26249259Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27249259Sdim * SUCH DAMAGE.
28249259Sdim *
29249259Sdim * $FreeBSD: head/usr.bin/calendar/calendar.h 212035 2010-08-30 22:45:32Z edwin $
30249259Sdim */
31249259Sdim
32249259Sdim#include <sys/types.h>
33249259Sdim#include <sys/uio.h>
34249259Sdim
35249259Sdim#define	SECSPERDAY	(24 * 60 * 60)
36249259Sdim#define	SECSPERHOUR	(60 * 60)
37249259Sdim#define	SECSPERMINUTE	(60)
38249259Sdim#define	MINSPERHOUR	(60)
39249259Sdim#define	HOURSPERDAY	(24)
40249259Sdim#define	FSECSPERDAY	(24.0 * 60.0 * 60.0)
41249259Sdim#define	FSECSPERHOUR	(60.0 * 60.0)
42249259Sdim#define	FSECSPERMINUTE	(60.0)
43249259Sdim#define	FMINSPERHOUR	(60.0)
44249259Sdim#define	FHOURSPERDAY	(24.0)
45249259Sdim
46249259Sdim#define	DAYSPERYEAR	365
47249259Sdim#define	DAYSPERLEAPYEAR	366
48249259Sdim
49249259Sdim/* Not yet categorized */
50249259Sdim
51249259Sdimextern struct passwd *pw;
52249259Sdimextern int doall;
53249259Sdimextern time_t t1, t2;
54249259Sdimextern const char *calendarFile;
55249259Sdimextern int yrdays;
56249259Sdimextern struct fixs neaster, npaskha, ncny, nfullmoon, nnewmoon;
57249259Sdimextern struct fixs nmarequinox, nsepequinox, njunsolstice, ndecsolstice;
58249259Sdimextern double UTCOffset;
59249259Sdimextern int EastLongitude;
60249259Sdim
61249259Sdim#define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
62249259Sdim
63249259Sdim/* Flags to determine the returned values by determinestyle() in parsedata.c */
64249259Sdim#define	F_NONE			0x00000
65249259Sdim#define	F_MONTH			0x00001
66249259Sdim#define	F_DAYOFWEEK		0x00002
67249259Sdim#define	F_DAYOFMONTH		0x00004
68249259Sdim#define	F_MODIFIERINDEX		0x00008
69249259Sdim#define	F_MODIFIEROFFSET	0x00010
70249259Sdim#define	F_SPECIALDAY		0x00020
71249259Sdim#define	F_ALLMONTH		0x00040
72249259Sdim#define	F_ALLDAY		0x00080
73249259Sdim#define	F_VARIABLE		0x00100
74249259Sdim#define	F_EASTER		0x00200
75249259Sdim#define	F_CNY			0x00400
76249259Sdim#define	F_PASKHA		0x00800
77249259Sdim#define	F_NEWMOON		0x01000
78249259Sdim#define	F_FULLMOON		0x02000
79249259Sdim#define	F_MAREQUINOX		0x04000
80249259Sdim#define	F_SEPEQUINOX		0x08000
81#define	F_JUNSOLSTICE		0x10000
82#define	F_DECSOLSTICE		0x20000
83#define	F_YEAR			0x40000
84
85#define	STRING_EASTER		"Easter"
86#define	STRING_PASKHA		"Paskha"
87#define	STRING_CNY		"ChineseNewYear"
88#define STRING_NEWMOON		"NewMoon"
89#define STRING_FULLMOON		"FullMoon"
90#define STRING_MAREQUINOX	"MarEquinox"
91#define STRING_SEPEQUINOX	"SepEquinox"
92#define STRING_JUNSOLSTICE	"JunSolstice"
93#define STRING_DECSOLSTICE	"DecSolstice"
94
95#define	MAXCOUNT		125	/* Random number of maximum number of
96					 * repeats of an event. Should be 52
97					 * (number of weeks per year), if you
98					 * want to show two years then it
99					 * should be 104. If you are seeing
100					 * more than this you are using this
101					 * program wrong.
102					 */
103
104/*
105 * All the astronomical calculations are carried out for the meridian 120
106 * degrees east of Greenwich.
107 */
108#define UTCOFFSET_CNY		8.0
109
110extern int	debug;		/* show parsing of the input */
111extern int	year1, year2;
112
113/* events.c */
114/*
115 * Event sorting related functions:
116 * - Use event_add() to create a new event
117 * - Use event_continue() to add more text to the last added event
118 * - Use event_print_all() to display them in time chronological order
119 */
120struct event *event_add(int, int, int, char *, int, char *, char *);
121void	event_continue(struct event *events, char *txt);
122void	event_print_all(FILE *fp);
123struct event {
124	int	year;
125	int	month;
126	int	day;
127	int	var;
128	char	*date;
129	char	*text;
130	char	*extra;
131	struct event *next;
132};
133
134/* locale.c */
135
136struct fixs {
137	char	*name;
138	size_t	len;
139};
140
141extern const char *days[];
142extern const char *fdays[];
143extern const char *fmonths[];
144extern const char *months[];
145extern const char *sequences[];
146extern struct fixs fndays[8];		/* full national days names */
147extern struct fixs fnmonths[13];	/* full national months names */
148extern struct fixs ndays[8];		/* short national days names */
149extern struct fixs nmonths[13];		/* short national month names */
150extern struct fixs nsequences[10];
151
152void	setnnames(void);
153void	setnsequences(char *);
154
155/* day.c */
156extern const struct tm tm0;
157extern char dayname[];
158void	settimes(time_t,int before, int after, int friday, struct tm *tp1, struct tm *tp2);
159time_t	Mktime(char *);
160
161/* parsedata.c */
162int	parsedaymonth(char *, int *, int *, int *, int *, char **);
163void	dodebug(char *type);
164
165/* io.c */
166void	cal(void);
167void	closecal(FILE *);
168FILE	*opencal(void);
169
170/* ostern.c / pashka.c */
171int	paskha(int);
172int	easter(int);
173
174/* dates.c */
175extern int cumdaytab[][14];
176extern int mondaytab[][14];
177extern int debug_remember;
178void	generatedates(struct tm *tp1, struct tm *tp2);
179void	dumpdates(void);
180int	remember_ymd(int y, int m, int d);
181int	remember_yd(int y, int d, int *rm, int *rd);
182int	first_dayofweek_of_year(int y);
183int	first_dayofweek_of_month(int y, int m);
184int	walkthrough_dates(struct event **e);
185void	addtodate(struct event *e, int year, int month, int day);
186
187/* pom.c */
188#define	MAXMOONS	18
189void	pom(int year, double UTCoffset, int *fms, int *nms);
190void	fpom(int year, double utcoffset, double *ffms, double *fnms);
191
192/* sunpos.c */
193void	equinoxsolstice(int year, double UTCoffset, int *equinoxdays, int *solsticedays);
194void	fequinoxsolstice(int year, double UTCoffset, double *equinoxdays, double *solsticedays);
195int	calculatesunlongitude30(int year, int degreeGMToffset, int *ichinesemonths);
196