Commit 1dbbe232 authored by rswindell's avatar rswindell
Browse files

Renamed strListAlloc() to strListInit().

Created strListAddList() and strListMerge().
parent 8069f5ce
......@@ -39,7 +39,7 @@
#include "genwrap.h" /* stricmp */
#include "str_list.h"
str_list_t strListAlloc()
str_list_t strListInit()
{
str_list_t list;
......@@ -63,7 +63,7 @@ size_t strListCount(const str_list_t list)
return(i);
}
str_list_t strListAddAt(str_list_t* list, const char* str, size_t count)
static str_list_t str_list_add_at(str_list_t* list, char* str, size_t count)
{
str_list_t lp;
......@@ -71,27 +71,47 @@ str_list_t strListAddAt(str_list_t* list, const char* str, size_t count)
return(NULL);
*list=lp;
if((lp[count]=(char*)malloc(strlen(str)+1))==NULL)
return(NULL);
strcpy(lp[count++],str);
lp[count++]=str;
lp[count]=NULL; /* terminate list */
return(lp);
}
str_list_t strListAddAt(str_list_t* list, const char* str, size_t count)
{
char* buf;
if((buf=(char*)malloc(strlen(str)+1))==NULL)
return(NULL);
strcpy(buf,str);
return(str_list_add_at(list,buf,count));
}
str_list_t strListAdd(str_list_t* list, const char* str)
{
return strListAddAt(list,str,strListCount(*list));
}
str_list_t strListAddList(str_list_t* list, str_list_t add_list)
{
size_t i,j;
j=strListCount(*list);
for(i=0;add_list[i];i++)
strListAddAt(list,add_list[i],j++);
return(*list);
}
str_list_t strListSplit(str_list_t* list, char* str, const char* delimit)
{
char* token;
if(list==NULL) {
if((*list = strListAlloc())==NULL)
if((*list = strListInit())==NULL)
return(NULL);
}
......@@ -117,6 +137,17 @@ str_list_t strListSplitCopy(str_list_t* list, const char* str, const char* delim
return(*list);
}
str_list_t strListMerge(str_list_t* list, str_list_t add_list)
{
size_t i,j;
j=strListCount(*list);
for(i=0;add_list[i];i++)
str_list_add_at(list,add_list[i],j++);
return(*list);
}
static int strListCompareAlpha(const void *arg1, const void *arg2)
{
return stricmp(*(char**)arg1, *(char**)arg2);
......
......@@ -47,7 +47,7 @@ extern "C" {
typedef char** str_list_t;
/* Returns an allocated and terminated string list */
str_list_t strListAlloc(void);
str_list_t strListInit(void);
/* Frees the strings in the list (and the list itself) */
void strListFree(str_list_t* list);
......@@ -59,6 +59,9 @@ str_list_t strListAdd(str_list_t* list, const char* str);
/* Adds a string into the list at a specific index */
str_list_t strListAddAt(str_list_t* list, const char* str, size_t index);
/* Append a string list onto an another string */
str_list_t strListAddList(str_list_t* list, str_list_t append_list);
/* 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);
......@@ -66,11 +69,17 @@ str_list_t strListSplit(str_list_t* list, 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);
/* Merge 2 string lists (no copying of string data) */
str_list_t strListMerge(str_list_t* list, 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);
/* Sort the strings in the string list */
void strListSortAlpha(str_list_t list);
void strListSortAlphaReverse(str_list_t list);
/* Case-sensitive sorting */
void strListSortAlphaCase(str_list_t list);
void strListSortAlphaCaseReverse(str_list_t list);
......
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