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 char inputbuffer[100]; 41 42 if (spinted.rc != 0) { 43 fprintf(stderr, "Process generated a return code of 0x%x.\n", 44 spinted.rc); 45 } 46 printf("[Hit return to continue]"); 47 fflush(stdout); 48 (void) gets(inputbuffer); 49 shell_active = 0; 50 setconnmode(); 51 ConnectScreen(); 52 } 53 return shell_active; 54 } 55 56 57 /* 58 * Called from telnet.c to fork a lower command.com. We 59 * use the spint... routines so that we can pick up 60 * interrupts generated by application programs. 61 */ 62 63 64 int 65 shell(argc,argv) 66 int argc; 67 char *argv[]; 68 { 69 70 ClearElement(spinted); 71 spinted.int_no = API_INTERRUPT_NUMBER; 72 if (argc == 1) { 73 command[0] = 0; 74 } else { 75 char *cmdptr; 76 int length; 77 78 argc--; 79 argv++; 80 strcpy(command, " /c"); 81 cmdptr = command+strlen(command); 82 while (argc) { 83 if ((cmdptr+strlen(*argv)) >= (command+sizeof command)) { 84 fprintf(stderr, "Argument list too long at argument *%s*.\n", 85 *argv); 86 return 0; 87 } 88 *cmdptr++ = ' '; /* Blank separators */ 89 strcpy(cmdptr, *argv); 90 cmdptr += strlen(cmdptr); 91 argc--; 92 argv++; 93 } 94 length = strlen(command)-1; 95 if (length < 0) { 96 length = 0; 97 } 98 command[0] = length; 99 } 100 need_to_start = 1; 101 shell_active = 1; 102 return 1; /* Go back to main loop */ 103 } 104