/*
- * A Swiss-Army Knife for CSV-like Files
+ * The Swiss-Army Knife for CSV-like Files
*
* (c) 2012 Martin Mares <mj@ucw.cz>
*/
-#define _GNU_SOURCE
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
}
return 1;
}
+ if (ovec[0] == ovec[1]) {
+ warn(fmt, "Regular expression matched an empty separator.");
+ new_field(i);
+ in_field->len = n - i;
+ return 1;
+ }
if (!fmt->sloppy || ovec[0]) {
new_field(i);
in_field->len = ovec[0] - i;
}
}
+ fields_reset(&out_fields);
if (want_select_fields)
select_fields();
else
Usage: xsv <in-format> [<out-format>] <options> [<fields>]\n\
\n\
Formats:\n\
--t, --tsv TAB-separated values (default)\n\
+-t, --tsv Tab-separated values (default)\n\
-c, --csv Comma-separated values\n\
-w, --ws Values separated by arbitrary whitespace\n\
-r, --regex=<rx> Separator given by Perl regular expression (input only)\n\
enum long_options {
OPT_HELP = 256,
+ OPT_VERSION,
OPT_TRIM,
OPT_ALWAYS_QUOTE,
OPT_TABLE,
{ "fs", 1, NULL, 'd' },
{ "grid", 0, NULL, OPT_GRID },
{ "header", 0, NULL, 'h' },
+ { "help", 0, NULL, OPT_HELP },
{ "quiet", 0, NULL, 'q' },
{ "regex", 1, NULL, 'r' },
{ "sloppy", 0, NULL, 's' },
{ "table-sep", 1, NULL, OPT_TABLE_SEP },
{ "trim", 0, NULL, OPT_TRIM },
{ "tsv", 0, NULL, 't' },
+ { "version", 0, NULL, OPT_VERSION },
{ "ws", 0, NULL, 'w' },
- { "help", 0, NULL, OPT_HELP },
{ NULL, 0, NULL, 0 },
};
break;
case OPT_HELP:
usage();
+ case OPT_VERSION:
+ puts("This is xsv version " VERSION ".");
+ exit(0);
case OPT_TRIM:
want_trim = 1;
break;