Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit f959f5e0 authored by rswindell's avatar rswindell

Created StrListSwap() function.

parent beabf67e
......@@ -162,6 +162,29 @@ char* strListReplace(const str_list_t list, size_t index, const char* str)
return(buf);
}
BOOL strListSwap(const str_list_t list, size_t index1, size_t index2)
{
char* tmp;
size_t count;
count = strListCount(list);
if(index1==STR_LIST_LAST_INDEX && count)
index1 = count-1;
if(index2==STR_LIST_LAST_INDEX && count)
index2 = count-1;
if(index1 >= count || index2 >= count || index1 == index2)
return(FALSE); /* invalid index, do nothing */
tmp=list[index1];
list[index1]=list[index2];
list[index2]=tmp;
return(TRUE);
}
char* strListAppend(str_list_t* list, const char* str, size_t index)
{
char* buf;
......
......@@ -53,32 +53,35 @@ typedef char** str_list_t;
str_list_t strListInit(void);
/* Frees the strings in the list (and the list itself) */
void strListFree(str_list_t* list);
void strListFree(str_list_t*);
/* Frees the strings in the list */
void strListFreeStrings(str_list_t list);
void strListFreeStrings(str_list_t);
/* Pass a pointer to a string list, the string to add (append) */
/* Returns the updated list or NULL on error */
char* strListAppend(str_list_t* list, const char* str, size_t index);
char* strListAppend(str_list_t*, const char* str, size_t index);
/* Append a string list onto another string list */
size_t strListAppendList(str_list_t* list, const str_list_t append_list);
size_t strListAppendList(str_list_t*, const str_list_t append_list);
/* Inserts a string into the list at a specific index */
char* strListInsert(str_list_t* list, const char* str, size_t index);
char* strListInsert(str_list_t*, const char* str, size_t index);
/* Insert a string list into another string list */
size_t strListInsertList(str_list_t* list, const str_list_t append_list, size_t index);
size_t strListInsertList(str_list_t*, const str_list_t append_list, size_t index);
/* Remove a string at a specific index */
char* strListRemove(str_list_t* list, size_t index);
char* strListRemove(str_list_t*, size_t index);
/* Remove and free a string at a specific index */
BOOL strListDelete(str_list_t* list, size_t index);
BOOL strListDelete(str_list_t*, size_t index);
/* Replace a string at a specific index */
char* strListReplace(const str_list_t list, size_t index, const char* str);
char* strListReplace(const str_list_t, size_t index, const char* str);
/* Swap the strings at index1 and index2 */
BOOL strListSwap(const str_list_t, size_t index1, size_t index2);
/* Convenience macros for pushing, popping strings (LIFO stack) */
#define strListPush(list, str) strListAppend(list, str, STR_LIST_LAST_INDEX)
......@@ -86,24 +89,24 @@ char* strListReplace(const str_list_t list, size_t index, const char* str);
/* Add to an exiting or new string list by splitting specified string (str) */
/* into multiple strings, separated by one of the delimit characters */
str_list_t strListSplit(str_list_t* list, char* str, const char* delimit);
str_list_t strListSplit(str_list_t*, char* str, const char* delimit);
/* Same as above, but copies str to temporary heap buffer first */
str_list_t strListSplitCopy(str_list_t* list, const char* str, const char* delimit);
str_list_t strListSplitCopy(str_list_t*, const char* str, const char* delimit);
/* Merge 2 string lists (no copying of string data) */
size_t strListMerge(str_list_t* list, str_list_t append_list);
size_t strListMerge(str_list_t*, str_list_t append_list);
/* Count the number of strings in the list and returns the count */
size_t strListCount(const str_list_t list);
size_t strListCount(const str_list_t);
/* Sort the strings in the string list */
void strListSortAlpha(str_list_t list);
void strListSortAlphaReverse(str_list_t list);
void strListSortAlpha(str_list_t);
void strListSortAlphaReverse(str_list_t);
/* Case-sensitive sorting */
void strListSortAlphaCase(str_list_t list);
void strListSortAlphaCaseReverse(str_list_t list);
void strListSortAlphaCase(str_list_t);
void strListSortAlphaCaseReverse(str_list_t);
/************/
/* File I/O */
......@@ -111,10 +114,10 @@ void strListSortAlphaCaseReverse(str_list_t list);
/* Read lines from file appending each line to string list */
/* Pass NULL list to have list allocated for you */
str_list_t strListReadFile(FILE* fp, str_list_t* list, size_t max_line_len);
str_list_t strListReadFile(FILE*, str_list_t*, size_t max_line_len);
/* Write to file (fp) each string in the list, optionally separated by separator (e.g. "\n") */
size_t strListWriteFile(FILE* fp, const str_list_t list, const char* separator);
size_t strListWriteFile(FILE*, const str_list_t, const char* separator);
#if defined(__cplusplus)
}
......
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