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