1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
3 * Copyright 2007 Massachusetts Institute of Technology.
6 * Export of this software from the United States of America may
7 * require a specific license from the United States Government.
8 * It is the responsibility of any person or organization contemplating
9 * export to obtain such a license before exporting.
11 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12 * distribute this software and its documentation for any purpose and
13 * without fee is hereby granted, provided that the above copyright
14 * notice appear in all copies and that both that copyright notice and
15 * this permission notice appear in supporting documentation, and that
16 * the name of M.I.T. not be used in advertising or publicity pertaining
17 * to distribution of the software without specific, written prior
18 * permission. Furthermore if you modify this software you must label
19 * your software as modified software and not distribute it in such a
20 * fashion that it might be confused with the original M.I.T. software.
21 * M.I.T. makes no representations about the suitability of
22 * this software for any purpose. It is provided "as is" without express
23 * or implied warranty.
26 * Copyright 1987, 1988 by MIT Student Information Processing Board
28 * For copyright information, see copyright.h.
30 #include "ss_internal.h"
31 #include "copyright.h"
32 #define size sizeof(ss_data *)
34 /* XXX The memory in _ss_table never gets freed up until program exit!
35 If you change the code to free it and stick a null pointer into
36 _ss_table[sci_idx], make sure you change the allocation routine to
37 not assume there are no null pointers in the middle of the
39 int ss_create_invocation(subsystem_name, version_string, info_ptr,
40 request_table_ptr, code_ptr)
41 char *subsystem_name, *version_string;
43 ss_request_table *request_table_ptr;
47 register ss_data *new_table;
48 register ss_data **table, **tmp;
52 new_table = (ss_data *) malloc(sizeof(ss_data));
53 if (new_table == NULL) {
58 if (table == (ss_data **) NULL) {
59 table = (ss_data **) malloc(2 * size);
64 table[0] = table[1] = (ss_data *)NULL;
67 initialize_ss_error_table ();
69 for (sci_idx = 1; table[sci_idx] != (ss_data *)NULL; sci_idx++)
71 tmp = (ss_data **) realloc((char *)table,
72 ((unsigned)sci_idx+2)*size);
77 _ss_table = table = tmp;
78 table[sci_idx+1] = (ss_data *) NULL;
79 table[sci_idx] = NULL;
81 new_table->subsystem_name = subsystem_name;
82 new_table->subsystem_version = version_string;
83 new_table->argv = (char **)NULL;
84 new_table->current_request = (char *)NULL;
85 new_table->info_dirs = (char **)malloc(sizeof(char *));
86 if (new_table->info_dirs == NULL) {
91 *new_table->info_dirs = (char *)NULL;
92 new_table->info_ptr = info_ptr;
93 if (asprintf(&new_table->prompt, "%s: ", subsystem_name) < 0) {
95 free(new_table->info_dirs);
99 new_table->abbrev_info = NULL;
100 new_table->flags.escape_disabled = 0;
101 new_table->flags.abbrevs_disabled = 0;
102 new_table->rqt_tables =
103 (ss_request_table **) calloc(2, sizeof(ss_request_table *));
104 if (new_table->rqt_tables == NULL) {
106 free(new_table->prompt);
107 free(new_table->info_dirs);
111 *(new_table->rqt_tables) = request_table_ptr;
112 *(new_table->rqt_tables+1) = (ss_request_table *) NULL;
113 table[sci_idx] = new_table;
118 ss_delete_invocation(sci_idx)
124 t = ss_info(sci_idx);
127 while(t->info_dirs[0] != (char *)NULL)
128 ss_delete_info_dir(sci_idx, t->info_dirs[0], &ignored_code);