skip-comments iterate: nidx

This commit is contained in:
John Kerl 2017-10-23 23:25:00 -07:00
parent 74a8e4af76
commit 2e2c348091
2 changed files with 51 additions and 17 deletions

View file

@ -19,6 +19,7 @@ typedef struct _lrec_reader_stdio_nidx_state_t {
int irslen;
int ifslen;
int allow_repeat_ifs;
char* comment_string;
size_t line_length;
} lrec_reader_stdio_nidx_state_t;
@ -43,6 +44,7 @@ lrec_reader_t* lrec_reader_stdio_nidx_alloc(char* irs, char* ifs, int allow_repe
pstate->irslen = strlen(irs);
pstate->ifslen = strlen(ifs);
pstate->allow_repeat_ifs = allow_repeat_ifs;
pstate->comment_string = comment_string;
// This is used to track nominal line length over the file read. Bootstrap with a default length.
pstate->line_length = MLR_ALLOC_READ_LINE_INITIAL_SIZE;
@ -88,8 +90,11 @@ static lrec_t* lrec_reader_stdio_nidx_process_single_irs_single_ifs_auto_line_te
FILE* input_stream = pvhandle;
lrec_reader_stdio_nidx_state_t* pstate = pvstate;
char* line = mlr_alloc_read_line_single_delimiter(input_stream, pstate->irs[0],
&pstate->line_length, TRUE, pctx);
char* line = pstate->comment_string == NULL
? mlr_alloc_read_line_single_delimiter(input_stream, pstate->irs[0],
&pstate->line_length, TRUE, pctx)
: mlr_alloc_read_line_single_delimiter_stripping_comments(input_stream, pstate->irs[0],
&pstate->line_length, TRUE, pstate->comment_string, pctx);
if (line == NULL) {
return NULL;
@ -102,8 +107,11 @@ static lrec_t* lrec_reader_stdio_nidx_process_single_irs_multi_ifs_auto_line_ter
FILE* input_stream = pvhandle;
lrec_reader_stdio_nidx_state_t* pstate = pvstate;
char* line = mlr_alloc_read_line_single_delimiter(input_stream, pstate->irs[0],
&pstate->line_length, TRUE, pctx);
char* line = pstate->comment_string == NULL
? mlr_alloc_read_line_single_delimiter(input_stream, pstate->irs[0],
&pstate->line_length, TRUE, pctx)
: mlr_alloc_read_line_single_delimiter_stripping_comments(input_stream, pstate->irs[0],
&pstate->line_length, TRUE, pstate->comment_string, pctx);
if (line == NULL) {
return NULL;
@ -116,8 +124,11 @@ static lrec_t* lrec_reader_stdio_nidx_process_single_irs_single_ifs(void* pvstat
FILE* input_stream = pvhandle;
lrec_reader_stdio_nidx_state_t* pstate = pvstate;
char* line = mlr_alloc_read_line_single_delimiter(input_stream, pstate->irs[0],
&pstate->line_length, FALSE, pctx);
char* line = pstate->comment_string == NULL
? mlr_alloc_read_line_single_delimiter(input_stream, pstate->irs[0],
&pstate->line_length, FALSE, pctx)
: mlr_alloc_read_line_single_delimiter_stripping_comments(input_stream, pstate->irs[0],
&pstate->line_length, FALSE, pstate->comment_string, pctx);
if (line == NULL)
return NULL;
@ -129,8 +140,11 @@ static lrec_t* lrec_reader_stdio_nidx_process_single_irs_multi_ifs(void* pvstate
FILE* input_stream = pvhandle;
lrec_reader_stdio_nidx_state_t* pstate = pvstate;
char* line = mlr_alloc_read_line_single_delimiter(input_stream, pstate->irs[0],
&pstate->line_length, FALSE, pctx);
char* line = pstate->comment_string == NULL
? mlr_alloc_read_line_single_delimiter(input_stream, pstate->irs[0],
&pstate->line_length, FALSE, pctx)
: mlr_alloc_read_line_single_delimiter_stripping_comments(input_stream, pstate->irs[0],
&pstate->line_length, FALSE, pstate->comment_string, pctx);
if (line == NULL)
return NULL;
@ -141,8 +155,11 @@ static lrec_t* lrec_reader_stdio_nidx_process_single_irs_multi_ifs(void* pvstate
static lrec_t* lrec_reader_stdio_nidx_process_multi_irs_single_ifs(void* pvstate, void* pvhandle, context_t* pctx) {
lrec_reader_stdio_nidx_state_t* pstate = pvstate;
FILE* input_stream = pvhandle;
char* line = mlr_alloc_read_line_multiple_delimiter(input_stream, pstate->irs, pstate->irslen,
&pstate->line_length);
char* line = pstate->comment_string == NULL
? mlr_alloc_read_line_multiple_delimiter(input_stream, pstate->irs, pstate->irslen,
&pstate->line_length)
: mlr_alloc_read_line_multiple_delimiter_stripping_comments(input_stream, pstate->irs, pstate->irslen,
&pstate->line_length, pstate->comment_string);
if (line == NULL)
return NULL;
else
@ -152,8 +169,11 @@ static lrec_t* lrec_reader_stdio_nidx_process_multi_irs_single_ifs(void* pvstate
static lrec_t* lrec_reader_stdio_nidx_process_multi_irs_multi_ifs(void* pvstate, void* pvhandle, context_t* pctx) {
lrec_reader_stdio_nidx_state_t* pstate = pvstate;
FILE* input_stream = pvhandle;
char* line = mlr_alloc_read_line_multiple_delimiter(input_stream, pstate->irs, pstate->irslen,
&pstate->line_length);
char* line = pstate->comment_string == NULL
? mlr_alloc_read_line_multiple_delimiter(input_stream, pstate->irs, pstate->irslen,
&pstate->line_length)
: mlr_alloc_read_line_multiple_delimiter_stripping_comments(input_stream, pstate->irs, pstate->irslen,
&pstate->line_length, pstate->comment_string);
if (line == NULL)
return NULL;
else

View file

@ -22,6 +22,7 @@ typedef struct _lrec_reader_stdio_xtab_state_t {
int allow_repeat_ips;
int do_auto_line_term;
int at_eof;
char* comment_string;
size_t line_length;
} lrec_reader_stdio_xtab_state_t;
@ -41,6 +42,7 @@ lrec_reader_t* lrec_reader_stdio_xtab_alloc(char* ifs, char* ips, int allow_repe
pstate->allow_repeat_ips = allow_repeat_ips;
pstate->do_auto_line_term = FALSE;
pstate->at_eof = FALSE;
pstate->comment_string = comment_string;
// This is used to track nominal line length over the file read. Bootstrap with a default length.
pstate->line_length = MLR_ALLOC_READ_LINE_INITIAL_SIZE;
@ -81,11 +83,23 @@ static lrec_t* lrec_reader_stdio_xtab_process(void* pvstate, void* pvhandle, con
slls_t* pxtab_lines = slls_alloc();
while (TRUE) {
char* line = (pstate->ifslen == 1)
? mlr_alloc_read_line_single_delimiter(input_stream, pstate->ifs[0],
&pstate->line_length, pstate->do_auto_line_term, pctx)
: mlr_alloc_read_line_multiple_delimiter(input_stream, pstate->ifs, pstate->ifslen,
&pstate->line_length);
char* line = NULL;
if (pstate->comment_string == NULL) {
if (pstate->ifslen == 1)
line = mlr_alloc_read_line_single_delimiter(input_stream, pstate->ifs[0],
&pstate->line_length, pstate->do_auto_line_term, pctx);
else
line = mlr_alloc_read_line_multiple_delimiter(input_stream, pstate->ifs, pstate->ifslen,
&pstate->line_length);
} else {
if (pstate->ifslen == 1)
line = mlr_alloc_read_line_single_delimiter_stripping_comments(input_stream, pstate->ifs[0],
&pstate->line_length, pstate->do_auto_line_term, pstate->comment_string, pctx);
else
line = mlr_alloc_read_line_multiple_delimiter_stripping_comments(input_stream, pstate->ifs, pstate->ifslen,
&pstate->line_length, pstate->comment_string);
}
if (line == NULL) { // EOF
// EOF or blank line terminates the stanza.