Whamcloud - gitweb
ChangeLog, dumpe2fs.8.in, dumpe2fs.c, mke2fs.8.in, mke2fs.c, partinfo.c:
[tools/e2fsprogs.git] / lib / ss / invocation.c
1 /*
2  * Copyright 1987, 1988 by MIT Student Information Processing Board
3  *
4  * This file may be copied under the terms of the GNU Public License.
5  */
6
7 #ifdef HAS_STDLIB_H
8 #include <stdlib.h>
9 #endif
10 #include "ss_internal.h"
11 #define size    sizeof(ss_data *)
12
13 int ss_create_invocation(subsystem_name, version_string, info_ptr,
14                          request_table_ptr, code_ptr)
15         const char *subsystem_name, *version_string;
16         void *info_ptr;
17         ss_request_table *request_table_ptr;
18         int *code_ptr;
19 {
20         register int sci_idx;
21         register ss_data *new_table;
22         register ss_data **table;
23
24         *code_ptr = 0;
25         table = _ss_table;
26         new_table = (ss_data *) malloc(sizeof(ss_data));
27
28         if (table == (ss_data **) NULL) {
29                 table = (ss_data **) malloc(2 * size);
30                 table[0] = table[1] = (ss_data *)NULL;
31         }
32         initialize_ss_error_table ();
33
34         for (sci_idx = 1; table[sci_idx] != (ss_data *)NULL; sci_idx++)
35                 ;
36         table = (ss_data **) realloc((char *)table,
37                                      ((unsigned)sci_idx+2)*size);
38         table[sci_idx+1] = (ss_data *) NULL;
39         table[sci_idx] = new_table;
40
41         new_table->subsystem_name = subsystem_name;
42         new_table->subsystem_version = version_string;
43         new_table->argv = (char **)NULL;
44         new_table->current_request = (char *)NULL;
45         new_table->info_dirs = (char **)malloc(sizeof(char *));
46         *new_table->info_dirs = (char *)NULL;
47         new_table->info_ptr = info_ptr;
48         new_table->prompt = malloc((unsigned)strlen(subsystem_name)+4);
49         strcpy(new_table->prompt, subsystem_name);
50         strcat(new_table->prompt, ":  ");
51 #ifdef silly
52         new_table->abbrev_info = ss_abbrev_initialize("/etc/passwd", code_ptr);
53 #else
54         new_table->abbrev_info = NULL;
55 #endif
56         new_table->flags.escape_disabled = 0;
57         new_table->flags.abbrevs_disabled = 0;
58         new_table->rqt_tables =
59                 (ss_request_table **) calloc(2, sizeof(ss_request_table *));
60         *(new_table->rqt_tables) = request_table_ptr;
61         *(new_table->rqt_tables+1) = (ss_request_table *) NULL;
62         _ss_table = table;
63         return(sci_idx);
64 }
65
66 void
67 ss_delete_invocation(sci_idx)
68         int sci_idx;
69 {
70         register ss_data *t;
71         int ignored_code;
72
73         t = ss_info(sci_idx);
74         free(t->prompt);
75         free((char *)t->rqt_tables);
76         while(t->info_dirs[0] != (char *)NULL)
77                 ss_delete_info_dir(sci_idx, t->info_dirs[0], &ignored_code);
78         free((char *)t->info_dirs);
79         free((char *)t);
80 }