Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

echo: add --contiguous option #166

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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 <value>: ignore all leading rows until the first row whose first column starts with the given value ",
" --overwrite <source>: overwrite cells using given source. Source may be:",
" - sqlite3://<filename>[?sql=<query>]",
Expand Down Expand Up @@ -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")) {
Expand Down