int moduleUnsetenv( Tcl_Interp *interp, char *variable) { #if WITH_DEBUGGING_UTIL_1 ErrorLogger( NO_ERR_START, LOC, _proc_moduleUnsetenv, NULL); #endif /** ** Don't unset the variable in Tcl Space. ** If module writer *REALLY* wants it gone, use $env **/ if( !(g_flags & (M_NONPERSIST | M_DISPLAY | M_WHATIS | M_HELP))) { store_hash_value( unsetenvHashTable, variable, NULL); clear_hash_value( setenvHashTable, variable); } #if WITH_DEBUGGING_UTIL_1 ErrorLogger( NO_ERR_END, LOC, _proc_moduleUnsetenv, NULL); #endif return( TCL_OK); } /** end of 'moduleUnsetenv' **/
void add_positional_variation_from_line(char *line) { if(non_blank_line(line)){ Move *next_variation = compose_positional_variation(line); if(next_variation != NULL){ /* We need a NULL fen string, because this is from * the initial position. */ store_hash_value(next_variation,(const char *)NULL); free_move_list(next_variation); /* We need to know globally that positional variations * are of interest. */ GlobalState.positional_variations = TRUE; } } }
int moduleSetenv( Tcl_Interp *interp, char *variable, char *value, int force) { char *oldval; /** Old value of 'variable' **/ #if WITH_DEBUGGING_UTIL_1 ErrorLogger( NO_ERR_START, LOC, _proc_moduleSetenv, NULL); #endif oldval = EMGetEnv( interp, variable); if (!oldval || !*oldval) null_free((void *)&oldval); /** ** Check to see if variable is already set correctly... **/ if( !(g_flags & (M_REMOVE|M_DISPLAY|M_SWITCH|M_NONPERSIST)) && oldval) { if( !strcmp( value, oldval)) { return( TCL_OK); /** -------- EXIT (SUCCESS) -------> **/ } } /** ** If I'm in SWSTATE1, I'm removing stuff from the old modulefile, so ** I'll just mark the variables that were used with the SWSTATE1 flag and ** return. ** ** When I come back through in SWSTATE2, I'm setting the variables that ** are in the new modulefile. So, I'll keep track of these by marking ** them as touched by SWSTATE2 and then actually setting their values in ** the environment down below. ** ** Finally, in SWSTATE3, I'll check to see if the variables in the old ** modulefiles that have been marked are still marked as SWSTATE1. If ** they are still the same, then I'll just unset them and return. ** ** And, if I'm not doing any switching, then just unset the variable if ** I'm in remove mode. **/ if( g_flags & M_SWSTATE1) { set_marked_entry( markVariableHashTable, variable, M_SWSTATE1); return( TCL_OK); /** -------- EXIT (SUCCESS) -------> **/ } else if( g_flags & M_SWSTATE2) { set_marked_entry( markVariableHashTable, variable, M_SWSTATE2); } else if( g_flags & M_SWSTATE3) { intptr_t marked_val; marked_val = chk_marked_entry( markVariableHashTable, variable); if( marked_val) { if( marked_val == M_SWSTATE1) return( moduleUnsetenv(interp, variable)); /** -------> **/ else return( TCL_OK); /** -------- EXIT (SUCCESS) -------> **/ } } else if( (g_flags & M_REMOVE) && !force) { return( moduleUnsetenv( interp, variable)); /** -------> **/ } /** ** Keep track of our changes just in case we have to bail out and restore ** the environment. **/ if( !(g_flags & (M_NONPERSIST | M_DISPLAY | M_WHATIS | M_HELP))) { store_hash_value( setenvHashTable, variable, value); clear_hash_value( unsetenvHashTable, variable); } /** ** Store the value into the environment **/ EMSetEnv( interp, variable, value); #if WITH_DEBUGGING_UTIL_1 ErrorLogger( NO_ERR_END, LOC, _proc_moduleSetenv, NULL); #endif return( TCL_OK); } /** End of 'moduleSetenv' **/
static int Remove_Path(Tcl_Interp *interp, char *variable, char *item, char *sw_marker, const char *delim) { char *oldpath, /** current path **/ *olditem; /** item from path **/ int i = 0, /** counter **/ found = 0, /** flag to indicate item was found **/ pcount = 0, /** count of items in path **/ addsep = 0, /** flag to add separator **/ marked = 0, /** flag path contains sw_marker **/ oldpathlen = 0; Tcl_DString _newpath; Tcl_DString *newpath = &_newpath; Tcl_DStringInit(newpath); /** ** Get the current value of the "PATH" environment variable **/ oldpath = (char *)EMGetEnv(interp, variable); if (!oldpath || !*oldpath) { null_free((void *)&oldpath); _TCLCHK(interp); goto success0; /** -------- EXIT (SUCCESS) -------> **/ } /* copy oldpath to not mess with the TCL value of env(PATH) */ if (!(oldpath = stringer(NULL,0, oldpath, NULL))) { if (OK != ErrorLogger(ERR_STRING, LOC, NULL)) { goto unwind0; } } /* get length of oldpath before it gets modified by xstrtok */ oldpathlen = (int)strlen(oldpath); /* determine if sw_marker is in the path */ olditem = xstrtok(oldpath, delim); while (olditem) { if (!strcmp(olditem, sw_marker)) { marked = 1; } pcount++; olditem = xstrtok(NULL, delim); } /** pointer arithmetic on oldpath ** if olditem starts at terminating null string of oldpath, ** it means the last character in oldpath was ":", meaning ** the last element was the empty string. use <= to catch ** this case and process the last empty element */ for (olditem = oldpath; olditem <= oldpath + oldpathlen; olditem += strlen(olditem) + 1) { if (strcmp(olditem, item)) { /* not the droids we're looking for */ if (Tcl_DStringLength(newpath)) { if (!Tcl_DStringAppend(newpath, delim, 1)) if (OK != ErrorLogger(ERR_STRING, LOC, NULL)) goto unwind1; } if (!Tcl_DStringAppend(newpath, olditem, -1)) if (OK != ErrorLogger(ERR_STRING, LOC, NULL)) goto unwind1; } else { /* bingo! Don't add it to new path */ found++; if ((g_flags & M_SWSTATE1) && !marked) { /** ** In state1, we're actually replacing old paths with ** the markers for future appends and prepends. ** ** We only want to do this once to mark the location ** the module was formed around. **/ marked = 1; if (Tcl_DStringLength(newpath)) { if (!Tcl_DStringAppend (newpath, delim, 1)) if (OK != ErrorLogger(ERR_STRING, LOC, NULL)) goto unwind1; } if (!Tcl_DStringAppend(newpath, sw_marker, -1)) if (OK != ErrorLogger(ERR_STRING, LOC, NULL)) goto unwind1; } } } if (!found) { goto success1; } if (Tcl_DStringLength(newpath)) { /** ** Cache the set. Clear the variable from the unset table just ** in case it was previously unset. **/ store_hash_value(setenvHashTable, variable, Tcl_DStringValue(newpath)); clear_hash_value(unsetenvHashTable, variable); /** ** Store the new PATH value into the environment. **/ (void) EMSetEnv( interp, variable, Tcl_DStringValue(newpath)); _TCLCHK(interp); } else { /** ** In this case, I should go ahead and unset the variable ** from the environment because I'm removing the very last ** path. ** ** First I'm going to clear the variable from the ** setenvHashTable just in case its already been altered ** and had a significant value at the time. It's very ** possible that I'm removing the only two or three paths ** from this variable. If that's the case, then all the ** earlier paths were marked for output in this hashTable. ** ** Secondly, I actually mark the the environment variable ** to be unset when output. **/ clear_hash_value(setenvHashTable, variable); moduleUnsetenv(interp, variable); /** ** moduleUnsetenv doesn't unset the variable in the Tcl ** space because the $env variable might need to be ** used again in the modulefile for locating other ** paths. BUT, since this was a path-type environment ** variable, the user is expecting this to be empty ** after removing the only remaining path. So, I set ** the variable empty here. **/ (void) EMSetEnv( interp, variable, ""); _TCLCHK(interp); } /** ** Free what has been used and return on success **/ success1: null_free((void *)&oldpath); success0: Tcl_DStringFree(newpath); return (TCL_OK); /** -------- EXIT (SUCCESS) -------> **/ unwind1: null_free((void *)&oldpath); unwind0: Tcl_DStringFree(newpath); return (TCL_ERROR); /** -------- EXIT (FAILURE) -------> **/ } /** End of 'Remove_Path' **/
/* Treat fen_string as being a position to be matched. */ void add_fen_positional_match(const char *fen_string) { store_hash_value((Move *)NULL,fen_string); GlobalState.positional_variations = TRUE; }