Skip to content

Commit

Permalink
Revert "sheet/index: Fix and test multi-line headings and line endings (
Browse files Browse the repository at this point in the history
#264)"

This reverts commit 7086ed0.
  • Loading branch information
liquidaty authored Nov 6, 2024
1 parent 7086ed0 commit f1317bc
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 2,850 deletions.
2 changes: 0 additions & 2 deletions app/sheet/read-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ static int read_data(struct zsvsheet_ui_buffer **uibufferp, // a new zsvsheet_

enum zsv_index_status zst;
if (uibuff->index_ready) {
opts.header_span = 0;
opts.rows_to_ignore = 0;
zst = zsv_index_seek_row(uibuff->index, &opts, start_row);

remaining_header_to_skip = 0;
Expand Down
23 changes: 1 addition & 22 deletions app/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ test-compare: test-%: ${BUILD_DIR}/bin/zsv_%${EXE}

test-sheet: test-%: ${BUILD_DIR}/bin/zsv_%${EXE} worldcitiespop_mil.csv test-sheet-all

test-sheet-all: test-sheet-1 test-sheet-2 test-sheet-3 test-sheet-4 test-sheet-5 test-sheet-6 test-sheet-7
test-sheet-all: test-sheet-1 test-sheet-2 test-sheet-3 test-sheet-4 test-sheet-5
@(for SESSION in $^; do ! tmux kill-session -t "$$SESSION" 2>/dev/null; done && ${TEST_PASS} || ${TEST_FAIL})

test-sheet-1: ${BUILD_DIR}/bin/zsv_sheet${EXE}
Expand Down Expand Up @@ -628,24 +628,3 @@ test-sheet-5: ${BUILD_DIR}/bin/zsv_sheet${EXE}
tmux send-keys -t $@ "q" && \
${CMP} ${TMP_DIR}/$@.out expected/$@.out && ${TEST_PASS} || ${TEST_FAIL})

test-sheet-6: ${BUILD_DIR}/bin/zsv_sheet${EXE}
@${TEST_INIT}
@echo 'set-option default-terminal "tmux-256color"' > ~/.tmux.conf
@(tmux new-session -x 80 -y 50 -d -s $@ "${PREFIX} $< -d 3 ${TEST_DATA_DIR}/test/mixed-line-endings.csv" && \
sleep 0.5 && \
tmux send-keys -t $@ "G" "C-u" "C-u" "C-u" && \
sleep 0.5 && \
tmux capture-pane -t $@ -p ${REDIRECT1} ${TMP_DIR}/$@.out && \
tmux send-keys -t $@ "q" && \
${CMP} ${TMP_DIR}/$@.out expected/$@.out && ${TEST_PASS} || ${TEST_FAIL})

test-sheet-7: ${BUILD_DIR}/bin/zsv_sheet${EXE}
@${TEST_INIT}
@echo 'set-option default-terminal "tmux-256color"' > ~/.tmux.conf
@(tmux new-session -x 80 -y 5 -d -s $@ "${PREFIX} $< -d 3 ${TEST_DATA_DIR}/test/mixed-line-endings.csv" && \
sleep 0.5 && \
tmux send-keys -t $@ "G" "g" "g" "C-u" "/" "1234" "Enter" && \
sleep 0.5 && \
tmux capture-pane -t $@ -p ${REDIRECT1} ${TMP_DIR}/$@.out && \
tmux send-keys -t $@ "q" && \
${CMP} ${TMP_DIR}/$@.out expected/$@.out && ${TEST_PASS} || ${TEST_FAIL})
50 changes: 0 additions & 50 deletions app/test/expected/test-sheet-6.out

This file was deleted.

5 changes: 0 additions & 5 deletions app/test/expected/test-sheet-7.out

This file was deleted.

35 changes: 11 additions & 24 deletions app/utils/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct zsv_index *zsv_index_new(void) {
enum zsv_index_status zsv_index_add_row(struct zsv_index *ix, zsv_parser parser) {
struct zsv_index_array *arr = ix->array;
size_t len = arr->len, cap = arr->capacity;
uint64_t line_end = zsv_cum_scanned_length(parser);
uint64_t line_end = zsv_cum_scanned_length(parser) + 1;

if (!ix->header_line_end) {
ix->header_line_end = line_end;
Expand Down Expand Up @@ -89,8 +89,8 @@ static void seek_row_handler(void *ctx) {
zsv_abort(c->parser);
}

static enum zsv_index_status seek_and_check_newline(long *offset, struct zsv_opts *opts) {
char new_line[2];
static enum zsv_index_status seek_and_check_newline(long offset, struct zsv_opts *opts) {
char maybe_space;
zsv_generic_read read = (zsv_generic_read)fread;
zsv_generic_seek seek = (zsv_generic_seek)fseek;
FILE *stream = opts->stream;
Expand All @@ -101,30 +101,17 @@ static enum zsv_index_status seek_and_check_newline(long *offset, struct zsv_opt
if (opts->read)
read = opts->read;

if (seek(stream, *offset, SEEK_SET))
if (seek(stream, offset, SEEK_SET))
return zsv_index_status_error;

size_t nmemb = read(new_line, 1, 2, stream);

if (nmemb < 1)
if (read(&maybe_space, 1, 1, stream) != 1)
return zsv_index_status_error;

if (new_line[0] == '\n') {
*offset += 1;
} else if (new_line[0] == '\r') {
if (new_line[1] == '\n') {
*offset += 1;
return zsv_index_status_ok;
}

*offset += 1;
} else {
return zsv_index_status_error;
if (!isspace(maybe_space)) {
if (seek(stream, offset, SEEK_SET))
return zsv_index_status_error;
}

if (seek(stream, *offset, SEEK_SET))
return zsv_index_status_error;

return zsv_index_status_ok;
}

Expand All @@ -136,7 +123,7 @@ enum zsv_index_status zsv_index_seek_row(const struct zsv_index *ix, struct zsv_
if (zist != zsv_index_status_ok)
return zist;

if ((zist = seek_and_check_newline((long *)&offset, opts)) != zsv_index_status_ok)
if ((zist = seek_and_check_newline(offset, opts)) != zsv_index_status_ok)
return zist;

if (!remaining_rows)
Expand All @@ -159,9 +146,9 @@ enum zsv_index_status zsv_index_seek_row(const struct zsv_index *ix, struct zsv_
if (zst != zsv_status_cancelled)
return zsv_index_status_error;

offset += zsv_cum_scanned_length(parser);
offset += zsv_cum_scanned_length(parser) + 1;

zsv_delete(parser);

return seek_and_check_newline((long *)&offset, opts);
return seek_and_check_newline(offset, opts);
}
Loading

0 comments on commit f1317bc

Please sign in to comment.