2 * Copyright (c) 1998 - 2000 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 __RCSID("$Heimdal: ss.c 15429 2005-06-16 19:24:11Z lha $"
45 ss_request_table
*table
;
48 static struct ss_subst subsystems
[2];
49 static int num_subsystems
;
52 ss_create_invocation(const char *subsystem
,
55 ss_request_table
*table
,
60 if(num_subsystems
>= sizeof(subsystems
) / sizeof(subsystems
[0])) {
64 ss
= &subsystems
[num_subsystems
];
65 ss
->name
= ss
->version
= ss
->info
= NULL
;
66 if (subsystem
!= NULL
) {
67 ss
->name
= strdup (subsystem
);
68 if (ss
->name
== NULL
) {
73 if (version
!= NULL
) {
74 ss
->version
= strdup (version
);
75 if (ss
->version
== NULL
) {
81 ss
->info
= strdup (info
);
82 if (ss
->info
== NULL
) {
89 return num_subsystems
++;
93 ss_error (int idx
, long code
, const char *fmt
, ...)
97 com_err_va (subsystems
[idx
].name
, code
, fmt
, ap
);
102 ss_perror (int idx
, long code
, const char *msg
)
104 ss_error(idx
, code
, "%s", msg
);
108 ss_execute_command(int idx
, char **argv
)
114 ret
= sl_command(subsystems
[idx
].table
, argc
, argv
);
115 if (ret
== SL_BADCOMMAND
)
116 return SS_ET_COMMAND_NOT_FOUND
;
121 ss_execute_line (int idx
, const char *line
)
123 char *buf
= strdup(line
);
130 sl_make_argv(buf
, &argc
, &argv
);
131 ret
= sl_command(subsystems
[idx
].table
, argc
, argv
);
133 if (ret
== SL_BADCOMMAND
)
134 return SS_ET_COMMAND_NOT_FOUND
;
141 char *prompt
= malloc(strlen(subsystems
[idx
].name
) + 3);
145 strcpy(prompt
, subsystems
[idx
].name
);
146 strcat(prompt
, ": ");
147 sl_loop(subsystems
[idx
].table
, prompt
);
153 ss_list_requests(int argc
, char **argv
/* , int idx, void *info */)
155 sl_help(subsystems
[0 /* idx */].table
, argc
, argv
);
160 ss_quit(int argc
, char **argv
)