1: #include "../h/rt.h"
   2: #include "../h/keyword.h"
   3: #ifdef SYSTIME
   4: #include <sys/time.h>
   5: #else SYSTIME
   6: #include <time.h>
   7: #endif SYSTIME
   8: #include <sys/types.h>
   9: #include <sys/times.h>
  10: 
  11: static char *day[] = {
  12:    "Sunday", "Monday", "Tuesday", "Wednesday",
  13:    "Thursday", "Friday", "Saturday"
  14:    };
  15: 
  16: static char *month[] = {
  17:    "January", "February", "March", "April", "May", "June",
  18:    "July", "August", "September", "October", "November", "December"
  19:    };
  20: 
  21: /*
  22:  * keywd - process keyword.
  23:  */
  24: 
  25: keywd(nargs, arg1)
  26: int nargs;
  27: struct descrip arg1;
  28:    {
  29:    register int hour, i;
  30:    register char *merid;
  31:    char sbuf[MAXSTRING];
  32:    struct tm *tbuf, *localtime();
  33:    struct tms tp;
  34:    long time(), clock, runtim;
  35:    char *alcstr();
  36: 
  37:    SetBound;
  38: 
  39:    /*
  40:     * This is just plug and chug code.  For whatever keyword is desired,
  41:     *  the appropriate value is dug out of the system and made into
  42:     *  a suitable Icon value.
  43:     *
  44:     * A few special cases are worth noting:
  45:     *  &fail - calls fail();
  46:     *  &pos, &random, &trace - trapped variables are made for possible
  47:     *   subsequent assignments.
  48:     */
  49:    switch (INTVAL(arg1)) {
  50:       case K_ASCII:
  51:          arg1.type = D_CSET;
  52:          BLKLOC(arg1) = (union block *) &k_ascii;
  53:          break;
  54:       case K_CLOCK:
  55:          sneed(8);
  56:          time(&clock);
  57:          tbuf = localtime(&clock);
  58:          sprintf(sbuf,"%02d:%02d:%02d",tbuf->tm_hour,tbuf->tm_min,tbuf->tm_sec);
  59:          STRLEN(arg1) = 8;
  60:          STRLOC(arg1) = alcstr(sbuf,8);
  61:          break;
  62:       case K_CSET:
  63:          arg1.type = D_CSET;
  64:          BLKLOC(arg1) = (union block *) &k_cset;
  65:          break;
  66:       case K_DATE:
  67:          sneed(10);
  68:          time(&clock);
  69:          tbuf = localtime(&clock);
  70:          sprintf(sbuf, "%04d/%02d/%02d",
  71:                       (tbuf->tm_year)+1900,tbuf->tm_mon+1,tbuf->tm_mday);
  72:          STRLEN(arg1) = 10;
  73:          STRLOC(arg1) = alcstr(sbuf,10);
  74:          break;
  75:       case K_DATELINE:
  76:          time(&clock);
  77:          tbuf = localtime(&clock);
  78:          if ((hour = tbuf->tm_hour) >= 12) {
  79:             merid = "pm";
  80:             if (hour > 12)
  81:                hour -= 12;
  82:             }
  83:          else {
  84:             merid = "am";
  85:             if (hour < 1)
  86:                hour += 12;
  87:             }
  88:          sprintf(sbuf, "%s, %s %d, %d  %d:%02d %s",
  89:                  day[tbuf->tm_wday], month[tbuf->tm_mon], tbuf->tm_mday,
  90:                  1900 + tbuf->tm_year, hour, tbuf->tm_min, merid);
  91:          sneed(i = strlen(sbuf));
  92:          STRLEN(arg1) = i;
  93:          STRLOC(arg1) = alcstr(sbuf, i);
  94:          break;
  95:       case K_ERROUT:
  96:          arg1.type = D_FILE;
  97:          BLKLOC(arg1) = (union block *) &k_errout;
  98:          break;
  99:       case K_FAIL:
 100:          fail();
 101:          break;
 102:       case K_HOST:
 103:          iconhost(sbuf);
 104:          sneed(i = strlen(sbuf));
 105:          STRLEN(arg1) = i;
 106:          STRLOC(arg1) = alcstr(sbuf, i);
 107:          break;
 108:       case K_INPUT:
 109:          arg1.type = D_FILE;
 110:          BLKLOC(arg1) = (union block *) &k_input;
 111:          break;
 112:       case K_LCASE:
 113:          arg1.type = D_CSET;
 114:          BLKLOC(arg1) = (union block *) &k_lcase;
 115:          break;
 116:       case K_LEVEL:
 117:          arg1.type = D_INTEGER;
 118:          INTVAL(arg1) = k_level;
 119:          break;
 120:       case K_MAIN:
 121:          arg1 = k_main;
 122:          break;
 123:       case K_NULL:
 124:          arg1 = nulldesc;
 125:          break;
 126:       case K_OUTPUT:
 127:          arg1.type = D_FILE;
 128:          BLKLOC(arg1) = (union block *) &k_output;
 129:          break;
 130:       case K_POS:
 131:          arg1.type = D_TVPOS;
 132:          INTVAL(arg1) = k_pos;
 133:          break;
 134:       case K_RANDOM:
 135:          arg1.type = D_TVRAND;
 136:          BLKLOC(arg1) = (union block *) &k_random;
 137:          break;
 138:       case K_SOURCE:
 139:          arg1 = BLKLOC(current)->estack.activator;
 140:          break;
 141:       case K_SUBJECT:
 142:          arg1.type = D_VAR;
 143:          BLKLOC(arg1) = (union block *) &k_subject;
 144:          break;
 145:       case K_TIME:
 146:          times(&tp);
 147:          runtim =
 148:            1000 * ((tp.tms_utime - starttime) / (double)HZ);
 149:          mkint(runtim, &arg1);
 150:          break;
 151:       case K_TRACE:
 152:          arg1.type = D_TVTRACE;
 153:          INTVAL(arg1) = k_trace;
 154:          break;
 155:       case K_UCASE:
 156:          arg1.type = D_CSET;
 157:          BLKLOC(arg1) = (union block *) &k_ucase;
 158:          break;
 159:       case K_VERSION:
 160:          sneed(i = strlen(VERSION));
 161:          STRLEN(arg1) = i;
 162:          STRLOC(arg1) = VERSION;
 163:          break;
 164:       case K_OPTIONS:
 165:          sneed(i = strlen(OPTIONS));
 166:          STRLEN(arg1) = i;
 167:          STRLOC(arg1) = OPTIONS;
 168:          break;
 169:       default:
 170:          syserr("keyword: unknown keyword type.");
 171:       }
 172:    ClearBound;
 173:    }

Defined functions

keywd defined in line 25; never used

Defined variables

day defined in line 11; used 1 times
  • in line 89
month defined in line 16; used 1 times
  • in line 89
Last modified: 1984-11-18
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1131
Valid CSS Valid XHTML 1.0 Strict