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

Diff for /src/usr.bin/calendar/day.c between version 1.1 and 1.4

version 1.1, 1996/12/05 06:04:39 version 1.4, 1998/03/30 06:59:26
Line 97 
Line 97 
   
         for (i = 0; i < 7; i++) {          for (i = 0; i < 7; i++) {
                 tm.tm_wday = i;                  tm.tm_wday = i;
                 strftime(buf, sizeof(buf), "%a", &tm);                  l = strftime(buf, sizeof(buf), "%a", &tm);
                 for (l = strlen(buf);                  for (; l > 0 && isspace((int)buf[l - 1]); l--)
                      l > 0 && isspace((int)buf[l - 1]);  
                      l--)  
                         ;                          ;
                 buf[l] = '\0';                  buf[l] = '\0';
                 if (ndays[i].name != NULL)                  if (ndays[i].name != NULL)
Line 109 
Line 107 
                         errx(1, "cannot allocate memory");                          errx(1, "cannot allocate memory");
                 ndays[i].len = strlen(buf);                  ndays[i].len = strlen(buf);
   
                 strftime(buf, sizeof(buf), "%A", &tm);                  l = strftime(buf, sizeof(buf), "%A", &tm);
                 for (l = strlen(buf);                  for (; l > 0 && isspace((int)buf[l - 1]); l--)
                      l > 0 && isspace((int)buf[l - 1]);  
                      l--)  
                         ;                          ;
                 buf[l] = '\0';                  buf[l] = '\0';
                 if (fndays[i].name != NULL)                  if (fndays[i].name != NULL)
Line 124 
Line 120 
   
         for (i = 0; i < 12; i++) {          for (i = 0; i < 12; i++) {
                 tm.tm_mon = i;                  tm.tm_mon = i;
                 strftime(buf, sizeof(buf), "%b", &tm);                  l = strftime(buf, sizeof(buf), "%b", &tm);
                 for (l = strlen(buf);                  for (; l > 0 && isspace((int)buf[l - 1]); l--)
                      l > 0 && isspace((int)buf[l - 1]);  
                      l--)  
                         ;                          ;
                 buf[l] = '\0';                  buf[l] = '\0';
                 if (nmonths[i].name != NULL)                  if (nmonths[i].name != NULL)
Line 136 
Line 130 
                         errx(1, "cannot allocate memory");                          errx(1, "cannot allocate memory");
                 nmonths[i].len = strlen(buf);                  nmonths[i].len = strlen(buf);
   
                 strftime(buf, sizeof(buf), "%B", &tm);                  l = strftime(buf, sizeof(buf), "%B", &tm);
                 for (l = strlen(buf);                  for (; l > 0 && isspace((int)buf[l - 1]); l--)
                      l > 0 && isspace((int)buf[l - 1]);  
                      l--)  
                         ;                          ;
                 buf[l] = '\0';                  buf[l] = '\0';
                 if (fnmonths[i].name != NULL)                  if (fnmonths[i].name != NULL)
Line 155 
Line 147 
         time_t now;          time_t now;
 {  {
         tp = localtime(&now);          tp = localtime(&now);
         if (isleap(tp->tm_year + 1900)) {          if (isleap(tp->tm_year + TM_YEAR_BASE)) {
                 yrdays = DAYSPERLYEAR;                  yrdays = DAYSPERLYEAR;
                 cumdays = daytab[1];                  cumdays = daytab[1];
         } else {          } else {
Line 173 
Line 165 
         setnnames();          setnnames();
 }  }
   
 /* convert Day[/Month][/Year] into unix time (since 1970)  /* convert [Year][Month]Day into unix time (since 1970)
  * Day: two digits, Month: two digits, Year: digits   * Year: two or four digits, Month: two digits, Day: two digits
  */   */
 time_t Mktime (date)  time_t Mktime (date)
     char *date;      char *date;
Line 187 
Line 179 
     tp = localtime(&t);      tp = localtime(&t);
   
     len = strlen(date);      len = strlen(date);
       if (len < 2)
           return((time_t)-1);
     tm.tm_sec = 0;      tm.tm_sec = 0;
     tm.tm_min = 0;      tm.tm_min = 0;
     tm.tm_hour = 0;      tm.tm_hour = 0;
Line 195 
Line 189 
     tm.tm_mon = tp->tm_mon;      tm.tm_mon = tp->tm_mon;
     tm.tm_year = tp->tm_year;      tm.tm_year = tp->tm_year;
   
       /* Day */
       tm.tm_mday = atoi(date + len - 2);
   
     /* day */      /* Month */
     *(date+2) = NULL;  
     tm.tm_mday = atoi(date);  
   
     /* month */  
     if (len >= 4) {      if (len >= 4) {
         *(date+5) = NULL;          *(date + len - 2) = '\0';
         tm.tm_mon = atoi(date+3) - 1;          tm.tm_mon = atoi(date + len - 4) - 1;
     }      }
   
     /* Year */      /* Year */
     if (len >= 7) {      if (len >= 7) {
         tm.tm_year = atoi(date+6);          *(date + len - 4) = '\0';
           tm.tm_year = atoi(date);
   
         /* tm_year up 1900 ... */          /* tm_year up TM_YEAR_BASE ... */
         if (tm.tm_year > 1900)          if (tm.tm_year < 70)
             tm.tm_year -= 1900;                  tm.tm_year += 2000 - TM_YEAR_BASE;
           else if (tm.tm_year < 100)
                   tm.tm_year += 1900 - TM_YEAR_BASE;
           else if (tm.tm_year > TM_YEAR_BASE)
                   tm.tm_year -= TM_YEAR_BASE;
     }      }
   
 #if DEBUG  #if DEBUG

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.4