2005-05-31 11:50:56 -04:00
|
|
|
/* SPAWN.C
|
|
|
|
* various operating system access commands
|
|
|
|
*
|
|
|
|
* modified by Petri Kutvonen
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2005-10-01 02:52:55 -04:00
|
|
|
#include <unistd.h>
|
2005-05-31 11:50:56 -04:00
|
|
|
#include "estruct.h"
|
|
|
|
#include "edef.h"
|
2005-10-01 01:52:45 -04:00
|
|
|
#include "efunc.h"
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if VMS
|
2005-09-30 18:26:09 -04:00
|
|
|
#define EFN 0 /* Event flag. */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
#include <ssdef.h> /* Random headers. */
|
2005-05-31 11:50:56 -04:00
|
|
|
#include <stsdef.h>
|
|
|
|
#include <descrip.h>
|
|
|
|
#include <iodef.h>
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
extern int oldmode[3]; /* In "termio.c" */
|
|
|
|
extern int newmode[3]; /* In "termio.c" */
|
|
|
|
extern short iochan; /* In "termio.c" */
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if V7 | USG | BSD
|
|
|
|
#include <signal.h>
|
|
|
|
#ifdef SIGWINCH
|
|
|
|
extern int chg_width, chg_height;
|
2010-02-27 05:38:24 -05:00
|
|
|
extern void sizesignal(int);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MSDOS & (MSC | TURBO)
|
|
|
|
#include <process.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a subjob with a copy of the command intrepreter in it. When the
|
|
|
|
* command interpreter exits, mark the screen as garbage so that you do a full
|
|
|
|
* repaint. Bound to "^X C". The message at the start in VMS puts out a newline.
|
|
|
|
* Under some (unknown) condition, you don't get one free when DCL starts up.
|
|
|
|
*/
|
2005-10-01 01:52:45 -04:00
|
|
|
int spawncli(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
#if V7 | USG | BSD
|
2010-02-27 05:38:22 -05:00
|
|
|
char *cp;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* don't allow this command if restricted */
|
|
|
|
if (restflag)
|
2005-09-30 18:26:09 -04:00
|
|
|
return (resterr());
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if VMS
|
2005-09-30 18:26:09 -04:00
|
|
|
movecursor(term.t_nrow, 0); /* In last line. */
|
|
|
|
mlputs("(Starting DCL)\r\n");
|
|
|
|
TTflush(); /* Ignore "ttcol". */
|
|
|
|
sgarbf = TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
sys(NULL);
|
|
|
|
sleep(1);
|
|
|
|
mlputs("\r\n(Returning from DCL)\r\n");
|
|
|
|
TTflush();
|
|
|
|
sleep(1);
|
2005-09-30 18:26:09 -04:00
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
#if MSDOS & (MSC | TURBO)
|
2005-09-30 18:26:09 -04:00
|
|
|
movecursor(term.t_nrow, 0); /* Seek to last line. */
|
|
|
|
TTflush();
|
2005-05-31 11:50:56 -04:00
|
|
|
TTkclose();
|
|
|
|
shellprog("");
|
|
|
|
TTkopen();
|
2005-09-30 18:26:09 -04:00
|
|
|
sgarbf = TRUE;
|
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
#if V7 | USG | BSD
|
2005-09-30 18:26:09 -04:00
|
|
|
movecursor(term.t_nrow, 0); /* Seek to last line. */
|
|
|
|
TTflush();
|
|
|
|
TTclose(); /* stty to old settings */
|
|
|
|
if ((cp = getenv("SHELL")) != NULL && *cp != '\0')
|
|
|
|
system(cp);
|
|
|
|
else
|
2005-05-31 11:50:56 -04:00
|
|
|
#if BSD
|
2005-09-30 18:26:09 -04:00
|
|
|
system("exec /bin/csh");
|
2005-05-31 11:50:56 -04:00
|
|
|
#else
|
2005-09-30 18:26:09 -04:00
|
|
|
system("exec /bin/sh");
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
sgarbf = TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
sleep(2);
|
2005-09-30 18:26:09 -04:00
|
|
|
TTopen();
|
2005-05-31 11:50:56 -04:00
|
|
|
TTkopen();
|
|
|
|
#ifdef SIGWINCH
|
|
|
|
/*
|
|
|
|
* This fools the update routines to force a full
|
|
|
|
* redraw with complete window size checking.
|
|
|
|
* -lbt
|
|
|
|
*/
|
|
|
|
chg_width = term.t_ncol;
|
2005-09-30 18:26:09 -04:00
|
|
|
chg_height = term.t_nrow + 1;
|
2005-05-31 11:50:56 -04:00
|
|
|
term.t_nrow = term.t_ncol = 0;
|
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BSD | __hpux | SVR4
|
|
|
|
|
2005-10-01 02:52:55 -04:00
|
|
|
int bktoshell(int f, int n)
|
2005-09-30 18:26:09 -04:00
|
|
|
{ /* suspend MicroEMACS and wait to wake up */
|
2005-05-31 11:50:56 -04:00
|
|
|
vttidy();
|
|
|
|
/******************************
|
2005-10-01 02:52:55 -04:00
|
|
|
int pid;
|
|
|
|
|
2005-05-31 11:50:56 -04:00
|
|
|
pid = getpid();
|
|
|
|
kill(pid,SIGTSTP);
|
|
|
|
******************************/
|
|
|
|
kill(0, SIGTSTP);
|
2005-10-01 02:52:55 -04:00
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
void rtfrmshell(void)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
TTopen();
|
|
|
|
curwp->w_flag = WFHARD;
|
|
|
|
sgarbf = TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run a one-liner in a subjob. When the command returns, wait for a single
|
|
|
|
* character to be typed, then mark the screen as garbage so a full repaint is
|
|
|
|
* done. Bound to "C-X !".
|
|
|
|
*/
|
2005-10-01 01:52:45 -04:00
|
|
|
int spawn(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
int s;
|
2005-09-30 18:26:09 -04:00
|
|
|
char line[NLINE];
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* don't allow this command if restricted */
|
|
|
|
if (restflag)
|
2005-09-30 18:26:09 -04:00
|
|
|
return (resterr());
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if VMS
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((s = mlreply("!", line, NLINE)) != TRUE)
|
|
|
|
return (s);
|
2005-05-31 11:50:56 -04:00
|
|
|
movecursor(term.t_nrow, 0);
|
2005-09-30 18:26:09 -04:00
|
|
|
TTflush();
|
|
|
|
s = sys(line); /* Run the command. */
|
2005-05-31 11:50:56 -04:00
|
|
|
if (clexec == FALSE) {
|
2005-09-30 18:26:09 -04:00
|
|
|
mlputs("\r\n\n(End)"); /* Pause. */
|
2005-05-31 11:50:56 -04:00
|
|
|
TTflush();
|
|
|
|
tgetc();
|
|
|
|
}
|
2005-09-30 18:26:09 -04:00
|
|
|
sgarbf = TRUE;
|
|
|
|
return (s);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
#if MSDOS
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((s = mlreply("!", line, NLINE)) != TRUE)
|
|
|
|
return (s);
|
2005-05-31 11:50:56 -04:00
|
|
|
movecursor(term.t_nrow, 0);
|
|
|
|
TTkclose();
|
2005-09-30 18:26:09 -04:00
|
|
|
shellprog(line);
|
2005-05-31 11:50:56 -04:00
|
|
|
TTkopen();
|
|
|
|
/* if we are interactive, pause here */
|
|
|
|
if (clexec == FALSE) {
|
2005-09-30 18:26:09 -04:00
|
|
|
mlputs("\r\n(End)");
|
|
|
|
tgetc();
|
|
|
|
}
|
|
|
|
sgarbf = TRUE;
|
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
#if V7 | USG | BSD
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((s = mlreply("!", line, NLINE)) != TRUE)
|
|
|
|
return (s);
|
|
|
|
TTflush();
|
|
|
|
TTclose(); /* stty to old modes */
|
2005-05-31 11:50:56 -04:00
|
|
|
TTkclose();
|
2005-09-30 18:26:09 -04:00
|
|
|
system(line);
|
|
|
|
fflush(stdout); /* to be sure P.K. */
|
|
|
|
TTopen();
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
if (clexec == FALSE) {
|
2005-09-30 18:26:09 -04:00
|
|
|
mlputs("(End)"); /* Pause. */
|
2005-05-31 11:50:56 -04:00
|
|
|
TTflush();
|
2005-09-30 18:26:09 -04:00
|
|
|
while ((s = tgetc()) != '\r' && s != ' ');
|
2005-05-31 11:50:56 -04:00
|
|
|
mlputs("\r\n");
|
|
|
|
}
|
|
|
|
TTkopen();
|
2005-09-30 18:26:09 -04:00
|
|
|
sgarbf = TRUE;
|
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run an external program with arguments. When it returns, wait for a single
|
|
|
|
* character to be typed, then mark the screen as garbage so a full repaint is
|
|
|
|
* done. Bound to "C-X $".
|
|
|
|
*/
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
int execprg(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
int s;
|
2005-09-30 18:26:09 -04:00
|
|
|
char line[NLINE];
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* don't allow this command if restricted */
|
|
|
|
if (restflag)
|
2005-09-30 18:26:09 -04:00
|
|
|
return (resterr());
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if VMS
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((s = mlreply("!", line, NLINE)) != TRUE)
|
|
|
|
return (s);
|
|
|
|
TTflush();
|
|
|
|
s = sys(line); /* Run the command. */
|
|
|
|
mlputs("\r\n\n(End)"); /* Pause. */
|
|
|
|
TTflush();
|
|
|
|
tgetc();
|
|
|
|
sgarbf = TRUE;
|
|
|
|
return (s);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MSDOS
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((s = mlreply("$", line, NLINE)) != TRUE)
|
|
|
|
return (s);
|
2005-05-31 11:50:56 -04:00
|
|
|
movecursor(term.t_nrow, 0);
|
|
|
|
TTkclose();
|
2005-09-30 18:26:09 -04:00
|
|
|
execprog(line);
|
2005-05-31 11:50:56 -04:00
|
|
|
TTkopen();
|
|
|
|
/* if we are interactive, pause here */
|
|
|
|
if (clexec == FALSE) {
|
2005-09-30 18:26:09 -04:00
|
|
|
mlputs("\r\n(End)");
|
|
|
|
tgetc();
|
|
|
|
}
|
|
|
|
sgarbf = TRUE;
|
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if V7 | USG | BSD
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((s = mlreply("!", line, NLINE)) != TRUE)
|
|
|
|
return (s);
|
|
|
|
TTputc('\n'); /* Already have '\r' */
|
|
|
|
TTflush();
|
|
|
|
TTclose(); /* stty to old modes */
|
|
|
|
system(line);
|
|
|
|
fflush(stdout); /* to be sure P.K. */
|
|
|
|
TTopen();
|
|
|
|
mlputs("(End)"); /* Pause. */
|
|
|
|
TTflush();
|
|
|
|
while ((s = tgetc()) != '\r' && s != ' ');
|
|
|
|
sgarbf = TRUE;
|
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pipe a one line command into a window
|
|
|
|
* Bound to ^X @
|
|
|
|
*/
|
2005-10-01 01:52:45 -04:00
|
|
|
int pipecmd(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
int s; /* return status from CLI */
|
2010-08-01 17:37:28 -04:00
|
|
|
struct window *wp; /* pointer to new window */
|
2010-02-27 05:38:22 -05:00
|
|
|
struct buffer *bp; /* pointer to buffer to zot */
|
2005-09-30 18:26:09 -04:00
|
|
|
char line[NLINE]; /* command line send to shell */
|
2005-05-31 11:50:56 -04:00
|
|
|
static char bname[] = "command";
|
|
|
|
|
|
|
|
static char filnam[NSTRING] = "command";
|
|
|
|
|
|
|
|
#if MSDOS
|
|
|
|
char *tmp;
|
|
|
|
FILE *fp;
|
2005-09-30 18:26:09 -04:00
|
|
|
int len;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* don't allow this command if restricted */
|
|
|
|
if (restflag)
|
2005-09-30 18:26:09 -04:00
|
|
|
return (resterr());
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if MSDOS
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((tmp = getenv("TMP")) == NULL
|
|
|
|
&& (tmp = getenv("TEMP")) == NULL)
|
2005-05-31 11:50:56 -04:00
|
|
|
strcpy(filnam, "command");
|
|
|
|
else {
|
|
|
|
strcpy(filnam, tmp);
|
|
|
|
len = strlen(tmp);
|
2005-09-30 18:26:09 -04:00
|
|
|
if (len <= 0 || filnam[len - 1] != '\\'
|
|
|
|
&& filnam[len - 1] != '/')
|
|
|
|
strcat(filnam, "\\");
|
|
|
|
strcat(filnam, "command");
|
|
|
|
}
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if VMS
|
|
|
|
mlwrite("Not available under VMS");
|
2005-09-30 18:26:09 -04:00
|
|
|
return (FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get the command to pipe in */
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((s = mlreply("@", line, NLINE)) != TRUE)
|
|
|
|
return (s);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* get rid of the command output buffer if it exists */
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((bp = bfind(bname, FALSE, 0)) != FALSE) {
|
2005-05-31 11:50:56 -04:00
|
|
|
/* try to make sure we are off screen */
|
|
|
|
wp = wheadp;
|
|
|
|
while (wp != NULL) {
|
|
|
|
if (wp->w_bufp == bp) {
|
|
|
|
#if PKCODE
|
|
|
|
if (wp == curwp)
|
|
|
|
delwind(FALSE, 1);
|
|
|
|
else
|
|
|
|
onlywind(FALSE, 1);
|
|
|
|
break;
|
|
|
|
#else
|
|
|
|
onlywind(FALSE, 1);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
if (zotbuf(bp) != TRUE)
|
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
return (FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
#if MSDOS
|
2005-09-30 18:26:09 -04:00
|
|
|
strcat(line, " >>");
|
|
|
|
strcat(line, filnam);
|
2005-05-31 11:50:56 -04:00
|
|
|
movecursor(term.t_nrow, 0);
|
|
|
|
TTkclose();
|
2005-09-30 18:26:09 -04:00
|
|
|
shellprog(line);
|
2005-05-31 11:50:56 -04:00
|
|
|
TTkopen();
|
2005-09-30 18:26:09 -04:00
|
|
|
sgarbf = TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
if ((fp = fopen(filnam, "r")) == NULL) {
|
|
|
|
s = FALSE;
|
|
|
|
} else {
|
|
|
|
fclose(fp);
|
|
|
|
s = TRUE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if V7 | USG | BSD
|
2005-09-30 18:26:09 -04:00
|
|
|
TTflush();
|
|
|
|
TTclose(); /* stty to old modes */
|
|
|
|
strcat(line, ">");
|
|
|
|
strcat(line, filnam);
|
|
|
|
system(line);
|
|
|
|
TTopen();
|
|
|
|
TTflush();
|
|
|
|
sgarbf = TRUE;
|
|
|
|
s = TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (s != TRUE)
|
2005-09-30 18:26:09 -04:00
|
|
|
return (s);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* split the current window to make room for the command output */
|
|
|
|
if (splitwind(FALSE, 1) == FALSE)
|
2005-09-30 18:26:09 -04:00
|
|
|
return (FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* and read the stuff in */
|
|
|
|
if (getfile(filnam, FALSE) == FALSE)
|
2005-09-30 18:26:09 -04:00
|
|
|
return (FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* make this window in VIEW mode, update all mode lines */
|
|
|
|
curwp->w_bufp->b_mode |= MDVIEW;
|
|
|
|
wp = wheadp;
|
|
|
|
while (wp != NULL) {
|
|
|
|
wp->w_flag |= WFMODE;
|
|
|
|
wp = wp->w_wndp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* and get rid of the temporary file */
|
|
|
|
unlink(filnam);
|
2005-09-30 18:26:09 -04:00
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* filter a buffer through an external DOS program
|
|
|
|
* Bound to ^X #
|
|
|
|
*/
|
2005-10-01 03:22:55 -04:00
|
|
|
int filter_buffer(int f, int n)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2010-02-27 05:38:22 -05:00
|
|
|
int s; /* return status from CLI */
|
|
|
|
struct buffer *bp; /* pointer to buffer to zot */
|
2005-09-30 18:26:09 -04:00
|
|
|
char line[NLINE]; /* command line send to shell */
|
2005-05-31 11:50:56 -04:00
|
|
|
char tmpnam[NFILEN]; /* place to store real file name */
|
|
|
|
static char bname1[] = "fltinp";
|
|
|
|
|
|
|
|
static char filnam1[] = "fltinp";
|
|
|
|
static char filnam2[] = "fltout";
|
|
|
|
|
|
|
|
/* don't allow this command if restricted */
|
|
|
|
if (restflag)
|
2005-09-30 18:26:09 -04:00
|
|
|
return (resterr());
|
2005-05-31 11:50:56 -04:00
|
|
|
|
2005-09-30 18:26:09 -04:00
|
|
|
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
|
|
|
|
return (rdonly()); /* we are in read only mode */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
#if VMS
|
|
|
|
mlwrite("Not available under VMS");
|
2005-09-30 18:26:09 -04:00
|
|
|
return (FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* get the filter name and its args */
|
2005-09-30 18:26:09 -04:00
|
|
|
if ((s = mlreply("#", line, NLINE)) != TRUE)
|
|
|
|
return (s);
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* setup the proper file names */
|
|
|
|
bp = curbp;
|
|
|
|
strcpy(tmpnam, bp->b_fname); /* save the original name */
|
|
|
|
strcpy(bp->b_fname, bname1); /* set it to our new one */
|
|
|
|
|
|
|
|
/* write it out, checking for errors */
|
|
|
|
if (writeout(filnam1) != TRUE) {
|
|
|
|
mlwrite("(Cannot write filter file)");
|
|
|
|
strcpy(bp->b_fname, tmpnam);
|
2005-09-30 18:26:09 -04:00
|
|
|
return (FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
#if MSDOS
|
2005-09-30 18:26:09 -04:00
|
|
|
strcat(line, " <fltinp >fltout");
|
2005-05-31 11:50:56 -04:00
|
|
|
movecursor(term.t_nrow - 1, 0);
|
|
|
|
TTkclose();
|
2005-09-30 18:26:09 -04:00
|
|
|
shellprog(line);
|
2005-05-31 11:50:56 -04:00
|
|
|
TTkopen();
|
2005-09-30 18:26:09 -04:00
|
|
|
sgarbf = TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
s = TRUE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if V7 | USG | BSD
|
2005-09-30 18:26:09 -04:00
|
|
|
TTputc('\n'); /* Already have '\r' */
|
|
|
|
TTflush();
|
|
|
|
TTclose(); /* stty to old modes */
|
|
|
|
strcat(line, " <fltinp >fltout");
|
|
|
|
system(line);
|
|
|
|
TTopen();
|
|
|
|
TTflush();
|
|
|
|
sgarbf = TRUE;
|
|
|
|
s = TRUE;
|
2005-05-31 11:50:56 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* on failure, escape gracefully */
|
2005-09-30 18:26:09 -04:00
|
|
|
if (s != TRUE || (readin(filnam2, FALSE) == FALSE)) {
|
2005-05-31 11:50:56 -04:00
|
|
|
mlwrite("(Execution failed)");
|
|
|
|
strcpy(bp->b_fname, tmpnam);
|
|
|
|
unlink(filnam1);
|
|
|
|
unlink(filnam2);
|
2005-09-30 18:26:09 -04:00
|
|
|
return (s);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* reset file name */
|
|
|
|
strcpy(bp->b_fname, tmpnam); /* restore name */
|
2005-09-30 18:26:09 -04:00
|
|
|
bp->b_flag |= BFCHG; /* flag it as changed */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* and get rid of the temporary file */
|
|
|
|
unlink(filnam1);
|
|
|
|
unlink(filnam2);
|
2005-09-30 18:26:09 -04:00
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if VMS
|
|
|
|
/*
|
|
|
|
* Run a command. The "cmd" is a pointer to a command string, or NULL if you
|
|
|
|
* want to run a copy of DCL in the subjob (this is how the standard routine
|
|
|
|
* LIB$SPAWN works. You have to do wierd stuff with the terminal on the way in
|
|
|
|
* and the way out, because DCL does not want the channel to be in raw mode.
|
|
|
|
*/
|
2005-10-01 01:52:45 -04:00
|
|
|
int sys(char *cmd)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
2005-09-30 18:26:09 -04:00
|
|
|
struct dsc$descriptor cdsc;
|
|
|
|
struct dsc$descriptor *cdscp;
|
|
|
|
long status;
|
|
|
|
long substatus;
|
|
|
|
long iosb[2];
|
|
|
|
|
|
|
|
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
|
|
|
|
oldmode, sizeof(oldmode), 0, 0, 0, 0);
|
|
|
|
if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
|
|
|
|
return (FALSE);
|
|
|
|
cdscp = NULL; /* Assume DCL. */
|
|
|
|
if (cmd != NULL) { /* Build descriptor. */
|
|
|
|
cdsc.dsc$a_pointer = cmd;
|
|
|
|
cdsc.dsc$w_length = strlen(cmd);
|
|
|
|
cdsc.dsc$b_dtype = DSC$K_DTYPE_T;
|
|
|
|
cdsc.dsc$b_class = DSC$K_CLASS_S;
|
|
|
|
cdscp = &cdsc;
|
|
|
|
}
|
|
|
|
status = LIB$SPAWN(cdscp, 0, 0, 0, 0, 0, &substatus, 0, 0, 0);
|
|
|
|
if (status != SS$_NORMAL)
|
|
|
|
substatus = status;
|
|
|
|
status = SYS$QIOW(EFN, iochan, IO$_SETMODE, iosb, 0, 0,
|
|
|
|
newmode, sizeof(newmode), 0, 0, 0, 0);
|
|
|
|
if (status != SS$_NORMAL || (iosb[0] & 0xFFFF) != SS$_NORMAL)
|
|
|
|
return (FALSE);
|
|
|
|
if ((substatus & STS$M_SUCCESS) == 0) /* Command failed. */
|
|
|
|
return (FALSE);
|
|
|
|
return (TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if MSDOS & (TURBO | MSC)
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
/*
|
|
|
|
* SHELLPROG: Execute a command in a subshell
|
|
|
|
*
|
|
|
|
* char *cmd; Incoming command line to execute
|
|
|
|
*/
|
|
|
|
int shellprog(char *cmd)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
char *shell; /* Name of system command processor */
|
|
|
|
char *p; /* Temporary pointer */
|
|
|
|
char swchar; /* switch character to use */
|
|
|
|
union REGS regs; /* parameters for dos call */
|
|
|
|
char comline[NSTRING]; /* constructed command line */
|
|
|
|
|
|
|
|
/* detect current switch character and set us up to use it */
|
|
|
|
regs.h.ah = 0x37; /* get setting data */
|
|
|
|
regs.h.al = 0x00; /* get switch character */
|
|
|
|
intdos(®s, ®s);
|
2005-09-30 18:26:09 -04:00
|
|
|
swchar = (char) regs.h.dl;
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* get name of system shell */
|
|
|
|
if ((shell = getenv("COMSPEC")) == NULL) {
|
2005-09-30 18:26:09 -04:00
|
|
|
return (FALSE); /* No shell located */
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* trim leading whitespace off the command */
|
|
|
|
while (*cmd == ' ' || *cmd == '\t') /* find out if null command */
|
|
|
|
cmd++;
|
|
|
|
|
|
|
|
/** If the command line is not empty, bring up the shell **/
|
|
|
|
/** and execute the command. Otherwise, bring up the **/
|
|
|
|
/** shell in interactive mode. **/
|
|
|
|
|
|
|
|
if (*cmd) {
|
|
|
|
strcpy(comline, shell);
|
|
|
|
strcat(comline, " ");
|
|
|
|
comline[strlen(comline) + 1] = 0;
|
|
|
|
comline[strlen(comline)] = swchar;
|
|
|
|
strcat(comline, "c ");
|
|
|
|
strcat(comline, cmd);
|
2005-09-30 18:26:09 -04:00
|
|
|
return (execprog(comline));
|
2005-05-31 11:50:56 -04:00
|
|
|
} else
|
2005-09-30 18:26:09 -04:00
|
|
|
return (execprog(shell));
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
|
2005-10-01 01:52:45 -04:00
|
|
|
/*
|
|
|
|
* EXECPROG:
|
|
|
|
* A function to execute a named program
|
|
|
|
* with arguments
|
|
|
|
*
|
|
|
|
* char *cmd; Incoming command line to execute
|
|
|
|
*/
|
|
|
|
int execprog(char *cmd)
|
2005-05-31 11:50:56 -04:00
|
|
|
{
|
|
|
|
char *sp; /* temporary string pointer */
|
|
|
|
char f1[38]; /* FCB1 area (not initialized */
|
|
|
|
char f2[38]; /* FCB2 area (not initialized */
|
|
|
|
char prog[NSTRING]; /* program filespec */
|
|
|
|
char tail[NSTRING]; /* command tail with length byte */
|
|
|
|
union REGS regs; /* parameters for dos call */
|
|
|
|
struct SREGS segreg; /* segment registers for dis call */
|
|
|
|
struct pblock { /* EXEC parameter block */
|
|
|
|
short envptr; /* 2 byte pointer to environment string */
|
|
|
|
char *cline; /* 4 byte pointer to command line */
|
|
|
|
char *fcb1; /* 4 byte pointer to FCB at PSP+5Ch */
|
|
|
|
char *fcb2; /* 4 byte pointer to FCB at PSP+6Ch */
|
|
|
|
} pblock;
|
|
|
|
char *flook();
|
|
|
|
|
|
|
|
/* parse the command name from the command line */
|
|
|
|
sp = prog;
|
|
|
|
while (*cmd && (*cmd != ' ') && (*cmd != '\t'))
|
|
|
|
*sp++ = *cmd++;
|
|
|
|
*sp = 0;
|
|
|
|
|
|
|
|
/* and parse out the command tail */
|
|
|
|
while (*cmd && ((*cmd == ' ') || (*cmd == '\t')))
|
|
|
|
++cmd;
|
2005-09-30 18:26:09 -04:00
|
|
|
*tail = (char) (strlen(cmd)); /* record the byte length */
|
2005-05-31 11:50:56 -04:00
|
|
|
strcpy(&tail[1], cmd);
|
|
|
|
strcat(&tail[1], "\r");
|
|
|
|
|
|
|
|
/* look up the program on the path trying various extentions */
|
|
|
|
if ((sp = flook(prog, TRUE)) == NULL)
|
|
|
|
if ((sp = flook(strcat(prog, ".exe"), TRUE)) == NULL) {
|
2005-09-30 18:26:09 -04:00
|
|
|
strcpy(&prog[strlen(prog) - 4], ".com");
|
2005-05-31 11:50:56 -04:00
|
|
|
if ((sp = flook(prog, TRUE)) == NULL)
|
2005-09-30 18:26:09 -04:00
|
|
|
return (FALSE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
strcpy(prog, sp);
|
|
|
|
|
|
|
|
/* get a pointer to this PSPs environment segment number */
|
|
|
|
segread(&segreg);
|
|
|
|
|
|
|
|
/* set up the EXEC parameter block */
|
|
|
|
pblock.envptr = 0; /* make the child inherit the parents env */
|
2005-09-30 18:26:09 -04:00
|
|
|
pblock.fcb1 = f1; /* point to a blank FCB */
|
|
|
|
pblock.fcb2 = f2; /* point to a blank FCB */
|
|
|
|
pblock.cline = tail; /* parameter line pointer */
|
2005-05-31 11:50:56 -04:00
|
|
|
|
|
|
|
/* and make the call */
|
|
|
|
regs.h.ah = 0x4b; /* EXEC Load or Execute a Program */
|
|
|
|
regs.h.al = 0x00; /* load end execute function subcode */
|
2005-09-30 18:26:09 -04:00
|
|
|
segreg.ds = ((unsigned long) (prog) >> 16); /* program name ptr */
|
|
|
|
regs.x.dx = (unsigned int) (prog);
|
|
|
|
segreg.es = ((unsigned long) (&pblock) >> 16); /* set up param block ptr */
|
|
|
|
regs.x.bx = (unsigned int) (&pblock);
|
2005-05-31 11:50:56 -04:00
|
|
|
#if TURBO | MSC
|
|
|
|
intdosx(®s, ®s, &segreg);
|
|
|
|
if (regs.x.cflag == 0) {
|
|
|
|
regs.h.ah = 0x4d; /* get child process return code */
|
|
|
|
intdos(®s, ®s); /* go do it */
|
|
|
|
rval = regs.x.ax; /* save child's return code */
|
|
|
|
} else
|
|
|
|
#if MSC
|
|
|
|
rval = -1;
|
|
|
|
#else
|
|
|
|
rval = -_doserrno; /* failed child call */
|
|
|
|
#endif
|
|
|
|
#endif
|
2005-09-30 18:26:09 -04:00
|
|
|
return ((rval < 0) ? FALSE : TRUE);
|
2005-05-31 11:50:56 -04:00
|
|
|
}
|
|
|
|
#endif
|