1: #
   2: /*
   3:  * acct [ -w wtmp ] [ -d ] [ -p people ]
   4:  */
   5: 
   6: #define TSIZE   30
   7: #define USIZE   200
   8: 
   9: struct {
  10:     char    name[8];
  11:     char    tty;
  12:     char    fill1;
  13:     float   time;
  14:     int fill2;
  15: } ibuf;
  16: 
  17: struct ubuf {
  18:     char    name[8];
  19:     float   utime;
  20: } ubuf[USIZE];
  21: 
  22: struct tbuf {
  23:     struct  ubuf    *userp;
  24:     float   ttime;
  25: } tbuf[TSIZE];
  26: 
  27: char    *wtmp;
  28: int pflag, byday;
  29: double  dtime;
  30: double  midnight;
  31: double  lastime;
  32: double  day 1440.;
  33: int pcount;
  34: char    **pptr;
  35: 
  36: int montab[] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
  37:         31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  38: 
  39: char    *monasc[] {
  40:     "Jan",
  41:     "Feb",
  42:     "Mar",
  43:     "Apr",
  44:     "May",
  45:     "Jun",
  46:     "Jul",
  47:     "Aug",
  48:     "Sep",
  49:     "Oct",
  50:     "Nov",
  51:     "Dec"
  52: };
  53: 
  54: main(argc, argv)
  55: char **argv;
  56: {
  57:     int c, fl;
  58:     register i;
  59:     register char *ip;
  60:     extern fin;
  61:     int f;
  62: 
  63:     wtmp = "/usr/adm/wtmp";
  64:     while (--argc > 0 && **++argv == '-')
  65:     switch(*++*argv) {
  66:     case 'd':
  67:         byday++;
  68:         continue;
  69: 
  70:     case 'w':
  71:         if (--argc>0)
  72:             wtmp = *++argv;
  73:         continue;
  74: 
  75:     case 'p':
  76:         pflag++;
  77:         continue;
  78:     }
  79:     pcount = argc;
  80:     pptr = argv;
  81:     if (fopen(wtmp, &fin) < 0) {
  82:         printf("No %s\n", wtmp);
  83:         return;
  84:     }
  85:     for(;;) {
  86:         ip = &ibuf;
  87:         for (i=0; i<16; i++) {
  88:             if ((c=getc(&fin)) < 0)
  89:                 goto brk;
  90:             *ip++ = c;
  91:         }
  92:         fl = 0;
  93:         for (i=0; i<8; i++) {
  94:             c = ibuf.name[i];
  95:             if ('0'<=c&&c<='9'||'a'<=c&&c<='z'||'A'<=c&&c<='Z') {
  96:                 if (fl)
  97:                     goto skip;
  98:                 continue;
  99:             }
 100:             if (c==' ' || c=='\0') {
 101:                 fl++;
 102:                 ibuf.name[i] = '\0';
 103:             } else
 104:                 goto skip;
 105:         }
 106:         loop();
 107:     skip:;
 108:     }
 109:     brk:
 110:     ibuf.name[0] = '\0';
 111:     ibuf.tty = '~';
 112:     time(&ibuf.time);
 113:     loop();
 114:     print();
 115: }
 116: 
 117: loop()
 118: {
 119:     double ltod();
 120:     register i;
 121:     register struct tbuf *tp;
 122:     register struct ubuf *up;
 123: 
 124:     if (ibuf.fill1||ibuf.fill2)
 125:         return;
 126:     ibuf.time = ltod(&ibuf.time)/60.;
 127:     if(ibuf.tty == '|') {
 128:         dtime = ibuf.time;
 129:         return;
 130:     }
 131:     if(ibuf.tty == '}') {
 132:         if(dtime == 0.)
 133:             return;
 134:         for(tp = tbuf; tp < &tbuf[TSIZE]; tp++)
 135:             tp->ttime =+ ibuf.time-dtime;
 136:         dtime = 0.;
 137:         return;
 138:     }
 139:     if (lastime>ibuf.time || lastime+(1.5*day)<ibuf.time)
 140:         midnight = 0.0;
 141:     if (midnight==0.0)
 142:         newday();
 143:     lastime = ibuf.time;
 144:     if (byday && ibuf.time > midnight) {
 145:         upall(1);
 146:         print();
 147:         newday();
 148:         for (up=ubuf; up < &ubuf[USIZE]; up++)
 149:             up->utime = 0.0;
 150:     }
 151:     if (ibuf.tty == '~') {
 152:         ibuf.name[0] = '\0';
 153:         upall(0);
 154:         return;
 155:     }
 156:     if ((i = ibuf.tty) >= 'a')
 157:         i =- 'a' - '9';
 158:     i =- '0';
 159:     if (i<0 || i>=TSIZE)
 160:         i = TSIZE-1;
 161:     tp = &tbuf[i];
 162:     update(tp, 0);
 163: }
 164: 
 165: print()
 166: {
 167:     int i;
 168:     float ttime, t;
 169: 
 170:     ttime = 0.0;
 171:     for (i=0; i<USIZE; i++) {
 172:         if(!among(i))
 173:             continue;
 174:         t = ubuf[i].utime;
 175:         if (t>0.0)
 176:             ttime =+ t;
 177:         if (pflag && ubuf[i].utime > 0.0) {
 178:             printf("\t%-8.8s%6.2f\n",
 179:                 ubuf[i].name, ubuf[i].utime/60.);
 180:         }
 181:     }
 182:     if (ttime > 0.0) {
 183:         pdate();
 184:         printf("\ttotal%9.2f\n", ttime/60.);
 185:     }
 186: }
 187: 
 188: upall(f)
 189: {
 190:     register struct tbuf *tp;
 191: 
 192:     for (tp=tbuf; tp < &tbuf[TSIZE]; tp++)
 193:         update(tp, f);
 194: }
 195: 
 196: update(tp, f)
 197: struct tbuf *tp;
 198: {
 199:     int i, j;
 200:     struct ubuf *up;
 201:     double t, t1;
 202: 
 203:     if (f)
 204:         t = midnight;
 205:     else
 206:         t = ibuf.time;
 207:     if (tp->userp) {
 208:         t1 = t - tp->ttime;
 209:         if (t1>0.0 && t1 < 1.5*day)
 210:             tp->userp->utime =+ t1;
 211:     }
 212:     tp->ttime = t;
 213:     if (f)
 214:         return;
 215:     if (ibuf.name[0]=='\0') {
 216:         tp->userp = 0;
 217:         return;
 218:     }
 219:     for (up=ubuf; up < &ubuf[USIZE]; up++) {
 220:         if (up->name[0] == '\0')
 221:             break;
 222:         for (j=0; j<8 && up->name[j]==ibuf.name[j]; j++);
 223:         if (j>=8)
 224:             break;
 225:     }
 226:     for (j=0; j<8; j++)
 227:         up->name[j] = ibuf.name[j];
 228:     tp->userp = up;
 229: }
 230: 
 231: among(i)
 232: {
 233:     register j, k;
 234:     register char *p;
 235: 
 236:     if (pcount==0)
 237:         return(1);
 238:     for (j=0; j<pcount; j++) {
 239:         p = pptr[j];
 240:         for (k=0; k<8; k++) {
 241:             if (*p == ubuf[i].name[k]) {
 242:                 if (*p++ == '\0')
 243:                     return(1);
 244:             } else
 245:                 break;
 246:         }
 247:     }
 248:     return(0);
 249: }
 250: 
 251: newday()
 252: {
 253:     if(midnight == 0.)
 254:         midnight = 240.;
 255:     while (midnight <= ibuf.time)
 256:         midnight =+ day;
 257: }
 258: 
 259: pdate()
 260: {
 261:     register days, mons, yrs;
 262:     double year, tim;
 263: 
 264:     if (byday==0)
 265:         return;
 266:     yrs = 2;
 267:     tim = 0.0;
 268:     for(;;) {
 269:         year = 365. * day;
 270:         if(yrs%4 == 0)
 271:             year =+ day;
 272:         if(tim+year > midnight)
 273:             break;
 274:         yrs++;
 275:         tim =+ year;
 276:     }
 277:     days = (midnight-tim-720.)/day;
 278:     montab[1] = 28;
 279:     if(yrs%4 == 0)
 280:         montab[1]++;
 281:     for (mons=0; montab[mons]<=days; mons++)
 282:         days =- montab[mons];
 283:     mons =% 12;
 284:     printf("%s %2d", monasc[mons], days+1);
 285: }

Defined functions

among defined in line 231; used 1 times
loop defined in line 117; used 2 times
main defined in line 54; never used
newday defined in line 251; used 2 times
pdate defined in line 259; used 1 times
print defined in line 165; used 2 times
upall defined in line 188; used 2 times
update defined in line 196; used 2 times

Defined variables

byday defined in line 28; used 3 times
day defined in line 32; used 6 times
dtime defined in line 29; used 4 times
lastime defined in line 31; used 3 times
midnight defined in line 30; used 10 times
monasc defined in line 39; used 1 times
montab defined in line 36; used 4 times
pcount defined in line 33; used 3 times
pflag defined in line 28; used 2 times
pptr defined in line 34; used 2 times
tbuf defined in line 25; used 5 times
ubuf defined in line 20; used 9 times
wtmp defined in line 27; used 4 times

Defined struct's

tbuf defined in line 22; used 6 times
ubuf defined in line 17; used 6 times

Defined macros

TSIZE defined in line 6; used 5 times
USIZE defined in line 7; used 4 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1412
Valid CSS Valid XHTML 1.0 Strict