Esempio n. 1
0
/*
 * Pipe a one line command into a window
 * Bound to ^X @
 * We use a unique temporary file name so that multiple instances of
 * MicroEMACS don't try to use the same file.
 */
PASCAL NEAR pipecmd(f, n)
{
        register EWINDOW *wp;    /* pointer to new window */
        register BUFFER *bp;    /* pointer to buffer to zot */
        register char *tmp;     /* ptr to TMP DOS environment variable */
        char line[NLINE];       /* command line send to shell */
        static char bname[] = "command";
        static char filnam[NSTRING];

        /* don't allow this command if restricted */
        if (restflag)
                return(resterr());

        /* get rid of the command output buffer if it exists */
        if ((bp=bfind(bname, FALSE, 0)) != FALSE) {
                /* try to make sure we are off screen */
                wp = wheadp;
                while (wp != NULL) {
                        if (wp->w_bufp == bp) {
                                onlywind(FALSE, 1);
                                break;
                        }
                        wp = wp->w_wndp;
                }
                /* get rid of the existing command buffer */
                if (zotbuf(bp) != TRUE)
                        return(FALSE);
        }

        /* get the command to pipe in */
        if (mlreply("@", line, NLINE) != TRUE)
                return(FALSE);

        /* Call mktemp() to get a unique filename in the tmp directory. */
        if ((tmp = getenv("TMP")) == NULL)
                filnam[0] = 0;
        else {
                strcpy(filnam, tmp);
                if (filnam[strlen(filnam) - 1] != '\\')
                        strcat(filnam, "\\");
        }
        strcat(filnam,"eXXXXXX");
        mktemp(filnam);

        /* redirect the command output to the output file */
        strcat(line, " >>");
        strcat(line, filnam);
        movecursor(term.t_nrow - 1, 0);

        /* execute the command */
        TTkclose();
        system(line);
        TTkopen();
        sgarbf = TRUE;

        /* did the output file get generated? */
        if (access( filnam, 0) != 0)
                return(FALSE);

        /* split the current window to make room for the command output */
        if (splitwind(FALSE, 1) == FALSE)
                        return(FALSE);

        /* and read the stuff in */
        if (getfile(filnam, FALSE) == FALSE)
                return(FALSE);

        /* rename the buffer */
        strcpy( curwp->w_bufp->b_bname, "command");
        /* 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);
        return(TRUE);
}
Esempio n. 2
0
/* the #ifdefs have been totally separated, for readability */
static int
spawn1(int rerun, int pressret)
{
#if DISP_IBMPC
	int	closed;
#endif
#if COMMON_SH_PROMPT
	register int	s;
	char	line[NLINE];	/* command line send to shell */

	if ((s = ShellPrompt(&save_shell[0], line, rerun)) != TRUE)
		return s;
#endif	/* COMMON_SH_PROMPT */

	/* take care of autowrite */
	if (writeall(FALSE,1,FALSE,TRUE,TRUE) != TRUE)
		return FALSE;

#if SYS_UNIX
#if DISP_X11
	(void)system_SHELL(line);
#else
	ttclean(TRUE);
	(void)system_SHELL(line);
	TTflush();
	ttunclean();
	if (pressret)
		pressreturn();
	TTopen();
	TTkopen();
	TTflush();
	sgarbf = TRUE;
#endif /* DISP_X11 */
	return AfterShell();
#endif /* SYS_UNIX */

#if	SYS_VMS
	TTputc('\n');			/* Already have '\r'	*/
	TTflush();
	s = sys(line);			/* Run the command.	*/
	mlforce("\r\n\n[End]");		/* Pause.		*/
	TTflush();
	(void)keystroke();
	sgarbf = TRUE;
	return (s);
#endif
#if	SYS_WIN31
	mlforce("[Not in Windows 3.1]");
	return FALSE;
#endif
#if	SYS_MSDOS || SYS_OS2 || SYS_WINNT
	bottomleft();
	TTputc('\n');
	TTflush();
	TTkclose();
#if	DISP_IBMPC
	/* If we don't reset to 80x25, parts of the shell-output will go
	 * astray.
	 */
	closed = term.t_ncol != 80 || term.t_nrow != 25;
	if (closed)
		TTclose();
#endif
	system(line);
	TTkopen();
	/* if we are interactive, pause here */
	if (pressret) {
		pressreturn();
	}
#if	DISP_IBMPC
	/* Reopen the display _after_ the prompt, to keep the shell-output
	 * in the same type of screen as the prompt.
	 */
	if (closed)
		TTopen();
#endif
	sgarbf = TRUE;
	return AfterShell();
#endif
}
Esempio n. 3
0
File: spawn.c Progetto: ytoto/uemacs
/*
 * 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.
 */
int spawncli(int f, int n)
{
#if     V7 | USG | BSD
	char *cp;
#endif

	/* don't allow this command if restricted */
	if (restflag)
		return resterr();
#if WINNT
	mlwrite("(unsupported)");
	return FALSE;
#endif

#if     VMS
	movecursor(term.t_nrow, 0);	/* In last line.        */
	mlputs("(Starting DCL)\r\n");
	TTflush();		/* Ignore "ttcol".      */
	sgarbf = TRUE;
	sys(NULL);
	sleep(1);
	mlputs("\r\n(Returning from DCL)\r\n");
	TTflush();
	sleep(1);
	return TRUE;
#endif
#if     MSDOS & (MSC | TURBO)
	movecursor(term.t_nrow, 0);	/* Seek to last line.   */
	TTflush();
	TTkclose();
	shellprog("");
	TTkopen();
	sgarbf = TRUE;
	return TRUE;
#endif
#if     V7 | USG | BSD
	movecursor(term.t_nrow, 0);	/* Seek to last line.   */
	TTflush();
	TTclose();		/* stty to old settings */
	TTkclose();		/* Close "keyboard" */
	if ((cp = getenv("SHELL")) != NULL && *cp != '\0')
		system(cp);
	else
#if	BSD
		system("exec /bin/csh");
#else
		system("exec /bin/sh");
#endif
	sgarbf = TRUE;
	sleep(2);
	TTopen();
	TTkopen();
#ifdef SIGWINCH
/*
 * This fools the update routines to force a full
 * redraw with complete window size checking.
 *		-lbt
 */
	chg_width = term.t_ncol;
	chg_height = term.t_nrow + 1;
	term.t_nrow = term.t_ncol = 0;
#endif
	return TRUE;
#endif
}
Esempio n. 4
0
File: spawn.c Progetto: ytoto/uemacs
/*
 * filter a buffer through an external DOS program
 * Bound to ^X #
 */
int filter_buffer(int f, int n)
{
	int s;		/* return status from CLI */
	struct buffer *bp;	/* pointer to buffer to zot */
	char line[NLINE];	/* command line send to shell */
	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)
		return resterr();

	if (curbp->b_mode & MDVIEW)	/* don't allow this command if      */
		return rdonly();	/* we are in read only mode     */

#if     VMS
	mlwrite("Not available under VMS");
	return FALSE;
#endif

	/* get the filter name and its args */
	if ((s = mlreply("#", line, NLINE)) != TRUE)
		return s;

	/* setup the proper file names */
	bp = curbp;
	xstrcpy(tmpnam, bp->b_fname);	/* save the original name */
	xstrcpy(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)");
		xstrcpy(bp->b_fname, tmpnam);
		return FALSE;
	}
