Browse Source

Add easycsv_get_row and easycsv_set_charp_to_value

Signed-off-by: Pradana AUMARS <paumars@courrier.dev>
master
Pradana AUMARS 12 months ago
parent
commit
b0e3062d59
  1. 78
      src/easycsv_p.c
  2. 36
      src/easycsv_p.h

78
src/easycsv_p.c

@ -88,46 +88,21 @@ easycsv_columns(const easycsv *csv)
return col;
}
/* char* */
/* _easycsv_getrow(const _easycsv *csv, */
/* const unsigned int row) */
/* { */
/* /\* ARGS CHECK *\/ */
/* if (csv == NULL) { */
/* _easycsv_printerror(csv, EASYCSV_NULLCSV); */
/* return NULL; */
/* } */
/* if (row > csv->rows) { */
/* _easycsv_printerror(csv, EASYCSV_OVERMAXROW); */
/* return NULL; */
/* } */
/* if (row == 0) { */
/* _easycsv_printerror(csv, EASYCSV_ZEROROW); */
/* return NULL; */
/* } */
/* /\* END ARGS CHECK *\/ */
/* /\* Allocate memory *\/ */
/* char *str = malloc(BUFSIZ); */
/* /\* Set file pointer to start *\/ */
/* rewind(csv->file); */
char*
easycsv_get_row(const easycsv *csv,
unsigned int row)
{
char *str = malloc(BUFSIZ);
easycsv_rewind(csv);
/* for (int i = 1; i < row; i++) */
/* { */
/* /\* skip until row is reached *\/ */
/* fscanf(csv->file, "%*[^\n]\n", NULL); */
/* } */
/* /\* Grab the row and store it in str *\/ */
/* fscanf(csv->file, "%s\n", str); */
for (int i = 1; i < row; i++) {
fscanf(csv->file, "%*[^\n]\n", NULL);
}
/* // printf("row: %s\n", str); */
fscanf(csv->file, "%s\n", str);
/* return str; */
/* } */
return str;
}
int
easycsv_rewind(const easycsv *csv)
@ -247,24 +222,19 @@ int _easycsv_checkifvalue(struct easycsv *csv, const int col, const int row)
/* return val; */
/* } */
/* char* */
/* _easycsv_setcharptovalue(const _easycsv *_priv, */
/* const char *rowstr, */
/* const unsigned int col) */
/* { */
/* char *pch = rowstr; */
/* for (unsigned int i = 1; i < col; i++) { */
/* pch = strchr(rowstr, ','); */
/* if (pch == NULL) { */
/* _easycsv_printerror(_priv, EASYCSV_NULLPTR); */
/* return NULL; */
/* } */
/* pch++; */
/* } */
char*
easycsv_set_charp_to_value(const char *rowstr,
unsigned int col)
{
/* Get first occurance of comma in str, the first value is ommited but not the comma */
char *pch = (char*) rowstr;
/* Repeat until desired col is found */
for (unsigned int i = 1; i < col; i++) {
pch = strpbrk(pch + 1, ",");
}
/* return pch; */
/* } */
return pch;
}
/* int */
/* _easycsv_checkcsvandstring_one(const _easycsv *csv, */

36
src/easycsv_p.h

@ -5,15 +5,17 @@
/*** Accès ***/
/* /\** */
/* * Returns string of a specific row, including '\n' character */
/* * @param[in] const pointer to _easycsv structure */
/* * @param[in] row number */
/* * @return string of row, NULL if error or none */
/* *\/ */
/* char* */
/* _easycsv_getrow(const _easycsv*, */
/* unsigned int); */
/**
* Returns string of a specific row, including '\n' character
* This function does not check parameters!
* This function does not produce errors!
* @param[in] const pointer to easycsv structure
* @param[in] row number
* @return string of row (heap-allocated)
*/
char*
easycsv_get_row(const easycsv*,
unsigned int);
/* /\** */
/* * Returns column number of a named column *\/ */
@ -39,11 +41,17 @@
/* const char*, */
/* const unsigned int); */
/* /\* Returns char pointer to start of value in rowstr *\/ */
/* char* */
/* _easycsv_setcharptovalue(const _easycsv*, */
/* const char*, */
/* const unsigned int); */
/**
* Returns char pointer towards the n-th occurence of ',' in a given string
* This function does not check parameters!
* This function does not produce errors!
* @param[in] string of row (string with multiple occurences of ',')
* @param[in] n-th occurence to place the char pointer
* @return char pointer towards the n-th occurence of ',' in a given string
*/
char*
easycsv_set_charp_to_value(const char*,
unsigned int);
/* /\* Insert value in row in specific column *\/ */
/* char* */

Loading…
Cancel
Save