EXPORT m64p_error CALL ConfigDeleteSection(const char *SectionName) { config_section **curr_section_link; config_section *next_section; if (!l_ConfigInit) return M64ERR_NOT_INIT; if (l_ConfigListActive == NULL) return M64ERR_INPUT_NOT_FOUND; /* find the named section and pull it out of the list */ curr_section_link = find_section_link(&l_ConfigListActive, SectionName); if (*curr_section_link == NULL) return M64ERR_INPUT_NOT_FOUND; next_section = (*curr_section_link)->next; /* delete the named section */ delete_section(*curr_section_link); /* fix the pointer to point to the next section after the deleted one */ *curr_section_link = next_section; return M64ERR_SUCCESS; }
void section::clear() { id.clear(); topics.clear(); std::for_each(sections.begin(), sections.end(), delete_section()); sections.clear(); }
static void delete_list(config_list *pConfigList) { config_section *curr_section = *pConfigList; while (curr_section != NULL) { config_section *next_section = curr_section->next; /* delete the section itself */ delete_section(curr_section); curr_section = next_section; } *pConfigList = NULL; }
EXPORT m64p_error CALL ConfigSaveSection(const char *SectionName) { config_section *curr_section, *new_section; config_section **insertion_point; if (!l_ConfigInit) return M64ERR_NOT_INIT; if (SectionName == NULL || strlen(SectionName) < 1) return M64ERR_INPUT_ASSERT; /* walk through the Active section list, looking for a case-insensitive name match */ curr_section = find_section(l_ConfigListActive, SectionName); if (curr_section == NULL) return M64ERR_INPUT_NOT_FOUND; /* duplicate this section */ new_section = section_deepcopy(curr_section); if (new_section == NULL) return M64ERR_NO_MEMORY; /* update config section that's in the Saved list with the new one */ insertion_point = find_alpha_section_link(&l_ConfigListSaved, SectionName); if (*insertion_point != NULL && osal_insensitive_strcmp((*insertion_point)->name, SectionName) == 0) { /* the section exists in the saved list and will be replaced */ new_section->next = (*insertion_point)->next; delete_section(*insertion_point); *insertion_point = new_section; } else { /* the section didn't exist in the saved list and has to be inserted */ new_section->next = *insertion_point; *insertion_point = new_section; } /* write the saved config list out to a file */ return (write_configlist_file()); }
EXPORT m64p_error CALL ConfigRevertChanges(const char *SectionName) { config_section **active_section_link, *active_section, *saved_section, *new_section; /* check input conditions */ if (!l_ConfigInit) return M64ERR_NOT_INIT; if (SectionName == NULL) return M64ERR_INPUT_ASSERT; /* walk through the Active section list, looking for a case-insensitive name match with input string */ active_section_link = find_section_link(&l_ConfigListActive, SectionName); active_section = *active_section_link; if (active_section == NULL) return M64ERR_INPUT_NOT_FOUND; /* walk through the Saved section list, looking for a case-insensitive name match */ saved_section = find_section(l_ConfigListSaved, SectionName); if (saved_section == NULL) { /* if this section isn't present in saved list, then it has been newly created */ return M64ERR_INPUT_NOT_FOUND; } /* copy the section as it is on the disk */ new_section = section_deepcopy(saved_section); if (new_section == NULL) return M64ERR_NO_MEMORY; /* replace active_section with saved_section in the linked list */ *active_section_link = new_section; new_section->next = active_section->next; /* release memory associated with active_section */ delete_section(active_section); return M64ERR_SUCCESS; }
static config_section * section_deepcopy(config_section *orig_section) { config_section *new_section; config_var *orig_var, *last_new_var; /* Input validation */ if (orig_section == NULL) return NULL; /* create and copy section struct */ new_section = config_section_create(orig_section->name); if (new_section == NULL) return NULL; /* create and copy all section variables */ orig_var = orig_section->first_var; last_new_var = NULL; while (orig_var != NULL) { config_var *new_var = config_var_create(orig_var->name, orig_var->comment); if (new_var == NULL) { delete_section(new_section); return NULL; } new_var->type = orig_var->type; switch (orig_var->type) { case M64TYPE_INT: case M64TYPE_BOOL: new_var->val.integer = orig_var->val.integer; break; case M64TYPE_FLOAT: new_var->val.number = orig_var->val.number; break; case M64TYPE_STRING: if (orig_var->val.string != NULL) { new_var->val.string = strdup(orig_var->val.string); if (new_var->val.string == NULL) { delete_section(new_section); return NULL; } } else new_var->val.string = NULL; break; } /* add the new variable to the new section */ if (last_new_var == NULL) new_section->first_var = new_var; else last_new_var->next = new_var; last_new_var = new_var; /* advance variable pointer in original section variable list */ orig_var = orig_var->next; } return new_section; }
section::~section() { std::for_each(sections.begin(), sections.end(), delete_section()); }