lrec-readers iterate

This commit is contained in:
John Kerl 2017-03-12 22:59:26 -04:00
parent 9bf2e5fe5c
commit bae00d0a6e
3 changed files with 5 additions and 5 deletions

View file

@ -142,7 +142,7 @@ char* mlr_alloc_read_line_single_delimiter(
int do_auto_line_term,
context_t* pctx)
{
size_t linecap = power_of_two_above(*pold_then_new_strlen);
size_t linecap = power_of_two_above(*pold_then_new_strlen + 1); // +1 for null-terminator
char* restrict line = mlr_malloc_or_die(linecap);
char* restrict p = line;
int reached_eof = FALSE;
@ -201,7 +201,7 @@ char* mlr_alloc_read_line_multiple_delimiter(
int delimiter_length,
size_t* pold_then_new_strlen)
{
size_t linecap = power_of_two_above(*pold_then_new_strlen);
size_t linecap = power_of_two_above(*pold_then_new_strlen + 1); // +1 for null-terminator
char* line = mlr_malloc_or_die(linecap);
char* p = line; // points to null-terminator in (chomped) output string
char* q = line; // points to end of line in (non-chomped) data read from file

View file

@ -39,6 +39,7 @@ ssize_t local_getdelim(char** restrict pline, size_t* restrict plinecap, int del
// work autodetect deeper into the callstack
#define MLR_ALLOC_READ_LINE_INITIAL_SIZE 128
char* mlr_alloc_read_line_single_delimiter(
FILE* fp,
int delimiter,

View file

@ -23,6 +23,7 @@ typedef struct _lrec_reader_stdio_dkvp_state_t {
int ifslen;
int ipslen;
int allow_repeat_ifs;
int line_length;
} lrec_reader_stdio_dkvp_state_t;
static void lrec_reader_stdio_dkvp_free(lrec_reader_t* preader);
@ -52,6 +53,7 @@ lrec_reader_t* lrec_reader_stdio_dkvp_alloc(char* irs, char* ifs, char* ips, int
pstate->ifslen = strlen(ifs);
pstate->ipslen = strlen(ips);
pstate->allow_repeat_ifs = allow_repeat_ifs;
pstate->line_length = MLR_ALLOC_READ_LINE_INITIAL_SIZE;
plrec_reader->pvstate = (void*)pstate;
plrec_reader->popen_func = file_reader_stdio_vopen;
@ -102,9 +104,6 @@ static lrec_t* lrec_reader_stdio_dkvp_process_single_irs_single_others_auto_line
// xxx init pstate->line_length @ prev
//char* line = mlr_alloc_read_line_single_delimiter(input_stream, pstate->irs[0],
// &pstate->line_length, xxxnolinecap, TRUE, pctx);
// pnew_linecap,
// do_auto_line_term,
// pctx);
// ----------------------------------------------------------------
char* line = mlr_get_cline_with_length(input_stream, pstate->irs[0], &line_length);