2 * Copyright 1987, 1988, 1989 by Massachusetts Institute of Technology
4 * For copyright info, see copyright.h.
10 #include "ss_internal.h"
11 #include "copyright.h"
15 * get_request(tbl, idx)
18 * Gets the idx'th request from the request table pointed to
21 * tbl (ss_request_table *)
22 * pointer to request table
26 * (ss_request_entry *)
27 * pointer to request table entry
29 * Has been replaced by a macro.
33 /* sigh. saber won't deal with pointer-to-const-struct */
34 static struct _ss_request_entry * get_request (tbl, idx)
35 ss_request_table * tbl;
38 struct _ss_request_table *tbl1 = (struct _ss_request_table *) tbl;
39 struct _ss_request_entry *e = (struct _ss_request_entry *) tbl1->requests;
43 #define get_request(tbl,idx) ((tbl) -> requests + (idx))
47 * check_request_table(rqtbl, argc, argv, sci_idx)
50 * If the command string in argv[0] is in the request table, execute
51 * the commands and return error code 0. Otherwise, return error
52 * code ss_et_command_not_found.
54 * rqtbl (ss_request_table *)
55 * pointer to request table
57 * number of elements in argv[]
59 * argument string array
61 * ss-internal index for subsystem control info structure
64 * zero if command found, ss_et_command_not_found otherwise
68 static int check_request_table (rqtbl, argc, argv, sci_idx)
69 register ss_request_table *rqtbl;
75 struct _ss_request_entry *request;
77 register ss_request_entry *request;
79 register ss_data *info;
80 register char const * const * name;
81 char *string = argv[0];
84 info = ss_info(sci_idx);
87 for (i = 0; (request = get_request(rqtbl, i))->command_names; i++) {
88 for (name = request->command_names; *name; name++)
89 if (!strcmp(*name, string)) {
90 info->current_request = request->command_names[0];
91 (request->function)(argc, (const char *const *) argv,
92 sci_idx,info->info_ptr);
93 info->current_request = (char *)NULL;
97 return(SS_ET_COMMAND_NOT_FOUND);
101 * really_execute_command(sci_idx, argc, argv)
104 * Fills in the argc, argv values in the subsystem entry and
105 * call the appropriate routine.
108 * ss-internal index for subsystem control info structure
110 * number of arguments in argument list
112 * pointer to parsed argument list (may be reallocated
113 * on abbrev expansion)
117 * Zero if successful, ss_et_command_not_found otherwise.
121 static int really_execute_command (sci_idx, argc, argv)
126 register ss_request_table **rqtbl;
127 register ss_data *info;
129 info = ss_info(sci_idx);
131 for (rqtbl = info->rqt_tables; *rqtbl; rqtbl++) {
132 if (check_request_table (*rqtbl, argc, *argv, sci_idx) == 0)
135 return(SS_ET_COMMAND_NOT_FOUND);
139 * ss_execute_command(sci_idx, argv)
142 * Executes a parsed command list within the subsystem.
145 * ss-internal index for subsystem control info structure
147 * parsed argument list
150 * Zero if successful, ss_et_command_not_found otherwise.
154 int ss_execute_command(sci_idx, argv)
156 register char *argv[];
158 register int i, argc;
162 for (argp = argv; *argp; argp++)
164 argp = (char **)malloc((argc+1)*sizeof(char *));
165 for (i = 0; i <= argc; i++)
167 i = really_execute_command(sci_idx, argc, &argp);
173 * ss_execute_line(sci_idx, line_ptr)
176 * Parses and executes a command line within a subsystem.
179 * ss-internal index for subsystem control info structure
181 * Pointer to command line to be parsed.
188 int ss_execute_line (sci_idx, line_ptr)
195 /* flush leading whitespace */
196 while (line_ptr[0] == ' ' || line_ptr[0] == '\t')
199 /* check if it should be sent to operating system for execution */
200 if (*line_ptr == '!') {
201 if (ss_info(sci_idx)->flags.escape_disabled)
202 return SS_ET_ESCAPE_DISABLED;
211 argv = ss_parse(sci_idx, line_ptr, &argc);
215 /* look it up in the request tables, execute if found */
216 return really_execute_command (sci_idx, argc, &argv);