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 30f46488 authored by rswindell's avatar rswindell

Renamed strListAdd() to strListAppend().

#define STR_LIST_APPEND and FIRST_NODE constants
More work on strListReadFile().
parent add08ce2
......@@ -153,7 +153,7 @@ str_list_t iniGetStringList(FILE* fp, const char* section, const char* key
token=strtok(list,sep);
while(token!=NULL) {
truncsp(token);
if(strListAdd(&lp,token,items++)==NULL)
if(strListAppend(&lp,token,items++)==NULL)
break;
token=strtok(NULL,sep);
}
......@@ -216,7 +216,7 @@ str_list_t iniGetSectionList(FILE* fp, const char* prefix)
if(prefix!=NULL)
if(strnicmp(p,prefix,strlen(prefix))!=0)
continue;
if(strListAdd(&lp,p,items++)==NULL)
if(strListAppend(&lp,p,items++)==NULL)
break;
}
......@@ -256,7 +256,7 @@ str_list_t iniGetKeyList(FILE* fp, const char* section)
continue;
*tp=0;
truncsp(p);
if(strListAdd(&lp,p,items++)==NULL)
if(strListAppend(&lp,p,items++)==NULL)
break;
}
......
......@@ -187,7 +187,7 @@ str_list_t listStringList(const link_list_t* list)
for(node=list->first; node!=NULL; node=node->next) {
if(node->data!=NULL)
strListAdd(&str_list, node->data);
strListAppend(&str_list, node->data, STR_LIST_APPEND);
}
MUTEX_UNLOCK(list);
......@@ -210,7 +210,7 @@ str_list_t listSubStringList(const list_node_t* node, long max)
for(count=0; count<max && node!=NULL; node=node->next) {
if(node->data!=NULL) {
strListAdd(&str_list, node->data);
strListAppend(&str_list, node->data, STR_LIST_APPEND);
count++;
}
}
......@@ -344,12 +344,11 @@ static list_node_t* list_add_node(link_list_t* list, list_node_t* node, list_nod
if(after==list->last) /* append to list */
list->last = node;
if(after==NULL) { /* insert at beginning of list */
if(after==FIRST_NODE) { /* insert at beginning of list */
if(list->first!=NULL)
list->first->prev = node;
list->first = node;
}
if(after!=NULL) {
} else {
if(after->next!=NULL) {
after->next->prev = node;
node->next = after->next;
......@@ -509,7 +508,7 @@ void* listRemoveNode(link_list_t* list, list_node_t* node)
if(list==NULL)
return(NULL);
if(node==NULL)
if(node==FIRST_NODE)
node=list->first;
if(node==NULL)
return(NULL);
......@@ -552,7 +551,7 @@ long listRemoveNodes(link_list_t* list, list_node_t* node, long max)
MUTEX_LOCK(list);
if(node==NULL)
if(node==FIRST_NODE)
node=list->first;
for(count=0; node!=NULL && count<max; node=node->next, count++)
......
......@@ -49,6 +49,8 @@
extern "C" {
#endif
#define FIRST_NODE NULL /* Special value to specify first node in list */
/* Valid link_list_t.flags bits */
#define LINK_LIST_MALLOC (1<<0) /* List/node allocated with malloc() */
#define LINK_LIST_ALWAYS_FREE (1<<1) /* Always free node data when removing */
......@@ -137,13 +139,13 @@ long listMerge(link_list_t* dest, const link_list_t* src, list_node_t* after);
/* Convenience macros for pushing, popping, and inserting nodes */
#define listPushNode(list, data) listAddNode(list, data, listLastNode(list))
#define listInsertNode(link, data) listAddNode(list, data, NULL)
#define listInsertNode(link, data) listAddNode(list, data, FIRST_NODE)
#define listPushNodeData(list, data, length) listAddNodeData(list, data, length, listLastNode(list))
#define listInsertNodeData(list, data, length) listAddNodeData(list, data, length, NULL)
#define listInsertNodeData(list, data, length) listAddNodeData(list, data, length, FIRST_NODE)
#define listPushNodeString(list, str) listAddNodeString(list, str, listLastNode(list))
#define listInsertNodeString(list, str) listAddNodeString(list, str, NULL)
#define listInsertNodeString(list, str) listAddNodeString(list, str, FIRST_NODE)
#define listPushStringList(list, str_list) listAddStringList(list, str_list, listLastNode(list))
#define listInsertStringList(list, str_list) listAddStringList(list, str_list, NULL)
#define listInsertStringList(list, str_list) listAddStringList(list, str_list, FIRST_NODE)
#define listPopNode(list) listRemoveNode(list, listLastNode(list))
/* Remove node from list, returning the node's data (if not free'd) */
......
......@@ -122,7 +122,7 @@ str_list_t strListRemove(str_list_t* list, size_t index)
return(lp);
}
str_list_t strListAdd(str_list_t* list, const char* str, size_t index)
str_list_t strListAppend(str_list_t* list, const char* str, size_t index)
{
char* buf;
......@@ -131,20 +131,20 @@ str_list_t strListAdd(str_list_t* list, const char* str, size_t index)
strcpy(buf,str);
if(index==0)
if(index==STR_LIST_APPEND)
index=strListCount(*list);
return(str_list_append(list,buf,index));
}
str_list_t strListAddList(str_list_t* list, const str_list_t add_list)
str_list_t strListAppendList(str_list_t* list, const str_list_t add_list)
{
size_t i;
size_t count;
count=strListCount(*list);
for(i=0; add_list[i]!=NULL; i++)
strListAdd(list,add_list[i],count++);
strListAppend(list,add_list[i],count++);
return(*list);
}
......@@ -181,7 +181,7 @@ str_list_t strListSplit(str_list_t* list, char* str, const char* delimit)
}
for(token = strtok(str, delimit); token!=NULL; token=strtok(NULL, delimit))
strListAdd(list, token, 0);
strListAppend(list, token, STR_LIST_APPEND);
return(*list);
}
......@@ -272,9 +272,9 @@ void strListFree(str_list_t* list)
}
}
str_list_t strListReadFile(FILE* fp, str_list_t* list, size_t max_line_len)
str_list_t strListReadFile(FILE* fp, str_list_t* list, size_t max_line_len, BOOL pad)
{
char* buf;
char* buf=NULL;
size_t count;
if(max_line_len<1)
......@@ -285,17 +285,22 @@ str_list_t strListReadFile(FILE* fp, str_list_t* list, size_t max_line_len)
return(NULL);
}
if((buf=malloc(max_line_len+1))==NULL)
return(NULL);
count = strListCount(*list);
while(!feof(fp)) {
if(buf==NULL && (buf=malloc(max_line_len+1))==NULL)
return(NULL);
if(fgets(buf,max_line_len+1,fp)==NULL)
break;
strListAdd(list, buf, count++);
if(pad) {
str_list_append(list, buf, count++);
buf=NULL;
} else
strListAppend(list, buf, count++);
}
free(buf);
if(buf)
free(buf);
return(*list);
}
......
......@@ -38,12 +38,15 @@
#ifndef _STR_LIST_H
#define _STR_LIST_H
#include <stdio.h> /* FILE */
#include "gen_defs.h"
#if defined(__cplusplus)
extern "C" {
#endif
#define STR_LIST_APPEND (~0)
typedef char** str_list_t;
/* Returns an allocated and terminated string list */
......@@ -57,10 +60,10 @@ void strListFreeStrings(str_list_t list);
/* Pass a pointer to a string list, the string to add (append) */
/* Returns the updated list or NULL on error */
str_list_t strListAdd(str_list_t* list, const char* str, size_t index);
str_list_t strListAppend(str_list_t* list, const char* str, size_t index);
/* Append a string list onto another string list */
str_list_t strListAddList(str_list_t* list, const str_list_t append_list);
str_list_t strListAppendList(str_list_t* list, const str_list_t append_list);
/* Inserts a string into the list at a specific index */
str_list_t strListInsert(str_list_t* list, const char* str, size_t index);
......@@ -98,7 +101,7 @@ 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* fp, str_list_t* list, size_t max_line_len, BOOL pad);
/* 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);
......
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