diff options
Diffstat (limited to 'src/util/ss/invocation.c')
-rw-r--r-- | src/util/ss/invocation.c | 163 |
1 files changed, 82 insertions, 81 deletions
diff --git a/src/util/ss/invocation.c b/src/util/ss/invocation.c index a7e17bd424..d9c4ea5fa7 100644 --- a/src/util/ss/invocation.c +++ b/src/util/ss/invocation.c @@ -1,3 +1,4 @@ +/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* * Copyright 2007 Massachusetts Institute of Technology. * All Rights Reserved. @@ -28,7 +29,7 @@ */ #include "ss_internal.h" #include "copyright.h" -#define size sizeof(ss_data *) +#define size sizeof(ss_data *) /* XXX The memory in _ss_table never gets freed up until program exit! If you change the code to free it and stick a null pointer into @@ -36,95 +37,95 @@ not assume there are no null pointers in the middle of the array. */ int ss_create_invocation(subsystem_name, version_string, info_ptr, - request_table_ptr, code_ptr) - char *subsystem_name, *version_string; - char *info_ptr; - ss_request_table *request_table_ptr; - int *code_ptr; + request_table_ptr, code_ptr) + char *subsystem_name, *version_string; + char *info_ptr; + ss_request_table *request_table_ptr; + int *code_ptr; { - register int sci_idx; - register ss_data *new_table; - register ss_data **table, **tmp; + register int sci_idx; + register ss_data *new_table; + register ss_data **table, **tmp; - *code_ptr = 0; - table = _ss_table; - new_table = (ss_data *) malloc(sizeof(ss_data)); - if (new_table == NULL) { - *code_ptr = errno; - return -1; - } + *code_ptr = 0; + table = _ss_table; + new_table = (ss_data *) malloc(sizeof(ss_data)); + if (new_table == NULL) { + *code_ptr = errno; + return -1; + } - if (table == (ss_data **) NULL) { - table = (ss_data **) malloc(2 * size); - if (table == NULL) { - *code_ptr = errno; - return -1; - } - table[0] = table[1] = (ss_data *)NULL; - _ss_table = table; - } - initialize_ss_error_table (); + if (table == (ss_data **) NULL) { + table = (ss_data **) malloc(2 * size); + if (table == NULL) { + *code_ptr = errno; + return -1; + } + table[0] = table[1] = (ss_data *)NULL; + _ss_table = table; + } + initialize_ss_error_table (); - for (sci_idx = 1; table[sci_idx] != (ss_data *)NULL; sci_idx++) - ; - tmp = (ss_data **) realloc((char *)table, - ((unsigned)sci_idx+2)*size); - if (tmp == NULL) { - *code_ptr = errno; - return 0; - } - _ss_table = table = tmp; - table[sci_idx+1] = (ss_data *) NULL; - table[sci_idx] = NULL; + for (sci_idx = 1; table[sci_idx] != (ss_data *)NULL; sci_idx++) + ; + tmp = (ss_data **) realloc((char *)table, + ((unsigned)sci_idx+2)*size); + if (tmp == NULL) { + *code_ptr = errno; + return 0; + } + _ss_table = table = tmp; + table[sci_idx+1] = (ss_data *) NULL; + table[sci_idx] = NULL; - new_table->subsystem_name = subsystem_name; - new_table->subsystem_version = version_string; - new_table->argv = (char **)NULL; - new_table->current_request = (char *)NULL; - new_table->info_dirs = (char **)malloc(sizeof(char *)); - if (new_table->info_dirs == NULL) { - *code_ptr = errno; - free(new_table); - return 0; - } - *new_table->info_dirs = (char *)NULL; - new_table->info_ptr = info_ptr; - if (asprintf(&new_table->prompt, "%s: ", subsystem_name) < 0) { - *code_ptr = errno; - free(new_table->info_dirs); - free(new_table); - return 0; - } - new_table->abbrev_info = NULL; - new_table->flags.escape_disabled = 0; - new_table->flags.abbrevs_disabled = 0; - new_table->rqt_tables = - (ss_request_table **) calloc(2, sizeof(ss_request_table *)); - if (new_table->rqt_tables == NULL) { - *code_ptr = errno; - free(new_table->prompt); - free(new_table->info_dirs); - free(new_table); - return 0; - } - *(new_table->rqt_tables) = request_table_ptr; - *(new_table->rqt_tables+1) = (ss_request_table *) NULL; - table[sci_idx] = new_table; - return(sci_idx); + new_table->subsystem_name = subsystem_name; + new_table->subsystem_version = version_string; + new_table->argv = (char **)NULL; + new_table->current_request = (char *)NULL; + new_table->info_dirs = (char **)malloc(sizeof(char *)); + if (new_table->info_dirs == NULL) { + *code_ptr = errno; + free(new_table); + return 0; + } + *new_table->info_dirs = (char *)NULL; + new_table->info_ptr = info_ptr; + if (asprintf(&new_table->prompt, "%s: ", subsystem_name) < 0) { + *code_ptr = errno; + free(new_table->info_dirs); + free(new_table); + return 0; + } + new_table->abbrev_info = NULL; + new_table->flags.escape_disabled = 0; + new_table->flags.abbrevs_disabled = 0; + new_table->rqt_tables = + (ss_request_table **) calloc(2, sizeof(ss_request_table *)); + if (new_table->rqt_tables == NULL) { + *code_ptr = errno; + free(new_table->prompt); + free(new_table->info_dirs); + free(new_table); + return 0; + } + *(new_table->rqt_tables) = request_table_ptr; + *(new_table->rqt_tables+1) = (ss_request_table *) NULL; + table[sci_idx] = new_table; + return(sci_idx); } void ss_delete_invocation(sci_idx) - int sci_idx; + int sci_idx; { - register ss_data *t; - int ignored_code; + register ss_data *t; + int ignored_code; - t = ss_info(sci_idx); - free(t->prompt); - free(t->rqt_tables); - while(t->info_dirs[0] != (char *)NULL) - ss_delete_info_dir(sci_idx, t->info_dirs[0], &ignored_code); - free(t->info_dirs); - free(t); + t = ss_info(sci_idx); + free(t->prompt); + free(t->rqt_tables); + while(t->info_dirs[0] != (char *)NULL) + ss_delete_info_dir(sci_idx, t->info_dirs[0], &ignored_code); + free(t->info_dirs); + free(t); } |