Obey -e flag when quoting is disabled

This commit is contained in:
Richard Mansfield
2017-01-31 10:50:56 +13:00
parent 4f10f09df8
commit 62f79ec3f3

View File

@@ -39,13 +39,15 @@ print_col(FILE *outfile, gchar *col_val, int quote_text, int col_type, int bin_l
size_t quote_len = strlen(quote_char); /* multibyte */ size_t quote_len = strlen(quote_char); /* multibyte */
size_t orig_escape_len = escape_char ? strlen(escape_char) : 0; size_t orig_escape_len = escape_char ? strlen(escape_char) : 0;
int quoting = quote_text && is_quote_type(col_type);
/* double the quote char if no escape char passed */ /* double the quote char if no escape char passed */
if (!escape_char) if (!escape_char)
escape_char = quote_char; escape_char = quote_char;
if (quote_text && is_quote_type(col_type)) { if (quoting)
fputs(quote_char, outfile); fputs(quote_char, outfile);
while (1) { while (1) {
if (is_binary_type(col_type)) { if (is_binary_type(col_type)) {
if (bin_mode == MDB_BINEXPORT_STRIP) if (bin_mode == MDB_BINEXPORT_STRIP)
@@ -56,29 +58,30 @@ print_col(FILE *outfile, gchar *col_val, int quote_text, int col_type, int bin_l
if (!*col_val) if (!*col_val)
break; break;
if (quote_len && !strncmp(col_val, quote_char, quote_len)) {
if (quoting && quote_len && !strncmp(col_val, quote_char, quote_len)) {
fprintf(outfile, "%s%s", escape_char, quote_char); fprintf(outfile, "%s%s", escape_char, quote_char);
col_val += quote_len; col_val += quote_len;
#ifndef DONT_ESCAPE_ESCAPE #ifndef DONT_ESCAPE_ESCAPE
} else if (orig_escape_len && !strncmp(col_val, escape_char, orig_escape_len)) { } else if (quoting && orig_escape_len && !strncmp(col_val, escape_char, orig_escape_len)) {
fprintf(outfile, "%s%s", escape_char, escape_char); fprintf(outfile, "%s%s", escape_char, escape_char);
col_val += orig_escape_len; col_val += orig_escape_len;
#endif #endif
} else if (is_binary_type(col_type) && *col_val <= 0 && bin_mode == MDB_BINEXPORT_OCTAL) { } else if (quoting && is_binary_type(col_type) && *col_val <= 0 && bin_mode == MDB_BINEXPORT_OCTAL) {
fprintf(outfile, "\\%03o", *(unsigned char*)col_val++); fprintf(outfile, "\\%03o", *(unsigned char*)col_val++);
} else if (escape_cr_lf && *col_val==13) { } else if (escape_cr_lf && is_quote_type(col_type) && *col_val==13) {
col_val++; col_val++;
putc('\\', outfile); putc('\\', outfile);
putc('r', outfile); putc('r', outfile);
} else if (escape_cr_lf && *col_val==10) { } else if (escape_cr_lf && is_quote_type(col_type) && *col_val==10) {
col_val++; col_val++;
putc('\\', outfile); putc('\\', outfile);
putc('n', outfile); putc('n', outfile);
} else if (escape_cr_lf && *col_val==9) { } else if (escape_cr_lf && is_quote_type(col_type) && *col_val==9) {
col_val++; col_val++;
putc('\\', outfile); putc('\\', outfile);
putc('t', outfile); putc('t', outfile);
} else if (escape_cr_lf && *col_val==92) { } else if (escape_cr_lf && is_quote_type(col_type) && *col_val==92) {
col_val++; col_val++;
putc('\\', outfile); putc('\\', outfile);
putc('\\', outfile); putc('\\', outfile);
@@ -86,9 +89,8 @@ print_col(FILE *outfile, gchar *col_val, int quote_text, int col_type, int bin_l
putc(*col_val++, outfile); putc(*col_val++, outfile);
} }
} }
if (quoting)
fputs(quote_char, outfile); fputs(quote_char, outfile);
} else
fputs(col_val, outfile);
} }
int int
main(int argc, char **argv) main(int argc, char **argv)