Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 1987, 1988 by MIT Student Information Processing Board |
| 3 | * |
Theodore Ts'o | 06cefee | 1999-10-23 01:16:22 +0000 | [diff] [blame] | 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. |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 12 | */ |
Theodore Ts'o | f3db356 | 1997-04-26 13:34:30 +0000 | [diff] [blame] | 13 | |
| 14 | #ifdef HAS_STDLIB_H |
| 15 | #include <stdlib.h> |
| 16 | #endif |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 17 | #include "ss_internal.h" |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 18 | #define size sizeof(ss_data *) |
Theodore Ts'o | 3ae497e | 2003-03-16 06:26:25 -0500 | [diff] [blame] | 19 | #ifdef HAVE_DLOPEN |
| 20 | #include <dlfcn.h> |
| 21 | #endif |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 22 | |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 23 | int ss_create_invocation(subsystem_name, version_string, info_ptr, |
| 24 | request_table_ptr, code_ptr) |
Theodore Ts'o | 1e3472c | 1997-04-29 14:53:37 +0000 | [diff] [blame] | 25 | const char *subsystem_name, *version_string; |
| 26 | void *info_ptr; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 27 | ss_request_table *request_table_ptr; |
| 28 | int *code_ptr; |
| 29 | { |
| 30 | register int sci_idx; |
| 31 | register ss_data *new_table; |
| 32 | register ss_data **table; |
| 33 | |
| 34 | *code_ptr = 0; |
| 35 | table = _ss_table; |
| 36 | new_table = (ss_data *) malloc(sizeof(ss_data)); |
| 37 | |
| 38 | if (table == (ss_data **) NULL) { |
| 39 | table = (ss_data **) malloc(2 * size); |
| 40 | table[0] = table[1] = (ss_data *)NULL; |
| 41 | } |
| 42 | initialize_ss_error_table (); |
| 43 | |
| 44 | for (sci_idx = 1; table[sci_idx] != (ss_data *)NULL; sci_idx++) |
| 45 | ; |
| 46 | table = (ss_data **) realloc((char *)table, |
| 47 | ((unsigned)sci_idx+2)*size); |
| 48 | table[sci_idx+1] = (ss_data *) NULL; |
| 49 | table[sci_idx] = new_table; |
| 50 | |
| 51 | new_table->subsystem_name = subsystem_name; |
| 52 | new_table->subsystem_version = version_string; |
| 53 | new_table->argv = (char **)NULL; |
| 54 | new_table->current_request = (char *)NULL; |
| 55 | new_table->info_dirs = (char **)malloc(sizeof(char *)); |
| 56 | *new_table->info_dirs = (char *)NULL; |
| 57 | new_table->info_ptr = info_ptr; |
| 58 | new_table->prompt = malloc((unsigned)strlen(subsystem_name)+4); |
| 59 | strcpy(new_table->prompt, subsystem_name); |
| 60 | strcat(new_table->prompt, ": "); |
| 61 | #ifdef silly |
| 62 | new_table->abbrev_info = ss_abbrev_initialize("/etc/passwd", code_ptr); |
| 63 | #else |
| 64 | new_table->abbrev_info = NULL; |
| 65 | #endif |
| 66 | new_table->flags.escape_disabled = 0; |
| 67 | new_table->flags.abbrevs_disabled = 0; |
| 68 | new_table->rqt_tables = |
| 69 | (ss_request_table **) calloc(2, sizeof(ss_request_table *)); |
| 70 | *(new_table->rqt_tables) = request_table_ptr; |
| 71 | *(new_table->rqt_tables+1) = (ss_request_table *) NULL; |
Theodore Ts'o | 3ae497e | 2003-03-16 06:26:25 -0500 | [diff] [blame] | 72 | |
| 73 | new_table->readline_handle = 0; |
| 74 | new_table->readline = 0; |
| 75 | new_table->add_history = 0; |
| 76 | new_table->redisplay = 0; |
| 77 | new_table->rl_completion_matches = 0; |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 78 | _ss_table = table; |
Theodore Ts'o | 3ae497e | 2003-03-16 06:26:25 -0500 | [diff] [blame] | 79 | #if defined(HAVE_DLOPEN) && defined(SHARED_ELF_LIB) |
| 80 | ss_get_readline(sci_idx); |
| 81 | #endif |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 82 | return(sci_idx); |
| 83 | } |
| 84 | |
| 85 | void |
| 86 | ss_delete_invocation(sci_idx) |
| 87 | int sci_idx; |
| 88 | { |
| 89 | register ss_data *t; |
| 90 | int ignored_code; |
| 91 | |
| 92 | t = ss_info(sci_idx); |
| 93 | free(t->prompt); |
Theodore Ts'o | 91835c1 | 2003-03-30 22:26:13 -0500 | [diff] [blame] | 94 | free(t->rqt_tables); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 95 | while(t->info_dirs[0] != (char *)NULL) |
| 96 | ss_delete_info_dir(sci_idx, t->info_dirs[0], &ignored_code); |
Theodore Ts'o | 91835c1 | 2003-03-30 22:26:13 -0500 | [diff] [blame] | 97 | free(t->info_dirs); |
Theodore Ts'o | 3ae497e | 2003-03-16 06:26:25 -0500 | [diff] [blame] | 98 | #if defined(HAVE_DLOPEN) && defined(SHARED_ELF_LIB) |
| 99 | if (t->readline_shutdown) |
| 100 | (*t->readline_shutdown)(t); |
| 101 | #endif |
Theodore Ts'o | 91835c1 | 2003-03-30 22:26:13 -0500 | [diff] [blame] | 102 | free(t); |
Theodore Ts'o | 3839e65 | 1997-04-26 13:21:57 +0000 | [diff] [blame] | 103 | } |