From 2ffdbf50740a5e5124c72fec0252b6fd71add8cf Mon Sep 17 00:00:00 2001 From: John Kerl Date: Wed, 1 Feb 2017 21:22:13 -0500 Subject: [PATCH] neaten --- c/input/lrec_reader_mmap_json.c | 18 ++++++++++-------- c/input/lrec_reader_mmap_xtab.c | 29 +++++++++++++++++++++++++---- c/input/lrec_reader_stdio_xtab.c | 2 -- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/c/input/lrec_reader_mmap_json.c b/c/input/lrec_reader_mmap_json.c index afd422567..582163049 100644 --- a/c/input/lrec_reader_mmap_json.c +++ b/c/input/lrec_reader_mmap_json.c @@ -128,15 +128,17 @@ static void lrec_reader_mmap_json_sof(void* pvstate, void* pvhandle) { while (TRUE) { // Find the first line-ending sequence (if any): LF or CRLF. - if (detected_line_term == NULL) { - for (char* p = phandle->sol; p < phandle->eof; p++) { - if (p[0] == '\n') { - if (p > phandle->sol && p[-1] == '\r') { - detected_line_term = "\r\n"; - } else { - detected_line_term = "\n"; + if (pstate->do_auto_line_term) { + if (detected_line_term == NULL) { + for (char* p = phandle->sol; p < phandle->eof; p++) { + if (p[0] == '\n') { + if (p > phandle->sol && p[-1] == '\r') { + detected_line_term = "\r\n"; + } else { + detected_line_term = "\n"; + } + break; } - break; } } } diff --git a/c/input/lrec_reader_mmap_xtab.c b/c/input/lrec_reader_mmap_xtab.c index 28c02f67a..9c1a448b7 100644 --- a/c/input/lrec_reader_mmap_xtab.c +++ b/c/input/lrec_reader_mmap_xtab.c @@ -126,8 +126,8 @@ static lrec_t* lrec_reader_mmap_xtab_process_multi_ifs_multi_ips(void* pvstate, lrec_t* lrec_parse_mmap_xtab_single_ifs_single_ips(file_reader_mmap_state_t* phandle, char ifs, char ips, int allow_repeat_ips, int do_auto_line_term, context_t* pctx) { - // xxx comment all this if (do_auto_line_term) { + // Skip over otherwise empty LF-only or CRLF-only lines. while (phandle->sol < phandle->eof) { if (*phandle->sol == '\n') { context_set_autodetected_lf(pctx); @@ -145,6 +145,7 @@ lrec_t* lrec_parse_mmap_xtab_single_ifs_single_ips(file_reader_mmap_state_t* pha } } } else { + // Skip over otherwise empty IRS-only lines. while (phandle->sol < phandle->eof && *phandle->sol == ifs) phandle->sol++; } @@ -235,9 +236,29 @@ lrec_t* lrec_parse_mmap_xtab_single_ifs_single_ips(file_reader_mmap_state_t* pha lrec_t* lrec_parse_mmap_xtab_single_ifs_multi_ips(file_reader_mmap_state_t* phandle, char ifs, char* ips, int ipslen, int allow_repeat_ips, int do_auto_line_term, context_t* pctx) { - // xxx autolineterm .... - while (phandle->sol < phandle->eof && *phandle->sol == ifs) - phandle->sol++; + if (do_auto_line_term) { + // Skip over otherwise empty LF-only or CRLF-only lines. + while (phandle->sol < phandle->eof) { + if (*phandle->sol == '\n') { + context_set_autodetected_lf(pctx); + phandle->sol += 1; + } else if (*phandle->sol == '\r') { + char* q = phandle->sol + 1; + if (q < phandle->eof && *q == '\n') { + context_set_autodetected_crlf(pctx); + phandle->sol += 2; + } else { + phandle->sol += 1; + } + } else { + break; + } + } + } else { + // Skip over otherwise empty IRS-only lines. + while (phandle->sol < phandle->eof && *phandle->sol == ifs) + phandle->sol++; + } if (phandle->sol >= phandle->eof) return NULL; diff --git a/c/input/lrec_reader_stdio_xtab.c b/c/input/lrec_reader_stdio_xtab.c index 755a9f939..528c940e9 100644 --- a/c/input/lrec_reader_stdio_xtab.c +++ b/c/input/lrec_reader_stdio_xtab.c @@ -79,7 +79,6 @@ static lrec_t* lrec_reader_stdio_xtab_process(void* pvstate, void* pvhandle, con while (TRUE) { int line_length = 0; - // xxx move all this into mlr_get_cline_auto_line_term ? char* line = (pstate->ifslen == 1) ? mlr_get_cline_with_length(input_stream, pstate->ifs[0], &line_length) : mlr_get_sline(input_stream, pstate->ifs, pstate->ifslen); @@ -106,7 +105,6 @@ static lrec_t* lrec_reader_stdio_xtab_process(void* pvstate, void* pvhandle, con pstate->allow_repeat_ips); } - // xxx simplify } else if (line[0] == '\r' && line[1] == '\0') { free(line); context_set_autodetected_crlf(pctx);