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