mirror of
https://github.com/mdbtools/mdbtools.git
synced 2025-07-17 19:22:14 +08:00
patch 'export' from Nirgal Vourgère
This commit is contained in:
parent
d794c6e2a1
commit
b4238ac88f
@ -26,40 +26,44 @@
|
|||||||
#undef MDB_BIND_SIZE
|
#undef MDB_BIND_SIZE
|
||||||
#define MDB_BIND_SIZE 200000
|
#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);
|
static char *escapes(char *s);
|
||||||
|
|
||||||
void
|
//#define DONT_ESCAPE_ESCAPE
|
||||||
print_col(gchar *col_val, int quote_text, int col_type, int bin_length, char *quote_char, char *escape_char)
|
static void
|
||||||
|
print_col(gchar *col_val, int quote_text, int col_type, int bin_len, char *quote_char, char *escape_char)
|
||||||
{
|
{
|
||||||
gchar *s;
|
size_t quote_len = strlen(quote_char); /* multibyte */
|
||||||
unsigned char c;
|
|
||||||
|
|
||||||
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);
|
fputs(quote_char,stdout);
|
||||||
if (col_type == MDB_OLE || col_type == MDB_BINARY) {
|
while (1) {
|
||||||
while (bin_length--) {
|
if (is_binary_type(col_type)) {
|
||||||
c = (unsigned char)*col_val++;
|
if (!bin_len--)
|
||||||
if (strlen(quote_char)==1 && c==quote_char[0] || c==escape_char[0]) {
|
break;
|
||||||
if (escape_char)
|
} else /* use \0 sentry */
|
||||||
fputs(escape_char,stdout);
|
if (!*col_val)
|
||||||
else /* double the quote char if no escape char passed */
|
break;
|
||||||
fputs(quote_char,stdout);
|
|
||||||
}
|
if (quote_len && !strncmp(col_val, quote_char, quote_len)) {
|
||||||
putc(c, stdout);
|
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);
|
fputs(quote_char,stdout);
|
||||||
} else
|
} else
|
||||||
fputs(col_val,stdout);
|
fputs(col_val,stdout);
|
||||||
|
Loading…
Reference in New Issue
Block a user