Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Main
Synchronet
Commits
a11eb7be
Commit
a11eb7be
authored
Mar 28, 2022
by
Rob Swindell
💬
Browse files
Add Open/CloseFile and ListFree methods
parent
4e990b47
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
17 deletions
+33
-17
src/xpdev/dat_file.c
src/xpdev/dat_file.c
+24
-17
src/xpdev/dat_file.h
src/xpdev/dat_file.h
+9
-0
No files found.
src/xpdev/dat_file.c
View file @
a11eb7be
/* 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
);
}
src/xpdev/dat_file.h
View file @
a11eb7be
...
...
@@ -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)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment