Skip to content
Snippets Groups Projects
Commit f2775b77 authored by rswindell's avatar rswindell
Browse files

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

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