date and time created 87/07/16 20:38:06 by denise
[unix-history] / usr / src / usr.bin / tn3270 / distribution / sys_dos / system.c
CommitLineData
190c655a
GM
1#include <stdio.h>
2
f478095f 3#include "../general/general.h"
4718d085 4#include "../ctlr/api.h"
190c655a
GM
5#include "spint.h"
6
9563b3d1
GM
7#include "../general/globals.h"
8
9
10static Spint spinted;
11static char command[256];
12static 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
21int
22shell_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 {
34987061
GM
40 char inputbuffer[100];
41
9563b3d1
GM
42 if (spinted.rc != 0) {
43 fprintf(stderr, "Process generated a return code of 0x%x.\n",
44 spinted.rc);
45 }
34987061
GM
46 printf("[Hit return to continue]");
47 fflush(stdout);
48 (void) gets(inputbuffer);
9563b3d1 49 shell_active = 0;
34987061
GM
50 setconnmode();
51 ConnectScreen();
9563b3d1
GM
52 }
53 return shell_active;
54}
190c655a
GM
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
64int
65shell(argc,argv)
66int argc;
67char *argv[];
68{
190c655a
GM
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 }
9563b3d1
GM
100 need_to_start = 1;
101 shell_active = 1;
102 return 1; /* Go back to main loop */
190c655a 103}