[BACK]Return to io.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / calendar

Diff for /src/usr.bin/calendar/io.c between version 1.5 and 1.6

version 1.5, 1998/11/08 04:31:13 version 1.6, 1998/12/13 07:31:08
Line 73 
Line 73 
 char *calendarHome = ".calendar"; /* HOME */  char *calendarHome = ".calendar"; /* HOME */
 char *calendarNoMail = "nomail";  /* don't sent mail if this file exist */  char *calendarNoMail = "nomail";  /* don't sent mail if this file exist */
   
 struct fixs neaster, npaskha;  
   
 struct iovec header[] = {  struct iovec header[] = {
         {"From: ", 6},          {"From: ", 6},
         {NULL, 0},          {NULL, 0},
Line 92 
Line 90 
         register int printing;          register int printing;
         register char *p;          register char *p;
         FILE *fp;          FILE *fp;
         int ch, l;          int ch, l, i;
         int var;          int var;
         char buf[2048 + 1];          char buf[2048 + 1];
         struct event *events, *cur_evt, *tmp;          struct event *events, *cur_evt, *ev1, *tmp;
         struct match *m;          struct match *m;
   
         events = NULL;          events = NULL;
Line 119 
Line 117 
                         setnnames();                          setnnames();
                         continue;                          continue;
                 }                  }
                 if (strncasecmp(buf, "Easter=", 7) == 0 && buf[7]) {                  /* User defined names for special events */
                         if (neaster.name != NULL)                  if ((p = strchr(buf, '='))) {
                                 free(neaster.name);                          for (i = 0; i < NUMEV; i++) {
                         if ((neaster.name = strdup(buf + 7)) == NULL)                          if (strncasecmp(buf, spev[i].name, spev[i].nlen) == 0 &&
                                 errx(1, "cannot allocate memory");                              (p - buf == spev[i].nlen) && buf[spev[i].nlen + 1]) {
                         neaster.len = strlen(buf + 7);                                  p++;
                                   if (spev[i].uname != NULL)
                                           free(spev[i].uname);
                                   if ((spev[i].uname = strdup(p)) == NULL)
                                           errx(1, "cannot allocate memory");
                                   spev[i].ulen = strlen(p);
                                   i = NUMEV + 1;
                           }
                           }
                   if (i > NUMEV)
                         continue;                          continue;
                 }                  }
                 if (strncasecmp(buf, "Paskha=", 7) == 0 && buf[7]) {  
                         if (npaskha.name != NULL)  
                                 free(npaskha.name);  
                         if ((npaskha.name = strdup(buf + 7)) == NULL)  
                                 errx(1, "cannot allocate memory");  
                         npaskha.len = strlen(buf + 7);  
                         continue;  
                 }  
                 if (buf[0] != '\t') {                  if (buf[0] != '\t') {
                         printing = (m = isnow(buf)) ? 1 : 0;                          printing = (m = isnow(buf)) ? 1 : 0;
                         if ((p = strchr(buf, '\t')) == NULL)                          if ((p = strchr(buf, '\t')) == NULL) {
                                   printing = 0;
                                 continue;                                  continue;
                           }
                         /* Need the following to catch hardwired "variable"                          /* Need the following to catch hardwired "variable"
                          * dates */                           * dates */
                         if (p > buf && p[-1] == '*')                          if (p > buf && p[-1] == '*')
Line 146 
Line 147 
                         else                          else
                                 var = 0;                                  var = 0;
                         if (printing) {                          if (printing) {
                                 struct tm tm;  
                                 struct match *foo;                                  struct match *foo;
                                 char *dsc;  
   
                                 dsc = NULL;                                  ev1 = NULL;
                                 while (m) {                                  while (m) {
                                 cur_evt = (struct event *) malloc(sizeof(struct event));                                  cur_evt = (struct event *) malloc(sizeof(struct event));
                                 if (cur_evt == NULL)                                  if (cur_evt == NULL)
                                         errx(1, "cannot allocate memory");                                          errx(1, "cannot allocate memory");
   
                                 tm.tm_sec = 0;  /* unused */                                  cur_evt->when = m->when;
                                 tm.tm_min = 0;  /* unused */                                  snprintf(cur_evt->print_date,
                                 tm.tm_hour = 12; /* unused */                                      sizeof(cur_evt->print_date), "%s%c",
                                 tm.tm_wday = 0; /* unused */                                      m->print_date, (var + m->var) ? '*' : ' ');
                                 tm.tm_mon = m->month - 1;                                  if (ev1) {
                                 tm.tm_mday = m->day;                                          cur_evt->desc = ev1->desc;
                                 tm.tm_year = m->year;                                          cur_evt->ldesc = NULL;
                                 tm.tm_isdst = tp->tm_isdst; /* unused */                                  } else {
                                 tm.tm_gmtoff = tp->tm_gmtoff; /* unused */                                          if ((cur_evt->ldesc = strdup(p)) == NULL)
                                 tm.tm_zone = tp->tm_zone; /* unused */  
                                 (void)strftime(cur_evt->print_date,  
                                     sizeof(cur_evt->print_date) - 1,  
                                 /*    "%a %b %d", &tm);  Skip weekdays */  
                                     "%b %d", &tm);  
                                 strcat(cur_evt->print_date,  
                                     (var + m->var) ? "*" : " ");  
                                 cur_evt->when = mktime(&tm);  
                                 if (dsc)  
                                         cur_evt->desc = dsc;  
                                 else {  
                                         if ((cur_evt->desc = strdup(p)) == NULL)  
                                                 errx(1, "cannot allocate memory");                                                  errx(1, "cannot allocate memory");
                                         dsc = cur_evt->desc;                                          cur_evt->desc = &(cur_evt->ldesc);
                                           ev1 = cur_evt;
                                 }                                  }
                                 insert(&events, cur_evt);                                  insert(&events, cur_evt);
                                 foo = m;                                  foo = m;
Line 188 
Line 176 
                         }                          }
                 }                  }
                 else if (printing) {                  else if (printing) {
                         if ((cur_evt->desc = realloc(cur_evt->desc,                          if ((ev1->ldesc = realloc(ev1->ldesc,
                             (2 + strlen(cur_evt->desc) + strlen(buf)))) == NULL)                              (2 + strlen(ev1->ldesc) + strlen(buf)))) == NULL)
                                 errx(1, "cannot allocate memory");                                  errx(1, "cannot allocate memory");
                         strcat(cur_evt->desc, "\n");                          strcat(ev1->ldesc, "\n");
                         strcat(cur_evt->desc, buf);                          strcat(ev1->ldesc, buf);
                 }                  }
         }          }
         tmp = events;          tmp = events;
         while (tmp) {          while (tmp) {
                 (void)fprintf(fp, "%s%s\n", tmp->print_date, tmp->desc);                  (void)fprintf(fp, "%s%s\n", tmp->print_date, *(tmp->desc));
                 /* Can't free descriptions since they may be shared */                  tmp = tmp->next;
                 (void)realloc(tmp->desc, 0);          }
           tmp = events;
           while (tmp) {
                 events = tmp;                  events = tmp;
                   if (tmp->ldesc)
                           free(tmp->ldesc);
                 tmp = tmp->next;                  tmp = tmp->next;
                 free(events);                  free(events);
         }          }
