Commit add08ce2 authored by rswindell's avatar rswindell
Browse files

Changed use of strListAdd().

Removed ustrListAddAt() (not needed).
Created iniReadFile() and iniWriteFile().
parent 909f6f27
......@@ -39,6 +39,7 @@
#include <string.h> /* strlen */
#include <ctype.h> /* isdigit */
#include "sockwrap.h" /* inet_addr */
#include "filewrap.h" /* chsize */
#include "ini_file.h"
#define INI_MAX_LINE_LEN 256 /* Maximum length of entire line, includes '\0' */
......@@ -152,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(strListAddAt(&lp,token,items++)==NULL)
if(strListAdd(&lp,token,items++)==NULL)
break;
token=strtok(NULL,sep);
}
......@@ -215,7 +216,7 @@ str_list_t iniGetSectionList(FILE* fp, const char* prefix)
if(prefix!=NULL)
if(strnicmp(p,prefix,strlen(prefix))!=0)
continue;
if(strListAddAt(&lp,p,items++)==NULL)
if(strListAdd(&lp,p,items++)==NULL)
break;
}
......@@ -255,7 +256,7 @@ str_list_t iniGetKeyList(FILE* fp, const char* section)
continue;
*tp=0;
truncsp(p);
if(strListAddAt(&lp,p,items++)==NULL)
if(strListAdd(&lp,p,items++)==NULL)
break;
}
......@@ -433,3 +434,27 @@ ulong iniGetBitField(FILE* fp, const char* section, const char* key,
return(v);
}
str_list_t iniReadFile(FILE* fp)
{
size_t i;
str_list_t list;
rewind(fp);
list = strListReadFile(fp, NULL, INI_MAX_VALUE_LEN);
if(list!=NULL) {
/* truncate the white-space off end of strings */
for(i=0; list[i]!=NULL; i++)
truncsp(list[i]);
}
return(list);
}
BOOL iniWriteFile(FILE* fp, const str_list_t list)
{
rewind(fp);
chsize(fileno(fp),0); /* truncate */
return(strListWriteFile(fp,list,"\n") == strListCount(list));
}
......@@ -85,6 +85,12 @@ void* iniFreeStringList(str_list_t list);
/* Free named string list returned from iniGetNamedStringList */
void* iniFreeNamedStringList(named_string_t** list);
/* File I/O Functions */
str_list_t iniReadFile(FILE* fp);
BOOL iniWriteFile(FILE* fp, const str_list_t list);
#if defined(__cplusplus)
}
#endif
......
......@@ -122,7 +122,7 @@ str_list_t strListRemove(str_list_t* list, size_t index)
return(lp);
}
str_list_t strListAddAt(str_list_t* list, const char* str, size_t count)
str_list_t strListAdd(str_list_t* list, const char* str, size_t index)
{
char* buf;
......@@ -131,12 +131,10 @@ str_list_t strListAddAt(str_list_t* list, const char* str, size_t count)
strcpy(buf,str);
return(str_list_append(list,buf,count));
}
if(index==0)
index=strListCount(*list);
str_list_t strListAdd(str_list_t* list, const char* str)
{
return strListAddAt(list,str,strListCount(*list));
return(str_list_append(list,buf,index));
}
str_list_t strListAddList(str_list_t* list, const str_list_t add_list)
......@@ -146,7 +144,7 @@ str_list_t strListAddList(str_list_t* list, const str_list_t add_list)
count=strListCount(*list);
for(i=0; add_list[i]!=NULL; i++)
strListAddAt(list,add_list[i],count++);
strListAdd(list,add_list[i],count++);
return(*list);
}
......@@ -183,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);
strListAdd(list, token, 0);
return(*list);
}
......@@ -294,7 +292,7 @@ str_list_t strListReadFile(FILE* fp, str_list_t* list, size_t max_line_len)
while(!feof(fp)) {
if(fgets(buf,max_line_len+1,fp)==NULL)
break;
strListAddAt(list, buf, count++);
strListAdd(list, buf, count++);
}
free(buf);
......@@ -312,7 +310,7 @@ size_t strListWriteFile(FILE* fp, const str_list_t list, const char* separator)
for(i=0; list[i]!=NULL; i++) {
if(fputs(list[i],fp)==EOF)
break;
if(seperator!=NULL && fputs(seperator,fp)==EOF)
if(separator!=NULL && fputs(separator,fp)==EOF)
break;
}
......
......@@ -57,10 +57,7 @@ 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);
/* Adds a string into the list at a specific index */
str_list_t strListAddAt(str_list_t* list, const char* str, size_t index);
str_list_t strListAdd(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);
......
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