home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume17 / calentool / part12 / holidays.c next >
Encoding:
C/C++ Source or Header  |  1991-04-06  |  11.0 KB  |  390 lines

  1. /*
  2.  * $Header: holidays.c,v 2.4 91/03/27 16:45:41 billr Exp $
  3.  */
  4. /*
  5.  * holidays.c
  6.  *
  7.  * Author: Bill Randle, Tektronix, Inc. <billr@saab.CNA.TEK.COM>
  8.  *    (based on a test driver by R.P.C. Rodgers)
  9.  *
  10.  * Copyright (C) 1989, Tektronix, Inc.  All Rights Reserved
  11.  *
  12.  * Permission is hereby granted to use and modify this code in source
  13.  * or binary form as long as it is not sold for profit and this copyright
  14.  * notice remains intact.
  15.  */
  16. /*
  17.  * functions from datelib (by R.P.C. Rodgers)
  18.  */
  19. #include "ct.h"        /* for the NO_HOLIDAYS #define */
  20. #ifndef NO_HOLIDAYS
  21.  
  22. #include <sys/time.h>
  23.  
  24. double    election_day();            /* Secular US holidays */
  25.  
  26. double    autumn_equinox(),        /* Astronomical events */
  27.     summer_solstice(),
  28.     vernal_equinox(),
  29.     winter_solstice();
  30.  
  31. double    ascension_day(),        /* Christian holidays */
  32.     ash_wednesday(),
  33.     corpus_christi(),
  34.     easter(),
  35.     easter_monday(),
  36.     easter_offset(),
  37.     first_sunday_advent(),
  38.     first_sunday_lent(),
  39.     fourth_sunday_lent(),
  40.     good_friday(),
  41.     maundy_thursday(),
  42.     palm_sunday(),
  43.     passion_sunday(),
  44.     rogation_sunday(),
  45.     septuagesima(),
  46.     sexagesima(),
  47.     quinquagesima(),
  48.     second_sunday_lent(),
  49.     shrove_monday(),
  50.     shrove_tuesday(),
  51.     third_sunday_lent(),
  52.     trinity_sunday(),
  53.     whitsunday();
  54.  
  55. double    islamic_new_year(),        /* Islamic holidays */
  56.     muharram_9(),
  57.     muharram_10(),
  58.     muharram_16(),
  59.     eid_i_milad_un_nabi(),
  60.     jumada_al_akhir_23(),
  61.     shab_e_miraj(),
  62.     shab_e_barat(),
  63.     shab_e_qadr(),
  64.     ramadan(),
  65.     eid_al_fitr(),
  66.     dhul_hijja_9(),
  67.     eid_al_adha(),
  68.     ghadir();
  69.  
  70. double    chanukah(),            /* Jewish holidays */
  71.     passover(),
  72.     passover_offset(),
  73.     purim(),
  74.     rosh_hashanah(),
  75.     shavuot(),
  76.     simchat_torah(),
  77.     sukkot(),
  78.     yom_kippur();
  79.  
  80. extern struct tm current;    /* current day displayed from calentool */
  81. #define NUM_ADATES    4
  82. #define NUM_CDATES    22
  83. #define NUM_IDATES    28
  84. #define NUM_JDATES    8
  85. #define NUM_SDATES    1
  86.  
  87. int    marked_note;
  88. int    gsave_year = -1;  /* indicates datelib initialized */
  89. struct appt_entry a_appts[NUM_ADATES], c_appts[NUM_CDATES];
  90. struct appt_entry i_appts[NUM_IDATES], j_appts[NUM_JDATES];
  91. struct appt_entry s_appts[NUM_SDATES];
  92.  
  93. int
  94. a_dates(flag)
  95. int flag;
  96. {
  97.     static int save_year = -1;
  98.  
  99.     /*
  100.      * Astromonical Events
  101.      */
  102.     if (!flag || current.tm_year == save_year)
  103.         return(NUM_ADATES);
  104.     marked_note = flag - 1;
  105.     if (current.tm_year != gsave_year) {
  106.         datelib_init(current.tm_year+1900);
  107.         gsave_year = current.tm_year;
  108.     }
  109.     save_year = current.tm_year;
  110.     get_date(&a_appts[0], "Vernal Equinox", vernal_equinox, TRUE);
  111.     get_date(&a_appts[1], "Summer Solstice", summer_solstice, TRUE);
  112.     get_date(&a_appts[2], "Autumn Equinox", autumn_equinox, TRUE);
  113.     get_date(&a_appts[3], "Winter Solstice", winter_solstice, TRUE);
  114.     return(NUM_ADATES);
  115. }
  116.  
  117. int
  118. c_dates(flag)
  119. int flag;
  120. {
  121.     static int save_year = -1;
  122.  
  123.     /*
  124.      * Christian holidays
  125.      */
  126.     if (!flag || current.tm_year == save_year)
  127.         return(NUM_CDATES);
  128.     marked_note = flag - 1;
  129.     if (current.tm_year != gsave_year) {
  130.         datelib_init(current.tm_year+1900);
  131.         gsave_year = current.tm_year;
  132.     }
  133.     save_year = current.tm_year;
  134.     get_date(&c_appts[0], "Septuagesima Sunday", septuagesima, FALSE);
  135.     get_date(&c_appts[1], "Sexagesima Sunday", sexagesima, FALSE);
  136.     get_date(&c_appts[2], "Quinquagesima Sunday", quinquagesima, FALSE);
  137.     get_date(&c_appts[3], "Shrove Monday", shrove_monday, FALSE);
  138.     get_date(&c_appts[4], "Shrove Tuesday (Mardi Gras)", shrove_tuesday, FALSE);
  139.     get_date(&c_appts[5], "Ash Wednesday", ash_wednesday, FALSE);
  140.     get_date(&c_appts[6], "First Sunday in Lent", first_sunday_lent, FALSE);
  141.     get_date(&c_appts[7], "Second Sunday in Lent", second_sunday_lent, FALSE);
  142.     get_date(&c_appts[8], "Third Sunday in Lent", third_sunday_lent, FALSE);
  143.     get_date(&c_appts[9], "Fourth Sunday in Lent", fourth_sunday_lent, FALSE);
  144.     get_date(&c_appts[10], "Passion Sunday", passion_sunday, FALSE);
  145.     get_date(&c_appts[11], "Palm Sunday", palm_sunday, FALSE);
  146.     get_date(&c_appts[12], "Maundy Thursday", maundy_thursday, FALSE);
  147.     get_date(&c_appts[13], "Good Friday", good_friday, FALSE);
  148.     get_date(&c_appts[14], "Easter", easter, FALSE);
  149.     get_date(&c_appts[15], "Easter Monday (Canada)", easter_monday, FALSE);
  150.     get_date(&c_appts[16], "Rogation Sunday", rogation_sunday, FALSE);
  151.     get_date(&c_appts[17], "Ascension Day", ascension_day, FALSE);
  152.     get_date(&c_appts[18], "Whitsunday", whitsunday, FALSE);
  153.     get_date(&c_appts[19], "Trinity Sunday", trinity_sunday, FALSE);
  154.     get_date(&c_appts[20], "Corpus Christi", corpus_christi, FALSE);
  155.     get_date(&c_appts[21], "First Sunday in Advent", first_sunday_advent, FALSE);
  156.     return(NUM_CDATES);
  157. }
  158.  
  159. int
  160. i_dates(flag)
  161. int flag;
  162. {
  163.     int ndates;
  164.     static int save_year = -1, i = 0;
  165.     int get_idate();
  166.  
  167.     /*
  168.      * Islamic holidays
  169.      */
  170.     if (!flag || current.tm_year == save_year)
  171.         return(i);
  172.     marked_note = flag - 1;
  173.     if (current.tm_year != gsave_year) {
  174.         datelib_init(current.tm_year+1900);
  175.         gsave_year = current.tm_year;
  176.     }
  177.     save_year = current.tm_year;
  178.     i = 0;
  179.     if (get_idate(&i_appts[i++],
  180.         "Muharram 1, %d A.H.: Islamic New Year", islamic_new_year, 1) == 2)
  181.         get_idate(&i_appts[i++],
  182.             "Muharram 1, %d A.H.: Islamic New Year", islamic_new_year, 2);
  183.     if (get_idate(&i_appts[i++],
  184.         "Muharram 9, %d A.H.: Day of fasting", muharram_9, 1) == 2)
  185.         get_idate(&i_appts[i++],
  186.             "Muharram 9, %d A.H.: Day of fasting", muharram_9, 2);
  187.     if (get_idate(&i_appts[i++],
  188.         "Muharram 10, %d A.H.: Deliverance of Moses from the Pharoah (for Shia Islam, martyrdom of Husain)",
  189.         muharram_10, 1) == 2)
  190.         get_idate(&i_appts[i++],
  191.             "Muharram 10, %d A.H.: Deliverance of Moses from the Pharoah (for Shia Islam, martyrdom of Husain)",
  192.             muharram_10, 2);
  193.     if (get_idate(&i_appts[i++],
  194.         "Muharram 16, %d A.H. (Imamat Day; Ismaili Khoja)", muharram_16, 1) == 2)
  195.         get_idate(&i_appts[i++],
  196.             "Muharram 16, %d A.H. (Imamat Day; Ismaili Khoja)", muharram_16, 2);
  197.     if (get_idate(&i_appts[i++],
  198.         "Rabi I 12, %d A.H. (Eid-i-Milad-un-Nabi: The Prophet's Birthday)",
  199.         eid_i_milad_un_nabi, 1) == 2)
  200.         get_idate(&i_appts[i++],
  201.             "Rabi I 12, %d A.H. (Eid-i-Milad-un-Nabi: The Prophet's Birthday)",
  202.             eid_i_milad_un_nabi, 2);
  203.     if (get_idate(&i_appts[i++],
  204.         "Jumada al-Akhir 23, %d A.H. (Birth of Agha Khan IV, Ismaili)",
  205.         jumada_al_akhir_23, 1) == 2)
  206.         get_idate(&i_appts[i++],
  207.             "Jumada al-Akhir 23, %d A.H. (Birth of Agha Khan IV, Ismaili)",
  208.             jumada_al_akhir_23, 2);
  209.     if (get_idate(&i_appts[i++],
  210.         "Rajab 27, %d A.H. (Shab-e-Mi'raj: The Prophet's Ascension)",
  211.         shab_e_miraj, 1) == 2)
  212.         get_idate(&i_appts[i++],
  213.             "Rajab 27, %d A.H. (Shab-e-Mi'raj: The Prophet's Ascension)",
  214.             shab_e_miraj, 2);
  215.     if (get_idate(&i_appts[i++],
  216.         "Shaban 15, %d A.H. (Shab-e-Bara't: Night, followed by day of fasting)",
  217.         shab_e_barat, 1) == 2)
  218.         get_idate(&i_appts[i++],
  219.             "Shaban 15, %d A.H. (Shab-e-Bara't: Night, followed by day of fasting)",
  220.             shab_e_barat, 2);
  221.     if (get_idate(&i_appts[i++],
  222.         "Ramadan 1, %d A.H. (Fasting month begins)", ramadan, 1) == 2)
  223.         get_idate(&i_appts[i++],
  224.             "Ramadan 1, %d A.H. (Fasting month begins)", ramadan, 2);
  225.     if (get_idate(&i_appts[i++],
  226.         "Ramadan 27, %d A.H. (Shab-e-Qadr: Night vigil)", shab_e_qadr, 1) == 2)
  227.         get_idate(&i_appts[i++],
  228.             "Ramadan 27, %d A.H. (Shab-e-Qadr: Night vigil)", shab_e_qadr, 2);
  229.     if (get_idate(&i_appts[i++],
  230.         "Shawwal 1, %d A.H. (Eid-al-Fitr: Day of Feast)", eid_al_fitr, 1) == 2)
  231.         get_idate(&i_appts[i++],
  232.             "Shawwal 1, %d A.H. (Eid-al-Fitr: Day of Feast)", eid_al_fitr, 2);
  233.     if (get_idate(&i_appts[i++],
  234.         "Dhul-Hijj 9, %d A.H. (Day of Pilgrimage at Arafat, Mecca)",
  235.         dhul_hijja_9, 1) == 2)
  236.         get_idate(&i_appts[i++],
  237.             "Dhul-Hijj 9, %d A.H. (Day of Pilgrimage at Arafat, Mecca)",
  238.             dhul_hijja_9, 2);
  239.     if (get_idate(&i_appts[i++],
  240.         "Dhul-Hijj 10, %d A.H. (Eid-al-Azha: Day of Abraham's Sacrifice)",
  241.         eid_al_adha, 1) == 2)
  242.         get_idate(&i_appts[i++],
  243.             "Dhul-Hijj 10, %d A.H. (Eid-al-Azha: Day of Abraham's Sacrifice)",
  244.             eid_al_adha, 2);
  245.     if (get_idate(&i_appts[i++],
  246.         "Dhul-Hijj 18, %d A.H. (Ghadir: Ali's Nomination)", ghadir, 1) == 2)
  247.         get_idate(&i_appts[i++],
  248.             "Dhul-Hijj 18, %d A.H. (Ghadir: Ali's Nomination)", ghadir, 2);
  249.     return(i);
  250. }
  251.  
  252. int
  253. j_dates(flag)
  254. int flag;
  255. {
  256.     char buf[24];
  257.     int jyear;
  258.     static int save_year = -1;
  259.  
  260.     /*
  261.      * Jewish holidays
  262.      */
  263.     if (!flag || current.tm_year == save_year)
  264.         return(NUM_JDATES);
  265.     marked_note = flag - 1;
  266.     if (current.tm_year != gsave_year) {
  267.         datelib_init(current.tm_year+1900);
  268.         gsave_year = current.tm_year;
  269.     }
  270.     save_year = current.tm_year;
  271.     get_jdate(&j_appts[0], "Purim", purim);
  272.     get_jdate(&j_appts[1], "First day of Passover (8 days)", passover);
  273.     get_jdate(&j_appts[2], "Shavuot (2 days)", shavuot);
  274.     get_jdate(&j_appts[3], "Rosh Hashanah (Jewish New Year) (2 days)", rosh_hashanah);
  275.     get_jdate(&j_appts[4], "Yom Kippur", yom_kippur);
  276.     get_jdate(&j_appts[5], "First day of Sukkot (9 days)", sukkot);
  277.     get_jdate(&j_appts[6], "Simchat Torah", simchat_torah);
  278.     get_jdate(&j_appts[7], "First day of Chanukah (8 days)", chanukah);
  279.     return(NUM_JDATES);
  280. }
  281.  
  282. int
  283. s_dates(flag)
  284. int flag;
  285. {
  286.     static int save_year = -1;
  287.  
  288.     /*
  289.      * SECULAR US HOLIDAYS
  290.      * [Holidays specified as a given date (e.g. July 4) or as
  291.      *  a known nth mday of a month (e.g. 2nd Monday) are not
  292.      *  calculated here.  They are available from one of the
  293.      *  auxillary date files.]
  294.      */
  295.     if (!flag || current.tm_year == save_year)
  296.         return(NUM_SDATES);
  297.     marked_note = flag - 1;
  298.     if (current.tm_year != gsave_year) {
  299.         datelib_init(current.tm_year+1900);
  300.         gsave_year = current.tm_year;
  301.     }
  302.     save_year = current.tm_year;
  303.     get_date(&s_appts[0], "Election Day", election_day, FALSE);
  304.     return(NUM_SDATES);
  305. }
  306.  
  307. /*
  308.  * check for gregorian (i.e. US secular & Christian) holidays
  309.  */
  310. get_date(aptr, str, func, timeflag)
  311. struct appt_entry *aptr;
  312. char *str;
  313. double (*func)();
  314. int timeflag;
  315. {
  316.     double    hday;
  317.     char     *julian_time();
  318.  
  319.     hday = (*func)(current.tm_year+1900);
  320.     fill_holiday(aptr, hday);
  321.     strcpy(aptr->str, str);
  322.     if (timeflag) {
  323.         strcat(aptr->str, julian_time(hday));
  324.         strcat(aptr->str, " GMT");
  325.     }
  326. }
  327.  
  328. /*
  329.  * check for Islamic holidays
  330.  */
  331. int
  332. get_idate(aptr, str, func, which)
  333. struct appt_entry *aptr;
  334. char *str;
  335. int (*func)();
  336. int which;
  337. {
  338.     double    date1, date2;
  339.     int    nr_dates, year1, year2;
  340.  
  341.     (void)(*func)(current.tm_year+1900, &nr_dates, &date1, &date2, &year1, &year2);
  342.     if (which == 1) {
  343.         fill_holiday(aptr, date1);
  344.         sprintf(aptr->str, str, year1);
  345.     } else if (which == 2 && nr_dates == 2) {
  346.         fill_holiday(aptr, date2);
  347.         sprintf(aptr->str, str, year2);
  348.     }
  349.     return (nr_dates);
  350. }
  351.  
  352. /*
  353.  * check for Jewish holidays
  354.  */
  355. get_jdate(aptr, str, func)
  356. struct appt_entry *aptr;
  357. char *str;
  358. double (*func)();
  359. {
  360.     int    jyear;
  361.     double    hday;
  362.     char    buf[32];
  363.  
  364.     hday = (*func)(current.tm_year+1900, &jyear);
  365.     fill_holiday(aptr, hday);
  366.     strcpy(aptr->str, str);
  367.     sprintf(buf, " [Jewish year %d]", jyear);
  368.     strcat(aptr->str, buf);
  369. }
  370.  
  371. fill_holiday(aptr, hday)
  372. struct appt_entry *aptr;
  373. double hday;
  374. {
  375.     int    month, year;
  376.     double    day;
  377.  
  378.     gregorian_date(&day, &month, &year, hday);
  379.     aptr->year = current.tm_year;
  380.     aptr->month = month - 1;
  381.     aptr->day = (int)day;
  382.     aptr->arrows = aptr->repeat = aptr->lookahead = 0;
  383.     aptr->runlength = 0;
  384.     aptr->warn = 10;
  385.     aptr->flags = (A_NOTE | READONLY);
  386.     if (marked_note)
  387.         aptr->flags |= MARKED;
  388. }
  389. #endif    /* NO_HOLIDAYS */
  390.