1: int timbuf[2];
   2: char    *cbp;
   3: 
   4: char *tzname[2];
   5: int dmsize[];
   6: char    cbuf[];
   7: char    *cbp;
   8: 
   9: struct {
  10:     char    name[8];
  11:     char    tty;
  12:     char    fill1;
  13:     int wtime[2];
  14:     int fill2;
  15: } wtmp[2];
  16: 
  17: main(argc, argv)
  18: int argc, **argv;
  19: {
  20:     register char *tzn;
  21:     extern int timezone, *localtime();
  22:     int wf, tfailed;
  23: 
  24:     tfailed = 0;
  25:     if(argc > 1) {
  26:         cbp = argv[1];
  27:         if(gtime()) {
  28:             write(1, "bad conversion\n", 15);
  29:             exit();
  30:         }
  31:         if (*cbp != 's') {
  32:     /* convert to Greenwich time, on assumption of Standard time. */
  33:             dpadd(timbuf, timezone);
  34:     /* Now fix up to local daylight time. */
  35:             if (localtime(timbuf)[8])
  36:                 dpadd(timbuf, -1*60*60);
  37:         }
  38:         time(wtmp[0].wtime);
  39:         wtmp[0].tty =  '|';
  40:         if(stime(timbuf) < 0) {
  41:             tfailed++;
  42:             write(1, "no permission\n", 14);
  43:         } else if ((wf = open("/usr/adm/wtmp", 1)) >= 0) {
  44:             time(wtmp[1].wtime);
  45:             wtmp[1].tty = '}';
  46:             seek(wf, 0, 2);
  47:             write(wf, wtmp, 32);
  48:         }
  49:     }
  50:     if (tfailed==0)
  51:         time(timbuf);
  52:     cbp = cbuf;
  53:     ctime(timbuf);
  54:     write(1, cbuf, 20);
  55:     tzn = tzname[localtime(timbuf)[8]];
  56:     if (tzn)
  57:         write(1, tzn, 3);
  58:     write(1, cbuf+19, 6);
  59: }
  60: 
  61: gtime()
  62: {
  63:     register int i;
  64:     register int y, t;
  65:     int d, h, m;
  66:     extern int *localtime();
  67:     int nt[2];
  68: 
  69:     t = gpair();
  70:     if(t<1 || t>12)
  71:         goto bad;
  72:     d = gpair();
  73:     if(d<1 || d>31)
  74:         goto bad;
  75:     h = gpair();
  76:     if(h == 24) {
  77:         h = 0;
  78:         d++;
  79:     }
  80:     m = gpair();
  81:     if(m<0 || m>59)
  82:         goto bad;
  83:     y = gpair();
  84:     if (y<0) {
  85:         time(nt);
  86:         y = localtime(nt)[5];
  87:     }
  88:     if (*cbp == 'p')
  89:         h =+ 12;
  90:     if (h<0 || h>23)
  91:         goto bad;
  92:     timbuf[0] = 0;
  93:     timbuf[1] = 0;
  94:     y =+ 1900;
  95:     for(i=1970; i<y; i++)
  96:         gdadd(dysize(i));
  97:     /* Leap year */
  98:     if (dysize(y)==366 && t >= 3)
  99:         gdadd(1);
 100:     while(--t)
 101:         gdadd(dmsize[t-1]);
 102:     gdadd(d-1);
 103:     gmdadd(24, h);
 104:     gmdadd(60, m);
 105:     gmdadd(60, 0);
 106:     return(0);
 107: 
 108: bad:
 109:     return(1);
 110: }
 111: 
 112: gdadd(n)
 113: {
 114:     register char *t;
 115: 
 116:     t = timbuf[1]+n;
 117:     if(t < timbuf[1])
 118:         timbuf[0]++;
 119:     timbuf[1] = t;
 120: }
 121: 
 122: gmdadd(m, n)
 123: {
 124:     register int t1;
 125: 
 126:     timbuf[0] =* m;
 127:     t1 = timbuf[1];
 128:     while(--m)
 129:         gdadd(t1);
 130:     gdadd(n);
 131: }
 132: 
 133: gpair()
 134: {
 135:     register int c, d;
 136:     register char *cp;
 137: 
 138:     cp = cbp;
 139:     if(*cp == 0)
 140:         return(-1);
 141:     c = (*cp++ - '0') * 10;
 142:     if (c<0 || c>100)
 143:         return(-1);
 144:     if(*cp == 0)
 145:         return(-1);
 146:     if ((d = *cp++ - '0') < 0 || d > 9)
 147:         return(-1);
 148:     cbp = cp;
 149:     return (c+d);
 150: }

Defined functions

gdadd defined in line 112; used 6 times
gmdadd defined in line 122; used 3 times
gpair defined in line 133; used 5 times
gtime defined in line 61; used 1 times
  • in line 27
main defined in line 17; never used

Defined variables

cbp defined in line 7; used 6 times
cbuf defined in line 6; used 3 times
dmsize defined in line 5; used 1 times
timbuf defined in line 1; used 15 times
tzname defined in line 4; used 1 times
  • in line 55
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1110
Valid CSS Valid XHTML 1.0 Strict