Line 212 
Line 204 
         char *p, **endp;          char *p, **endp;
         int *flags;          int *flags;
 {  {
         int val, var;          int val, var, i;
         char *start, savech;          char *start, savech;
   
         for (; !isdigit(*p) && !isalpha(*p) && *p != '*'; ++p)          for (; !isdigit(*p) && !isalpha(*p) && *p != '*'; ++p)
                 ;                  ;
         if (*p == '*') {                        /* `*' is current month */          if (*p == '*') {                        /* `*' is every month */
                 *flags |= F_ISMONTH;                  *flags |= F_ISMONTH;
                 *endp = p+1;                  *endp = p+1;
                 return (tp->tm_mon + 1);                  return (-1);    /* means 'every month' */
         }          }
         if (isdigit(*p)) {          if (isdigit(*p)) {
                 val = strtol(p, &p, 10);        /* if 0, it's failure */                  val = strtol(p, &p, 10);        /* if 0, it's failure */
Line 250 
Line 242 
   
             /* variable weekday */              /* variable weekday */
             if ((var = getdayvar(start)) != 0) {              if ((var = getdayvar(start)) != 0) {
                 if (var <=5 && var >= -4)                  if (var <= 5 && var >= -4)
                     val += var * 10;                      val += var * 10;
 #ifdef DEBUG  #ifdef DEBUG
                 printf("var: %d\n", var);                  printf("var: %d\n", var);
Line 258 
Line 250 
             }              }
         }          }
   
         /* Easter */          /* Try specials (Easter, Paskha, ...) */
         else if ((val = geteaster(start, tp->tm_year + TM_YEAR_BASE)) != 0)  
             *flags |= F_EASTER;  
   
         /* Paskha */  
         else if ((val = getpaskha(start, tp->tm_year + TM_YEAR_BASE)) != 0)  
             *flags |= F_EASTER;  
   
         /* undefined rest */  
         else {          else {
                 *p = savech;                  for (i = 0; i < NUMEV; i++) {
                 return (0);                          if (strncasecmp(start, spev[i].name, spev[i].nlen) == 0) {
                                   start += spev[i].nlen;
                                   val = i + 1;
                                   i = NUMEV + 1;
                           } else if (spev[i].uname != NULL &&
                               strncasecmp(start, spev[i].uname, spev[i].ulen) == 0) {
                                   start += spev[i].ulen;
                                   val = i + 1;
                                   i = NUMEV + 1;
                           }
                   }
                   if (i > NUMEV) {
                           switch(*start) {
                           case '-':
                           case '+':
                              var = atoi(start);
                              if (var > 365 || var < -365)
                                      return (0); /* Someone is just being silly */
                              val += (NUMEV + 1) * var;
                              /* We add one to the matching event and multiply by
                               * (NUMEV + 1) so as not to return 0 if there's a match.
                               * val will overflow if there is an obscenely large
                               * number of special events. */
                              break;
                           }
                   *flags |= F_SPECIAL;
                   }
                   if (!(*flags & F_SPECIAL)) {
                   /* undefined rest */
                           *p = savech;
                           return (0);
                   }
         }          }
         for (*p = savech; !isdigit(*p) && !isalpha(*p) && *p != '*'; ++p)          for (*p = savech; !isdigit(*p) && !isalpha(*p) && *p != '*'; ++p)
                 ;                  ;

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6