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