No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / lib / sl / ss.c
blob80129be2fee0c92015101bbb792a473ca20e1e20
1 /*
2 * Copyright (c) 1998 - 2000 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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
31 * SUCH DAMAGE.
34 #include "sl_locl.h"
35 #include <com_err.h>
36 #include "ss.h"
38 __RCSID("$Heimdal: ss.c 15429 2005-06-16 19:24:11Z lha $"
39 "$NetBSD$");
41 struct ss_subst {
42 char *name;
43 char *version;
44 char *info;
45 ss_request_table *table;
48 static struct ss_subst subsystems[2];
49 static int num_subsystems;
51 int
52 ss_create_invocation(const char *subsystem,
53 const char *version,
54 const char *info,
55 ss_request_table *table,
56 int *code)
58 struct ss_subst *ss;
60 if(num_subsystems >= sizeof(subsystems) / sizeof(subsystems[0])) {
61 *code = 17;
62 return 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) {
69 *code = ENOMEM;
70 return 0;
73 if (version != NULL) {
74 ss->version = strdup (version);
75 if (ss->version == NULL) {
76 *code = ENOMEM;
77 return 0;
80 if (info != NULL) {
81 ss->info = strdup (info);
82 if (ss->info == NULL) {
83 *code = ENOMEM;
84 return 0;
87 ss->table = table;
88 *code = 0;
89 return num_subsystems++;
92 void
93 ss_error (int idx, long code, const char *fmt, ...)
95 va_list ap;
96 va_start(ap, fmt);
97 com_err_va (subsystems[idx].name, code, fmt, ap);
98 va_end(ap);
101 void
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)
110 int argc = 0;
111 int ret;
113 while(argv[argc++]);
114 ret = sl_command(subsystems[idx].table, argc, argv);
115 if (ret == SL_BADCOMMAND)
116 return SS_ET_COMMAND_NOT_FOUND;
117 return 0;
121 ss_execute_line (int idx, const char *line)
123 char *buf = strdup(line);
124 int argc;
125 char **argv;
126 int ret;
128 if (buf == NULL)
129 return ENOMEM;
130 sl_make_argv(buf, &argc, &argv);
131 ret = sl_command(subsystems[idx].table, argc, argv);
132 free(buf);
133 if (ret == SL_BADCOMMAND)
134 return SS_ET_COMMAND_NOT_FOUND;
135 return 0;
139 ss_listen (int idx)
141 char *prompt = malloc(strlen(subsystems[idx].name) + 3);
142 if (prompt == NULL)
143 return ENOMEM;
145 strcpy(prompt, subsystems[idx].name);
146 strcat(prompt, ": ");
147 sl_loop(subsystems[idx].table, prompt);
148 free(prompt);
149 return 0;
153 ss_list_requests(int argc, char **argv /* , int idx, void *info */)
155 sl_help(subsystems[0 /* idx */].table, argc, argv);
156 return 0;
160 ss_quit(int argc, char **argv)
162 return 1;