1: #ifndef lint
   2: static char sccsid[] = "@(#)lcmd2.c	3.11 4/24/85";
   3: #endif
   4: 
   5: /*
   6:  * Copyright (c) 1983 Regents of the University of California,
   7:  * All rights reserved.  Redistribution permitted subject to
   8:  * the terms of the Berkeley Software License Agreement.
   9:  */
  10: 
  11: #include "defs.h"
  12: #include "string.h"
  13: #include "value.h"
  14: #include "var.h"
  15: #include "lcmd.h"
  16: #include <sys/resource.h>
  17: #include "alias.h"
  18: 
  19: /*ARGSUSED*/
  20: l_iostat(v, a)
  21: struct value *v, *a;
  22: {
  23:     register struct ww *w;
  24: 
  25:     if ((w = openiwin(14, "IO Statistics")) == 0) {
  26:         error("Can't open statistics window: %s.", wwerror());
  27:         return;
  28:     }
  29:     wwprintf(w, "ttflush\twrite\terror\tzero\tchar\n");
  30:     wwprintf(w, "%d\t%d\t%d\t%d\t%d\n",
  31:         wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc);
  32:     wwprintf(w, "wwwrite\tattempt\tchar\n");
  33:     wwprintf(w, "%d\t%d\t%d\n",
  34:         wwnwwr, wwnwwra, wwnwwrc);
  35:     wwprintf(w, "wwupdat\tline\tmiss\tmajor\tmiss\n");
  36:     wwprintf(w, "%d\t%d\t%d\t%d\t%d\n",
  37:         wwnupdate, wwnupdline, wwnupdmiss, wwnmajline, wwnmajmiss);
  38:     wwprintf(w, "select\terror\tzero\n");
  39:     wwprintf(w, "%d\t%d\t%d\n",
  40:         wwnselect, wwnselecte, wwnselectz);
  41:     wwprintf(w, "read\terror\tzero\tchar\n");
  42:     wwprintf(w, "%d\t%d\t%d\t%d\n",
  43:         wwnread, wwnreade, wwnreadz, wwnreadc);
  44:     wwprintf(w, "ptyread\terror\tzero\tcontrol\tdata\tchar\n");
  45:     wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\n",
  46:         wwnwread, wwnwreade, wwnwreadz,
  47:         wwnwreadp, wwnwreadd, wwnwreadc);
  48:     waitnl(w);
  49:     closeiwin(w);
  50: }
  51: 
  52: struct lcmd_arg arg_time[] = {
  53:     { "who",    1,  ARG_STR },
  54:     0
  55: };
  56: 
  57: /*ARGSUSED*/
  58: l_time(v, a)
  59: struct value *v;
  60: register struct value *a;
  61: {
  62:     register struct ww *w;
  63:     struct rusage rusage;
  64:     struct timeval timeval;
  65:     char *strtime();
  66: 
  67:     if ((w = openiwin(6, "Timing and Resource Usage")) == 0) {
  68:         error("Can't open time window: %s.", wwerror());
  69:         return;
  70:     }
  71: 
  72:     (void) gettimeofday(&timeval, (struct timezone *)0);
  73:     timeval.tv_sec -= starttime.tv_sec;
  74:     if ((timeval.tv_usec -= starttime.tv_usec) < 0) {
  75:         timeval.tv_sec--;
  76:         timeval.tv_usec += 1000000;
  77:     }
  78:     (void) getrusage(a->v_type == V_STR
  79:             && str_match(a->v_str, "children", 1)
  80:         ? RUSAGE_CHILDREN : RUSAGE_SELF, &rusage);
  81: 
  82:     wwprintf(w, "time\t\tutime\t\tstime\t\tmaxrss\tixrss\tidrss\tisrss\n");
  83:     wwprintf(w, "%-16s", strtime(&timeval));
  84:     wwprintf(w, "%-16s", strtime(&rusage.ru_utime));
  85:     wwprintf(w, "%-16s", strtime(&rusage.ru_stime));
  86:     wwprintf(w, "%D\t%D\t%D\t%D\n",
  87:         rusage.ru_maxrss, rusage.ru_ixrss,
  88:         rusage.ru_idrss, rusage.ru_isrss);
  89:     wwprintf(w, "minflt\tmajflt\tnswap\tinblk\toublk\tmsgsnd\tmsgrcv\tnsigs\tnvcsw\tnivcsw\n");
  90:     wwprintf(w, "%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\t%D\n",
  91:         rusage.ru_minflt, rusage.ru_majflt, rusage.ru_nswap,
  92:         rusage.ru_inblock, rusage.ru_oublock,
  93:         rusage.ru_msgsnd, rusage.ru_msgrcv, rusage.ru_nsignals,
  94:         rusage.ru_nvcsw, rusage.ru_nivcsw);
  95: 
  96:     waitnl(w);
  97:     closeiwin(w);
  98: }
  99: 
 100: char *
 101: strtime(t)
 102: register struct timeval *t;
 103: {
 104:     char fill = 0;
 105:     static char buf[20];
 106:     register char *p = buf;
 107: 
 108:     if (t->tv_sec > 60*60) {
 109:         (void) sprintf(p, "%D:", t->tv_sec / (60*60));
 110:         while (*p++)
 111:             ;
 112:         p--;
 113:         t->tv_sec %= 60*60;
 114:         fill++;
 115:     }
 116:     if (t->tv_sec > 60) {
 117:         (void) sprintf(p, fill ? "%02D:" : "%D:", t->tv_sec / 60);
 118:         while (*p++)
 119:             ;
 120:         p--;
 121:         t->tv_sec %= 60;
 122:         fill++;
 123:     }
 124:     (void) sprintf(p, fill ? "%02D.%02d" : "%D.%02D",
 125:         t->tv_sec, t->tv_usec / 10000);
 126:     return buf;
 127: }
 128: 
 129: /*ARGSUSED*/
 130: l_list(v, a)
 131: struct value *v, *a;
 132: {
 133:     register struct ww *w, *wp;
 134:     register i;
 135:     int n;
 136: 
 137:     for (n = 0, i = 0; i < NWINDOW; i++)
 138:         if (window[i] != 0)
 139:             n++;
 140:     if (n == 0) {
 141:         error("No windows.");
 142:         return;
 143:     }
 144:     if ((w = openiwin(n + 2, "Windows")) == 0) {
 145:         error("Can't open listing window: %s.", wwerror());
 146:         return;
 147:     }
 148:     for (i = 0; i < NWINDOW; i++) {
 149:         if ((wp = window[i]) == 0)
 150:             continue;
 151:         wwprintf(w, "%c %c %-13s %-.*s\n",
 152:             wp == selwin ? '*' : ' ',
 153:             i + '1',
 154:             wp->ww_state == WWS_HASPROC ? "" : "(No process)",
 155:             wwncol - 20,
 156:             wp->ww_label ? wp->ww_label : "(No label)");
 157:     }
 158:     waitnl(w);
 159:     closeiwin(w);
 160: }
 161: 
 162: /*ARGSUSED*/
 163: l_variable(v, a)
 164: struct value *v, *a;
 165: {
 166:     register struct ww *w;
 167:     int printvar();
 168: 
 169:     if ((w = openiwin(wwnrow - 3, "Variables")) == 0) {
 170:         error("Can't open variable window: %s.", wwerror());
 171:         return;
 172:     }
 173:     if (var_walk(printvar, (int)w) >= 0)
 174:         waitnl(w);
 175:     closeiwin(w);
 176: }
 177: 
 178: printvar(w, r)
 179: register struct ww *w;
 180: register struct var *r;
 181: {
 182:     if (more(w, 0) == 2)
 183:         return -1;
 184:     wwprintf(w, "%16s    ", r->r_name);
 185:     switch (r->r_val.v_type) {
 186:     case V_STR:
 187:         wwprintf(w, "%s\n", r->r_val.v_str);
 188:         break;
 189:     case V_NUM:
 190:         wwprintf(w, "%d\n", r->r_val.v_num);
 191:         break;
 192:     case V_ERR:
 193:         wwprintf(w, "ERROR\n");
 194:         break;
 195:     }
 196:     return 0;
 197: }
 198: 
 199: struct lcmd_arg arg_shell[] = {
 200:     { "",   0,      ARG_ANY|ARG_LIST },
 201:     0
 202: };
 203: 
 204: l_shell(v, a)
 205:     struct value *v, *a;
 206: {
 207:     register char **pp;
 208:     register struct value *vp;
 209: 
 210:     if (a->v_type == V_ERR) {
 211:         if ((v->v_str = str_cpy(shellfile)) != 0)
 212:             v->v_type = V_STR;
 213:         return;
 214:     }
 215:     if (v->v_str = shellfile) {
 216:         v->v_type = V_STR;
 217:         for (pp = shell + 1; *pp; pp++) {
 218:             str_free(*pp);
 219:             *pp = 0;
 220:         }
 221:     }
 222:     for (pp = shell, vp = a;
 223:          vp->v_type != V_ERR && pp < &shell[sizeof shell/sizeof *shell-1];
 224:          pp++, vp++)
 225:         if ((*pp = vp->v_type == V_STR ?
 226:              str_cpy(vp->v_str) : str_itoa(vp->v_num)) == 0) {
 227:             /* just leave shell[] the way it is */
 228:             p_memerror();
 229:             break;
 230:         }
 231:     if (shellfile = *shell)
 232:         if (*shell = rindex(shellfile, '/'))
 233:             (*shell)++;
 234:         else
 235:             *shell = shellfile;
 236: }
 237: 
 238: struct lcmd_arg arg_alias[] = {
 239:     { "",   0,      ARG_STR },
 240:     { "",   0,      ARG_STR|ARG_LIST },
 241:     0
 242: };
 243: 
 244: l_alias(v, a)
 245:     struct value *v, *a;
 246: {
 247:     if (a->v_type == V_ERR) {
 248:         register struct ww *w;
 249:         int printalias();
 250: 
 251:         if ((w = openiwin(wwnrow - 3, "Aliases")) == 0) {
 252:             error("Can't open alias window: %s.", wwerror());
 253:             return;
 254:         }
 255:         if (alias_walk(printalias, (int)w) >= 0)
 256:             waitnl(w);
 257:         closeiwin(w);
 258:     } else {
 259:         register struct alias *ap = 0;
 260: 
 261:         if (ap = alias_lookup(a->v_str)) {
 262:             if ((v->v_str = str_cpy(ap->a_buf)) == 0) {
 263:                 p_memerror();
 264:                 return;
 265:             }
 266:             v->v_type = V_STR;
 267:         }
 268:         if (a[1].v_type == V_STR) {
 269:             register struct value *vp;
 270:             register char *p, *q;
 271:             char *str;
 272:             register n;
 273: 
 274:             for (n = 0, vp = a + 1; vp->v_type != V_ERR; vp++, n++)
 275:                 for (p = vp->v_str; *p; p++, n++)
 276:                     ;
 277:             if ((str = str_alloc(n)) == 0) {
 278:                 p_memerror();
 279:                 return;
 280:             }
 281:             for (q = str, vp = a + 1; vp->v_type != V_ERR;
 282:                  vp++, q[-1] = ' ')
 283:                 for (p = vp->v_str; *q++ = *p++;)
 284:                     ;
 285:             q[-1] = 0;
 286:             if ((ap = alias_set(a[0].v_str, (char *)0)) == 0) {
 287:                 p_memerror();
 288:                 str_free(str);
 289:                 return;
 290:             }
 291:             ap->a_buf = str;
 292:         }
 293:     }
 294: }
 295: 
 296: printalias(w, a)
 297: register struct ww *w;
 298: register struct alias *a;
 299: {
 300:     if (more(w, 0) == 2)
 301:         return -1;
 302:     wwprintf(w, "%16s    %s\n", a->a_name, a->a_buf);
 303:     return 0;
 304: }
 305: 
 306: struct lcmd_arg arg_unalias[] = {
 307:     { "alias",  1,  ARG_STR },
 308:     0
 309: };
 310: 
 311: l_unalias(v, a)
 312: struct value *v, *a;
 313: {
 314:     if (a->v_type == ARG_STR)
 315:         v->v_num = alias_unset(a->v_str);
 316:     v->v_type = V_NUM;
 317: }
 318: 
 319: struct lcmd_arg arg_echo[] = {
 320:     { "window", 1,  ARG_NUM },
 321:     { "",       0,  ARG_ANY|ARG_LIST },
 322:     0
 323: };
 324: 
 325: /*ARGSUSED*/
 326: l_echo(v, a)
 327: struct value *v;
 328: register struct value *a;
 329: {
 330:     char buf[20];
 331:     struct ww *w;
 332: 
 333:     if ((w = vtowin(a++, selwin)) == 0)
 334:         return;
 335:     while (a->v_type != V_ERR) {
 336:         if (a->v_type == V_NUM) {
 337:             (void) sprintf(buf, "%d", a->v_num);
 338:             (void) wwwrite(w, buf, strlen(buf));
 339:         } else
 340:             (void) wwwrite(w, a->v_str, strlen(a->v_str));
 341:         if ((++a)->v_type != V_ERR)
 342:             (void) wwwrite(w, " ", 1);
 343:     }
 344:     (void) wwwrite(w, "\r\n", 2);
 345: }

Defined functions

l_alias defined in line 244; used 2 times
l_echo defined in line 326; used 2 times
l_iostat defined in line 20; used 2 times
l_list defined in line 130; used 2 times
l_shell defined in line 204; used 2 times
l_time defined in line 58; used 2 times
l_unalias defined in line 311; used 2 times
l_variable defined in line 163; used 2 times
printalias defined in line 296; used 2 times
printvar defined in line 178; used 2 times
strtime defined in line 100; used 4 times

Defined variables

arg_alias defined in line 238; never used
arg_echo defined in line 319; never used
arg_shell defined in line 199; never used
arg_time defined in line 52; never used
arg_unalias defined in line 306; never used
sccsid defined in line 2; never used
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3371
Valid CSS Valid XHTML 1.0 Strict