From: Martin Mares Date: Mon, 23 Jul 2012 18:19:22 +0000 (+0200) Subject: Added --ws mode X-Git-Tag: v1.0~47 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=f13d72b8bb0640b1b52ab7257377e202f7520c4e;p=xsv.git Added --ws mode --- diff --git a/xsv.c b/xsv.c index fa7964d..38f1fde 100644 --- a/xsv.c +++ b/xsv.c @@ -160,6 +160,31 @@ static void csv_write(void) putchar('\n'); } +static int ws_read(void) +{ + int ws = 0; + for (;;) { + int c = getchar(); + if (c < 0) + return !!fields_count(&in_fields); + if (c == '\r') + continue; + if (c == '\n') + return 1; + if (c == ' ' || c == '\t' || c == '\f') { + ensure_field(); + if (!ws) + new_field(); + ws++; + } else { + ensure_field(); + *line_push(&in_line) = c; + in_field->len++; + ws = 0; + } + } +} + /*** Field selection ***/ struct selector { @@ -276,6 +301,10 @@ static void set_format(int format_id) f->write_line = csv_write; break; case FORM_WS: + f->fs = ' '; + f->quote = -1; + f->read_line = ws_read; + f->write_line = csv_write; break; }