Commit | Line | Data |
---|---|---|
5a7ee08a | 1 | /*- |
ad787160 C |
2 | * Copyright (c) 1980, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
5a7ee08a | 4 | * |
ad787160 C |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
3cd5310a | 32 | */ |
b7330e9f | 33 | |
3cd5310a | 34 | #ifndef lint |
ad787160 | 35 | static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93"; |
5a7ee08a | 36 | #endif /* not lint */ |
b7330e9f ML |
37 | |
38 | /* | |
39 | * Miscellaneous commands "edit" and "help". | |
40 | * Also, output redirection routine "setout" and "unsetout". | |
41 | */ | |
42 | ||
43 | #include "defs.h" | |
44 | #include "tree.h" | |
45 | #include "command.h" | |
46 | #include "object.h" | |
47 | #include "mappings.h" | |
48 | #include "sym.h" | |
49 | #include "symtab.h" | |
50 | ||
51 | extern char *getenv(); | |
52 | ||
53 | #define DEF_EDITOR "vi" | |
54 | ||
55 | /* | |
56 | * Invoke an editor on the given file. Which editor to use might change | |
57 | * installation to installation. For now, we use "vi". In any event, | |
58 | * the environment variable "EDITOR" overrides any default. | |
59 | */ | |
60 | ||
61 | edit(filename) | |
62 | char *filename; | |
63 | { | |
64 | char *ed; | |
65 | FILE *fp; | |
66 | SYM *s; | |
67 | ADDRESS addr; | |
68 | char buff[10]; | |
69 | ||
70 | if ((ed = getenv("EDITOR")) == NIL) { | |
71 | ed = DEF_EDITOR; | |
72 | } | |
73 | fp = fopen(filename, "r"); | |
74 | if (fp == NIL) { | |
75 | s = st_lookup(symtab, filename); | |
76 | if (s == NIL) { | |
77 | error("can't read \"%s\"", filename); | |
78 | } | |
79 | s = which(s); | |
80 | if (!isblock(s)) { | |
81 | error("can't read \"%s\"", filename); | |
82 | } | |
83 | addr = firstline(s); | |
84 | filename = srcfilename(addr); | |
85 | sprintf(buff, "+%d", srcline(addr)); | |
86 | call(ed, stdin, stdout, buff, filename, NIL); | |
87 | } else { | |
88 | fclose(fp); | |
89 | call(ed, stdin, stdout, filename, NIL); | |
90 | } | |
91 | } | |
92 | ||
1f39d302 ML |
93 | /* |
94 | * Send some nasty mail to the current pdx support person. | |
95 | */ | |
96 | ||
97 | gripe() | |
98 | { | |
82d3cd01 | 99 | char *maintainer = "4bsd-bugs@Berkeley.EDU"; |
1f39d302 ML |
100 | |
101 | puts("Type control-D to end your message. Be sure to include"); | |
102 | puts("your name and the name of the file you are debugging."); | |
103 | putchar('\n'); | |
104 | call("Mail", stdin, stdout, maintainer, NIL); | |
105 | puts("Thank you."); | |
106 | } | |
107 | ||
b7330e9f ML |
108 | /* |
109 | * Give the user some help. | |
110 | */ | |
111 | ||
112 | help() | |
113 | { | |
114 | puts("pdx command subset summary:"); | |
115 | putchar('\n'); | |
116 | puts("run - begin execution of the program"); | |
117 | puts("cont - continue execution"); | |
118 | puts("step - single step one line"); | |
119 | puts("next - step to next line (skip over calls)"); | |
120 | puts("trace <line#> - trace execution of the line"); | |
121 | puts("trace <proc> - trace calls to the procedure"); | |
122 | puts("trace <var> - trace changes to the variable"); | |
123 | puts("trace <exp> at <line#> - print <exp> when <line> is reached"); | |
124 | puts("stop at <line> - suspend execution at the line"); | |
125 | puts("stop in <proc> - suspend execution when <proc> is called"); | |
126 | puts("status - print trace/stop's in effect"); | |
127 | puts("delete <number> - remove trace or stop of given number"); | |
128 | puts("call <proc> - call the procedure"); | |
129 | puts("where - print currently active procedures"); | |
130 | puts("print <exp> - print the value of the expression"); | |
131 | puts("whatis <name> - print the declaration of the name"); | |
c3f38968 ML |
132 | puts("list <line>, <line> - list source lines"); |
133 | puts("edit <proc> - edit file containing <proc>"); | |
1f39d302 | 134 | puts("gripe - send mail to the person in charge of pdx"); |
b7330e9f ML |
135 | puts("quit - exit pdx"); |
136 | } | |
137 | ||
138 | /* | |
139 | * Divert output to the given file name. | |
140 | * Cannot redirect to an existing file. | |
141 | */ | |
142 | ||
143 | LOCAL int so_fd; | |
144 | LOCAL BOOLEAN notstdout; | |
145 | ||
146 | setout(filename) | |
147 | char *filename; | |
148 | { | |
149 | FILE *fp; | |
150 | ||
151 | if ((fp = fopen(filename, "r")) != NIL) { | |
152 | fclose(fp); | |
153 | error("%s: file already exists", filename); | |
154 | } else { | |
155 | so_fd = dup(1); | |
156 | close(1); | |
157 | if (creat(filename, 0666) == NIL) { | |
158 | unsetout(); | |
159 | error("can't create %s", filename); | |
160 | } | |
161 | notstdout = TRUE; | |
162 | } | |
163 | } | |
164 | ||
165 | /* | |
166 | * Revert output to standard output. | |
167 | */ | |
168 | ||
169 | unsetout() | |
170 | { | |
171 | fflush(stdout); | |
172 | close(1); | |
173 | if (dup(so_fd) != 1) { | |
174 | panic("standard out dup failed"); | |
175 | } | |
176 | close(so_fd); | |
177 | notstdout = FALSE; | |
178 | } | |
179 | ||
180 | BOOLEAN isredirected() | |
181 | { | |
182 | return(notstdout); | |
183 | } |