Skip to content
Snippets Groups Projects
Commit a11eb7be authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Add Open/CloseFile and ListFree methods

parent 4e990b47
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
/* dat_file.c */
/* Functions to deal with comma (CSV) and tab-delimited files and lists */
/* $Id: dat_file.c,v 1.8 2018/07/24 01:13:09 rswindell Exp $ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
......@@ -15,23 +11,11 @@
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* See the GNU Lesser General Public License for more details: lgpl.txt or *
* http://www.fsf.org/copyleft/lesser.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
......@@ -288,3 +272,26 @@ str_list_t* dataReadFile(FILE* fp, str_list_t* columns, dataLineParser_t linePar
return(records);
}
BOOL dataListFree(str_list_t* list)
{
size_t i;
if(list == NULL)
return FALSE;
for(i=0; list[i]!=NULL; i++)
strListFree(&list[i]);
strListFree(list);
return TRUE;
}
FILE* dataOpenFile(const char* path, const char* mode)
{
return fopen(path, mode);
}
int dataCloseFile(FILE* fp)
{
return fclose(fp);
}
......@@ -58,6 +58,9 @@ str_list_t* dataReadFile(FILE* fp, str_list_t* columns, dataLineParser_t);
str_list_t dataCreateList(const str_list_t records[], const str_list_t columns, dataLineCreator_t);
BOOL dataWriteFile(FILE* fp, const str_list_t records[], const str_list_t columns
,const char* separator, dataLineCreator_t);
FILE* dataOpenFile(const char* path, const char* mode);
int dataCloseFile(FILE*);
BOOL dataListFree(str_list_t*);
/* CSV (comma separated value) API */
char* csvLineCreator(const str_list_t);
......@@ -66,6 +69,9 @@ str_list_t csvLineParser(const char* line);
#define csvCreateList(rec,col) dataCreateList(rec,col,csvLineCreator)
#define csvReadFile(fp,col) dataReadFile(fp,col,csvLineParser)
#define csvWriteFile(fp,rec,sep,col) dataWriteFile(fp,rec,col,sep,csvLineCreator)
#define cvsOpenFile(path, mode) dataOpenFile(path, mode)
#define csvCloseFile(fp) dataCloseFile(fp)
#define cvsListFree(list) dataListFree(list)
/* Tab-delimited API */
char* tabLineCreator(const str_list_t);
......@@ -74,6 +80,9 @@ str_list_t tabLineParser(const char* line);
#define tabCreateList(rec,col) dataCreateList(rec,col,tabLineCreator)
#define tabReadFile(fp,col) dataReadFile(fp,col,tabLineParser)
#define tabWriteFile(fp,rec,sep,col) dataWriteFile(fp,rec,col,sep,tabLineCreator)
#define tabOpenFile(path, mode) dataOpenFile(path, mode)
#define tabCloseFile(fp) dataCloseFile(fp)
#define tabListFree(list) dataListFree(list)
#if defined(__cplusplus)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment