From 1b5b29ff8b06ed0b4946aa21f9c8ed98ffa98cac Mon Sep 17 00:00:00 2001 From: Rob Swindell <rob@synchro.net> Date: Mon, 28 Mar 2022 23:54:55 -0700 Subject: [PATCH] Add Open/CloseFile and ListFree methods --- src/xpdev/dat_file.c | 41 ++++++++++++++++++++++++----------------- src/xpdev/dat_file.h | 9 +++++++++ 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/xpdev/dat_file.c b/src/xpdev/dat_file.c index 7b8e5b6cd0..37b4fa8313 100644 --- a/src/xpdev/dat_file.c +++ b/src/xpdev/dat_file.c @@ -1,9 +1,5 @@ -/* 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); +} diff --git a/src/xpdev/dat_file.h b/src/xpdev/dat_file.h index 4c45d8a97c..0f69a4a69b 100644 --- a/src/xpdev/dat_file.h +++ b/src/xpdev/dat_file.h @@ -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) } -- GitLab