Whamcloud - gitweb
Update changelogs for 1.22.
[tools/e2fsprogs.git] / lib / ss / invocation.c
1 /*
2  * Copyright 1987, 1988 by MIT Student Information Processing Board
3  *
4  * Permission to use, copy, modify, and distribute this software and
5  * its documentation for any purpose is hereby granted, provided that
6  * the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
7  * advertising or publicity pertaining to distribution of the software
8  * without specific, written prior permission.  M.I.T. and the
9  * M.I.T. S.I.P.B. make no representations about the suitability of
10  * this software for any purpose.  It is provided "as is" without
11  * express or implied warranty.
12  */
13
14 #ifdef HAS_STDLIB_H
15 #include <stdlib.h>
16 #endif
17 #include "ss_internal.h"
18 #define size    sizeof(ss_data *)
19
20 int ss_create_invocation(subsystem_name, version_string, info_ptr,
21                          request_table_ptr, code_ptr)
22         const char *subsystem_name, *version_string;
23         void *info_ptr;
24         ss_request_table *request_table_ptr;
25         int *code_ptr;
26 {
27         register int sci_idx;
28         register ss_data *new_table;
29         register ss_data **table;
30
31         *code_ptr = 0;
32         table = _ss_table;
33         new_table = (ss_data *) malloc(sizeof(ss_data));
34
35         if (table == (ss_data **) NULL) {
36                 table = (ss_data **) malloc(2 * size);
37                 table[0] = table[1] = (ss_data *)NULL;
38         }
39         initialize_ss_error_table ();
40
41         for (sci_idx = 1; table[sci_idx] != (ss_data *)NULL; sci_idx++)
42                 ;
43         table = (ss_data **) realloc((char *)table,
44                                      ((unsigned)sci_idx+2)*size);
45         table[sci_idx+1] = (ss_data *) NULL;
46         table[sci_idx] = new_table;
47
48         new_table->subsystem_name = subsystem_name;
49         new_table->subsystem_version = version_string;
50         new_table->argv = (char **)NULL;
51         new_table->current_request = (char *)NULL;
52         new_table->info_dirs = (char **)malloc(sizeof(char *));
53         *new_table->info_dirs = (char *)NULL;
54         new_table->info_ptr = info_ptr;
55         new_table->prompt = malloc((unsigned)strlen(subsystem_name)+4);
56         strcpy(new_table->prompt, subsystem_name);
57         strcat(new_table->prompt, ":  ");
58 #ifdef silly
59         new_table->abbrev_info = ss_abbrev_initialize("/etc/passwd", code_ptr);
60 #else
61         new_table->abbrev_info = NULL;
62 #endif
63         new_table->flags.escape_disabled = 0;
64         new_table->flags.abbrevs_disabled = 0;
65         new_table->rqt_tables =
66                 (ss_request_table **) calloc(2, sizeof(ss_request_table *));
67         *(new_table->rqt_tables) = request_table_ptr;
68         *(new_table->rqt_tables+1) = (ss_request_table *) NULL;
69         _ss_table = table;
70         return(sci_idx);
71 }
72
73 void
74 ss_delete_invocation(sci_idx)
75         int sci_idx;
76 {
77         register ss_data *t;
78         int ignored_code;
79
80         t = ss_info(sci_idx);
81         free(t->prompt);
82         free((char *)t->rqt_tables);
83         while(t->info_dirs[0] != (char *)NULL)
84                 ss_delete_info_dir(sci_idx, t->info_dirs[0], &ignored_code);
85         free((char *)t->info_dirs);
86         free((char *)t);
87 }