1: #include "remind.h"
   2: 
   3: dtime()
   4: /* Compute delivery time.  Return 1 if NOW else 0. */
   5: {
   6:     register struct tm *p;
   7:     register int f;
   8:     char datespec; /* Date specified flag */
   9: 
  10:     m.tsent = time((time_t *)0);
  11: #ifdef DEBUG
  12:     fprintf(stderr,"tsent = %D\n",m.tsent);
  13: #endif
  14:     p = localtime(&m.tsent);
  15:     /* If some other day and no time spec, make 12:00 am. */
  16:     if ( (datespec = (month|day|year) != 0) && (hour|minute) == 0)
  17:         hour = minute = ABSOLUTE;
  18: 
  19:     /* Compute delivery time */
  20: 
  21:     f = fix(minute, p->tm_min);
  22:     p->tm_hour += f/60;
  23:     minute = f%60;
  24: 
  25:     f = fix(hour, p->tm_hour);
  26:     p->tm_mday += f/24;
  27:     hour = f%24;
  28: 
  29:     day = fix(day, p->tm_mday);
  30:     while (day > (f = (p->tm_mon==1 && p->tm_year%4 ? 29 : dmsize[p->tm_mon])))
  31:     {   day -= f;
  32:         if (++p->tm_mon >= 12)
  33:         {   p->tm_mon = 0;
  34:             ++p->tm_year;
  35:         }
  36:     }
  37: 
  38:     if (month&ABSOLUTE)
  39:         month = (f = month&~ABSOLUTE) ? --f : f;
  40:     else
  41:         month += p->tm_mon;
  42:     p->tm_year += month/12;
  43:     month %= 12;
  44:     ++month;
  45: 
  46:     year = fix(year, p->tm_year);
  47:     if (year < 10) year += 70;
  48: 
  49:     /* Convert to seconds past 0000 1 Jan 1970 GMT using
  50: 	 * algorithm in date.c
  51: 	 */
  52:     gtime();
  53: 
  54: #ifdef DEBUG
  55:     fprintf(stderr,"tdeliver is %D\ttsent is %D\n",m.tdeliver,m.tsent);
  56:     fprintf(stderr,"sent: %s",ctime(&m.tsent));
  57:     fprintf(stderr,"deliver: %s",ctime(&m.tdeliver));
  58: #endif DEBUG
  59:     if ((f = tdiff(&m.tdeliver,&m.tsent)) > 0)
  60:         return(0);
  61:     else if (datespec == 0  && f < -60)  /* Try tomorrow, same time */
  62:     {       for (f = 3; f--; )  /* Add 8 hours 3 times */
  63:             m.tdeliver += 28800;
  64:         if (tdiff(&m.tdeliver,&m.tsent) > 0)
  65:             return(0);
  66:     }
  67:     return(1);
  68: }
  69: 
  70: fix(x,y)
  71: int x,y;
  72: {   return(x&ABSOLUTE ? x&~ABSOLUTE : y + x);
  73: }
  74: 
  75: tdiff(tim1,tim2)
  76: struct dp_int *tim1, *tim2;
  77: {   /* Returns min(tim1-tim2, sgn(tim1-tim2)*32767) */
  78:     register char *i, *j;
  79:     register int k;
  80:     if (tim1->unsgnd1 < tim2->unsgnd1)
  81:         return (-32767);
  82:     if (tim1->unsgnd1 > tim2->unsgnd1)
  83:         return (32767);
  84:     if ((i = tim1->unsgnd2) >= (j = tim2->unsgnd2))
  85:     {       k = i - j;
  86:         return (k&0100000 ? 32767 : k);
  87:     }
  88:     else
  89:     {       k = j - i;
  90:         return (k&0100000 ? -32767 : -k);
  91:     }
  92: }
  93: 
  94: /* Get date or time. */
  95: getdt(pp)
  96: char *pp;
  97: {   char *p;
  98:     register int i;
  99:     p = pp;
 100:     switch (*p++)
 101:     {
 102:       case ':':
 103:         minute = getinteg(&p);
 104:         return(*p);
 105:       case '/':
 106:         return(getdayr(&p));
 107:     }
 108:     p--;
 109:     i = getinteg(&p);
 110:     if (p==pp) return(1);
 111:     switch (*p++)
 112:     {
 113:       case '/':
 114:         month = i;
 115:         return(getdayr(&p));
 116:       case 'a':
 117:       case 'p':
 118:       case '\0':
 119:         p--;
 120:         hour = i;
 121:         minute = hour&ABSOLUTE; /* If hr is relative, */
 122:         break;          /* so is assumed mins */
 123:       case ':':
 124:         hour = i;
 125:         minute = getinteg(&p);
 126:         if ((hour&ABSOLUTE) == 0 && (minute&ABSOLUTE))
 127:             minute &= ~ABSOLUTE;
 128:     }
 129:     if (hour&ABSOLUTE)
 130:         if (*p == 'p')
 131:         {   if (p[1] == 'm')
 132:             {   if ((hour&~ABSOLUTE) < 12)
 133:                     hour += 12;
 134:                 p += 2;
 135:             }
 136:         }
 137:         else if (*p == 'a')
 138:         {   if (p[1] == 'm')
 139:             {   if ((hour&~ABSOLUTE) == 12)
 140:                     hour -= 12;
 141:                 p += 2;
 142:             }
 143:         }
 144:     return(*p);
 145: }
 146: 
 147: getdayr(pp)
 148: char **pp;
 149: {
 150: 
 151:     day = getinteg(pp);
 152:     if (*(*pp) == '/')
 153:     {   (*pp)++;
 154:         year = getinteg(pp);
 155:     }
 156:     return (*(*pp));
 157: }
 158: 
 159: getinteg(pp)
 160: char **pp;
 161: {   register char *p;
 162:     register int i;
 163:     register int d;
 164:     int flag;
 165: 
 166:     p = *pp;
 167:     i = 0;
 168:     if (*p == '+')
 169:     {   flag = 0;
 170:         p++;
 171:     }
 172:     else flag = ABSOLUTE;
 173:     while ((d=digit(*p++)) >= 0)
 174:     {   i *= 10;
 175:         i += d;
 176:     }
 177:     if (--p == *pp) flag = 0; /* Treat null field as incremental 0 */
 178:     *pp = p;
 179:     return (flag|i);
 180: }
 181: 
 182: digit(c)
 183: char c;
 184: {   return (c>='0' && c<='9' ? c - '0' : -1);
 185: }
 186: gtime()
 187: {
 188:     register int i;
 189:     register struct tm *tp;
 190:     int tzone;
 191:     struct timeb T;
 192: 
 193:     ftime(&T);
 194:     tzone = T.timezone*60;
 195:     m.tdeliver = 0L;
 196:     year += 1900;
 197:     for(i=1970; i<year; i++)
 198:         gdadd(dysize(i));
 199:     gdadd((year%4==0 && month>2 ? day : day-1));
 200:     while(--month)
 201:         gdadd(dmsize[month-1]);
 202:     gmdadd(24, hour);
 203:     gmdadd(60, minute);
 204:     gmdadd(60, 0);
 205:     /* convert to Greenwich time, on assumption of Standard time. */
 206: 
 207:         m.tdeliver += tzone;
 208:     /* Now fix up to local daylight time. */
 209:         tp = localtime(&m.tdeliver);
 210:         if (tp->tm_isdst)
 211:             m.tdeliver -= 60*60;
 212:     return(0);
 213: }
 214: 
 215: gmdadd(k, n)
 216: {   /* 0<m<127 (maybe more, but 127 is safe) */
 217:     register int sc;  /* sum/carry */
 218:     register char *c;
 219:     c = (char *)&m.tdeliver;
 220:     c[2] = sc = k * (c[2]&0377);
 221:     sc = sc>>8 & 0377;
 222:     c[3] = sc += k * (c[3]&0377);
 223:     sc = sc>>8 & 0377;
 224:     c[0] = sc += k * (c[0]&0377);
 225:     sc = sc>>8 & 0377;
 226:     c[1] = sc + k * (c[1]&0377);
 227:     gdadd(n);
 228: }

Defined functions

digit defined in line 182; used 1 times
dtime defined in line 3; used 1 times
fix defined in line 70; used 4 times
getdayr defined in line 147; used 2 times
getdt defined in line 95; used 1 times
getinteg defined in line 159; used 5 times
gmdadd defined in line 215; used 3 times
gtime defined in line 186; used 1 times
  • in line 52
tdiff defined in line 75; used 6 times
Last modified: 1981-09-28
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1008
Valid CSS Valid XHTML 1.0 Strict