103 lines
2.9 KiB
C
103 lines
2.9 KiB
C
|
#ifndef EASYCSV_H
|
||
|
#define EASYCSV_H
|
||
|
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <string.h>
|
||
|
#include <unistd.h>
|
||
|
#include <sys/sendfile.h>
|
||
|
#include <sys/stat.h>
|
||
|
#include <fcntl.h>
|
||
|
#include <time.h>
|
||
|
|
||
|
/* Flags for error messages */
|
||
|
typedef enum {
|
||
|
EASYCSV_ERROROFF,
|
||
|
EASYCSV_ERRORSTDERR,
|
||
|
EASYCSV_ERRORSTDOUT
|
||
|
} EASYCSV_ERRORMSG;
|
||
|
|
||
|
/* Using our own flags to facilitate changing modes during file copying phases */
|
||
|
typedef enum {
|
||
|
EASYCSV_R,
|
||
|
EASYCSV_W
|
||
|
} EASYCSV_MODE;
|
||
|
|
||
|
typedef enum {
|
||
|
EASYCSV_REPLACE,
|
||
|
EASYCSV_APPEND,
|
||
|
EASYCSV_APPEND_R,
|
||
|
} EASYCSV_VALMODE;
|
||
|
|
||
|
typedef struct _easycsv _easycsv;
|
||
|
|
||
|
typedef struct easycsv {
|
||
|
EASYCSV_MODE mode;
|
||
|
_easycsv *_priv; // private members
|
||
|
} easycsv;
|
||
|
|
||
|
/*
|
||
|
* ============================
|
||
|
* FUNCTION PROTOTYPES - PUBLIC
|
||
|
* ============================
|
||
|
*/
|
||
|
|
||
|
/* (Constructor) Initialise easycsv */
|
||
|
easycsv* easycsv_init(const char*, const EASYCSV_MODE);
|
||
|
|
||
|
/* (Constructor) Initialise easycsv with error message option */
|
||
|
easycsv* easycsv_init_errormsg(const char*, const EASYCSV_MODE, const EASYCSV_ERRORMSG);
|
||
|
|
||
|
/* (Destructor) Free easycsv memory */
|
||
|
void easycsv_free(easycsv*);
|
||
|
|
||
|
/* Insert in */
|
||
|
// int easycsv_insertrow(struct easycsv*, const char*, const int);
|
||
|
|
||
|
/* Create new column on the RHS of an existing one */
|
||
|
int easycsv_pushcolumn(easycsv*, const char*);
|
||
|
|
||
|
/* Insert string in a specific cell */
|
||
|
int easycsv_insertvalue(const easycsv*, const char*, const unsigned int, const unsigned int);
|
||
|
|
||
|
/* Insert string in a vacant cell under a named column */
|
||
|
int easycsv_pushcolumnvalue(const easycsv*, const char*, const char*);
|
||
|
|
||
|
/* Insert string in a specific cell with named column in row 1 */
|
||
|
int easycsv_insertcolumnvalue(const easycsv*, const char*, const unsigned int, const char*, const EASYCSV_VALMODE);
|
||
|
|
||
|
/* Insert array of string pointers */
|
||
|
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 */
|
||
|
int easycsv_appendcsv(easycsv*, easycsv*);
|
||
|
|
||
|
/* Read string in a specific cell */
|
||
|
const char *easycsv_readvalue(const easycsv*, const unsigned int, const unsigned int);
|
||
|
|
||
|
/* Read string in a specific cell with named column in row 1 */
|
||
|
const char *easycsv_readcolumnvalue(const easycsv*, const char*, const unsigned int);
|
||
|
|
||
|
/* Number of rows in entire CSV file */
|
||
|
int easycsv_printrows(const easycsv*);
|
||
|
|
||
|
/* Number of columns in entire CSV file */
|
||
|
int easycsv_printcolumns(const easycsv*);
|
||
|
|
||
|
#endif /* EASYCSV_H */
|