File: errors.c

package info (click to toggle)
zsv 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 49,160 kB
  • sloc: ansic: 175,811; cpp: 56,301; sh: 3,623; makefile: 3,048; javascript: 577; cs: 90; awk: 70; python: 41; sql: 15
file content (45 lines) | stat: -rw-r--r-- 1,496 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
struct zsvsheet_errors_data {
  struct zsvsheet_ui_buffer *uib;
  size_t rows_fetched;
  const char *row_data[1];
};

const unsigned char **zsvsheet_errors_header(void *d) {
  struct zsvsheet_errors_data *data = d;
  data->row_data[0] = "Error";
  return (const unsigned char **)data->row_data;
}

const unsigned char *zsvsheet_errors_status(void *_) {
  (void)(_);
  return (const unsigned char *)"<esc> to exit, then :errors-clear to clear";
}

const unsigned char **zsvsheet_errors_row(void *d) {
  struct zsvsheet_errors_data *data = d;
  while (data->rows_fetched < data->uib->parse_errs.count) {
    data->row_data[0] = data->uib->parse_errs.errors[data->rows_fetched];
    data->rows_fetched++;
    if (data->row_data[0] && *data->row_data[0])
      return (const unsigned char **)data->row_data;
  }
  return NULL;
}

static zsvsheet_status zsvsheet_errors_handler(struct zsvsheet_proc_context *ctx) {
  struct zsvsheet_errors_data d = {0};
  d.uib = zsvsheet_buffer_current(ctx);
  if (!d.uib)
    return zsvsheet_status_error;
  if (ctx->proc_id == zsvsheet_builtin_proc_errors_clear) {
    uib_parse_errs_clear(&d.uib->parse_errs);
    return zsvsheet_status_ok;
  }
  if (d.uib->parse_errs.count == 0) {
    zsvsheet_ui_buffer_set_status(d.uib, "No errors");
    return zsvsheet_status_ok;
  }
  const size_t cols = 1;
  return zsvsheet_buffer_new_static(ctx, cols, zsvsheet_errors_header, zsvsheet_errors_row, zsvsheet_errors_status, &d,
                                    NULL);
}