Added more features
This commit is contained in:
parent
e1d1e9f723
commit
a143d3db93
1050
src/easycsv.c
1050
src/easycsv.c
File diff suppressed because it is too large
Load Diff
189
src/easycsv.h
189
src/easycsv.h
@ -9,30 +9,41 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
/* Flags for error messages */
|
/* Flags for error messages */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
EASYCSV_ERRORSTDERR = 0, // default
|
||||||
EASYCSV_ERROROFF,
|
EASYCSV_ERROROFF,
|
||||||
EASYCSV_ERRORSTDERR,
|
|
||||||
EASYCSV_ERRORSTDOUT
|
EASYCSV_ERRORSTDOUT
|
||||||
} EASYCSV_ERRORMSG;
|
} EASYCSV_ERRORMSG;
|
||||||
|
|
||||||
/* Using our own flags to facilitate changing modes during file copying phases */
|
/* Flags to facilitate changing modes during file copying phases */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
EASYCSV_UNKNOWNMODE = 0,
|
||||||
EASYCSV_R,
|
EASYCSV_R,
|
||||||
EASYCSV_W
|
EASYCSV_W
|
||||||
} EASYCSV_MODE;
|
} EASYCSV_MODE;
|
||||||
|
|
||||||
|
/* Flags to parameterise the easycsv_insertvalue */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
EASYCSV_REPLACE,
|
EASYCSV_REPLACE, /* (Default) Replaces word */
|
||||||
EASYCSV_APPEND,
|
EASYCSV_CONCAT, /* Concantates word at the end */
|
||||||
EASYCSV_APPEND_R,
|
EASYCSV_RCONCAT, /* Concantates word from the start */
|
||||||
} EASYCSV_VALMODE;
|
} EASYCSV_VALMODE;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
EASYCSV_ALPHA, /* sort alphabetically */
|
||||||
|
EASYCSV_RALPHA, /* sort reverse alphabetically */
|
||||||
|
EASYCSV_NUMER, /* sort numerically, from lowest value to highest */
|
||||||
|
EASYCSV_RNUMER /* sort from highest value to lowest */
|
||||||
|
} EASYCSV_SORT;
|
||||||
|
|
||||||
typedef struct _easycsv _easycsv;
|
typedef struct _easycsv _easycsv;
|
||||||
|
|
||||||
|
/* Public easycsv members */
|
||||||
typedef struct easycsv {
|
typedef struct easycsv {
|
||||||
EASYCSV_MODE mode;
|
EASYCSV_MODE mode; // end users able to easily modify mode to their needs
|
||||||
_easycsv *_priv; // private members
|
_easycsv *_priv; // private members
|
||||||
} easycsv;
|
} easycsv;
|
||||||
|
|
||||||
@ -42,61 +53,155 @@ typedef struct easycsv {
|
|||||||
* ============================
|
* ============================
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* CONSTRUCTORS AND DESTRUCTORS */
|
||||||
|
|
||||||
/* (Constructor) Initialise easycsv */
|
/* (Constructor) Initialise easycsv */
|
||||||
easycsv* easycsv_init(const char*, const EASYCSV_MODE);
|
easycsv*
|
||||||
|
easycsv_init(const char*,
|
||||||
|
const EASYCSV_MODE);
|
||||||
|
|
||||||
/* (Constructor) Initialise easycsv with error message option */
|
/* (Constructor) Initialise easycsv with error message option */
|
||||||
easycsv* easycsv_init_errormsg(const char*, const EASYCSV_MODE, const EASYCSV_ERRORMSG);
|
easycsv*
|
||||||
|
easycsv_init_errormsg(const char*,
|
||||||
|
const EASYCSV_MODE,
|
||||||
|
const EASYCSV_ERRORMSG);
|
||||||
|
|
||||||
/* (Destructor) Free easycsv memory */
|
/* (Destructor) Free easycsv memory */
|
||||||
void easycsv_free(easycsv*);
|
void
|
||||||
|
easycsv_free(easycsv*);
|
||||||
|
|
||||||
/* Insert in */
|
/* GENERIC ALGORITHMS */
|
||||||
// int easycsv_insertrow(struct easycsv*, const char*, const int);
|
|
||||||
|
|
||||||
/* Create new column on the RHS of an existing one */
|
/* Find value and returns row and column in unsigned int pointers */
|
||||||
int easycsv_pushcolumn(easycsv*, const char*);
|
int
|
||||||
|
easycsv_findvalue(const easycsv*,
|
||||||
|
const char*,
|
||||||
|
unsigned int*,
|
||||||
|
unsigned int*);
|
||||||
|
|
||||||
/* Insert string in a specific cell */
|
/* Find number of instances of value */
|
||||||
int easycsv_insertvalue(const easycsv*, const char*, const unsigned int, const unsigned int);
|
int
|
||||||
|
easycsv_findnumvalue(const easycsv*,
|
||||||
|
const char*);
|
||||||
|
|
||||||
/* Insert string in a vacant cell under a named column */
|
int
|
||||||
int easycsv_pushcolumnvalue(const easycsv*, const char*, const char*);
|
easycsv_sortrow(const easycsv*,
|
||||||
|
const char*,
|
||||||
|
const EASYCSV_SORT);
|
||||||
|
|
||||||
/* Insert string in a specific cell with named column in row 1 */
|
int
|
||||||
int easycsv_insertcolumnvalue(const easycsv*, const char*, const unsigned int, const char*, const EASYCSV_VALMODE);
|
easycsv_sortcolumn(const easycsv*,
|
||||||
|
const char*, const
|
||||||
/* Insert array of string pointers */
|
EASYCSV_SORT);
|
||||||
int easycsv_pushcolumnstrarray(const easycsv*, const char*[], const char*);
|
|
||||||
|
|
||||||
/* Insert array of void pointers */
|
|
||||||
int easycsv_pushcolumnvoidarray(const easycsv*, const void*[], const char*);
|
|
||||||
|
|
||||||
/* Delete CSV value */
|
|
||||||
int easycsv_deletevalue(const easycsv*, const unsigned int, const unsigned int);
|
|
||||||
|
|
||||||
/* Delete column with unsigned int */
|
|
||||||
int easycsv_deletecolumnint(const easycsv*, const unsigned int);
|
|
||||||
|
|
||||||
/* Delete column with str */
|
|
||||||
int easycsv_deletecolumnstr(const easycsv*, const char*);
|
|
||||||
|
|
||||||
/* Delete column value with str */
|
|
||||||
int easycsv_deletecolumnstrvalue(const easycsv*, const char*, const char*);
|
|
||||||
|
|
||||||
/* Append to CSV files */
|
/* Append to CSV files */
|
||||||
int easycsv_appendcsv(easycsv*, easycsv*);
|
int
|
||||||
|
easycsv_appendcsv(easycsv*,
|
||||||
|
easycsv*);
|
||||||
|
|
||||||
|
/* READ VALUE */
|
||||||
|
|
||||||
/* Read string in a specific cell */
|
/* Read string in a specific cell */
|
||||||
const char *easycsv_readvalue(const easycsv*, const unsigned int, const unsigned int);
|
char*
|
||||||
|
easycsv_readvalue(const easycsv*,
|
||||||
|
const unsigned int,
|
||||||
|
const unsigned int);
|
||||||
|
|
||||||
/* Read string in a specific cell with named column in row 1 */
|
/* Read string in a specific cell with named column in row 1 */
|
||||||
const char *easycsv_readcolumnvalue(const easycsv*, const char*, const unsigned int);
|
char*
|
||||||
|
easycsv_readcolumnvalue(const easycsv*,
|
||||||
|
const char*,
|
||||||
|
const unsigned int);
|
||||||
|
|
||||||
/* Number of rows in entire CSV file */
|
/* Number of rows in entire CSV file */
|
||||||
int easycsv_printrows(const easycsv*);
|
int
|
||||||
|
easycsv_printrows(const easycsv*);
|
||||||
|
|
||||||
/* Number of columns in entire CSV file */
|
/* Number of columns in entire CSV file */
|
||||||
int easycsv_printcolumns(const easycsv*);
|
int
|
||||||
|
easycsv_printcolumns(const easycsv*);
|
||||||
|
|
||||||
|
/* INSERT VALUE -- AT SPECIFIC ROW AND COLUMN */
|
||||||
|
|
||||||
|
// int easycsv_insertrow(struct easycsv*, const char*, const int);
|
||||||
|
|
||||||
|
/* Insert string in a specific cell */
|
||||||
|
int
|
||||||
|
easycsv_insertvalue(easycsv*,
|
||||||
|
const char*,
|
||||||
|
const unsigned int,
|
||||||
|
const unsigned int);
|
||||||
|
|
||||||
|
/* Insert string in a specific cell with specific mode */
|
||||||
|
int
|
||||||
|
easycsv_insertvaluemode(easycsv*,
|
||||||
|
const char*,
|
||||||
|
const unsigned int,
|
||||||
|
const unsigned int,
|
||||||
|
const EASYCSV_VALMODE);
|
||||||
|
|
||||||
|
/* Insert string in a specific cell with named column in row 1 */
|
||||||
|
int
|
||||||
|
easycsv_insertcolumnvalue(easycsv*,
|
||||||
|
const char*,
|
||||||
|
const unsigned int,
|
||||||
|
const char*);
|
||||||
|
|
||||||
|
/* Insert string in a specific cell with named column in row 1 with specific mode */
|
||||||
|
int
|
||||||
|
easycsv_insertcolumnvaluemode(easycsv*,
|
||||||
|
const char*,
|
||||||
|
const unsigned int,
|
||||||
|
const char*,
|
||||||
|
const EASYCSV_VALMODE);
|
||||||
|
|
||||||
|
/* PUSH VALUE */
|
||||||
|
|
||||||
|
/* Create new column on the RHS of an existing one */
|
||||||
|
int
|
||||||
|
easycsv_pushcolumn(easycsv*,
|
||||||
|
const char*);
|
||||||
|
|
||||||
|
/* Insert string in a vacant cell under a named column */
|
||||||
|
int
|
||||||
|
easycsv_pushcolumnvalue(easycsv*,
|
||||||
|
const char*,
|
||||||
|
const char*);
|
||||||
|
|
||||||
|
/* Insert array of string pointers */
|
||||||
|
int
|
||||||
|
easycsv_pushcolumnstrarr(easycsv*,
|
||||||
|
const char*[],
|
||||||
|
const char*);
|
||||||
|
|
||||||
|
/* Insert array of void pointers */
|
||||||
|
int
|
||||||
|
easycsv_pushcolumnvoidarr(easycsv*,
|
||||||
|
const void*[],
|
||||||
|
const char*);
|
||||||
|
|
||||||
|
/* DELETE VALUES -- use INSERT VALUE with empty string*/
|
||||||
|
|
||||||
|
/* Delete CSV value */
|
||||||
|
int
|
||||||
|
easycsv_deletevalue(easycsv*,
|
||||||
|
const unsigned int,
|
||||||
|
const unsigned int);
|
||||||
|
|
||||||
|
/* Delete numbered column */
|
||||||
|
int
|
||||||
|
easycsv_deletecolumnint(const easycsv*,
|
||||||
|
const unsigned int);
|
||||||
|
|
||||||
|
/* Delete named column */
|
||||||
|
int
|
||||||
|
easycsv_deletecolumnstr(const easycsv*,
|
||||||
|
const char*);
|
||||||
|
|
||||||
|
/* Delete column value with str */
|
||||||
|
int
|
||||||
|
easycsv_deletecolumnstrvalue(const easycsv*,
|
||||||
|
const char*,
|
||||||
|
const char*);
|
||||||
|
|
||||||
#endif /* EASYCSV_H */
|
#endif /* EASYCSV_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user