1 /* $Id: shell.c,v 1.1.1.1 2000/06/27 01:47:56 amura Exp $ */
2 /*
3  *		Shell commands.
4  * The file contains the command
5  * processor, shell-command
6  *	written by Kaoru Maeda.
7  */
8 
9 /*
10  * $Log: shell.c,v $
11  * Revision 1.1.1.1  2000/06/27 01:47:56  amura
12  * import to CVS
13  *
14  */
15 
16 #include "config.h"	/* 91.01.10  by S.Yoshida */
17 #include "def.h"
18 
19 #ifndef NO_SHELL
20 /*ARGSUSED*/
shellcmnd(f,n)21 shellcmnd(f, n)
22 {
23 	char	buf[CMDLINELENGTH];
24 	char	*result;
25 	extern char *call_process();
26 	extern int isetmark(),gotobob();
27 	int	s;
28 	BUFFER	*bp, *obp;
29 	WINDOW	*wp, *owp;
30 	WINDOW	*popbuf();
31 
32 	s = ereply("Shell command: ", buf, sizeof buf);
33 	if (s != TRUE)
34 		return s;
35 	if ((f & FFARG) == 0) {
36 		if ((bp = bfind("*Shell Command Output*", TRUE)) == NULL) return FALSE;
37 		if ((wp = popbuf(bp)) == NULL) return FALSE;
38 		bp->b_flag &= ~BFCHG;		/* Blow away old.	*/
39 		if (bclear(bp) != TRUE) return FALSE;
40 		obp = curbp; owp = curwp;
41 		curbp = bp; curwp = wp;
42 	}
43 	if ((result = call_process(buf, NULL)) == NULL)
44 		return FALSE;
45 	isetmark();
46 	ewprintf(result);
47 	s = insertfile(result, (char *)NULL);
48 	if((f & FFARG) == 0) {
49 		(VOID) gotobob(0, 1);
50 		bp->b_dotp = wp->w_dotp;
51 		bp->b_doto = wp->w_doto;
52 		curbp = obp;
53 		curwp = owp;
54 		bp->b_flag &= ~BFCHG;
55 	}
56 	unlink(result);
57 	return s;
58 }
59 #endif
60