From b4238ac88f105b3dd4f9069bead0b4c2bd187d7c Mon Sep 17 00:00:00 2001 From: Brian Bruns Date: Mon, 21 Feb 2011 14:11:41 -0500 Subject: [PATCH] =?UTF-8?q?patch=20'export'=20from=20Nirgal=20Vourg=C3=A8r?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/mdb-export.c | 58 +++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/util/mdb-export.c b/src/util/mdb-export.c index f4c8d1f..36e950b 100644 --- a/src/util/mdb-export.c +++ b/src/util/mdb-export.c @@ -26,40 +26,44 @@ #undef MDB_BIND_SIZE #define MDB_BIND_SIZE 200000 -#define is_text_type(x) (x==MDB_TEXT || x==MDB_OLE || x==MDB_MEMO || x==MDB_DATETIME || x==MDB_BINARY) +#define is_quote_type(x) (x==MDB_TEXT || x==MDB_OLE || x==MDB_MEMO || x==MDB_DATETIME || x==MDB_BINARY) +#define is_binary_type(x) (x==MDB_OLE || x==MDB_BINARY) static char *escapes(char *s); -void -print_col(gchar *col_val, int quote_text, int col_type, int bin_length, char *quote_char, char *escape_char) +//#define DONT_ESCAPE_ESCAPE +static void +print_col(gchar *col_val, int quote_text, int col_type, int bin_len, char *quote_char, char *escape_char) { - gchar *s; - unsigned char c; + size_t quote_len = strlen(quote_char); /* multibyte */ - if (quote_text && is_text_type(col_type)) { + size_t orig_escape_len = escape_char ? strlen(escape_char) : 0; + + /* double the quote char if no escape char passed */ + if (!escape_char) + escape_char = quote_char; + + if (quote_text && is_quote_type(col_type)) { fputs(quote_char,stdout); - if (col_type == MDB_OLE || col_type == MDB_BINARY) { - while (bin_length--) { - c = (unsigned char)*col_val++; - if (strlen(quote_char)==1 && c==quote_char[0] || c==escape_char[0]) { - if (escape_char) - fputs(escape_char,stdout); - else /* double the quote char if no escape char passed */ - fputs(quote_char,stdout); - } - putc(c, stdout); - } + while (1) { + if (is_binary_type(col_type)) { + if (!bin_len--) + break; + } else /* use \0 sentry */ + if (!*col_val) + break; + + if (quote_len && !strncmp(col_val, quote_char, quote_len)) { + fprintf(stdout, "%s%s", escape_char, quote_char); + col_val += quote_len; +#ifndef DONT_ESCAPE_ESCAPE + } else if (orig_escape_len && !strncmp(col_val, escape_char, orig_escape_len)) { + fprintf(stdout, "%s%s", escape_char, escape_char); + col_val += orig_escape_len; +#endif + } else + putc(*col_val++, stdout); } - else - for (s=col_val;(c=*s);s++) { - if (strlen(quote_char)==1 && c==quote_char[0] || c==escape_char[0]) { - if (escape_char) - fputs(escape_char,stdout); - else /* double the quote char if no escape char passed */ - fputs(quote_char,stdout); - } - putc(c, stdout); - } fputs(quote_char,stdout); } else fputs(col_val,stdout);