Commit f2775b77 authored by rswindell's avatar rswindell
Browse files

Created str_list_t definition for String List variables/arguments (char**).

parent 20b53534
......@@ -40,7 +40,6 @@
#include <ctype.h> /* isdigit */
#include "sockwrap.h" /* inet_addr */
#include "ini_file.h"
#include "str_list.h" /* strList functions */
#define INI_MAX_LINE_LEN 256 /* Maximum length of entire line, includes '\0' */
......@@ -132,15 +131,15 @@ char* iniGetString(FILE* fp, const char* section, const char* key, const char* d
return(value);
}
char** iniGetStringList(FILE* fp, const char* section, const char* key
str_list_t iniGetStringList(FILE* fp, const char* section, const char* key
,const char* sep, const char* deflt)
{
char* value;
char buf[INI_MAX_VALUE_LEN];
char** lp;
char* token;
char list[INI_MAX_VALUE_LEN];
ulong items=0;
str_list_t lp;
if((value=get_value(fp,section,key,buf))==NULL || *value==0 /* blank */)
value=(char*)deflt;
......@@ -160,7 +159,7 @@ char** iniGetStringList(FILE* fp, const char* section, const char* key
return(lp);
}
void* iniFreeStringList(char** list)
void* iniFreeStringList(str_list_t list)
{
strListFree(&list);
return(list);
......@@ -185,13 +184,13 @@ void* iniFreeNamedStringList(named_string_t** list)
return(NULL);
}
char** iniGetSectionList(FILE* fp, const char* prefix)
str_list_t iniGetSectionList(FILE* fp, const char* prefix)
{
char* p;
char* tp;
char** lp;
char str[INI_MAX_LINE_LEN];
ulong items=0;
str_list_t lp;
if((lp=strListAlloc())==NULL)
return(NULL);
......@@ -223,13 +222,13 @@ char** iniGetSectionList(FILE* fp, const char* prefix)
return(lp);
}
char** iniGetKeyList(FILE* fp, const char* section)
str_list_t iniGetKeyList(FILE* fp, const char* section)
{
char* p;
char* tp;
char** lp;
char str[INI_MAX_LINE_LEN];
ulong items=0;
str_list_t lp;
if((lp=strListAlloc())==NULL)
return(NULL);
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -39,6 +39,7 @@
#define _INI_FILE_H
#include "genwrap.h"
#include "str_list.h" /* strList_t */
#define INI_MAX_VALUE_LEN 128 /* Maximum value length, includes '\0' */
......@@ -53,9 +54,9 @@ extern "C" {
/* Read all section names and return as an allocated string list */
/* Optionally (if prefix!=NULL), returns a subset of section names */
char** iniGetSectionList (FILE* fp, const char* prefix);
str_list_t iniGetSectionList (FILE* fp, const char* prefix);
/* Read all key names and return as an allocated string list */
char** iniGetKeyList (FILE* fp, const char* section);
str_list_t iniGetKeyList (FILE* fp, const char* section);
/* Read all key and value pairs and return as a named string list */
named_string_t**
iniGetNamedStringList (FILE* fp, const char* section);
......@@ -63,7 +64,7 @@ named_string_t**
/* These functions read a single key of the specified type */
char* iniGetString (FILE* fp, const char* section, const char* key,
const char* deflt, char* value);
char** iniGetStringList(FILE* fp, const char* section, const char* key
str_list_t iniGetStringList(FILE* fp, const char* section, const char* key
,const char* sep, const char* deflt);
long iniGetInteger (FILE* fp, const char* section, const char* key,
long deflt);
......@@ -79,7 +80,7 @@ ulong iniGetBitField (FILE* fp, const char* section, const char* key,
ini_bitdesc_t* bitdesc, ulong deflt);
/* Free string list returned from iniGet*List functions */
void* iniFreeStringList(char** list);
void* iniFreeStringList(str_list_t list);
/* Free named string list returned from iniGetNamedStringList */
void* iniFreeNamedStringList(named_string_t** list);
......
......@@ -38,18 +38,18 @@
#include <stdlib.h> /* malloc */
#include "str_list.h"
char** strListAlloc()
str_list_t strListAlloc()
{
char** list;
str_list_t list;
if((list=malloc(sizeof(char*)))==NULL)
if((list=(str_list_t)malloc(sizeof(char*)))==NULL)
return(NULL);
list[0]=NULL; /* terminated by default */
return(list);
}
size_t strListCount(char** list)
size_t strListCount(str_list_t list)
{
size_t i;
......@@ -62,15 +62,15 @@ size_t strListCount(char** list)
return(i);
}
char** strListAddAt(char*** list, char* str, size_t count)
str_list_t strListAddAt(str_list_t* list, char* str, size_t count)
{
char** lp;
str_list_t lp;
if((lp=realloc(*list,sizeof(char*)*(count+2)))==NULL)
if((lp=(str_list_t)realloc(*list,sizeof(char*)*(count+2)))==NULL)
return(NULL);
*list=lp;
if((lp[count]=malloc(strlen(str)+1))==NULL)
if((lp[count]=(char*)malloc(strlen(str)+1))==NULL)
return(NULL);
strcpy(lp[count++],str);
......@@ -80,12 +80,12 @@ char** strListAddAt(char*** list, char* str, size_t count)
}
char** strListAdd(char*** list, char* str)
str_list_t strListAdd(str_list_t* list, char* str)
{
return strListAddAt(list,str,strListCount(*list));
}
void strListFree(char*** list)
void strListFree(str_list_t* list)
{
size_t i;
......
......@@ -44,21 +44,23 @@
extern "C" {
#endif
typedef char** str_list_t;
/* Returns an allocated and terminated string list */
char** strListAlloc(void);
str_list_t strListAlloc(void);
/* Frees the strings in the list (and the list itself) */
void strListFree(char*** list);
void strListFree(str_list_t* list);
/* Pass a pointer to a string list, the string to add */
/* Returns the updated list or NULL on error */
char** strListAdd(char*** list, char* str);
str_list_t strListAdd(str_list_t* list, char* str);
/* Adds a string into the list at a specific index */
char** strListAddAt(char*** list, char* str, size_t index);
str_list_t strListAddAt(str_list_t* list, char* str, size_t index);
/* Count the number of strings in the list and returns the count */
size_t strListCount(char** list);
size_t strListCount(str_list_t list);
#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