1: static char Sccsid[] = "a9.c @(#)a9.c	1.4	10/1/82 Berkeley ";
   2: #include "apl.h"
   3: #include <math.h>
   4: 
   5: ex_dibm()
   6: {
   7:     register j, arg;
   8:     register struct item *p;
   9: 
  10:     /* Dyadic i-beam functions.  I-beam 63 assumes that the
  11: 	 * "empty" system call (check whether pipe empty) has been
  12: 	 * implemented in the Unix kernel.
  13: 	 */
  14: 
  15:     arg = topfix();     /* Get left argument */
  16: 
  17:     switch(topfix()) {
  18: 
  19:     default:
  20:         error("unknown i-beam");
  21: 
  22:     case 29: /* Set origin, return old one */
  23:         datum = thread.iorg;
  24:         thread.iorg = arg;
  25:         break;
  26: 
  27:     case 30: /* Set width, return old one */
  28:         datum = thread.width;
  29:         thread.width = arg;
  30:         break;
  31: 
  32:     case 31: /* Set number of digits, return old one */
  33:         datum = thread.digits;
  34:         thread.digits = arg;
  35:         break;
  36: 
  37:     case 34: /* "Nice" system call */
  38:         datum = nice(arg);
  39:         break;
  40: 
  41:     case 35: /* "Sleep" system call */
  42:         datum = sleep(arg);
  43:         break;
  44: 
  45:     case 38: /* Sets random seed */
  46:         datum = thread.rl;
  47:         thread.rl = arg;
  48:         srand((int) arg);
  49:         break;
  50: 
  51: 
  52:     case 63: /* "Empty" system call */
  53:         datum = empty(arg);
  54:         break;
  55: 
  56:     case 90: /* Enable/disable exit with ")off" only */
  57:         datum = offexit;
  58:         arg = !!arg;
  59:         offexit = arg ? isatty(0) : arg;
  60:         break;
  61: 
  62:     case 99: /* Buffer flush */
  63:         /* Warning -- information is lost if an input pipe
  64: 		 * file descriptor is flushed.  No checking is
  65: 		 * made for this i-beam function!!
  66: 		 */
  67: #ifdef NBUF
  68:         datum = newbuf(-1, arg);
  69: #else
  70:         datum = zero;       /* No-op if unbuffered */
  71: #endif
  72:         break;
  73: 
  74:     }
  75: 
  76:     p = newdat(DA, 0, 1);
  77:     p->datap[0] = datum;
  78:     *sp++ = p;
  79: 
  80: }
  81: 
  82: int afnfree, afnused;
  83: 
  84: 
  85: ex_mibm()
  86: {
  87:     struct tm *tp, *localtime();
  88:     struct si *gp;
  89:     register struct item *p;
  90:     register struct nlist *np;
  91:     register i;
  92:     long tvec;
  93:     struct {
  94:         long proc_user_time;
  95:         long proc_system_time;
  96:         long child_user_time;
  97:         long child_system_time;
  98:     } t;
  99: 
 100:     switch(topfix()) {
 101: 
 102:     default:
 103:         error("unknown i-beam");
 104: 
 105:     case 20: /* time of day */
 106:         time(&tvec);
 107:         goto tod;
 108: 
 109:     case 21: /* CPU time */
 110:         times(&t);
 111:         datum = t.proc_user_time+t.proc_system_time;
 112:         break;
 113: 
 114:     case 22: /* ws bytes unused */
 115:         datum = afnfree;
 116:         break;
 117: 
 118:     case 24: /* starting time */
 119:         tvec = stime;
 120: 
 121:     tod:
 122:         tp = localtime(&tvec);
 123:         datum = 60.*(tp->tm_sec+60.*(tp->tm_min+60.*tp->tm_hour));
 124:         break;
 125: 
 126:     case 25: /* date */
 127:         time(&tvec);
 128:         goto dt;
 129: 
 130:     case 26:    /* current line */
 131:         datum = (gsip ? gsip->funlc - 1 : 0);
 132:         break;
 133: 
 134:     case 27: /* vector of line numbers of fn activations # */
 135:         i = 0;
 136:         gp = gsip;
 137:         while(gp){
 138:             if(gp->np)
 139:                 i++;
 140:             gp = gp->sip;
 141:         }
 142:         p = newdat(DA, 1, i);
 143:         gp = gsip;
 144:         i = 0;
 145:         while(gp){
 146:             if(gp->np);
 147:                 p->datap[i++] = gp->funlc - 1;
 148:             gp = gp->sip;
 149:         }
 150:         *sp++ = p;
 151:         return;
 152: 
 153:     /*
 154: 	 * non standard I functions
 155: 	 */
 156: 
 157:     case 28: /* starting date */
 158:         tvec = stime;
 159: 
 160:     dt:
 161:         tp = localtime(&tvec);
 162:         datum = tp->tm_year+100.*(tp->tm_mday+100.*(tp->tm_mon+1));
 163:         break;
 164: 
 165:     case 29: /* iorg */
 166:         datum = thread.iorg;
 167:         break;
 168: 
 169:     case 30: /* width */
 170:         datum = thread.width;
 171:         break;
 172: 
 173:     case 31: /* digits */
 174:         datum = thread.digits;
 175:         break;
 176: 
 177:     case 32: /* ws bytes in use */
 178:         datum = afnused;
 179:         break;
 180: 
 181:     case 36: /* 2nd element of ib27 */
 182:         datum = ((gsip && gsip->sip) ? gsip->sip->funlc - 1 : 0);
 183:         break;
 184: 
 185:     case 40: /* Total accumulated child's time */
 186:         times(&t);
 187:         datum = t.child_user_time+t.child_system_time;
 188:         break;
 189: 
 190:     case 41: /* Total accumulated user time -- including all kids */
 191:         times(&t);
 192:         datum = t.proc_user_time+t.child_user_time;
 193:         break;
 194: 
 195:     case 42: /* Total system time -- including all kids */
 196:         times(&t);
 197:         datum = t.proc_system_time+t.child_system_time;
 198:         break;
 199: 
 200:     case 43: /* User time -- parent only */
 201:         times(&t);
 202:         datum = t.proc_user_time;
 203:         break;
 204: 
 205:     case 44: /* System time -- parent only */
 206:         times(&t);
 207:         datum = t.proc_system_time;
 208:         break;
 209: 
 210:     case 95: /* dump namelist */
 211:         for (np=nlist; np->namep; np++)
 212:             printf("%s: use=%d, type=%d, itemp=%o, label=%d\n",
 213:                 np->namep, np->use, np->type, np->itemp,
 214:                 np->label);
 215:         datum = 0;
 216:         break;
 217: 
 218:     case 96:
 219:         dstack();
 220: 
 221:     case 97:
 222:         datum = (sp - stack) / 2;
 223:         break;
 224: 
 225:     case 98: /* turn off alloc/free trace */
 226:         datum = aftrace;
 227:         aftrace = 0;
 228:         break;
 229: 
 230:     case 99: /* turn on alloc/free trace */
 231:         datum = aftrace;
 232:         aftrace = 1;
 233:         break;
 234:     }
 235:     p = newdat(DA, 0, 1);
 236:     p->datap[0] = datum;
 237:     *sp++ = p;
 238: }

Defined functions

ex_dibm defined in line 5; used 2 times
ex_mibm defined in line 85; used 2 times

Defined variables

Sccsid defined in line 1; never used
afnfree defined in line 82; used 1 times
afnused defined in line 82; used 1 times
Last modified: 1983-06-22
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1277
Valid CSS Valid XHTML 1.0 Strict