197 lines
4.2 KiB
C
197 lines
4.2 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>
|
|
#include <stdint.h>
|
|
|
|
/* Flags for error messages */
|
|
typedef enum {
|
|
EASYCSV_ERRORSTDERR = 0, // default
|
|
EASYCSV_ERROROFF,
|
|
EASYCSV_ERRORSTDOUT
|
|
} EASYCSV_ERRORMSG;
|
|
|
|
/* Flags to facilitate changing modes during file copying phases */
|
|
typedef enum {
|
|
EASYCSV_UNKNOWNMODE = 0,
|
|
EASYCSV_R,
|
|
EASYCSV_W
|
|
} EASYCSV_MODE;
|
|
|
|
/* Flags to parameterise the easycsv_insertvalue */
|
|
typedef enum {
|
|
EASYCSV_REPLACE, /* (Default) Replaces word */
|
|
EASYCSV_CONCAT, /* Concantates word at the end */
|
|
EASYCSV_RCONCAT, /* Concantates word from the start */
|
|
} 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;
|
|
|
|
/* Public easycsv members */
|
|
typedef struct easycsv {
|
|
EASYCSV_MODE mode; // end users able to easily modify mode to their needs
|
|
_easycsv *_priv; // private members
|
|
} easycsv;
|
|
|
|
/*
|
|
* ============================
|
|
* FUNCTION PROTOTYPES - PUBLIC
|
|
* ============================
|
|
*/
|
|
|
|
/* CONSTRUCTORS AND DESTRUCTORS */
|
|
|
|
/* (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*);
|
|
|
|
/* GENERIC ALGORITHMS */
|
|
|
|
/* Find value and returns row and column in unsigned int pointers */
|
|
int
|
|
easycsv_findvalue(const easycsv*,
|
|
const char*,
|
|
unsigned int*,
|
|
unsigned int*);
|
|
|
|
/* Find number of instances of value */
|
|
int
|
|
easycsv_findnumvalue(const easycsv*,
|
|
const char*);
|
|
|
|
int
|
|
easycsv_sortrow(easycsv*,
|
|
const char*,
|
|
const EASYCSV_SORT);
|
|
|
|
int
|
|
easycsv_sortcolumn(easycsv*,
|
|
const char*,
|
|
const EASYCSV_SORT);
|
|
|
|
/* Append to CSV files */
|
|
int
|
|
easycsv_appendcsv(easycsv*,
|
|
easycsv*);
|
|
|
|
int
|
|
easycsv_compress(easycsv*);
|
|
|
|
/* READ VALUE */
|
|
|
|
/* Read string in a specific cell */
|
|
char*
|
|
easycsv_readvalue(const easycsv*,
|
|
const unsigned int,
|
|
const unsigned int);
|
|
|
|
/* Read string in a specific cell with named column in row 1 */
|
|
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*);
|
|
|
|
/* 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*);
|
|
|
|
/* 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(easycsv*,
|
|
const unsigned int);
|
|
|
|
/* Delete named column */
|
|
int
|
|
easycsv_deletecolumnstr(easycsv*,
|
|
const char*);
|
|
|
|
/* Delete numered row */
|
|
|
|
/* Delete named row */
|
|
|
|
#endif /* EASYCSV_H */
|