Beispiel #1
0
EXPORT m64p_error CALL ConfigRevertChanges(const char *SectionName)
{
    config_section *input_section, *curr_section, *new_section, *temp_next_ptr;

    /* 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 */
    input_section = l_ConfigListActive;
    while (input_section != NULL)
    {
        if (osal_insensitive_strcmp(SectionName, input_section->name) == 0)
            break;
        input_section = input_section->next;
    }
    if (input_section == NULL)
        return M64ERR_INPUT_NOT_FOUND;

    /* walk through the Saved section list, looking for a case-insensitive name match */
    curr_section = l_ConfigListSaved;
    while (curr_section != NULL)
    {
        if (osal_insensitive_strcmp(SectionName, curr_section->name) == 0)
            break;
        curr_section = curr_section->next;
    }
    /* if this section isn't present in saved list, then it has been newly created */
    if (curr_section == NULL)
        return M64ERR_INPUT_NOT_FOUND;

    /* we need to save the "next" pointer in the active section, because this will get blown away by the deepcopy */
    temp_next_ptr = input_section->next;
    /* delete the variables from the Active section */
    delete_section_vars(input_section);
    /* copy all of the section data from the Saved section to the Active one */
    new_section = section_deepcopy(curr_section, input_section);
    if (new_section == NULL)
        return M64ERR_NO_MEMORY;  /* it's very bad if this happens, because original data from Active section has been deleted */
    /* new_section should be == to input_section.  now put the "next" pointer back */
    input_section->next = temp_next_ptr;

    /* should be good to go */
    return M64ERR_SUCCESS;
}
Beispiel #2
0
static void copy_configlist_active_to_saved(void)
{
    config_section *curr_section = l_ConfigListActive;
    config_section *last_section = NULL;

    /* delete any pre-existing Saved config list */
    delete_list(&l_ConfigListSaved);

    /* duplicate all of the config sections in the Active list, adding them to the Saved list */
    while (curr_section != NULL)
    {
        config_section *new_section = section_deepcopy(curr_section, NULL);
        if (new_section == NULL) break;
        if (last_section == NULL)
            l_ConfigListSaved = new_section;
        else
            last_section->next = new_section;
        last_section = new_section;
        curr_section = curr_section->next;
    }
}
Beispiel #3
0
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());
}
Beispiel #4
0
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;
}
Beispiel #5
0
EXPORT m64p_error CALL ConfigSaveSection(const char *SectionName)
{
    config_section *curr_section, *new_section;

    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 = l_ConfigListActive;
    while (curr_section != NULL)
    {
        if (osal_insensitive_strcmp(SectionName, curr_section->name) == 0)
            break;
        curr_section = curr_section->next;
    }
    if (curr_section == NULL)
        return M64ERR_INPUT_NOT_FOUND;

    /* duplicate this section */
    new_section = section_deepcopy(curr_section, NULL);
    if (new_section == NULL)
        return M64ERR_NO_MEMORY;

    /* update config section that's in the Saved list with the new one */
    if (l_ConfigListSaved == NULL || osal_insensitive_strcmp(SectionName, l_ConfigListSaved->name) < 0)
    {
        /* the saved section is new and goes at the beginning of the list */
        new_section->next = l_ConfigListSaved;
        l_ConfigListSaved = new_section;
    }
    else if (osal_insensitive_strcmp(SectionName, l_ConfigListSaved->name) == 0)
    {
        /* the saved section replaces the first section in the list */
        new_section->next = l_ConfigListSaved->next;
        delete_section_vars(l_ConfigListSaved);
        free(l_ConfigListSaved);
        l_ConfigListSaved = new_section;
    }
    else
    {
        curr_section = l_ConfigListSaved;
        while (curr_section->next != NULL && osal_insensitive_strcmp(SectionName, curr_section->next->name) > 0)
            curr_section = curr_section->next;
        if (curr_section->next == NULL || osal_insensitive_strcmp(SectionName, curr_section->next->name) < 0)
        {
            /* the saved section is new and goes after the curr_section */
            new_section->next = curr_section->next;
            curr_section->next = new_section;
        }
        else
        {
            /* the saved section replaces curr_section->next */
            config_section *old_section = curr_section->next;
            new_section->next = old_section->next;
            delete_section_vars(old_section);
            free(old_section);
            curr_section->next = new_section;
        }
    }

    /* write the saved config list out to a file */
    return (write_configlist_file());
}