#if     MSDOS
	strcat(line, " <fltinp >fltout");
	movecursor(term.t_nrow - 1, 0);
	TTkclose();
	shellprog(line);
	TTkopen();
	sgarbf = TRUE;
	s = TRUE;
#endif

#if     V7 | USG | BSD
	TTputc('\n');		/* Already have '\r'    */
	TTflush();
	TTclose();		/* stty to old modes    */
	TTkclose();
	strcat(line, " <fltinp >fltout");
	system(line);
	TTopen();
	TTkopen();
	TTflush();
	sgarbf = TRUE;
	s = TRUE;
#endif

	/* on failure, escape gracefully */
	if (s != TRUE || (readin(filnam2, FALSE) == FALSE)) {
		mlwrite("(Execution failed)");
		xstrcpy(bp->b_fname, tmpnam);
		unlink(filnam1);
		unlink(filnam2);
		return s;
	}

	/* reset file name */
	xstrcpy(bp->b_fname, tmpnam);	/* restore name */
	bp->b_flag |= BFCHG;	/* flag it as changed */

	/* and get rid of the temporary file */
	unlink(filnam1);
	unlink(filnam2);
	return TRUE;
}
Esempio n. 5
0
File: spawn.c Progetto: ytoto/uemacs
/*
 * Pipe a one line command into a window
 * Bound to ^X @
 */
