#include #include #include #include #include #include "dda_ti_dsl.h" #include "dda_input.h" static int InitDone = FALSE; /** * This function parses the inputs provided by the user * and makes it available to all the lower level functions. * * @return 1 OK, Non-zero Not OK */ int DDA_init_envs(void) { int i; int num_elems = NUM_ELEMS(DDA_Env_Input); char *ptr = NULL; if(!InitDone) { /* Clear up the inuse flags if they have been involuntarily set */ for (i = 0; i < num_elems; i++) { DDA_Env_Input[i].in_use &= ~IN_USE_FLAG; /* Search the list of known envs. */ ptr = prom_getenv((char *)DDA_Env_Input[i].name); if(ptr) { if(DDA_Env_Input[i].in_use & VAL_IS_PTR) { DDA_Env_Input[i].CpValue = DDA_malloc(strlen(ptr) + 1); if(DDA_Env_Input[i].CpValue) { int j; int len = strlen(ptr); for(j = 0; j < len; j++) { DDA_Env_Input[i].CpValue[j] = *ptr++; } DDA_Env_Input[i].CpValue[j] = '\0'; DDA_Env_Input[i].in_use |= IN_USE_FLAG; } } else { if((*ptr == '0') && ((*(ptr + 1) == 'x') || (*(ptr + 1) == 'X'))) { DDA_Env_Input[i].IntValue = os_atoh(ptr + 2); } else { DDA_Env_Input[i].IntValue = os_atoi(ptr); } DDA_Env_Input[i].in_use |= IN_USE_FLAG; } /* Clean it up for the next one. */ ptr = NULL; } } InitDone = TRUE; } return 1; } /** * This function parses the inputs provided by the user * and checks whether the specified string has been set * by the user. * * @return 1 Found the string as input, 0 String not set by user. */ int DDA_get_value_from_name(const char *variable_name, void * result) { int ctr; int num_elems = NUM_ELEMS(DDA_Env_Input); int len = strlen(variable_name); int retval = 0; /* Default not found */ int *Ip = (int *)result; char **Cp = (char **)result; if((InitDone) && (len)) { for(ctr = 0; ctr < num_elems; ctr++) { if(!DDA_atm_memcmp((char *)variable_name, DDA_Env_Input[ctr].name, len)) { if(DDA_Env_Input[ctr].in_use & VAL_IS_PTR) { *Cp = (char *)DDA_Env_Input[ctr].CpValue; } else { *Ip = (int)DDA_Env_Input[ctr].IntValue; } retval = 1; break; } } } else result = NULL; return retval; } /** * This function parses the inputs provided by the user * and checks whether the specified offset has been set * by the user. * * @return 1 Found the variable as input, 0 variable not set by user. */ int DDA_get_value_from_offset(int offset, void * result) { int num_elems = NUM_ELEMS(DDA_Env_Input); int retval = 0; /* Default not found */ int *Ip = (int *)result; char **Cp = (char **)result; if((InitDone) && (offset >= 0 || offset < num_elems)) { if(DDA_Env_Input[offset].in_use & IN_USE_FLAG) { if(DDA_Env_Input[offset].in_use & VAL_IS_PTR) { *Cp = (char *)DDA_Env_Input[offset].CpValue; } else { *Ip = (int)DDA_Env_Input[offset].IntValue; } retval = 1; } } else result = NULL; return retval; } /** * This function cleans up the input table and * frees the strings. * * @return 1 OK, 0 Not OK */ int DDA_close_envs(void) { int i; int num_elems = NUM_ELEMS(DDA_Env_Input); if(InitDone) { /* Clear up the inuse flags if they have been involuntarily set */ for (i = 0; i < num_elems; i++) { if(DDA_Env_Input[i].in_use & IN_USE_FLAG) { /* free the list of known envs srrings. */ if(DDA_Env_Input[i].in_use & VAL_IS_PTR) { DDA_free(DDA_Env_Input[i].CpValue); DDA_Env_Input[i].CpValue = NULL; } /* Clear in-use flag. */ DDA_Env_Input[i].in_use &= ~IN_USE_FLAG; } } InitDone = FALSE; } return 1; }