[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.35 and 1.47

version 1.35, 2009/10/27 23:59:36 version 1.47, 2017/09/25 19:13:56
Line 29 
Line 29 
  * SUCH DAMAGE.   * SUCH DAMAGE.
  */   */
   
 #include <sys/param.h>  
 #include <sys/stat.h>  #include <sys/stat.h>
 #include <sys/time.h>  #include <sys/time.h>
 #include <sys/types.h>  #include <sys/types.h>
Line 45 
Line 44 
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <tzfile.h>  
 #include <unistd.h>  #include <unistd.h>
   #include <limits.h>
   
 #include "pathnames.h"  #include "pathnames.h"
 #include "calendar.h"  #include "calendar.h"
Line 90 
Line 89 
                 if (strncmp(buf, "LANG=", 5) == 0) {                  if (strncmp(buf, "LANG=", 5) == 0) {
                         (void) setlocale(LC_ALL, buf + 5);                          (void) setlocale(LC_ALL, buf + 5);
                         setnnames();                          setnnames();
                         if (!strcmp(buf + 5, "ru_RU.KOI8-R") ||                          if (!strcmp(buf + 5, "ru_RU.UTF-8") ||
                             !strcmp(buf + 5, "uk_UA.KOI8-U") ||                              !strcmp(buf + 5, "uk_UA.UTF-8") ||
                             !strcmp(buf + 5, "by_BY.KOI8-B")) {                              !strcmp(buf + 5, "by_BY.UTF-8")) {
                                 bodun_maybe++;                                  bodun_maybe++;
                                 bodun = 0;                                  bodun = 0;
                                 if (prefix)                                  free(prefix);
                                         free(prefix);  
                                 prefix = NULL;                                  prefix = NULL;
                         } else                          } else
                                 bodun_maybe = 0;                                  bodun_maybe = 0;
Line 121 
Line 119 
                                 calendar = LUNAR;                                  calendar = LUNAR;
                 } else if (bodun_maybe && strncmp(buf, "BODUN=", 6) == 0) {                  } else if (bodun_maybe && strncmp(buf, "BODUN=", 6) == 0) {
                         bodun++;                          bodun++;
                         if (prefix)                          free(prefix);
                                 free(prefix);  
                         if ((prefix = strdup(buf + 6)) == NULL)                          if ((prefix = strdup(buf + 6)) == NULL)
                                 err(1, NULL);                                  err(1, NULL);
                         continue;                          continue;
Line 135 
Line 132 
                                     (p - buf == spev[i].nlen) &&                                      (p - buf == spev[i].nlen) &&
                                     buf[spev[i].nlen + 1]) {                                      buf[spev[i].nlen + 1]) {
                                         p++;                                          p++;
                                         if (spev[i].uname != NULL)                                          free(spev[i].uname);
                                                 free(spev[i].uname);  
                                         if ((spev[i].uname = strdup(p)) == NULL)                                          if ((spev[i].uname = strdup(p)) == NULL)
                                                 err(1, NULL);                                                  err(1, NULL);
                                         spev[i].ulen = strlen(p);                                          spev[i].ulen = strlen(p);
Line 160 
Line 156 
                                 var = 0;                                  var = 0;
                         if (printing) {                          if (printing) {
                                 struct match *foo;                                  struct match *foo;
   
                                 ev1 = NULL;                                  ev1 = NULL;
                                 while (m) {                                  while (m) {
                                         cur_evt = malloc(sizeof(struct event));                                          cur_evt = malloc(sizeof(struct event));
                                         if (cur_evt == NULL)                                          if (cur_evt == NULL)
                                                 err(1, NULL);                                                  err(1, NULL);
   
                                         cur_evt->when = m->when;                                          cur_evt->when = m->when;
                                         snprintf(cur_evt->print_date,                                          snprintf(cur_evt->print_date,
                                             sizeof(cur_evt->print_date), "%s%c",                                              sizeof(cur_evt->print_date), "%s%c",
Line 208 
Line 204 
         tmp = events;          tmp = events;
         while (tmp) {          while (tmp) {
                 events = tmp;                  events = tmp;
                 if (tmp->ldesc)                  free(tmp->ldesc);
                         free(tmp->ldesc);  
                 tmp = tmp->next;                  tmp = tmp->next;
                 free(events);                  free(events);
         }          }
Line 222 
Line 217 
         int val, var, i;          int val, var, i;
         char *start, savech;          char *start, savech;
   
         for (; !isdigit(*p) && !isalpha(*p) && *p != '*' && *p != '\t'; ++p)          for (; !isdigit((unsigned char)*p) && !isalpha((unsigned char)*p) &&
               *p != '*' && *p != '\t'; ++p)
                 ;                  ;
         if (*p == '*') {                        /* `*' is every month */          if (*p == '*') {                        /* `*' is every month */
                 *flags |= F_ISMONTH;                  *flags |= F_ISMONTH;
                 *endp = p+1;                  *endp = p+1;
                 return (-1);    /* means 'every month' */                  return (-1);    /* means 'every month' */
         }          }
         if (isdigit(*p)) {          if (isdigit((unsigned char)*p)) {
                 val = strtol(p, &p, 10);        /* if 0, it's failure */                  val = strtol(p, &p, 10);        /* if 0, it's failure */
                 for (; !isdigit(*p) && !isalpha(*p) && *p != '*'; ++p)                  for (; !isdigit((unsigned char)*p) &&
                       !isalpha((unsigned char)*p) && *p != '*'; ++p)
                         ;                          ;
                 *endp = p;                  *endp = p;
                 return (val);                  return (val);
         }          }
         for (start = p; isalpha(*++p);)          for (start = p; isalpha((unsigned char)*++p);)
                 ;                  ;
   
         /* Sunday-1 */          /* Sunday-1 */
         if (*p == '+' || *p == '-')          if (*p == '+' || *p == '-')
                 for(; isdigit(*++p); )                  for(; isdigit((unsigned char)*++p); )
                         ;                          ;
   
         savech = *p;          savech = *p;
Line 280 
Line 277 
                         }                          }
                 }                  }
                 if (i > NUMEV) {                  if (i > NUMEV) {
                         switch(*start) {                          const char *errstr;
   
                           switch (*start) {
                         case '-':                          case '-':
                         case '+':                          case '+':
                                 var = atoi(start);                                  var = strtonum(start + 1, 0, 365, &errstr);
                                 if (var > 365 || var < -365)                                  if (errstr)
                                         return (0); /* Someone is just being silly */                                          return (0); /* Someone is just being silly */
                                   if (*start == '-')
                                           var = -var;
                                 val += (NUMEV + 1) * var;                                  val += (NUMEV + 1) * var;
                                 /* We add one to the matching event and multiply by                                  /* We add one to the matching event and multiply by
                                  * (NUMEV + 1) so as not to return 0 if there's a match.                                   * (NUMEV + 1) so as not to return 0 if there's a match.
Line 293 
Line 294 
                                  * number of special events. */                                   * number of special events. */
                                 break;                                  break;
                         }                          }
                         *flags |= F_SPECIAL;                          *flags |= F_SPECIAL;
                 }                  }
                 if (!(*flags & F_SPECIAL)) {                  if (!(*flags & F_SPECIAL)) {
                         /* undefined rest */                          /* undefined rest */
Line 301 
Line 302 
                         return (0);                          return (0);
                 }                  }
         }          }
         for (*p = savech; !isdigit(*p) && !isalpha(*p) && *p != '*' && *p != '\t'; ++p)          for (*p = savech; !isdigit((unsigned char)*p) &&
               !isalpha((unsigned char)*p) && *p != '*' && *p != '\t'; ++p)
                 ;                  ;
         *endp = p;          *endp = p;
         return (val);          return (val);
Line 329 
Line 331 
                 }                  }
         }          }
   
         if (pipe(pdes) < 0)          if (pipe(pdes) < 0) {
                   close(fdin);
                 return (NULL);                  return (NULL);
           }
         switch (vfork()) {          switch (vfork()) {
         case -1:                        /* error */          case -1:                        /* error */
                 (void)close(pdes[0]);                  (void)close(pdes[0]);
                 (void)close(pdes[1]);                  (void)close(pdes[1]);
                   close(fdin);
                 return (NULL);                  return (NULL);
         case 0:          case 0:
                 dup2(fdin, STDIN_FILENO);                  dup2(fdin, STDIN_FILENO);
Line 344 
Line 349 
                         (void)close(pdes[1]);                          (void)close(pdes[1]);
                 }                  }
                 (void)close(pdes[0]);                  (void)close(pdes[0]);
                 /*                  /*
                  * Set stderr to /dev/null.  Necessary so that cron does not                   * Set stderr to /dev/null.  Necessary so that cron does not
                  * wait for cpp to finish if it's running calendar -a.                   * wait for cpp to finish if it's running calendar -a.
                  */                   */
Line 380 
Line 385 
         struct stat sbuf;          struct stat sbuf;
         int nread, pdes[2], status;          int nread, pdes[2], status;
         char buf[1024];          char buf[1024];
           pid_t pid = -1;
   
         if (!doall)          if (!doall)
                 return;                  return;
Line 389 
Line 395 
                 goto done;                  goto done;
         if (pipe(pdes) < 0)          if (pipe(pdes) < 0)
                 goto done;                  goto done;
         switch (vfork()) {          switch ((pid = vfork())) {
         case -1:                        /* error */          case -1:                        /* error */
                 (void)close(pdes[0]);                  (void)close(pdes[0]);
                 (void)close(pdes[1]);                  (void)close(pdes[1]);
Line 416 
Line 422 
                 (void)write(pdes[1], buf, nread);                  (void)write(pdes[1], buf, nread);
         (void)close(pdes[1]);          (void)close(pdes[1]);
 done:   (void)fclose(fp);  done:   (void)fclose(fp);
         while (wait(&status) >= 0)          if (pid != -1) {
                 ;                  while (waitpid(pid, &status, 0) == -1) {
                           if (errno != EINTR)
                                   break;
                   }
           }
 }  }
   
   

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.47