2 * Copyright 1987, 1988, 1989 by Massachusetts Institute of Technology
4 * For copyright info, see copyright.h.
7 #include "ss_internal.h"
12 static char const rcsid[] =
17 * get_request(tbl, idx)
20 * Gets the idx'th request from the request table pointed to
23 * tbl (ss_request_table *)
24 * pointer to request table
28 * (ss_request_entry *)
29 * pointer to request table entry
31 * Has been replaced by a macro.
35 /* sigh. saber won't deal with pointer-to-const-struct */
36 static struct _ss_request_entry * get_request (tbl, idx)
37 ss_request_table * tbl;
40 struct _ss_request_table *tbl1 = (struct _ss_request_table *) tbl;
41 struct _ss_request_entry *e = (struct _ss_request_entry *) tbl1->requests;
45 #define get_request(tbl,idx) ((tbl) -> requests + (idx))
49 * check_request_table(rqtbl, argc, argv, sci_idx)
52 * If the command string in argv[0] is in the request table, execute
53 * the commands and return error code 0. Otherwise, return error
54 * code ss_et_command_not_found.
56 * rqtbl (ss_request_table *)
57 * pointer to request table
59 * number of elements in argv[]
61 * argument string array
63 * ss-internal index for subsystem control info structure
66 * zero if command found, ss_et_command_not_found otherwise
70 static int check_request_table (rqtbl, argc, argv, sci_idx)
71 register ss_request_table *rqtbl;
77 struct _ss_request_entry *request;
79 register ss_request_entry *request;
81 register ss_data *info;
82 register char const * const * name;
83 char *string = argv[0];
86 info = ss_info(sci_idx);
89 for (i = 0; (request = get_request(rqtbl, i))->command_names; i++) {
90 for (name = request->command_names; *name; name++)
91 if (!strcmp(*name, string)) {
92 info->current_request = request->command_names[0];
93 (request->function)(argc, (const char *const *) argv,
94 sci_idx,info->info_ptr);
95 info->current_request = (char *)NULL;
99 return(SS_ET_COMMAND_NOT_FOUND);
103 * really_execute_command(sci_idx, argc, argv)
106 * Fills in the argc, argv values in the subsystem entry and
107 * call the appropriate routine.
110 * ss-internal index for subsystem control info structure
112 * number of arguments in argument list
114 * pointer to parsed argument list (may be reallocated
115 * on abbrev expansion)
119 * Zero if successful, ss_et_command_not_found otherwise.
123 static int really_execute_command (sci_idx, argc, argv)
128 register ss_request_table **rqtbl;
129 register ss_data *info;
131 info = ss_info(sci_idx);
133 for (rqtbl = info->rqt_tables; *rqtbl; rqtbl++) {
134 if (check_request_table (*rqtbl, argc, *argv, sci_idx) == 0)
137 return(SS_ET_COMMAND_NOT_FOUND);
141 * ss_execute_command(sci_idx, argv)
144 * Executes a parsed command list within the subsystem.
147 * ss-internal index for subsystem control info structure
149 * parsed argument list
152 * Zero if successful, ss_et_command_not_found otherwise.
156 ss_execute_command(sci_idx, argv)
158 register char *argv[];
160 register int i, argc;
164 for (argp = argv; *argp; argp++)
166 argp = (char **)malloc((argc+1)*sizeof(char *));
167 for (i = 0; i <= argc; i++)
169 i = really_execute_command(sci_idx, argc, &argp);
175 * ss_execute_line(sci_idx, line_ptr)
178 * Parses and executes a command line within a subsystem.
181 * ss-internal index for subsystem control info structure
183 * Pointer to command line to be parsed.
190 int ss_execute_line (sci_idx, line_ptr)
197 /* flush leading whitespace */
198 while (line_ptr[0] == ' ' || line_ptr[0] == '\t')
201 /* check if it should be sent to operating system for execution */
202 if (*line_ptr == '!') {
203 if (ss_info(sci_idx)->flags.escape_disabled)
204 return SS_ET_ESCAPE_DISABLED;
213 argv = ss_parse(sci_idx, line_ptr, &argc);
217 /* look it up in the request tables, execute if found */
218 return really_execute_command (sci_idx, argc, &argv);