|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1983 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * This code is derived from software contributed to Berkeley by ! 6: * Edward Wang at The University of California, Berkeley. ! 7: * ! 8: * Redistribution and use in source and binary forms are permitted provided ! 9: * that: (1) source distributions retain this entire copyright notice and ! 10: * comment, and (2) distributions including binaries display the following ! 11: * acknowledgement: ``This product includes software developed by the ! 12: * University of California, Berkeley and its contributors'' in the ! 13: * documentation or other materials provided with the distribution and in ! 14: * all advertising materials mentioning features or use of this software. ! 15: * Neither the name of the University nor the names of its contributors may ! 16: * be used to endorse or promote products derived from this software without ! 17: * specific prior written permission. ! 18: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED ! 19: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF ! 20: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 21: */ ! 22: ! 23: #ifndef lint ! 24: static char sccsid[] = "@(#)lcmd2.c 3.23 (Berkeley) 6/17/90"; ! 25: #endif /* not lint */ ! 26: ! 27: #include "defs.h" ! 28: #include "string.h" ! 29: #include "value.h" ! 30: #include "var.h" ! 31: #include "lcmd.h" ! 32: #include <sys/resource.h> ! 33: #include "alias.h" ! 34: ! 35: /*ARGSUSED*/ ! 36: l_iostat(v, a) ! 37: struct value *v, *a; ! 38: { ! 39: register struct ww *w; ! 40: ! 41: if ((w = openiwin(16, "IO Statistics")) == 0) { ! 42: error("Can't open statistics window: %s.", wwerror()); ! 43: return; ! 44: } ! 45: wwprintf(w, "ttflush\twrite\terror\tzero\tchar\n"); ! 46: wwprintf(w, "%d\t%d\t%d\t%d\t%d\n", ! 47: wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc); ! 48: wwprintf(w, "token\tuse\tbad\tsaving\ttotal\tbaud\n"); ! 49: wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d/%d (%.1f/%.1f)\n", ! 50: wwntokdef, wwntokuse, wwntokbad, wwntoksave, wwntokc, ! 51: wwntokc - wwntoksave ? ! 52: (int) ((float) wwbaud * wwntokc / ! 53: (wwntokc - wwntoksave)) : ! 54: wwbaud, ! 55: wwnwrc ? (int) ((float) wwbaud * (wwnwrc + wwntoksave) / ! 56: wwnwrc) : ! 57: wwbaud, ! 58: wwntokc - wwntoksave ? ! 59: (float) wwntokc / (wwntokc - wwntoksave) : 1.0, ! 60: wwnwrc ? (float) (wwnwrc + wwntoksave) / wwnwrc : 1.0); ! 61: wwprintf(w, "wwwrite\tattempt\tchar\n"); ! 62: wwprintf(w, "%d\t%d\t%d\n", ! 63: wwnwwr, wwnwwra, wwnwwrc); ! 64: wwprintf(w, "wwupdat\tline\tmiss\tscan\tclreol\tclreos\tmiss\tline\n"); ! 65: wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", ! 66: wwnupdate, wwnupdline, wwnupdmiss, wwnupdscan, wwnupdclreol, ! 67: wwnupdclreos, wwnupdclreosmiss, wwnupdclreosline); ! 68: wwprintf(w, "select\terror\tzero\n"); ! 69: wwprintf(w, "%d\t%d\t%d\n", ! 70: wwnselect, wwnselecte, wwnselectz); ! 71: wwprintf(w, "read\terror\tzero\tchar\n"); ! 72: wwprintf(w, "%d\t%d\t%d\t%d\n", ! 73: wwnread, wwnreade, wwnreadz, wwnreadc); ! 74: wwprintf(w, "ptyread\terror\tzero\tcontrol\tdata\tchar\n"); ! 75: wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\n", ! 76: wwnwread, wwnwreade, wwnwreadz, ! 77: wwnwreadp, wwnwreadd, wwnwreadc); ! 78: waitnl(w); ! 79: closeiwin(w); ! 80: } ! 81: ! 82: struct lcmd_arg arg_time[] = { ! 83: { "who", 1, ARG_STR }, ! 84: 0 ! 85: }; ! 86: ! 87: /*ARGSUSED*/ ! 88: l_time(v, a) ! 89: struct value *v; ! 90: register struct value *a; ! 91: { ! 92: register struct ww *w; ! 93: struct rusage rusage; ! 94: struct timeval timeval; ! 95: char *strtime(); ! 96: ! 97: if ((w = openiwin(8, "Timing and Resource Usage")) == 0) { ! 98: error("Can't open time window: %s.", wwerror()); ! 99: return; ! 100: } ! 101: ! 102: (void) gettimeofday(&timeval, (struct timezone *)0); ! 103: timeval.tv_sec -= starttime.tv_sec; ! 104: if ((timeval.tv_usec -= starttime.tv_usec) < 0) { ! 105: timeval.tv_sec--; ! 106: timeval.tv_usec += 1000000; ! 107: } ! 108: (void) getrusage(a->v_type == V_STR ! 109: && str_match(a->v_str, "children", 1) ! 110: ? RUSAGE_CHILDREN : RUSAGE_SELF, &rusage); ! 111: ! 112: wwprintf(w, "%-15s %-15s %-15s\n", ! 113: "time", "utime", "stime"); ! 114: wwprintf(w, "%-15s ", strtime(&timeval)); ! 115: wwprintf(w, "%-15s ", strtime(&rusage.ru_utime)); ! 116: wwprintf(w, "%-15s\n", strtime(&rusage.ru_stime)); ! 117: wwprintf(w, "%-15s %-15s %-15s %-15s\n", ! 118: "maxrss", "ixrss", "idrss", "isrss"); ! 119: wwprintf(w, "%-15ld %-15ld %-15ld %-15ld\n", ! 120: rusage.ru_maxrss, rusage.ru_ixrss, ! 121: rusage.ru_idrss, rusage.ru_isrss); ! 122: wwprintf(w, "%-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s %-7s\n", ! 123: "minflt", "majflt", "nswap", "inblk", "oublk", ! 124: "msgsnd", "msgrcv", "nsigs", "nvcsw", "nivcsw"); ! 125: wwprintf(w, "%-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld %-7ld\n", ! 126: rusage.ru_minflt, rusage.ru_majflt, rusage.ru_nswap, ! 127: rusage.ru_inblock, rusage.ru_oublock, ! 128: rusage.ru_msgsnd, rusage.ru_msgrcv, rusage.ru_nsignals, ! 129: rusage.ru_nvcsw, rusage.ru_nivcsw); ! 130: ! 131: waitnl(w); ! 132: closeiwin(w); ! 133: } ! 134: ! 135: char * ! 136: strtime(t) ! 137: register struct timeval *t; ! 138: { ! 139: char fill = 0; ! 140: static char buf[20]; ! 141: register char *p = buf; ! 142: ! 143: if (t->tv_sec > 60*60) { ! 144: (void) sprintf(p, "%ld:", t->tv_sec / (60*60)); ! 145: while (*p++) ! 146: ; ! 147: p--; ! 148: t->tv_sec %= 60*60; ! 149: fill++; ! 150: } ! 151: if (t->tv_sec > 60) { ! 152: (void) sprintf(p, fill ? "%02ld:" : "%ld:", t->tv_sec / 60); ! 153: while (*p++) ! 154: ; ! 155: p--; ! 156: t->tv_sec %= 60; ! 157: fill++; ! 158: } ! 159: (void) sprintf(p, fill ? "%02ld.%02d" : "%ld.%02ld", ! 160: t->tv_sec, t->tv_usec / 10000); ! 161: return buf; ! 162: } ! 163: ! 164: /*ARGSUSED*/ ! 165: l_list(v, a) ! 166: struct value *v, *a; ! 167: { ! 168: register struct ww *w, *wp; ! 169: register i; ! 170: int n; ! 171: ! 172: for (n = 0, i = 0; i < NWINDOW; i++) ! 173: if (window[i] != 0) ! 174: n++; ! 175: if (n == 0) { ! 176: error("No windows."); ! 177: return; ! 178: } ! 179: if ((w = openiwin(n + 2, "Windows")) == 0) { ! 180: error("Can't open listing window: %s.", wwerror()); ! 181: return; ! 182: } ! 183: for (i = 0; i < NWINDOW; i++) { ! 184: if ((wp = window[i]) == 0) ! 185: continue; ! 186: wwprintf(w, "%c %c %-13s %-.*s\n", ! 187: wp == selwin ? '+' : (wp == lastselwin ? '-' : ' '), ! 188: i + '1', ! 189: wp->ww_state == WWS_HASPROC ? "" : "(No process)", ! 190: wwncol - 20, ! 191: wp->ww_label ? wp->ww_label : "(No label)"); ! 192: } ! 193: waitnl(w); ! 194: closeiwin(w); ! 195: } ! 196: ! 197: /*ARGSUSED*/ ! 198: l_variable(v, a) ! 199: struct value *v, *a; ! 200: { ! 201: register struct ww *w; ! 202: int printvar(); ! 203: ! 204: if ((w = openiwin(wwnrow - 3, "Variables")) == 0) { ! 205: error("Can't open variable window: %s.", wwerror()); ! 206: return; ! 207: } ! 208: if (var_walk(printvar, (int)w) >= 0) ! 209: waitnl(w); ! 210: closeiwin(w); ! 211: } ! 212: ! 213: printvar(w, r) ! 214: register struct ww *w; ! 215: register struct var *r; ! 216: { ! 217: if (more(w, 0) == 2) ! 218: return -1; ! 219: wwprintf(w, "%16s ", r->r_name); ! 220: switch (r->r_val.v_type) { ! 221: case V_STR: ! 222: wwprintf(w, "%s\n", r->r_val.v_str); ! 223: break; ! 224: case V_NUM: ! 225: wwprintf(w, "%d\n", r->r_val.v_num); ! 226: break; ! 227: case V_ERR: ! 228: wwprintf(w, "ERROR\n"); ! 229: break; ! 230: } ! 231: return 0; ! 232: } ! 233: ! 234: struct lcmd_arg arg_def_shell[] = { ! 235: { "", 0, ARG_ANY|ARG_LIST }, ! 236: 0 ! 237: }; ! 238: ! 239: l_def_shell(v, a) ! 240: struct value *v, *a; ! 241: { ! 242: register char **pp; ! 243: register struct value *vp; ! 244: ! 245: if (a->v_type == V_ERR) { ! 246: if ((v->v_str = str_cpy(default_shellfile)) != 0) ! 247: v->v_type = V_STR; ! 248: return; ! 249: } ! 250: if (v->v_str = default_shellfile) { ! 251: v->v_type = V_STR; ! 252: for (pp = default_shell + 1; *pp; pp++) { ! 253: str_free(*pp); ! 254: *pp = 0; ! 255: } ! 256: } ! 257: for (pp = default_shell, vp = a; ! 258: vp->v_type != V_ERR && ! 259: pp < &default_shell[sizeof default_shell/sizeof *default_shell-1]; ! 260: pp++, vp++) ! 261: if ((*pp = vp->v_type == V_STR ? ! 262: str_cpy(vp->v_str) : str_itoa(vp->v_num)) == 0) { ! 263: /* just leave default_shell[] the way it is */ ! 264: p_memerror(); ! 265: break; ! 266: } ! 267: if (default_shellfile = *default_shell) ! 268: if (*default_shell = rindex(default_shellfile, '/')) ! 269: (*default_shell)++; ! 270: else ! 271: *default_shell = default_shellfile; ! 272: } ! 273: ! 274: struct lcmd_arg arg_alias[] = { ! 275: { "", 0, ARG_STR }, ! 276: { "", 0, ARG_STR|ARG_LIST }, ! 277: 0 ! 278: }; ! 279: ! 280: l_alias(v, a) ! 281: struct value *v, *a; ! 282: { ! 283: if (a->v_type == V_ERR) { ! 284: register struct ww *w; ! 285: int printalias(); ! 286: ! 287: if ((w = openiwin(wwnrow - 3, "Aliases")) == 0) { ! 288: error("Can't open alias window: %s.", wwerror()); ! 289: return; ! 290: } ! 291: if (alias_walk(printalias, (int)w) >= 0) ! 292: waitnl(w); ! 293: closeiwin(w); ! 294: } else { ! 295: register struct alias *ap = 0; ! 296: ! 297: if (ap = alias_lookup(a->v_str)) { ! 298: if ((v->v_str = str_cpy(ap->a_buf)) == 0) { ! 299: p_memerror(); ! 300: return; ! 301: } ! 302: v->v_type = V_STR; ! 303: } ! 304: if (a[1].v_type == V_STR) { ! 305: register struct value *vp; ! 306: register char *p, *q; ! 307: char *str; ! 308: register n; ! 309: ! 310: for (n = 0, vp = a + 1; vp->v_type != V_ERR; vp++, n++) ! 311: for (p = vp->v_str; *p; p++, n++) ! 312: ; ! 313: if ((str = str_alloc(n)) == 0) { ! 314: p_memerror(); ! 315: return; ! 316: } ! 317: for (q = str, vp = a + 1; vp->v_type != V_ERR; ! 318: vp++, q[-1] = ' ') ! 319: for (p = vp->v_str; *q++ = *p++;) ! 320: ; ! 321: q[-1] = 0; ! 322: if ((ap = alias_set(a[0].v_str, (char *)0)) == 0) { ! 323: p_memerror(); ! 324: str_free(str); ! 325: return; ! 326: } ! 327: ap->a_buf = str; ! 328: } ! 329: } ! 330: } ! 331: ! 332: printalias(w, a) ! 333: register struct ww *w; ! 334: register struct alias *a; ! 335: { ! 336: if (more(w, 0) == 2) ! 337: return -1; ! 338: wwprintf(w, "%16s %s\n", a->a_name, a->a_buf); ! 339: return 0; ! 340: } ! 341: ! 342: struct lcmd_arg arg_unalias[] = { ! 343: { "alias", 1, ARG_STR }, ! 344: 0 ! 345: }; ! 346: ! 347: l_unalias(v, a) ! 348: struct value *v, *a; ! 349: { ! 350: if (a->v_type == ARG_STR) ! 351: v->v_num = alias_unset(a->v_str); ! 352: v->v_type = V_NUM; ! 353: } ! 354: ! 355: struct lcmd_arg arg_echo[] = { ! 356: { "window", 1, ARG_NUM }, ! 357: { "", 0, ARG_ANY|ARG_LIST }, ! 358: 0 ! 359: }; ! 360: ! 361: /*ARGSUSED*/ ! 362: l_echo(v, a) ! 363: struct value *v; ! 364: register struct value *a; ! 365: { ! 366: char buf[20]; ! 367: struct ww *w; ! 368: ! 369: if ((w = vtowin(a++, selwin)) == 0) ! 370: return; ! 371: while (a->v_type != V_ERR) { ! 372: if (a->v_type == V_NUM) { ! 373: (void) sprintf(buf, "%d", a->v_num); ! 374: (void) wwwrite(w, buf, strlen(buf)); ! 375: } else ! 376: (void) wwwrite(w, a->v_str, strlen(a->v_str)); ! 377: if ((++a)->v_type != V_ERR) ! 378: (void) wwwrite(w, " ", 1); ! 379: } ! 380: (void) wwwrite(w, "\r\n", 2); ! 381: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.