2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
7 * Copyright 1987, 1988, 1989 by Massachusetts Institute of Technology
9 * For copyright info, see copyright.h.
12 #include "ss_internal.h"
13 #include "copyright.h"
18 * get_request(tbl, idx)
21 * Gets the idx'th request from the request table pointed to
24 * tbl (ss_request_table *)
25 * pointer to request table
29 * (ss_request_entry *)
30 * pointer to request table entry
32 * Has been replaced by a macro.
36 /* sigh. saber won't deal with pointer-to-const-struct */
37 static struct _ss_request_entry
* get_request (tbl
, idx
)
38 ss_request_table
* tbl
;
41 struct _ss_request_table
*tbl1
= (struct _ss_request_table
*) tbl
;
42 struct _ss_request_entry
*e
= (struct _ss_request_entry
*) tbl1
->requests
;
46 #define get_request(tbl,idx) ((tbl) -> requests + (idx))
50 * check_request_table(rqtbl, argc, argv, sci_idx)
53 * If the command string in argv[0] is in the request table, execute
54 * the commands and return error code 0. Otherwise, return error
55 * code ss_et_command_not_found.
57 * rqtbl (ss_request_table *)
58 * pointer to request table
60 * number of elements in argv[]
62 * argument string array
64 * ss-internal index for subsystem control info structure
67 * zero if command found, ss_et_command_not_found otherwise
71 static int check_request_table (rqtbl
, argc
, argv
, sci_idx
)
72 register ss_request_table
*rqtbl
;
78 struct _ss_request_entry
*request
;
80 register ss_request_entry
*request
;
82 register ss_data
*info
;
83 register char const * const * name
;
84 char *string
= argv
[0];
87 info
= ss_info(sci_idx
);
90 for (i
= 0; (request
= get_request(rqtbl
, i
))->command_names
; i
++) {
91 for (name
= request
->command_names
; *name
; name
++)
92 if (!strcmp(*name
, string
)) {
93 info
->current_request
= request
->command_names
[0];
94 (request
->function
)(argc
, (const char *const *) argv
,
95 sci_idx
,info
->info_ptr
);
96 info
->current_request
= NULL
;
100 return(SS_ET_COMMAND_NOT_FOUND
);
104 * really_execute_command(sci_idx, argc, argv)
107 * Fills in the argc, argv values in the subsystem entry and
108 * call the appropriate routine.
111 * ss-internal index for subsystem control info structure
113 * number of arguments in argument list
115 * pointer to parsed argument list (may be reallocated
116 * on abbrev expansion)
120 * Zero if successful, ss_et_command_not_found otherwise.
124 static int really_execute_command (sci_idx
, argc
, argv
)
129 register ss_request_table
**rqtbl
;
130 register ss_data
*info
;
132 info
= ss_info(sci_idx
);
134 for (rqtbl
= info
->rqt_tables
; *rqtbl
; rqtbl
++) {
135 if (check_request_table (*rqtbl
, argc
, *argv
, sci_idx
) == 0)
138 return(SS_ET_COMMAND_NOT_FOUND
);
142 * ss_execute_command(sci_idx, argv)
145 * Executes a parsed command list within the subsystem.
148 * ss-internal index for subsystem control info structure
150 * parsed argument list
153 * Zero if successful, ss_et_command_not_found otherwise.
158 ss_execute_command(sci_idx
, argv
)
160 register char *argv
[];
162 register int i
, argc
;
166 for (argp
= argv
; *argp
; argp
++)
168 argp
= (char **)malloc((argc
+1)*sizeof(char *));
169 for (i
= 0; i
<= argc
; i
++)
171 i
= really_execute_command(sci_idx
, argc
, &argp
);
177 * ss_execute_line(sci_idx, line_ptr)
180 * Parses and executes a command line within a subsystem.
183 * ss-internal index for subsystem control info structure
185 * Pointer to command line to be parsed.
192 int ss_execute_line (sci_idx
, line_ptr
)
199 /* flush leading whitespace */
200 while (line_ptr
[0] == ' ' || line_ptr
[0] == '\t')
203 /* check if it should be sent to operating system for execution */
204 if (*line_ptr
== '!') {
205 if (ss_info(sci_idx
)->flags
.escape_disabled
)
206 return SS_ET_ESCAPE_DISABLED
;
215 /* Solaris Kerberos */
216 (void) ss_parse(sci_idx
, line_ptr
, &argc
, &argv
, 0);
220 /* look it up in the request tables, execute if found */
221 ret
= really_execute_command (sci_idx
, argc
, &argv
);