1 #include <stdio.h>
2 
3 #include "../general/general.h"
4 #include "../ctlr/api.h"
5 #include "spint.h"
6 
7 #include "../general/globals.h"
8 
9 
10 static Spint spinted;
11 static char command[256];
12 static int need_to_start = 0;
13 
14 /*
15  * shell_continue() actually runs the command, and looks for API
16  * requests coming back in.
17  *
18  * We are called from the main loop in telnet.c.
19  */
20 
21 int
22 shell_continue()
23 {
24     /*
25      * spint_start() returns when either the command has finished, or when
26      * the required interrupt comes in.  In the latter case, the appropriate
27      * thing to do is to process the interrupt, and then return to
28      * the interrupt issuer by calling spint_continue().
29      */
30     if (need_to_start) {
31 	need_to_start = 0;
32 	spint_start(command, &spinted);
33     }
34 
35     if (spinted.done == 0) {
36 	/* Process request */
37 	handle_api(&spinted.regs, &spinted.sregs);
38 	spint_continue(&spinted);
39     } else {
40 	if (spinted.rc != 0) {
41 	    fprintf(stderr, "Process generated a return code of 0x%x.\n",
42 								spinted.rc);
43 	}
44 	shell_active = 0;
45     }
46     return shell_active;
47 }
48 
49 
50 /*
51  * Called from telnet.c to fork a lower command.com.  We
52  * use the spint... routines so that we can pick up
53  * interrupts generated by application programs.
54  */
55 
56 
57 int
58 shell(argc,argv)
59 int	argc;
60 char	*argv[];
61 {
62 
63     ClearElement(spinted);
64     spinted.int_no = API_INTERRUPT_NUMBER;
65     if (argc == 1) {
66 	command[0] = 0;
67     } else {
68 	char *cmdptr;
69 	int length;
70 
71 	argc--;
72 	argv++;
73 	strcpy(command, " /c");
74 	cmdptr = command+strlen(command);
75 	while (argc) {
76 	    if ((cmdptr+strlen(*argv)) >= (command+sizeof command)) {
77 		fprintf(stderr, "Argument list too long at argument *%s*.\n",
78 			    *argv);
79 		return 0;
80 	    }
81 	    *cmdptr++ = ' ';		/* Blank separators */
82 	    strcpy(cmdptr, *argv);
83 	    cmdptr += strlen(cmdptr);
84 	    argc--;
85 	    argv++;
86 	}
87 	length = strlen(command)-1;
88 	if (length < 0) {
89 	    length = 0;
90 	}
91 	command[0] = length;
92     }
93     need_to_start = 1;
94     shell_active = 1;
95     return 1;			/* Go back to main loop */
96 }
97