Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Vesa Oikonen
tpcclib
Commits
b4b8cd30
Commit
b4b8cd30
authored
Jun 17, 2020
by
Vesa Oikonen
Browse files
added csvList()
parent
695ed5da
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
v2/libtpccsv/csv.c
View file @
b4b8cd30
...
...
@@ -53,7 +53,7 @@ void csvFree(
@pre Before first use initialize the CSV struct with csvInit().
@return enum tpcerror (TPCERROR_OK when successful).
@author Vesa Oikonen
@sa csvInit, csvFree, csvDuplicate, csvSetDimensions
@sa csvInit, csvFree, csvDuplicate, csvSetDimensions
, csvList
*/
int
csvAllocate
(
/** Pointer to CSV. */
...
...
@@ -286,7 +286,7 @@ int csvSetDimensions(
/*****************************************************************************/
/** Check whether CSV is regular, that is, each row contain the same number of columns.
@author Vesa Oikonen
@sa csvTrimRight, csvSetDimensions, csvRowLength, csvRead, csvDuplicate
@sa csvTrimRight, csvSetDimensions, csvRowLength,
csvWrite,
csvRead, csvDuplicate
@return Returns 1 if CSV is regular, 0 if not.
*/
int
csvIsRegular
(
...
...
v2/libtpccsv/csvio.c
View file @
b4b8cd30
...
...
@@ -14,13 +14,40 @@
#include "tpccsv.h"
/*****************************************************************************/
/*****************************************************************************/
/** Write CSV data as a tab separated list into file opened for writing.
List contains the cell rows, columns, and values.
Data is not sorted, and cell contents are written as they are, that is, no conversions for
decimal separator is done here.
@return enum tpcerror (TPCERROR_OK when successful).
@author Vesa Oikonen
@sa csvWrite, csvSetDimensions, csvTrimRight
*/
int
csvList
(
/** Pointer to CSV structure, contents of which are to be written. */
CSV
*
csv
,
/** Output file pointer; usually stdout. */
FILE
*
fp
)
{
if
(
fp
==
NULL
)
return
TPCERROR_CANNOT_WRITE
;
if
(
csv
==
NULL
||
csv
->
nr
<
1
)
return
TPCERROR_NO_DATA
;
for
(
int
i
=
0
;
i
<
csv
->
nr
;
i
++
)
if
(
fprintf
(
fp
,
"%d
\t
%d
\t
%s
\n
"
,
1
+
csv
->
c
[
i
].
row
,
1
+
csv
->
c
[
i
].
col
,
csv
->
c
[
i
].
content
)
<
5
)
return
TPCERROR_CANNOT_WRITE
;
return
(
TPCERROR_OK
);
}
/*****************************************************************************/
/*****************************************************************************/
/** Write CSV data into file opened for writing, using the column separator specified inside CSV structure.
Field contents are written as they are, that is, no conversions for decimal separator is done here.
@return enum tpcerror (TPCERROR_OK when successful).
@author Vesa Oikonen
@sa csvRead, csvSetDimensions, csvTrimRight
@sa csvRead,
csvList,
csvSetDimensions, csvTrimRight
*/
int
csvWrite
(
/** Pointer to CSV structure, contents of which are to be written. */
...
...
v2/libtpccsv/libtpccsv.c
View file @
b4b8cd30
...
...
@@ -104,13 +104,15 @@ int main(
i
++
;
if
((
ret
=
test_csvRemoveComments
(
&
status
))
!=
0
)
{
fprintf
(
stderr
,
"failed (%d).
\n
"
,
ret
);
return
(
i
);}
/* csvio */
i
++
;
if
((
ret
=
test_csv
Write
(
verbose
))
!=
0
)
{
i
++
;
if
((
ret
=
test_csv
List
(
&
status
))
!=
0
)
{
fprintf
(
stderr
,
"failed (%d).
\n
"
,
ret
);
return
(
i
);}
i
++
;
if
((
ret
=
test_csv
PutLine
(
verbose
))
!=
0
)
{
i
++
;
if
((
ret
=
test_csv
Write
(
&
status
))
!=
0
)
{
fprintf
(
stderr
,
"failed (%d).
\n
"
,
ret
);
return
(
i
);}
i
++
;
if
((
ret
=
test_csvPutLine
WithSpaces
(
verbose
))
!=
0
)
{
i
++
;
if
((
ret
=
test_csvPutLine
(
&
status
))
!=
0
)
{
fprintf
(
stderr
,
"failed (%d).
\n
"
,
ret
);
return
(
i
);}
i
++
;
if
((
ret
=
test_csvRead
(
verbose
))
!=
0
)
{
i
++
;
if
((
ret
=
test_csvPutLineWithSpaces
(
&
status
))
!=
0
)
{
fprintf
(
stderr
,
"failed (%d).
\n
"
,
ret
);
return
(
i
);}
i
++
;
if
((
ret
=
test_csvRead
(
&
status
))
!=
0
)
{
fprintf
(
stderr
,
"failed (%d).
\n
"
,
ret
);
return
(
i
);}
/* csvfind */
i
++
;
if
((
ret
=
test_csvFindField
(
&
status
))
!=
0
)
{
...
...
v2/libtpccsv/test_csvio.c
View file @
b4b8cd30
This diff is collapsed.
Click to expand it.
v2/libtpccsv/test_tpccsv.h
View file @
b4b8cd30
...
...
@@ -36,10 +36,11 @@ int test_csvRemoveComments(TPCSTATUS *status);
/*****************************************************************************/
/* csvio */
int
test_csvWrite
(
int
verbose
);
int
test_csvRead
(
int
verbose
);
int
test_csvPutLine
(
int
verbose
);
int
test_csvPutLineWithSpaces
(
int
verbose
);
int
test_csvList
(
TPCSTATUS
*
status
);
int
test_csvWrite
(
TPCSTATUS
*
status
);
int
test_csvRead
(
TPCSTATUS
*
status
);
int
test_csvPutLine
(
TPCSTATUS
*
status
);
int
test_csvPutLineWithSpaces
(
TPCSTATUS
*
status
);
/*****************************************************************************/
/*****************************************************************************/
...
...
v2/libtpccsv/tpccsv.h
View file @
b4b8cd30
...
...
@@ -72,6 +72,7 @@ int csvRemoveComments(CSV *csv);
/*****************************************************************************/
/* csvio.c */
int
csvList
(
CSV
*
csv
,
FILE
*
fp
);
int
csvWrite
(
CSV
*
csv
,
int
regular
,
FILE
*
fp
,
TPCSTATUS
*
status
);
int
csvRead
(
CSV
*
csv
,
FILE
*
fp
,
TPCSTATUS
*
status
);
int
csvPutLine
(
CSV
*
csv
,
const
char
*
line
,
TPCSTATUS
*
status
);
...
...
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