Annotation of 42BSD/ucb/pascal/pdx/tree/misc.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.