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