Commit 2c7c37b0 authored by Rob Swindell's avatar Rob Swindell 💬
Browse files

iniSortSections() supports an optional section prefix

Needed for echocfg option to sort linked nodes upon reading/writing sbbsecho.ini, for Ray Quinn (1:214/23).
parent 80de2727
...@@ -442,15 +442,16 @@ BOOL iniRemoveSections(str_list_t* list, const char* prefix) ...@@ -442,15 +442,16 @@ BOOL iniRemoveSections(str_list_t* list, const char* prefix)
} }
// This sorts comments too, so should not be used on human created/edited files // This sorts comments too, so should not be used on human created/edited files
BOOL iniSortSections(str_list_t* list, BOOL sort_keys) BOOL iniSortSections(str_list_t* list, const char* prefix, BOOL sort_keys)
{ {
size_t i; size_t i;
str_list_t root_keys; str_list_t root_keys = NULL;
str_list_t new_list; str_list_t new_list;
str_list_t keys; str_list_t keys;
str_list_t section_list = iniGetSectionList(*list, /* prefix */NULL); str_list_t section_list = iniGetSectionList(*list, prefix);
root_keys = iniGetSection(*list, ROOT_SECTION); if(prefix == NULL)
root_keys = iniGetSection(*list, ROOT_SECTION);
if(section_list == NULL && root_keys == NULL) if(section_list == NULL && root_keys == NULL)
return TRUE; return TRUE;
...@@ -459,7 +460,12 @@ BOOL iniSortSections(str_list_t* list, BOOL sort_keys) ...@@ -459,7 +460,12 @@ BOOL iniSortSections(str_list_t* list, BOOL sort_keys)
if(section_list != NULL) if(section_list != NULL)
strListSortAlphaCase(section_list); strListSortAlphaCase(section_list);
new_list = strListInit(); if(prefix == NULL)
new_list = strListInit();
else {
new_list = strListDup(*list);
iniRemoveSections(&new_list, prefix);
}
if(new_list == NULL) { if(new_list == NULL) {
strListFree(&section_list); strListFree(&section_list);
strListFree(&root_keys); strListFree(&root_keys);
...@@ -2465,7 +2471,7 @@ void main(int argc, char** argv) ...@@ -2465,7 +2471,7 @@ void main(int argc, char** argv)
continue; continue;
} }
if((list=iniReadFile(fp)) != NULL) { if((list=iniReadFile(fp)) != NULL) {
iniSortSections(&list, TRUE); iniSortSections(&list, NULL, TRUE);
for(size_t j = 0; list[j] != NULL; j++) for(size_t j = 0; list[j] != NULL; j++)
printf("%s\n", list[j]); printf("%s\n", list[j]);
strListFree(&list); strListFree(&list);
......
...@@ -276,7 +276,7 @@ DLLEXPORT BOOL iniRemoveValue(str_list_t*, const char* section, const char* k ...@@ -276,7 +276,7 @@ DLLEXPORT BOOL iniRemoveValue(str_list_t*, const char* section, const char* k
DLLEXPORT BOOL iniRemoveSection(str_list_t*, const char* section); DLLEXPORT BOOL iniRemoveSection(str_list_t*, const char* section);
DLLEXPORT BOOL iniRemoveSections(str_list_t*, const char* prefix); DLLEXPORT BOOL iniRemoveSections(str_list_t*, const char* prefix);
DLLEXPORT BOOL iniRenameSection(str_list_t*, const char* section, const char* newname); DLLEXPORT BOOL iniRenameSection(str_list_t*, const char* section, const char* newname);
DLLEXPORT BOOL iniSortSections(str_list_t*, BOOL sort_keys); DLLEXPORT BOOL iniSortSections(str_list_t*, const char* prefix, BOOL sort_keys);
DLLEXPORT BOOL iniHasInclude(const str_list_t); DLLEXPORT BOOL iniHasInclude(const str_list_t);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment