Commit b4b8cd30 authored by Vesa Oikonen's avatar Vesa Oikonen
Browse files

added csvList()

parent 695ed5da
......@@ -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(
......
......@@ -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. */
......
......@@ -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_csvWrite(verbose))!=0) {
i++; if((ret=test_csvList(&status))!=0) {
fprintf(stderr, "failed (%d).\n", ret); return(i);}
i++; if((ret=test_csvPutLine(verbose))!=0) {
i++; if((ret=test_csvWrite(&status))!=0) {
fprintf(stderr, "failed (%d).\n", ret); return(i);}
i++; if((ret=test_csvPutLineWithSpaces(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) {
......
This diff is collapsed.
......@@ -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);
/*****************************************************************************/
/*****************************************************************************/
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment