EXPORT m64p_error CALL ConfigSetParameter(m64p_handle ConfigSectionHandle, const char *ParamName, m64p_type ParamType, const void *ParamValue) { config_section *section; config_var *var; /* check input conditions */ if (!l_ConfigInit) return M64ERR_NOT_INIT; if (ConfigSectionHandle == NULL || ParamName == NULL || ParamValue == NULL || (int) ParamType < 1 || (int) ParamType > 4) return M64ERR_INPUT_ASSERT; section = (config_section *) ConfigSectionHandle; if (section->magic != SECTION_MAGIC) return M64ERR_INPUT_INVALID; /* if this parameter doesn't already exist, then create it and add it to the section */ var = find_section_var(section, ParamName); if (var == NULL) { var = (config_var *) malloc(sizeof(config_var)); if (var == NULL) return M64ERR_NO_MEMORY; strncpy(var->name, ParamName, 63); var->name[63] = 0; var->type = M64TYPE_INT; var->val_int = 0; var->val_string = NULL; var->comment = NULL; var->next = NULL; append_var_to_section(section, var); } /* set this parameter's value */ var->type = ParamType; switch(ParamType) { case M64TYPE_INT: var->val_int = *((int *) ParamValue); break; case M64TYPE_FLOAT: var->val_float = *((float *) ParamValue); break; case M64TYPE_BOOL: var->val_int = (*((int *) ParamValue) != 0); break; case M64TYPE_STRING: if (var->val_string != NULL) free(var->val_string); var->val_string = (char *) malloc(strlen((char *) ParamValue) + 1); if (var->val_string == NULL) return M64ERR_NO_MEMORY; memcpy(var->val_string, ParamValue, strlen((char *) ParamValue) + 1); break; default: /* this is logically impossible because of the ParamType check at the top of this function */ break; } return M64ERR_SUCCESS; }
EXPORT m64p_error CALL ConfigSetParameter(m64p_handle ConfigSectionHandle, const char *ParamName, m64p_type ParamType, const void *ParamValue) { config_section *section; config_var *var; /* check input conditions */ if (!l_ConfigInit) return M64ERR_NOT_INIT; if (ConfigSectionHandle == NULL || ParamName == NULL || ParamValue == NULL || (int) ParamType < 1 || (int) ParamType > 4) return M64ERR_INPUT_ASSERT; section = (config_section *) ConfigSectionHandle; if (section->magic != SECTION_MAGIC) return M64ERR_INPUT_INVALID; /* if this parameter doesn't already exist, then create it and add it to the section */ var = find_section_var(section, ParamName); if (var == NULL) { var = config_var_create(ParamName, NULL); if (var == NULL) return M64ERR_NO_MEMORY; append_var_to_section(section, var); } /* cleanup old values */ switch (var->type) { case M64TYPE_STRING: free(var->val.string); break; default: break; } /* set this parameter's value */ var->type = ParamType; switch(ParamType) { case M64TYPE_INT: var->val.integer = *((int *) ParamValue); break; case M64TYPE_FLOAT: var->val.number = *((float *) ParamValue); break; case M64TYPE_BOOL: var->val.integer = (*((int *) ParamValue) != 0); break; case M64TYPE_STRING: var->val.string = strdup((char *)ParamValue); if (var->val.string == NULL) return M64ERR_NO_MEMORY; break; default: /* this is logically impossible because of the ParamType check at the top of this function */ break; } return M64ERR_SUCCESS; }
EXPORT m64p_error CALL ConfigSetDefaultString(m64p_handle ConfigSectionHandle, const char *ParamName, const char * ParamValue, const char *ParamHelp) { config_section *section; config_var *var; /* check input conditions */ if (!l_ConfigInit) return M64ERR_NOT_INIT; if (ConfigSectionHandle == NULL || ParamName == NULL || ParamValue == NULL) return M64ERR_INPUT_ASSERT; section = (config_section *) ConfigSectionHandle; if (section->magic != SECTION_MAGIC) return M64ERR_INPUT_INVALID; /* if this parameter already exists, then just return successfully */ var = find_section_var(section, ParamName); if (var != NULL) return M64ERR_SUCCESS; /* otherwise create a new config_var object and add it to this section */ var = config_var_create(ParamName, ParamHelp); if (var == NULL) return M64ERR_NO_MEMORY; var->type = M64TYPE_STRING; var->val.string = strdup(ParamValue); if (var->val.string == NULL) { delete_var(var); return M64ERR_NO_MEMORY; } append_var_to_section(section, var); return M64ERR_SUCCESS; }
EXPORT m64p_error CALL ConfigSetDefaultString(m64p_handle ConfigSectionHandle, const char *ParamName, const char * ParamValue, const char *ParamHelp) { config_section *section; config_var *var; /* check input conditions */ if (!l_ConfigInit) return M64ERR_NOT_INIT; if (ConfigSectionHandle == NULL || ParamName == NULL || ParamValue == NULL) return M64ERR_INPUT_ASSERT; section = (config_section *) ConfigSectionHandle; if (section->magic != SECTION_MAGIC) return M64ERR_INPUT_INVALID; /* if this parameter already exists, then just return successfully */ var = find_section_var(section, ParamName); if (var != NULL) return M64ERR_SUCCESS; /* otherwise create a new config_var object and add it to this section */ var = (config_var *) malloc(sizeof(config_var)); if (var == NULL) return M64ERR_NO_MEMORY; strncpy(var->name, ParamName, 63); var->name[63] = 0; var->type = M64TYPE_STRING; var->val_string = (char *) malloc(strlen(ParamValue) + 1); if (var->val_string == NULL) return M64ERR_NO_MEMORY; strcpy(var->val_string, ParamValue); if (ParamHelp == NULL) var->comment = NULL; else { var->comment = (char *) malloc(strlen(ParamHelp) + 1); if (var->comment == NULL) return M64ERR_NO_MEMORY; strcpy(var->comment, ParamHelp); } var->next = NULL; append_var_to_section(section, var); return M64ERR_SUCCESS; }