This commit is contained in:
John Kerl 2017-02-01 21:22:13 -05:00
parent d49d6b963c
commit 2ffdbf5074
3 changed files with 35 additions and 14 deletions

View file

@ -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;
}
}
}

View file

@ -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;

View file

@ -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);