EasyCSV/src/easycsv.h

197 lines
4.2 KiB
C
Raw Normal View History

2018-02-11 18:14:34 +01:00
#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>
2018-02-21 20:40:51 +01:00
#include <stdint.h>
2018-02-11 18:14:34 +01:00
/* Flags for error messages */
typedef enum {
2018-02-21 20:40:51 +01:00
EASYCSV_ERRORSTDERR = 0, // default
2018-02-11 18:14:34 +01:00
EASYCSV_ERROROFF,
EASYCSV_ERRORSTDOUT
} EASYCSV_ERRORMSG;
2018-02-21 20:40:51 +01:00
/* Flags to facilitate changing modes during file copying phases */
2018-02-11 18:14:34 +01:00
typedef enum {
2018-02-21 20:40:51 +01:00
EASYCSV_UNKNOWNMODE = 0,
2018-02-11 18:14:34 +01:00
EASYCSV_R,
EASYCSV_W
} EASYCSV_MODE;
2018-02-21 20:40:51 +01:00
/* Flags to parameterise the easycsv_insertvalue */
2018-02-11 18:14:34 +01:00
typedef enum {
2018-02-21 20:40:51 +01:00
EASYCSV_REPLACE, /* (Default) Replaces word */
EASYCSV_CONCAT, /* Concantates word at the end */
EASYCSV_RCONCAT, /* Concantates word from the start */
2018-02-11 18:14:34 +01:00
} EASYCSV_VALMODE;
2018-02-21 20:40:51 +01:00
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;
2018-02-11 18:14:34 +01:00
typedef struct _easycsv _easycsv;
2018-02-21 20:40:51 +01:00
/* Public easycsv members */
2018-02-11 18:14:34 +01:00
typedef struct easycsv {
2018-02-21 20:40:51 +01:00
EASYCSV_MODE mode; // end users able to easily modify mode to their needs
2018-02-11 18:14:34 +01:00
_easycsv *_priv; // private members
} easycsv;
/*
* ============================
* FUNCTION PROTOTYPES - PUBLIC
* ============================
*/
2018-02-21 20:40:51 +01:00
/* CONSTRUCTORS AND DESTRUCTORS */
2018-02-11 18:14:34 +01:00
/* (Constructor) Initialise easycsv */
2018-02-21 20:40:51 +01:00
easycsv*
easycsv_init(const char*,
const EASYCSV_MODE);
2018-02-11 18:14:34 +01:00
/* (Constructor) Initialise easycsv with error message option */
2018-02-21 20:40:51 +01:00
easycsv*
easycsv_init_errormsg(const char*,
const EASYCSV_MODE,
const EASYCSV_ERRORMSG);
2018-02-11 18:14:34 +01:00
/* (Destructor) Free easycsv memory */
2018-02-21 20:40:51 +01:00
void
easycsv_free(easycsv*);
2018-02-11 18:14:34 +01:00
2018-02-21 20:40:51 +01:00
/* GENERIC ALGORITHMS */
2018-02-11 18:14:34 +01:00
2018-02-21 20:40:51 +01:00
/* Find value and returns row and column in unsigned int pointers */
int
easycsv_findvalue(const easycsv*,
const char*,
unsigned int*,
unsigned int*);
2018-02-11 18:14:34 +01:00
2018-02-21 20:40:51 +01:00
/* Find number of instances of value */
int
easycsv_findnumvalue(const easycsv*,
const char*);
2018-02-11 18:14:34 +01:00
2018-02-21 20:40:51 +01:00
int
2018-02-22 14:23:23 +01:00
easycsv_sortrow(easycsv*,
2018-02-21 20:40:51 +01:00
const char*,
const EASYCSV_SORT);
2018-02-11 18:14:34 +01:00
2018-02-21 20:40:51 +01:00
int
2018-02-22 14:23:23 +01:00
easycsv_sortcolumn(easycsv*,
const char*,
const EASYCSV_SORT);
2018-02-11 18:14:34 +01:00
2018-02-21 20:40:51 +01:00
/* Append to CSV files */
int
easycsv_appendcsv(easycsv*,
easycsv*);
2018-02-11 18:14:34 +01:00
2018-02-22 14:23:23 +01:00
int
easycsv_compress(easycsv*);
2018-02-21 20:40:51 +01:00
/* READ VALUE */
2018-02-11 18:14:34 +01:00
2018-02-21 20:40:51 +01:00
/* Read string in a specific cell */
char*
easycsv_readvalue(const easycsv*,
const unsigned int,
const unsigned int);
2018-02-11 18:14:34 +01:00
2018-02-21 20:40:51 +01:00
/* Read string in a specific cell with named column in row 1 */
char*
easycsv_readcolumnvalue(const easycsv*,
const char*,
const unsigned int);
2018-02-11 18:14:34 +01:00
2018-02-21 20:40:51 +01:00
/* Number of rows in entire CSV file */
int
easycsv_printrows(const easycsv*);
2018-02-11 18:14:34 +01:00
2018-02-21 20:40:51 +01:00
/* Number of columns in entire CSV file */
int
easycsv_printcolumns(const easycsv*);
2018-02-11 18:14:34 +01:00
2018-02-21 20:40:51 +01:00
/* INSERT VALUE -- AT SPECIFIC ROW AND COLUMN */
2018-02-11 18:14:34 +01:00
2018-02-21 20:40:51 +01:00
// int easycsv_insertrow(struct easycsv*, const char*, const int);
2018-02-11 18:14:34 +01:00
2018-02-21 20:40:51 +01:00
/* 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);
2018-02-11 18:14:34 +01:00
2018-02-21 20:40:51 +01:00
/* 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 */
2018-02-11 18:14:34 +01:00
2018-02-21 20:40:51 +01:00
/* 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
2018-02-22 14:23:23 +01:00
easycsv_deletecolumnint(easycsv*,
2018-02-21 20:40:51 +01:00
const unsigned int);
/* Delete named column */
int
2018-02-22 14:23:23 +01:00
easycsv_deletecolumnstr(easycsv*,
2018-02-21 20:40:51 +01:00
const char*);
2018-02-22 14:23:23 +01:00
/* Delete numered row */
/* Delete named row */
2018-02-11 18:14:34 +01:00
#endif /* EASYCSV_H */