int pipecmd(int f, int n)
{
	int s;		/* return status from CLI */
	struct window *wp;	/* pointer to new window */
	struct buffer *bp;	/* pointer to buffer to zot */
	char line[NLINE];	/* command line send to shell */
	static char bname[] = "command";

	static char filnam[NSTRING] = "command";

#if     MSDOS
	char *tmp;
	FILE *fp;
	int len;
#endif

	/* don't allow this command if restricted */
	if (restflag)
		return resterr();

#if	MSDOS
	if ((tmp = getenv("TMP")) == NULL
	    && (tmp = getenv("TEMP")) == NULL)
		xstrcpy(filnam, "command");
	else {
		xstrcpy(filnam, tmp);
		len = strlen(tmp);
		if (len <= 0 || filnam[len - 1] != '\\'
		    && filnam[len - 1] != '/')
			strcat(filnam, "\\");
		strcat(filnam, "command");
	}
#endif

#if     VMS
	mlwrite("Not available under VMS");
	return FALSE;
#endif

	/* get the command to pipe in */
	if ((s = mlreply("@", line, NLINE)) != TRUE)
		return s;

	/* get rid of the command output buffer if it exists */
	if ((bp = bfind(bname, FALSE, 0)) != FALSE) {
		/* 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)

			return FALSE;
	}
#if     MSDOS
	strcat(line, " >>");
	strcat(line, filnam);
	movecursor(term.t_nrow, 0);
	TTkclose();
	shellprog(line);
	TTkopen();
	sgarbf = TRUE;
	if ((fp = fopen(filnam, "r")) == NULL) {
		s = FALSE;
	} else {
		fclose(fp);
		s = TRUE;
	}
#endif

#if     V7 | USG | BSD
	TTflush();
	TTclose();		/* stty to old modes    */
	TTkclose();
	strcat(line, ">");
	strcat(line, filnam);
	system(line);
	TTopen();
	TTkopen();
	TTflush();
	sgarbf = TRUE;
	s = TRUE;
#endif

	if (s != TRUE)
		return s;

	/* split the current window to make room for the command output */
	if (splitwind(FALSE, 1) == FALSE)
		return FALSE;

	/* and read the stuff in */
	if (getfile(filnam, FALSE) == FALSE)
		return FALSE;

	/* 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);
	return TRUE;
}
Esempio n. 6
0
File: spawn.c Progetto: ytoto/uemacs
/*
 * 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 !".
 */
int spawn(int f, int n)
{
#ifndef WINNT
	int s;
	char line[NLINE];
#endif

	/* don't allow this command if restricted */
	if (restflag)
		return resterr();
#ifdef WINNT
	mlwrite("(unsupported)");
	return FALSE;
#endif

#if     VMS
	if ((s = mlreply("!", line, NLINE)) != TRUE)
		return s;
	movecursor(term.t_nrow, 0);
	TTflush();
	s = sys(line);		/* Run the command.     */
	if (clexec == FALSE) {
		mlputs("\r\n\n(End)");	/* Pause.               */
		TTflush();
		tgetc();
	}
	sgarbf = TRUE;
	return s;
#endif
#if     MSDOS
	if ((s = mlreply("!", line, NLINE)) != TRUE)
		return s;
	movecursor(term.t_nrow, 0);
	TTkclose();
	shellprog(line);
	TTkopen();
	/* if we are interactive, pause here */
	if (clexec == FALSE) {
		mlputs("\r\n(End)");
		tgetc();
	}
	sgarbf = TRUE;
	return TRUE;
#endif
#if     V7 | USG | BSD
	if ((s = mlreply("!", line, NLINE)) != TRUE)
		return s;
	TTflush();
	TTclose();		/* stty to old modes    */
	TTkclose();
	system(line);
	fflush(stdout);		/* to be sure P.K.      */
	TTopen();

	if (clexec == FALSE) {
		mlputs("(End)");	/* Pause.               */
		TTflush();
		while ((s = tgetc()) != '\r' && s != ' ');
		mlputs("\r\n");
	}
	TTkopen();
	sgarbf = TRUE;
	return TRUE;
#endif
}