/* uvec_decrease - internal function to decrease the size of vector * if newcap <= 0 then decrease by default size else compute new capacity */ static int uvec_decrease(uvec *uv, int newcap) { newcap = ((newcap <= 0) ? UVECPREVLENGTH(uv->capacity) : newcap); if (!(uv->vector = (char **)module_realloc(uv->vector, (size_t)((unsigned long)newcap * sizeof(char *))))) { return -1; } uv->capacity = newcap; return 0; }
/* uvec_increase - internal function to increase the size of vector * if newcap <= 0 then increase by default size else compute new capacity */ static int uvec_increase(uvec *uv, int newcap) { int i; newcap = ((newcap <= 0) ? UVECNEXTLENGTH(uv->capacity) : newcap); if (!(uv->vector = (char **)module_realloc(uv->vector, (size_t)((unsigned long)newcap * sizeof(char *))))) { return -1; } uv->capacity = newcap; /* zero out extra capacity */ for ((i = uv->number); (i < uv->capacity); ++i) { uv->vector[i] = (char *) NULL; } return 0; }
int ModuleCmd_Update( Tcl_Interp *interp, int count, char *module_list[]) { #ifdef BEGINENV char *buf, /** Read buffer **/ *var_ptr, /** Pointer to a variables name **/ *val_ptr, /** Pointer to a variables value **/ **load_list, /** List of loaded modules **/ *tmpload, /** LOADEDMODULES contents **/ *loaded, /** Buffer for tokenization **/ *filename; /** The name of the file, where the **/ /** beginning environment resides **/ FILE *file; /** Handle to read in a file **/ int list_count = 0, maxlist = 16, /** Max. number of list entries **/ buffer_size = UPD_BUFSIZE; /** Current size of the input buffer **/ char *ptr, c; /** Read pointers and char buffer **/ # if BEGINENV == 99 if (!EMGetEnv( interp,"MODULESBEGINENV")) { ErrorLogger( ERR_BEGINENVX, LOC, NULL); return( TCL_ERROR); /** -------- EXIT (FAILURE) -------> **/ } # endif /** ** Nothing loaded so far - we're ready! **/ if(!(tmpload = (char *) getenv("LOADEDMODULES"))) { if( OK != ErrorLogger( ERR_MODULE_PATH, LOC, NULL)) goto unwind0; else goto success0; } /** ** First I'll update the environment with whatever in _MODULESBEGINENV_ **/ filename = EMGetEnv( interp,"_MODULESBEGINENV_"); if(filename && *filename) { /** ** Read the begining environment **/ if((file = fopen( filename, "r"))) { if(!(buf = stringer(NULL, buffer_size, NULL ))) if( OK != ErrorLogger( ERR_STRING, LOC, NULL)) goto unwind0; while( !feof( file)) { /** ** Trigger on entries of the type ** <variable> = <value> **/ ptr = buf; while( !feof( file)) { if((ptr-buf) >= buffer_size-10) { /** 10 bytes safety **/ null_free((void *) &buf); if(!(buf = stringer(NULL, buffer_size += UPD_BUFSIZE, NULL ))) if( OK != ErrorLogger( ERR_STRING, LOC, NULL)) goto unwind0; } /** ** Read a character and put it into the read buffer. Check ** for the lines (CR) or a terminator character ... **/ if( '\n' == (*ptr++ = c = fgetc( file))) { *ptr++ = c = '\0'; break; } if( !c) break; } /** while **/ /** ** If there hasn't been a terminator so far, put it at the ** end of the line. Therefor we've left a safety space at the ** buffers end ;-) **/ if( c) *ptr++ = '\0'; /** ** Now let's evaluate the read line **/ if( (var_ptr = strchr( buf, '=')) ) { *var_ptr = '\0'; val_ptr = var_ptr+1; var_ptr = buf; /** ** Reset the environment to the values derivered from the ** _MODULESBEGINENV_. ** Do not change the LOADEDMODULES variable ;-) ** Do not change the TCL_LIBRARY and TK_LIBRARY also. **/ if( strncmp( var_ptr, "LOADEDMODULES", 12) && strncmp( var_ptr, "TCL_LIBRARY", 10 ) && strncmp( var_ptr, "TK_LIBRARY", 9 )) { if( !strncmp( var_ptr, "MODULEPATH", 10)) moduleSetenv( interp, var_ptr, val_ptr, 1); else EMSetEnv( interp, var_ptr, val_ptr); } } /** if( var_ptr) **/ } /** while **/ /** ** Close the _MODULESBEGINENV_ file anf free up the read buffer. **/ null_free((void *) &buf); if( EOF == fclose( file)) if( OK != ErrorLogger( ERR_CLOSE, LOC, filename, NULL)) goto unwind0; } else { /** if( fopen) **/ if( OK != ErrorLogger( ERR_OPEN, LOC, filename,_(em_reading),NULL)) goto unwind0; } /** if( fopen) **/ } /** if( filename) **/ null_free((void *) &filename); /** ** Allocate memory for a buffer to tokenize the list of loaded modules ** and a list buffer **/ if(!(load_list = (char**) module_malloc( maxlist*sizeof(char**)))) if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL)) goto unwind0; if(!(loaded = stringer(NULL, 0, tmpload, NULL))) if( OK != ErrorLogger( ERR_STRING, LOC, NULL)) goto unwind1; /** ** Tokenize and build the list **/ if( *loaded) { for( load_list[ list_count++] = xstrtok( loaded, ":"); load_list[ list_count-1]; load_list[ list_count++] = xstrtok( NULL, ":") ) { /** ** Conditionally we have to double the space, we've allocated for ** the list **/ if( list_count >= maxlist) { maxlist = maxlist<<1; if(!(load_list = (char**) module_realloc( (char *) load_list, maxlist*sizeof(char**)))) if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL)) goto unwind1; } /** if( maxlist) **/ } /** for **/ /** ** Load all the modules in the list **/ ModuleCmd_Load( interp, 1, list_count, load_list); } /** ** Free up what has been allocated and return on success **/ null_free((void *) &loaded); null_free((void *) &load_list); success0: return( TCL_OK); /** -------- EXIT (SUCCESS) -------> **/ unwind1: null_free((void *) &load_list); unwind0: null_free((void *) &filename); #else /* BEGINENV */ ErrorLogger( ERR_BEGINENV, LOC, NULL); #endif /* !BEGINENV */ return( TCL_ERROR); /** -------- EXIT (FAILURE) -------> **/ } /** End of 'ModuleCmd_Update' **/
int SourceRC(Tcl_Interp *interp, char *path, char *name) { struct stat stats; /** Buffer for the stat() systemcall **/ int save_flags, i = 0; char *buffer; int Result = TCL_OK; static char **srclist = (char **)NULL; static int listsize = 0, listndx = 0; /* dummy condition to use 'i': */ if (i == 0) { ; } /** ** If there is a problem with the input parameters it means, that ** we do not have to source anything ** Only a valid TCL interpreter should be there **/ if (!path || !name) { return (TCL_OK); } if (!interp) { return (TCL_ERROR); } /** ** Build the full name of the RC file ** Avoid duplicate sourcing **/ if ((char *)NULL == (buffer = stringer(NULL, 0, path,"/", name, NULL))) { if (OK != ErrorLogger(ERR_STRING, LOC, NULL)) { goto unwind0; } } /** ** Check whether the RC file exists and has the magic cookie inside **/ if (!stat(buffer, &stats)) { if (check_magic(buffer, MODULES_MAGIC_COOKIE, MODULES_MAGIC_COOKIE_LENGTH)) { /** ** Set the flags to 'load only'. This prevents from accidently ** printing something **/ save_flags = g_flags; g_flags = M_LOAD; /** ** Source now **/ if (TCL_ERROR == Execute_TclFile(interp, buffer)) { if (OK != ErrorLogger(ERR_SOURCE, LOC, buffer, NULL)) { Result = TCL_ERROR; } } g_flags = save_flags; /** ** Save the currently sourced file in the list ** Check whether the list is big enough to fit in a new entry **/ if (!listsize) { listsize = SRCFRAG; if ((char **)NULL == (srclist = (char **)module_malloc((size_t)((unsigned long)listsize * sizeof(char **))))) { ErrorLogger(ERR_ALLOC, LOC, NULL); goto unwind1; } } else if ((listndx + 1) >= listsize) { listsize += SRCFRAG; if (!(srclist = (char **)module_realloc(srclist, (size_t)((unsigned long)listsize * sizeof(char **))))) { ErrorLogger(ERR_ALLOC, LOC, NULL); goto unwind1; } } /** ** Put the current RC files name on the list: **/ srclist[listndx++] = buffer; } else { ErrorLogger(ERR_MAGIC, LOC, buffer, NULL); null_free((void *)&buffer); } } /** end "if (!stat)" **/ /** ** Return our result **/ return (Result); unwind1: null_free((void *)&buffer); unwind0: return (TCL_ERROR); } /** End of 'SourceRC' **/
int cmdModuleWhatis( ClientData client_data, Tcl_Interp *interp, int argc, CONST84 char *argv[]) { int i = 1; #if WITH_DEBUGGING_CALLBACK ErrorLogger( NO_ERR_START, LOC, _proc_cmdModuleWhatis, NULL); #endif /** ** Help mode **/ if( g_flags & M_HELP) return( TCL_OK); /** -------- EXIT (SUCCESS) -------> **/ /** ** Parameter check **/ if( argc < 2) { if( OK != ErrorLogger( ERR_USAGE, LOC, argv[0], " string", NULL)) return( TCL_ERROR); /** -------- EXIT (FAILURE) -------> **/ } /** ** If we don't have any whatis list buffer until now, we will create one **/ if( !whatis) { whatis_size = WHATIS_FRAG; if((char **) NULL == (whatis = module_malloc(whatis_size * sizeof(char *)))){ ErrorLogger( ERR_ALLOC, LOC, NULL); return( TCL_ERROR); /** -------- EXIT (FAILURE) -------> **/ } } /** ** Display mode? **/ if( g_flags & M_DISPLAY) { fprintf( stderr, "%s\t ", argv[ 0]); for( i=1; i<argc; i++) fprintf( stderr, "%s ", argv[ i]); fprintf( stderr, "\n"); return( TCL_OK); /** ------- EXIT PROCEDURE -------> **/ } /** ** Check if printing is requested **/ if( g_flags & M_WHATIS ) { while( i < argc) { /** ** Conditionally we have to enlarge our buffer **/ while( whatis_ndx + 2 >= whatis_size) { whatis_size += WHATIS_FRAG; if(!(whatis = module_realloc( whatis, whatis_size * sizeof( char *)))) { ErrorLogger( ERR_ALLOC, LOC, NULL); return( TCL_ERROR); /** -------- EXIT (FAILURE) -------> **/ } } /** ** Put the string on the buffer **/ if((char *) NULL == (whatis[ whatis_ndx++] = strdup( argv[ i++]))) { if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL)) return( TCL_ERROR); whatis_ndx--; } } /** while **/ } /** if **/ /** ** Put a trailing terminator on the buffer **/ whatis[ whatis_ndx] = (char *) NULL; #if WITH_DEBUGGING_CALLBACK ErrorLogger( NO_ERR_END, LOC, _proc_cmdModuleWhatis, NULL); #endif return( TCL_OK); } /** End of 'cmdModuleWhatis' **/