1*31895Sminshall /* 2*31895Sminshall * Copyright (c) 1984-1987 by the Regents of the 3*31895Sminshall * University of California and by Gregory Glenn Minshall. 4*31895Sminshall * 5*31895Sminshall * Permission to use, copy, modify, and distribute these 6*31895Sminshall * programs and their documentation for any purpose and 7*31895Sminshall * without fee is hereby granted, provided that this 8*31895Sminshall * copyright and permission appear on all copies and 9*31895Sminshall * supporting documentation, the name of the Regents of 10*31895Sminshall * the University of California not be used in advertising 11*31895Sminshall * or publicity pertaining to distribution of the programs 12*31895Sminshall * without specific prior permission, and notice be given in 13*31895Sminshall * supporting documentation that copying and distribution is 14*31895Sminshall * by permission of the Regents of the University of California 15*31895Sminshall * and by Gregory Glenn Minshall. Neither the Regents of the 16*31895Sminshall * University of California nor Gregory Glenn Minshall make 17*31895Sminshall * representations about the suitability of this software 18*31895Sminshall * for any purpose. It is provided "as is" without 19*31895Sminshall * express or implied warranty. 20*31895Sminshall */ 21*31895Sminshall 22*31895Sminshall #ifndef lint 23*31895Sminshall static char sccsid[] = "@(#)system.c 1.6 (Berkeley) 07/17/87"; 24*31895Sminshall #endif /* not lint */ 25*31895Sminshall 2631184Sminshall #include <stdio.h> 2731184Sminshall 2831185Sminshall #include "../general/general.h" 2931874Sminshall #include "../ctlr/api.h" 3031184Sminshall #include "spint.h" 3131184Sminshall 3231212Sminshall #include "../general/globals.h" 3331184Sminshall 3431184Sminshall 3531212Sminshall static Spint spinted; 3631212Sminshall static char command[256]; 3731212Sminshall static int need_to_start = 0; 3831212Sminshall 3931184Sminshall /* 4031212Sminshall * shell_continue() actually runs the command, and looks for API 4131212Sminshall * requests coming back in. 4231212Sminshall * 4331212Sminshall * We are called from the main loop in telnet.c. 4431212Sminshall */ 4531212Sminshall 4631212Sminshall int 4731212Sminshall shell_continue() 4831212Sminshall { 4931212Sminshall /* 5031212Sminshall * spint_start() returns when either the command has finished, or when 5131212Sminshall * the required interrupt comes in. In the latter case, the appropriate 5231212Sminshall * thing to do is to process the interrupt, and then return to 5331212Sminshall * the interrupt issuer by calling spint_continue(). 5431212Sminshall */ 5531212Sminshall if (need_to_start) { 5631212Sminshall need_to_start = 0; 5731212Sminshall spint_start(command, &spinted); 5831212Sminshall } 5931212Sminshall 6031212Sminshall if (spinted.done == 0) { 6131212Sminshall /* Process request */ 6231212Sminshall handle_api(&spinted.regs, &spinted.sregs); 6331212Sminshall spint_continue(&spinted); 6431212Sminshall } else { 6531884Sminshall char inputbuffer[100]; 6631884Sminshall 6731212Sminshall if (spinted.rc != 0) { 6831212Sminshall fprintf(stderr, "Process generated a return code of 0x%x.\n", 6931212Sminshall spinted.rc); 7031212Sminshall } 7131884Sminshall printf("[Hit return to continue]"); 7231884Sminshall fflush(stdout); 7331884Sminshall (void) gets(inputbuffer); 7431212Sminshall shell_active = 0; 7531884Sminshall setconnmode(); 7631884Sminshall ConnectScreen(); 7731212Sminshall } 7831212Sminshall return shell_active; 7931212Sminshall } 8031212Sminshall 8131212Sminshall 8231212Sminshall /* 8331184Sminshall * Called from telnet.c to fork a lower command.com. We 8431184Sminshall * use the spint... routines so that we can pick up 8531184Sminshall * interrupts generated by application programs. 8631184Sminshall */ 8731184Sminshall 8831184Sminshall 8931184Sminshall int 9031184Sminshall shell(argc,argv) 9131184Sminshall int argc; 9231184Sminshall char *argv[]; 9331184Sminshall { 9431184Sminshall 9531184Sminshall ClearElement(spinted); 9631184Sminshall spinted.int_no = API_INTERRUPT_NUMBER; 9731184Sminshall if (argc == 1) { 9831184Sminshall command[0] = 0; 9931184Sminshall } else { 10031184Sminshall char *cmdptr; 10131184Sminshall int length; 10231184Sminshall 10331184Sminshall argc--; 10431184Sminshall argv++; 10531184Sminshall strcpy(command, " /c"); 10631184Sminshall cmdptr = command+strlen(command); 10731184Sminshall while (argc) { 10831184Sminshall if ((cmdptr+strlen(*argv)) >= (command+sizeof command)) { 10931184Sminshall fprintf(stderr, "Argument list too long at argument *%s*.\n", 11031184Sminshall *argv); 11131184Sminshall return 0; 11231184Sminshall } 11331184Sminshall *cmdptr++ = ' '; /* Blank separators */ 11431184Sminshall strcpy(cmdptr, *argv); 11531184Sminshall cmdptr += strlen(cmdptr); 11631184Sminshall argc--; 11731184Sminshall argv++; 11831184Sminshall } 11931184Sminshall length = strlen(command)-1; 12031184Sminshall if (length < 0) { 12131184Sminshall length = 0; 12231184Sminshall } 12331184Sminshall command[0] = length; 12431184Sminshall } 12531212Sminshall need_to_start = 1; 12631212Sminshall shell_active = 1; 12731212Sminshall return 1; /* Go back to main loop */ 12831184Sminshall } 129