From bcd1625f293e05913e01d30d2bb01f62838ab5da Mon Sep 17 00:00:00 2001 From: liquidaty Date: Sun, 14 Apr 2024 17:56:02 -0700 Subject: [PATCH] echo: add --contiguous option --- app/echo.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/echo.c b/app/echo.c index e64fb47c..cde03356 100644 --- a/app/echo.c +++ b/app/echo.c @@ -53,7 +53,8 @@ struct zsv_echo_data { unsigned char *skip_until_prefix; size_t skip_until_prefix_len; unsigned char trim_white:1; - unsigned char _:7; + unsigned char contiguous:1; + unsigned char _:6; }; /** @@ -95,6 +96,8 @@ static void zsv_echo_row(void *hook) { cell.str = (unsigned char *)zsv_strtrim(cell.str, &cell.len); zsv_writer_cell(data->csv_writer, i == 0, cell.str, cell.len, cell.quoted); } + } else if(VERY_UNLIKELY(data->contiguous && zsv_row_is_blank(data->parser))) { + zsv_abort(data->parser); } else { for(size_t i = 0, j = zsv_cell_count(data->parser); i < j; i++) { if(VERY_UNLIKELY(data->overwrite.row_ix == data->row_ix && data->overwrite.col_ix == i)) { @@ -132,6 +135,7 @@ const char *zsv_echo_usage_msg[] = { "Options:", " -b : output with BOM", " --trim : trim whitespace", + " --contiguous : stop output upon scanning an entire row of blank values", " --skip-until : ignore all leading rows until the first row whose first column starts with the given value ", " --overwrite : overwrite cells using given source. Source may be:", " - sqlite3://[?sql=]", @@ -229,6 +233,8 @@ int ZSV_MAIN_FUNC(ZSV_COMMAND)(int argc, const char *argv[], struct zsv_opts *op const char *arg = argv[arg_i]; if(!strcmp(arg, "-b")) writer_opts.with_bom = 1; + else if(!strcmp(arg, "--contiguous")) + data.contiguous = 1; else if(!strcmp(arg, "--trim")) data.trim_white = 1; else if(!strcmp(arg, "--skip-until")) {