/usr.bin/calendar/calendar.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 196 lines · 115 code · 23 blank · 58 comment · 5 complexity · 95e8e6c500d9b28063b0d232eb125fbb MD5 · raw file

  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$
  30. */
  31. #include <sys/types.h>
  32. #include <sys/uio.h>
  33. #define SECSPERDAY (24 * 60 * 60)
  34. #define SECSPERHOUR (60 * 60)
  35. #define SECSPERMINUTE (60)
  36. #define MINSPERHOUR (60)
  37. #define HOURSPERDAY (24)
  38. #define FSECSPERDAY (24.0 * 60.0 * 60.0)
  39. #define FSECSPERHOUR (60.0 * 60.0)
  40. #define FSECSPERMINUTE (60.0)
  41. #define FMINSPERHOUR (60.0)
  42. #define FHOURSPERDAY (24.0)
  43. #define DAYSPERYEAR 365
  44. #define DAYSPERLEAPYEAR 366
  45. /* Not yet categorized */
  46. extern struct passwd *pw;
  47. extern int doall;
  48. extern time_t t1, t2;
  49. extern const char *calendarFile;
  50. extern int yrdays;
  51. extern struct fixs neaster, npaskha, ncny, nfullmoon, nnewmoon;
  52. extern struct fixs nmarequinox, nsepequinox, njunsolstice, ndecsolstice;
  53. extern double UTCOffset;
  54. extern int EastLongitude;
  55. #define isleap(y) ((((y) % 4) == 0 && ((y) % 100) != 0) || ((y) % 400) == 0)
  56. /* Flags to determine the returned values by determinestyle() in parsedata.c */
  57. #define F_NONE 0x00000
  58. #define F_MONTH 0x00001
  59. #define F_DAYOFWEEK 0x00002
  60. #define F_DAYOFMONTH 0x00004
  61. #define F_MODIFIERINDEX 0x00008
  62. #define F_MODIFIEROFFSET 0x00010
  63. #define F_SPECIALDAY 0x00020
  64. #define F_ALLMONTH 0x00040
  65. #define F_ALLDAY 0x00080
  66. #define F_VARIABLE 0x00100
  67. #define F_EASTER 0x00200
  68. #define F_CNY 0x00400
  69. #define F_PASKHA 0x00800
  70. #define F_NEWMOON 0x01000
  71. #define F_FULLMOON 0x02000
  72. #define F_MAREQUINOX 0x04000
  73. #define F_SEPEQUINOX 0x08000
  74. #define F_JUNSOLSTICE 0x10000
  75. #define F_DECSOLSTICE 0x20000
  76. #define F_YEAR 0x40000
  77. #define STRING_EASTER "Easter"
  78. #define STRING_PASKHA "Paskha"
  79. #define STRING_CNY "ChineseNewYear"
  80. #define STRING_NEWMOON "NewMoon"
  81. #define STRING_FULLMOON "FullMoon"
  82. #define STRING_MAREQUINOX "MarEquinox"
  83. #define STRING_SEPEQUINOX "SepEquinox"
  84. #define STRING_JUNSOLSTICE "JunSolstice"
  85. #define STRING_DECSOLSTICE "DecSolstice"
  86. #define MAXCOUNT 125 /* Random number of maximum number of
  87. * repeats of an event. Should be 52
  88. * (number of weeks per year), if you
  89. * want to show two years then it
  90. * should be 104. If you are seeing
  91. * more than this you are using this
  92. * program wrong.
  93. */
  94. /*
  95. * All the astronomical calculations are carried out for the meridian 120
  96. * degrees east of Greenwich.
  97. */
  98. #define UTCOFFSET_CNY 8.0
  99. extern int debug; /* show parsing of the input */
  100. extern int year1, year2;
  101. /* events.c */
  102. /*
  103. * Event sorting related functions:
  104. * - Use event_add() to create a new event
  105. * - Use event_continue() to add more text to the last added event
  106. * - Use event_print_all() to display them in time chronological order
  107. */
  108. struct event *event_add(int, int, int, char *, int, char *, char *);
  109. void event_continue(struct event *events, char *txt);
  110. void event_print_all(FILE *fp);
  111. struct event {
  112. int year;
  113. int month;
  114. int day;
  115. int var;
  116. char *date;
  117. char *text;
  118. char *extra;
  119. struct event *next;
  120. };
  121. /* locale.c */
  122. struct fixs {
  123. char *name;
  124. size_t len;
  125. };
  126. extern const char *days[];
  127. extern const char *fdays[];
  128. extern const char *fmonths[];
  129. extern const char *months[];
  130. extern const char *sequences[];
  131. extern struct fixs fndays[8]; /* full national days names */
  132. extern struct fixs fnmonths[13]; /* full national months names */
  133. extern struct fixs ndays[8]; /* short national days names */
  134. extern struct fixs nmonths[13]; /* short national month names */
  135. extern struct fixs nsequences[10];
  136. void setnnames(void);
  137. void setnsequences(char *);
  138. /* day.c */
  139. extern const struct tm tm0;
  140. extern char dayname[];
  141. void settimes(time_t,int before, int after, int friday, struct tm *tp1, struct tm *tp2);
  142. time_t Mktime(char *);
  143. /* parsedata.c */
  144. int parsedaymonth(char *, int *, int *, int *, int *, char **);
  145. void dodebug(char *type);
  146. /* io.c */
  147. void cal(void);
  148. void closecal(FILE *);
  149. FILE *opencal(void);
  150. /* ostern.c / paskha.c */
  151. int paskha(int);
  152. int easter(int);
  153. int j2g(int);
  154. /* dates.c */
  155. extern int cumdaytab[][14];
  156. extern int mondaytab[][14];
  157. extern int debug_remember;
  158. void generatedates(struct tm *tp1, struct tm *tp2);
  159. void dumpdates(void);
  160. int remember_ymd(int y, int m, int d);
  161. int remember_yd(int y, int d, int *rm, int *rd);
  162. int first_dayofweek_of_year(int y);
  163. int first_dayofweek_of_month(int y, int m);
  164. int walkthrough_dates(struct event **e);
  165. void addtodate(struct event *e, int year, int month, int day);
  166. /* pom.c */
  167. #define MAXMOONS 18
  168. void pom(int year, double UTCoffset, int *fms, int *nms);
  169. void fpom(int year, double utcoffset, double *ffms, double *fnms);
  170. /* sunpos.c */
  171. void equinoxsolstice(int year, double UTCoffset, int *equinoxdays, int *solsticedays);
  172. void fequinoxsolstice(int year, double UTCoffset, double *equinoxdays, double *solsticedays);
  173. int calculatesunlongitude30(int year, int degreeGMToffset, int *ichinesemonths);