995
|
1 /*
|
|
2 * The routines in this file are called to create a subjob running a command
|
|
3 * interpreter. This code is a big fat nothing on CP/M-86. You lose.
|
|
4 */
|
|
5 #include <stdio.h>
|
|
6 #include "ueed.h"
|
|
7
|
|
8 #ifdef AMIGA
|
|
9 #define NEW 1006
|
|
10 #endif
|
|
11
|
|
12 #ifdef VMS
|
|
13 #define EFN 0 /* Event flag. */
|
|
14
|
|
15 #include <ssdef.h> /* Random headers. */
|
|
16 #include <stsdef.h>
|
|
17 #include <descrip.h>
|
|
18 #include <iodef.h>
|
|
19
|
|
20 extern int oldmode[]; /* In "termio.c" */
|
|
21 extern int newmode[]; /* In "termio.c" */
|
|
22 extern short iochan; /* In "termio.c" */
|
|
23 #endif
|
|
24
|
|
25 #ifdef MSDOS
|
|
26 #include <dos.h>
|
|
27 #endif
|
|
28
|
|
29 #ifdef V7
|
|
30 #include <signal.h>
|
|
31 #endif
|
|
32
|
|
33 #ifdef OSK
|
|
34 #include <sgstat.h>
|
|
35 extern struct sgbuf ostate; /* In "termio.c" */
|
|
36 extern struct sgbuf nstate; /* In "termio.c" */
|
|
37 #endif
|
|
38
|
|
39 /*
|
|
40 * Create a subjob with a copy of the command intrepreter in it. When the
|
|
41 * command interpreter exits, mark the screen as garbage so that you do a full
|
|
42 * repaint. Bound to "C-C". The message at the start in VMS puts out a newline.
|
|
43 * Under some (unknown) condition, you don't get one free when DCL starts up.
|
|
44 */
|
|
45 spawncli(f, n)
|
|
46 {
|
|
47 #ifdef AMIGA
|
|
48 long newcli;
|
|
49
|
|
50 newcli = Open("CON:1/1/639/199/MicroEmacs Subprocess", NEW);
|
|
51 mlwrite("[Starting new CLI]");
|
|
52 sgarbf = TRUE;
|
|
53 Execute("", newcli, 0);
|
|
54 Close(newcli);
|
|
55 return(TRUE);
|
|
56 #endif
|
|
57 #ifdef VMS
|
|
58 movecursor(term.t_nrow, 0); /* In last line. */
|
|
59 mlputs("[Starting DCL]\r\n");
|
|
60 (*term.t_flush)(); /* Ignore "ttcol". */
|
|
61 sgarbf = TRUE;
|
|
62 return (sys(NULL)); /* NULL => DCL. */
|
|
63 #endif
|
|
64 #ifdef CPM
|
|
65 mlwrite("Not in CP/M-86");
|
|
66 #endif
|
|
67 #ifdef MSDOS
|
|
68 movecursor(term.t_nrow, 0); /* Seek to last line. */
|
|
69 (*term.t_flush)();
|
|
70 sys("\\command.com", ""); /* Run CLI. */
|
|
71 sgarbf = TRUE;
|
|
72 return(TRUE);
|
|
73 #endif
|
|
74 #ifdef V7
|
|
75 register char *cp;
|
|
76 char *getenv();
|
|
77 movecursor(term.t_nrow, 0); /* Seek to last line. */
|
|
78 (*term.t_flush)();
|
|
79 ttclose(); /* stty to old settings */
|
|
80 if ((cp = getenv("SHELL")) != NULL && *cp != '\0')
|
|
81 system(cp);
|
|
82 else
|
|
83 system("exec /bin/sh");
|
|
84 sgarbf = TRUE;
|
|
85 sleep(2);
|
|
86 ttopen();
|
|
87 return(TRUE);
|
|
88 #endif
|
|
89 #ifdef OSK
|
|
90 register char *cp;
|
|
91 char *getenv();
|
|
92 movecursor(term.t_nrow, 0); /* Seek to last line. */
|
|
93 (*term.t_flush)();
|
|
94 setstat(0, 0, &ostate); /* stty to old settings */
|
|
95 if ((cp = getenv("SHELL")) != NULL && *cp != '\0')
|
|
96 system(cp);
|
|
97 else
|
|
98 system("shell");
|
|
99 sgarbf = TRUE;
|
|
100 setstat(0, 0, &nstate);
|
|
101 return(TRUE);
|
|
102 #endif
|
|
103 }
|
|
104
|
|
105 /*
|
|
106 * Run a one-liner in a subjob. When the command returns, wait for a single
|
|
107 * character to be typed, then mark the screen as garbage so a full repaint is
|
|
108 * done. Bound to "C-X !".
|
|
109 */
|
|
110 spawn(f, n)
|
|
111 {
|
|
112 register int s;
|
|
113 char line[NLINE];
|
|
114 #ifdef AMIGA
|
|
115 long newcli;
|
|
116
|
|
117 newcli = Open("CON:1/1/639/199/MicroEmacs Subprocess", NEW);
|
|
118 if ((s=mlreply("CLI command: ", line, NLINE)) != TRUE)
|
|
119 return (s);
|
|
120 Execute(line,0,newcli);
|
|
121 Close(newcli);
|
|
122 while ((*term.t_getchar)() != '\r') /* Pause. */
|
|
123 ;
|
|
124 sgarbf = TRUE;
|
|
125 return(TRUE);
|
|
126 #endif
|
|
127 #ifdef VMS
|
|
128 if ((s=mlreply("DCL command: ", line, NLINE)) != TRUE)
|
|
129 return (s);
|
|
130 (*term.t_putchar)('\n'); /* Already have '\r' */
|
|
131 (*term.t_flush)();
|
|
132 s = sys(line); /* Run the command. */
|
|
133 mlputs("\r\n\n[End]"); /* Pause. */
|
|
134 (*term.t_flush)();
|
|
135 while ((*term.t_getchar)() != '\r')
|
|
136 ;
|
|
137 sgarbf = TRUE;
|
|
138 return (s);
|
|
139 #endif
|
|
140 #ifdef CPM
|
|
141 mlwrite("Not in CP/M-86");
|
|
142 return (FALSE);
|
|
143 #endif
|
|
144 #ifdef MSDOS
|
|
145 if ((s=mlreply("MS-DOS command: ", line, NLINE)) != TRUE)
|
|
146 return (s);
|
|
147 system(line);
|
|
148 while ((*term.t_getchar)() != '\r') /* Pause. */
|
|
149 ;
|
|
150 sgarbf = TRUE;
|
|
151 return (TRUE);
|
|
152 #endif
|
|
153 #ifdef V7
|
|
154 if ((s=mlreply("! ", line, NLINE)) != TRUE)
|
|
155 return (s);
|
|
156 (*term.t_putchar)('\n'); /* Already have '\r' */
|
|
157 (*term.t_flush)();
|
|
158 ttclose(); /* stty to old modes */
|
|
159 system(line);
|
|
160 sleep(2);
|
|
161 ttopen();
|
|
162 mlputs("[End]"); /* Pause. */
|
|
163 (*term.t_flush)();
|
|
164 while ((s = (*term.t_getchar)()) != '\r' && s != ' ')
|
|
165 ;
|
|
166 sgarbf = TRUE;
|
|
167 return (TRUE);
|
|
168 #endif
|
|
169 #ifdef OSK
|
|
170 if ((s=mlreply("! ", line, NLINE)) != TRUE)
|
|
171 return (s);
|
|
172 (*term.t_putchar)('\l'); /* Already have '\r' */
|
|
173 (*term.t_flush)();
|
|
174 setstat(0, 0, &ostate); /* stty to old modes */
|
|
175 s=system(line);
|
|
176 setstat(0, 0, &nstate);
|
|
177 mlputs("[End]"); /* Pause. */
|
|
178 (*term.t_flush)();
|
|
179 while ((s = (*term.t_getchar)()) != '\r' && s != ' ')
|
|
180 ;
|
|
181 sgarbf = TRUE;
|
|
182 return (TRUE);
|
|
183 #endif
|
|
184 }
|
|
185
|
|
186 #ifdef VMS
|
|
187 /*
|
|
188 * Run a command. The "cmd" is a pointer to a command string, or NULL if you
|
|
189 * want to run a copy of DCL in the subjob (this is how the standard routine
|
|
190 * LIB$SPAWN works. You have to do wierd stuff with the terminal on the way in
|
|
191 * and the way out, because DCL does not want the channel to be in raw mode.
|
|
192 */
|
|
193 sys(cmd)
|
|
194 register char *cmd;
|
|
195 {
|
|
196 struct dsc$descriptor cdsc;
|
|
197 struct dsc$descriptor *cdscp;
|
|
198 long status;
|
|
199 long substatus;
|
|
200 long iosb[2];
|
|
201
|
|
202 status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
|
|
203 oldmode, sizeof(oldmode), 0, 0, 0, 0);
|
|
204 if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
|
|
205 return (FALSE);
|
|
206 cdscp = NULL; /* Assume DCL. */
|
|
207 if (cmd != NULL) { /* Build descriptor. */
|
|
208 cdsc.dsc$a_pointer = cmd;
|
|
209 cdsc.dsc$w_length = strlen(cmd);
|
|
210 cdsc.dsc$b_dtype = DSC$K_DTYPE_T;
|
|
211 cdsc.dsc$b_class = DSC$K_CLASS_S;
|
|
212 cdscp = &cdsc;
|
|
213 }
|
|
214 status = LIB$SPAWN(cdscp, 0, 0, 0, 0, 0, &substatus, 0, 0, 0);
|
|
215 if (status != SS$_NORMAL)
|
|
216 substatus = status;
|
|
217 status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
|
|
218 newmode, sizeof(newmode), 0, 0, 0, 0);
|
|
219 if (status!=SS$_NORMAL || (iosb[0]&0xFFFF)!=SS$_NORMAL)
|
|
220 return (FALSE);
|
|
221 if ((substatus&STS$M_SUCCESS) == 0) /* Command failed. */
|
|
222 return (FALSE);
|
|
223 return (TRUE);
|
|
224 }
|
|
225 #endif
|
|
226
|
|
227 #ifdef MSDOS
|
|
228 /*
|
|
229 * This routine, once again by Bob McNamara, is a C translation of the "system"
|
|
230 * routine in the MWC-86 run time library. It differs from the "system" routine
|
|
231 * in that it does not unconditionally append the string ".exe" to the end of
|
|
232 * the command name. We needed to do this because we want to be able to spawn
|
|
233 * off "command.com". We really do not understand what it does, but if you don't
|
|
234 * do it exactly "malloc" starts doing very very strange things.
|
|
235 */
|
|
236 sys(cmd, tail)
|
|
237 char *cmd;
|
|
238 char *tail;
|
|
239 {
|
|
240 #ifdef MWC_86
|
|
241 register unsigned n;
|
|
242 extern char *__end;
|
|
243
|
|
244 n = __end + 15;
|
|
245 n >>= 4;
|
|
246 n = ((n + dsreg() + 16) & 0xFFF0) + 16;
|
|
247 return(execall(cmd, tail, n));
|
|
248 #endif
|
|
249
|
|
250 #ifdef LATTICE
|
|
251 return forklp(cmd, tail, NULL);
|
|
252 #endif
|
|
253 }
|
|
254 #endif
|
|
255
|
|
256
|