Ejemplo n.º 1
0
void main_calendar( long todayAbs, long endAbs) /* the range of the desired printout */
{
    date_t todayGreg, todayHeb;
    holstorep_t holi_start,holip;         /* a list of holidays for today */
    year_t theYear;
    char *omerStr ;
    int omer, day_of_week, first_weekday, returnedMask;
    int omer_today, sedra_today, candle_today, holidays_today, molad_today;
    molad_t moladNext;
    int monthNext;
    int today_zemanim, i_zman;
    int num_zmanim = sizeof (zemanim) / sizeof (struct _zman); 
    char buffer[80];
    
/* Used to decide whether a particular type of daily info should be
   included in the abbreviated view. In abbreviated mode things like
   sunrise, daf, omer are printed once a week. */
#define INCLUDE_TODAY(_sw) \
  ( (_sw) && ((!abbrev_sw) || (first_weekday == day_of_week)))
    
    todayHeb = abs2hebrew (todayAbs);
    todayGreg = abs2greg (todayAbs);
    
    theYear = yearData (todayHeb.yy);

    /* plug in light_offset before starting the loop */
    for (i_zman = 0; i_zman < num_zmanim; i_zman ++)
       if (zemanim[i_zman].flags == ZMAN_CANDLES_BEFORE)
          zemanim[i_zman].min_offset = light_offset;
       else if (zemanim[i_zman].flags == ZMAN_CANDLES_AFTER ||
                zemanim[i_zman].flags == ZMAN_HAVDALAH )
          zemanim[i_zman].min_offset = havdalah_minutes;
        

    /*============== Main Year Loop ==============*/
    
    
    reset_Omer (todayHeb.yy);
    if (sedraAllWeek_sw || sedrot_sw)
        reset_sedra (todayHeb.yy);
    first_weekday = day_of_week = (int) (todayAbs % 7L);
    while (todayAbs <= endAbs)
    {
        /* get the holidays for today */
      returnedMask = getHebHolidays (todayHeb, &holip);
      
      sedra_today = sedraAllWeek_sw || (sedrot_sw && (day_of_week == SAT));
      omer_today = printOmer_sw &&
          (todayAbs >= beginOmer) &&
          (todayAbs <= endOmer);
      holidays_today = holip &&
        (!noHolidays_sw || (returnedMask & USER_EVENT));
      molad_today = printMolad_sw &&
          (day_of_week == SAT) &&
          (todayHeb.dd >= 23 && todayHeb.dd <= 29) &&
          (todayHeb.mm != ELUL); /* no birkat hachodesh before rosh hashana */
      
      today_zemanim = 0;
      if (INCLUDE_TODAY(default_zemanim))
         today_zemanim |= default_zemanim;
      if (candleLighting_sw)
      {
         if (day_of_week == FRI)
            today_zemanim |= ZMAN_CANDLES_BEFORE;
         else
         {
            if (returnedMask & LIGHT_CANDLES)
               today_zemanim |= (day_of_week == SAT) ?
                  ZMAN_CANDLES_AFTER : ZMAN_CANDLES_BEFORE;
            else 
               if ((returnedMask & LIGHT_CANDLES_TZEIS) &&
                   ! (returnedMask & YOM_TOV_ENDS))
                  today_zemanim |= ZMAN_CANDLES_AFTER;
         }
         if (!(today_zemanim & (ZMAN_CANDLES_BEFORE | ZMAN_CANDLES_AFTER)) &&
             (day_of_week == SAT || returnedMask & YOM_TOV_ENDS))
            today_zemanim |= ZMAN_HAVDALAH;
         if (!(today_zemanim & (ZMAN_CANDLES_BEFORE)) &&
             (returnedMask & CHANUKAH_CANDLES))
           today_zemanim |= ZMAN_CANDLES_AFTER; /* even if havdalah */
      }
      if (INCLUDE_TODAY(printHebDates_sw) ||
          ((printSomeHebDates_sw || printHebDates_sw) && 
           (holidays_today || sedra_today || omer_today || 
            (today_zemanim & (ZMAN_CANDLES_BEFORE|ZMAN_CANDLES_AFTER|ZMAN_HAVDALAH)))))
      {
          PrintGregDate (todayGreg);
          printf ("%d%s of %s, %d\n",
                  todayHeb.dd,       /* print the hebrew date */
                  numSuffix( todayHeb.dd ),
                  _(hMonths[LEAP_YR_HEB( todayHeb.yy )][todayHeb.mm].name),
                  todayHeb.yy);
      }
      
      if (printSunriseSunset_sw)
      {
          print_sunrise_sunset(todayGreg);
      }
      
      /* print the sedra, if desired */
      if (sedra_today)
      {
          char sedraStr[40];
          int foundSedra = sedra( todayAbs, sedraStr, 40 );
          if (foundSedra)
          {
              PrintGregDate( todayGreg );
              printf( "%s %s\n",
                      _("Parashat"),
                      sedraStr );
          }
      }
      
      /* print today's holidays */
      holi_start=holip;         /* store the head of the list for freeing */
      for (; holip; holip = holip->next)
      {
          if (!noHolidays_sw || (holip->typeMask & USER_EVENT))
          {
              PrintGregDate( todayGreg ); 
              puts( holip->name ); 
          }
      }
      
      /* Print the Omer */
      if (INCLUDE_TODAY(omer_today))
      {
          initStr (&omerStr, NM_LEN);
          omer = (int) (todayAbs - beginOmer + 1L);
          if (!tabs_sw)
          {
              strncat (omerStr, hc_itoa (omer), NM_LEN);
              strncat (omerStr, numSuffix (omer), NM_LEN);
              strncat (omerStr, " day of the Omer", NM_LEN);
          }
          else
          {
              strncat (omerStr, "Omer: ", NM_LEN);
              strncat (omerStr, hc_itoa (omer), NM_LEN);
          }
          PrintGregDate (todayGreg);
          printf ("%s\n", omerStr);
          free( omerStr );
      }
      
      if (INCLUDE_TODAY(dafYomi_sw))
         hebcal_dafyomi(&todayGreg);
      
      /* Print CandleLighting times  */
      if (today_zemanim)
      {
          print_candlelighting_times (today_zemanim,
                                      day_of_week, todayGreg);
      }
      
      /* Print Molad */
      if (molad_today)
      {
          PrintGregDate (todayGreg);
          monthNext = (todayHeb.mm == MONTHS_IN_HEB(todayHeb.yy) ? 1 : todayHeb.mm + 1);
          moladNext = get_molad(todayHeb.yy, monthNext);
          printf ("Molad %s: %s, %d minutes and %d chalakim after %d %s\n",
              hMonths[LEAP_YR_HEB(todayHeb.yy)][monthNext].name,
              ShortDayNames[dayOfWeek(abs2greg(moladNext.day))],
              (int) moladNext.chalakim / 18,
              moladNext.chalakim % 18,
              (moladNext.hour > 12 ? moladNext.hour - 12 : moladNext.hour),
              (moladNext.hour > 12 ? "PM" : "AM")
          );
      }

      incHebGregDate (&todayHeb, &todayGreg, &todayAbs, &day_of_week, &theYear);
      
#     ifdef PLUG_LEAKS
      free_holidays(*holip);
#     endif
    }
#undef INCLUDE_TODAY
}
Ejemplo n.º 2
0
void incDate (date_t *dt, long n)			/* increments dt by n days */
{
  *dt = abs2greg (greg2abs (*dt) + n);
}