|
TPCCLIB
|
Header file for library libtpccsv. More...
#include "tpcclibConfig.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include "tpcextensions.h"Go to the source code of this file.
Data Structures | |
| struct | CSV_item |
| struct | CSV |
Functions | |
| void | csvInit (CSV *csv) |
| void | csvFree (CSV *csv) |
| int | csvAllocate (CSV *csv, int nr) |
| int | csvDuplicate (CSV *csv1, CSV *csv2) |
| Make a duplicate of CSV structure. | |
| int | csvPutString (CSV *csv, const char *s, int newline) |
| int | csvPutDouble (CSV *csv, double v, int newline, int tointl) |
| int | csvPutInt (CSV *csv, int v, int newline) |
| int | csvRowLength (CSV *csv, int row) |
| int | csvSetDimensions (CSV *csv) |
| int | csvIsRegular (CSV *csv) |
| int | csvTrimRight (CSV *csv) |
| char * | csvCell (CSV *csv, int row, int col) |
| int | csvCellReplace (CSV *csv, int row, int col, const char *s) |
| int | csvRemoveItem (CSV *csv, int i) |
| int | csvRemoveEmptyRows (CSV *csv) |
| int | csvRemoveComments (CSV *csv) |
| int | csvReorg (CSV *d, TPCSTATUS *status) |
| int | csvTranspose (CSV *d) |
| 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) |
| int | csvPutLineWithSpaces (CSV *csv, const char *line, TPCSTATUS *status) |
| int | csvCleanSpaces (CSV *csv) |
| int | csvFindField (CSV *csv, const char *s, int start_index) |
| int | csvSearchField (CSV *csv, const char *s, int start_index) |
Header file for library libtpccsv.
CSV and TSV data processing and file i/o
Definition in file tpccsv.h.
| int csvAllocate | ( | CSV * | csv, |
| int | nr ) |
Allocate memory for list of field items for CSV data.
Any previous content is preserved.
| csv | Pointer to CSV. |
| nr | Nr of field items to add to the list. |
Definition at line 58 of file csv.c.
Referenced by csvDuplicate(), csvPutString(), parWriteCSV(), and tacWriteCSV().
| char * csvCell | ( | CSV * | csv, |
| int | row, | ||
| int | col ) |
Get the CVS field contents in specified row and column.
Definition at line 358 of file csv.c.
Referenced by csvDuplicate(), csvRemoveEmptyRows(), csvWrite(), parReadFIT(), parReadRES(), tacRead(), tacReadCarimasTxt(), tacReadInveonCSV(), tacReadMat(), tacReadQView(), tacReadSIF(), and tacReadSimple().
| int csvCellReplace | ( | CSV * | csv, |
| int | row, | ||
| int | col, | ||
| const char * | s ) |
Replace the value of CVS field.
| csv | Pointer to CSV. |
| row | CSV row index. |
| col | CSV column index. |
| s | Field string to add; can be empty ("" or NULL). |
Definition at line 380 of file csv.c.
| int csvCleanSpaces | ( | CSV * | csv | ) |
Removes any initial and trailing space characters from CSV. Space characters in the middle of the string are not removed.
| csv | Pointer to CSV, the content of which is to be cleaned. |
Definition at line 422 of file csvio.c.
Referenced by parReadCSV().
Make a duplicate of CSV structure.
Previous contents are copied. In the duplicate the space is allocated for row_nr times col_nr cells.
| csv1 | Pointer to the source CSV. |
| csv2 | Pointer to the target CSV; must be initiated; any old contents are deleted. |
| int csvFindField | ( | CSV * | csv, |
| const char * | s, | ||
| int | start_index ) |
Find the CSV field with specified content. Search is case-insensitive, but otherwise match must be exact.
| csv | Pointer to CSV. |
| s | Field value to be searched for. |
| start_index | CSV item index [0..nr-1] from which search is started. |
Definition at line 27 of file csvfind.c.
Referenced by parReadRES(), and tacRead4DM().
| void csvFree | ( | CSV * | csv | ) |
Free memory allocated for CSV data. All contents are destroyed.
| csv | Pointer to CSV. |
Definition at line 38 of file csv.c.
Referenced by csvDuplicate(), parRead(), parWriteCSV(), tacRead(), and tacWriteCSV().
| void csvInit | ( | CSV * | csv | ) |
Initiate the CSV struct before any use.
| csv | Pointer to CSV. |
Definition at line 22 of file csv.c.
Referenced by csvFree(), parRead(), parWriteCSV(), tacFormatDetermine(), tacRead(), and tacWriteCSV().
| int csvIsRegular | ( | CSV * | csv | ) |
Check whether CSV is regular, that is, each row contain the same number of columns.
| csv | Pointer to CSV |
Definition at line 292 of file csv.c.
Referenced by tacRead(), tacReadMat(), and tacReadSimple().
| int csvList | ( | CSV * | csv, |
| FILE * | fp ) |
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.
| csv | Pointer to CSV structure, contents of which are to be written. |
| fp | Output file pointer; usually stdout. |
Definition at line 27 of file csvio.c.
Referenced by tacReadSIF().
| int csvPutDouble | ( | CSV * | csv, |
| double | v, | ||
| int | newline, | ||
| int | tointl ) |
Add specified double value as string into CSV.
| csv | Pointer to initiated CSV; previous contents are not changed. |
| v | Double value to add; NaN is added as an empty field. |
| newline | New line (1) or same line (0). |
| tointl | Convert (1) or do not convert (0) commas to semicolons and dots to commas. |
Definition at line 193 of file csv.c.
Referenced by parWriteCSV(), and tacWriteCSV().
| int csvPutInt | ( | CSV * | csv, |
| int | v, | ||
| int | newline ) |
Add specified integer value as string into CSV.
| csv | Pointer to initiated CSV; previous contents are not changed |
| v | Integer value to add; use csvPutString() to add an empty field |
| newline | New line (1) or same line (0) |
Definition at line 222 of file csv.c.
Referenced by parWriteCSV().
Process a given text line (string) to add a new row of fields to CSV, using as field delimiter the character specified in CSV structure.
| csv | Pointer to initiated CSV; previous contents are not changed. |
| line | Pointer to the CSV file line to be processed. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 251 of file csvio.c.
Referenced by csvRead().
Process a given text line (string) to add a new row of fields to CSV, using spaces as field delimiters, independent on what is told in CSV struct.
| csv | Pointer to initiated CSV; previous contents are not changed. |
| line | Pointer to the CSV file line to be processed. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 351 of file csvio.c.
Referenced by csvRead().
| int csvPutString | ( | CSV * | csv, |
| const char * | s, | ||
| int | newline ) |
Add specified string to CSV.
| csv | Pointer to initiated CSV; previous contents are not changed. |
| s | Field string to add; can be empty ("" or NULL). |
| newline | New line (1) or same line (0). |
Definition at line 144 of file csv.c.
Referenced by csvPutDouble(), csvPutInt(), csvPutLine(), csvPutLineWithSpaces(), parWriteCSV(), tacReadSIF(), and tacWriteCSV().
Read CSV file contents into CSV structure, allocating memory as needed.
Lines consisting only of space characters, including tabs, are not read. Partial support for spaces as delimiters.
| csv | Pointer to CSV to read into; any previous contents of CSV are preserved. |
| fp | Input file pointer. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 124 of file csvio.c.
Referenced by parRead(), tacFormatDetermine(), and tacRead().
| int csvRemoveComments | ( | CSV * | csv | ) |
Remove those cells from CSV structure whose contents start with '#'.
| csv | Pointer to CSV. |
Definition at line 470 of file csv.c.
| int csvRemoveEmptyRows | ( | CSV * | csv | ) |
Remove empty rows from CSV. Rows that contain only empty cells or cells that start with '#' are considered empty.
| csv | Pointer to CSV. |
Definition at line 434 of file csv.c.
| int csvRemoveItem | ( | CSV * | csv, |
| int | i ) |
Remove item from CSV data structure.
| csv | Pointer to CSV. |
| i | Index of item to delete. |
Definition at line 409 of file csv.c.
Referenced by csvRemoveComments(), csvRemoveEmptyRows(), and csvTrimRight().
Sort CSV data array by increasing row and column numbers.
| d | Pointer to CSV structure. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 503 of file csv.c.
Referenced by csvTranspose(), and tacReadSIF().
| int csvRowLength | ( | CSV * | csv, |
| int | row ) |
Count the nr of columns on specified CSV row.
Definition at line 244 of file csv.c.
Referenced by csvWrite(), parReadFIT(), parReadRES(), tacReadDFT(), tacReadSIF(), and tacReadSimple().
| int csvSearchField | ( | CSV * | csv, |
| const char * | s, | ||
| int | start_index ) |
Find the CSV field which contains the given search string. Search is case-insensitive.
| csv | Pointer to CSV. |
| s | String to be searched for inside field values. |
| start_index | CSV field index [0..nr-1] from which search is started. |
Definition at line 50 of file csvfind.c.
Referenced by parReadFIT(), and tacRead4DM().
| int csvSetDimensions | ( | CSV * | csv | ) |
Set the number of rows and columns in CSV table, based on the row and column stored with each cell. CSV may not be regular, thus maximum row and column numbers are used.
| csv | Pointer to CSV structure. |
Definition at line 269 of file csv.c.
Referenced by csvTranspose().
| int csvTranspose | ( | CSV * | csv | ) |
Transpose data in CSV structure.
To work properly, CSV should not contain comment cells/lines.
| csv | Pointer to CSV. |
Definition at line 530 of file csv.c.
| int csvTrimRight | ( | CSV * | csv | ) |
Remove empty cells from the right side of CVS table until a non-empty column is reached.
Resulting CSV may still not be regular.
| csv | Pointer to CSV |
Definition at line 321 of file csv.c.
Referenced by tacReadSimple().
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.
| csv | Pointer to CSV structure, contents of which are to be written. |
| regular | Forced regularization (1), or not (0); if regularized, then row_nr rows are written, each with col_nr columns; otherwise, empty rows are not written, and missing cells are not written to the end of rows. |
| fp | Output file pointer. |
| status | Pointer to status data; enter NULL if not needed. |
Definition at line 52 of file csvio.c.
Referenced by parRead(), parReadFIT(), parReadRES(), parWriteCSV(), tacRead(), tacReadSimple(), and tacWriteCSV().