|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. The Berkeley software License Agreement ! 4: * specifies the terms and conditions for redistribution. ! 5: */ ! 6: ! 7: #ifndef lint ! 8: static char sccsid[] = "@(#)misc.c 5.2 (Berkeley) 4/7/87"; ! 9: #endif not lint ! 10: ! 11: /* ! 12: * Miscellaneous commands "edit" and "help". ! 13: * Also, output redirection routine "setout" and "unsetout". ! 14: */ ! 15: ! 16: #include "defs.h" ! 17: #include "tree.h" ! 18: #include "command.h" ! 19: #include "object.h" ! 20: #include "mappings.h" ! 21: #include "sym.h" ! 22: #include "symtab.h" ! 23: ! 24: extern char *getenv(); ! 25: ! 26: #define DEF_EDITOR "vi" ! 27: ! 28: /* ! 29: * Invoke an editor on the given file. Which editor to use might change ! 30: * installation to installation. For now, we use "vi". In any event, ! 31: * the environment variable "EDITOR" overrides any default. ! 32: */ ! 33: ! 34: edit(filename) ! 35: char *filename; ! 36: { ! 37: char *ed; ! 38: FILE *fp; ! 39: SYM *s; ! 40: ADDRESS addr; ! 41: char buff[10]; ! 42: ! 43: if ((ed = getenv("EDITOR")) == NIL) { ! 44: ed = DEF_EDITOR; ! 45: } ! 46: fp = fopen(filename, "r"); ! 47: if (fp == NIL) { ! 48: s = st_lookup(symtab, filename); ! 49: if (s == NIL) { ! 50: error("can't read \"%s\"", filename); ! 51: } ! 52: s = which(s); ! 53: if (!isblock(s)) { ! 54: error("can't read \"%s\"", filename); ! 55: } ! 56: addr = firstline(s); ! 57: filename = srcfilename(addr); ! 58: sprintf(buff, "+%d", srcline(addr)); ! 59: call(ed, stdin, stdout, buff, filename, NIL); ! 60: } else { ! 61: fclose(fp); ! 62: call(ed, stdin, stdout, filename, NIL); ! 63: } ! 64: } ! 65: ! 66: /* ! 67: * Send some nasty mail to the current pdx support person. ! 68: */ ! 69: ! 70: gripe() ! 71: { ! 72: char *maintainer = "[email protected]"; ! 73: ! 74: puts("Type control-D to end your message. Be sure to include"); ! 75: puts("your name and the name of the file you are debugging."); ! 76: putchar('\n'); ! 77: call("Mail", stdin, stdout, maintainer, NIL); ! 78: puts("Thank you."); ! 79: } ! 80: ! 81: /* ! 82: * Give the user some help. ! 83: */ ! 84: ! 85: help() ! 86: { ! 87: puts("pdx command subset summary:"); ! 88: putchar('\n'); ! 89: puts("run - begin execution of the program"); ! 90: puts("cont - continue execution"); ! 91: puts("step - single step one line"); ! 92: puts("next - step to next line (skip over calls)"); ! 93: puts("trace <line#> - trace execution of the line"); ! 94: puts("trace <proc> - trace calls to the procedure"); ! 95: puts("trace <var> - trace changes to the variable"); ! 96: puts("trace <exp> at <line#> - print <exp> when <line> is reached"); ! 97: puts("stop at <line> - suspend execution at the line"); ! 98: puts("stop in <proc> - suspend execution when <proc> is called"); ! 99: puts("status - print trace/stop's in effect"); ! 100: puts("delete <number> - remove trace or stop of given number"); ! 101: puts("call <proc> - call the procedure"); ! 102: puts("where - print currently active procedures"); ! 103: puts("print <exp> - print the value of the expression"); ! 104: puts("whatis <name> - print the declaration of the name"); ! 105: puts("list <line>, <line> - list source lines"); ! 106: puts("edit <proc> - edit file containing <proc>"); ! 107: puts("gripe - send mail to the person in charge of pdx"); ! 108: puts("quit - exit pdx"); ! 109: } ! 110: ! 111: /* ! 112: * Divert output to the given file name. ! 113: * Cannot redirect to an existing file. ! 114: */ ! 115: ! 116: LOCAL int so_fd; ! 117: LOCAL BOOLEAN notstdout; ! 118: ! 119: setout(filename) ! 120: char *filename; ! 121: { ! 122: FILE *fp; ! 123: ! 124: if ((fp = fopen(filename, "r")) != NIL) { ! 125: fclose(fp); ! 126: error("%s: file already exists", filename); ! 127: } else { ! 128: so_fd = dup(1); ! 129: close(1); ! 130: if (creat(filename, 0666) == NIL) { ! 131: unsetout(); ! 132: error("can't create %s", filename); ! 133: } ! 134: notstdout = TRUE; ! 135: } ! 136: } ! 137: ! 138: /* ! 139: * Revert output to standard output. ! 140: */ ! 141: ! 142: unsetout() ! 143: { ! 144: fflush(stdout); ! 145: close(1); ! 146: if (dup(so_fd) != 1) { ! 147: panic("standard out dup failed"); ! 148: } ! 149: close(so_fd); ! 150: notstdout = FALSE; ! 151: } ! 152: ! 153: BOOLEAN isredirected() ! 154: { ! 155: return(notstdout); ! 156: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.