zsv 1.4.4-x86_64-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +187 -0
  3. data/LICENSE +21 -0
  4. data/README.md +203 -0
  5. data/ext/zsv/ZSV_UPSTREAM +7 -0
  6. data/ext/zsv/common.h +22 -0
  7. data/ext/zsv/extconf.rb +102 -0
  8. data/ext/zsv/options.c +126 -0
  9. data/ext/zsv/options.h +28 -0
  10. data/ext/zsv/options_internal.h +8 -0
  11. data/ext/zsv/parser.c +503 -0
  12. data/ext/zsv/parser.h +75 -0
  13. data/ext/zsv/row.c +169 -0
  14. data/ext/zsv/row.h +45 -0
  15. data/ext/zsv/upstream.rb +55 -0
  16. data/ext/zsv/vendor/zsv/LICENSE +21 -0
  17. data/ext/zsv/vendor/zsv/VENDORED_FROM +2 -0
  18. data/ext/zsv/vendor/zsv/configure +1212 -0
  19. data/ext/zsv/vendor/zsv/include/zsv/api.h +375 -0
  20. data/ext/zsv/vendor/zsv/include/zsv/common.h +397 -0
  21. data/ext/zsv/vendor/zsv/include/zsv/ext/implementation.h +62 -0
  22. data/ext/zsv/vendor/zsv/include/zsv/ext/implementation_private.h +113 -0
  23. data/ext/zsv/vendor/zsv/include/zsv/ext/sheet.h +80 -0
  24. data/ext/zsv/vendor/zsv/include/zsv/ext.h +333 -0
  25. data/ext/zsv/vendor/zsv/include/zsv/utils/appname.h +51 -0
  26. data/ext/zsv/vendor/zsv/include/zsv/utils/arg.h +139 -0
  27. data/ext/zsv/vendor/zsv/include/zsv/utils/cache.h +49 -0
  28. data/ext/zsv/vendor/zsv/include/zsv/utils/clock.h +36 -0
  29. data/ext/zsv/vendor/zsv/include/zsv/utils/compiler.h +69 -0
  30. data/ext/zsv/vendor/zsv/include/zsv/utils/db.h +19 -0
  31. data/ext/zsv/vendor/zsv/include/zsv/utils/dirs.h +149 -0
  32. data/ext/zsv/vendor/zsv/include/zsv/utils/dl.h +22 -0
  33. data/ext/zsv/vendor/zsv/include/zsv/utils/emcc/fs_api.h +28 -0
  34. data/ext/zsv/vendor/zsv/include/zsv/utils/err.h +22 -0
  35. data/ext/zsv/vendor/zsv/include/zsv/utils/file-mem.h +18 -0
  36. data/ext/zsv/vendor/zsv/include/zsv/utils/file.h +125 -0
  37. data/ext/zsv/vendor/zsv/include/zsv/utils/jq.h +65 -0
  38. data/ext/zsv/vendor/zsv/include/zsv/utils/json.h +19 -0
  39. data/ext/zsv/vendor/zsv/include/zsv/utils/mem.h +19 -0
  40. data/ext/zsv/vendor/zsv/include/zsv/utils/memmem.h +13 -0
  41. data/ext/zsv/vendor/zsv/include/zsv/utils/os.h +145 -0
  42. data/ext/zsv/vendor/zsv/include/zsv/utils/output.h +34 -0
  43. data/ext/zsv/vendor/zsv/include/zsv/utils/overwrite.h +71 -0
  44. data/ext/zsv/vendor/zsv/include/zsv/utils/overwrite_writer.h +53 -0
  45. data/ext/zsv/vendor/zsv/include/zsv/utils/prop.h +119 -0
  46. data/ext/zsv/vendor/zsv/include/zsv/utils/rng.h +35 -0
  47. data/ext/zsv/vendor/zsv/include/zsv/utils/signal.h +25 -0
  48. data/ext/zsv/vendor/zsv/include/zsv/utils/sql.h +13 -0
  49. data/ext/zsv/vendor/zsv/include/zsv/utils/string.h +173 -0
  50. data/ext/zsv/vendor/zsv/include/zsv/utils/utf8.h +41 -0
  51. data/ext/zsv/vendor/zsv/include/zsv/utils/win/dl.h +25 -0
  52. data/ext/zsv/vendor/zsv/include/zsv/utils/writer.h +109 -0
  53. data/ext/zsv/vendor/zsv/include/zsv/zsv_export.h +33 -0
  54. data/ext/zsv/vendor/zsv/include/zsv.h.in +18 -0
  55. data/ext/zsv/vendor/zsv/src/Makefile +238 -0
  56. data/ext/zsv/vendor/zsv/src/vector_delim.c +60 -0
  57. data/ext/zsv/vendor/zsv/src/zsv.c +622 -0
  58. data/ext/zsv/vendor/zsv/src/zsv_internal.c +789 -0
  59. data/ext/zsv/vendor/zsv/src/zsv_scan_delim.c +285 -0
  60. data/ext/zsv/vendor/zsv/src/zsv_scan_delim_fast.c +741 -0
  61. data/ext/zsv/vendor/zsv/src/zsv_scan_fixed.c +88 -0
  62. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_avx2.h +89 -0
  63. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_neon.h +80 -0
  64. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_sse2.h +93 -0
  65. data/ext/zsv/vendor/zsv/src/zsv_scan_simd_wasm.h +79 -0
  66. data/ext/zsv/vendor/zsv/src/zsv_strencode.c +84 -0
  67. data/ext/zsv/zsv_ext.c +417 -0
  68. data/lib/zsv/3.3/zsv.so +0 -0
  69. data/lib/zsv/3.4/zsv.so +0 -0
  70. data/lib/zsv/4.0/zsv.so +0 -0
  71. data/lib/zsv/errors.rb +32 -0
  72. data/lib/zsv/input.rb +88 -0
  73. data/lib/zsv/options.rb +132 -0
  74. data/lib/zsv/strict_validator.rb +124 -0
  75. data/lib/zsv/version.rb +5 -0
  76. data/lib/zsv.rb +183 -0
  77. metadata +196 -0
@@ -0,0 +1,397 @@
1
+ /*
2
+ * Copyright (C) 2021 Tai Chi Minh Ralph Eastwood, Matt Wong and Guarnerix dba Liquidaty
3
+ * All rights reserved
4
+ *
5
+ * This file is part of zsv/lib, distributed under the license defined at
6
+ * https://opensource.org/licenses/MIT
7
+ */
8
+
9
+ #ifndef ZSV_COMMON_H
10
+ #define ZSV_COMMON_H
11
+
12
+ #ifdef __cplusplus
13
+ #define ZSV_BEGIN_DECL extern "C" {
14
+ #define ZSV_END_DECL }
15
+ #else
16
+ #define ZSV_BEGIN_DECL
17
+ #define ZSV_END_DECL /* empty */
18
+ #endif
19
+
20
+ enum zsv_status {
21
+ zsv_status_ok = 0,
22
+ zsv_status_cancelled,
23
+ zsv_status_no_more_input,
24
+ zsv_status_invalid_option,
25
+ zsv_status_memory,
26
+ zsv_status_error,
27
+ zsv_status_row,
28
+ /* Fast SIMD engine only: input violates RFC 4180 (e.g. a quote in the
29
+ * middle of an unquoted cell). The fast engine requires standard CSV;
30
+ * use ZSV_MODE_COMPAT (the scalar/legacy engine) for non-standard input. */
31
+ zsv_status_nonstandard_csv,
32
+ zsv_status_done = 100
33
+ #ifdef ZSV_EXTRAS
34
+ ,
35
+ zsv_status_max_rows_read = 999
36
+ #endif
37
+ };
38
+
39
+ /**
40
+ * `zsv_parser` is the type of a zsv parser handle
41
+ */
42
+ typedef struct zsv_scanner *zsv_parser;
43
+
44
+ /**
45
+ * Structure returned by `zsv_get_cell()` for fetching a parsed CSV cell value
46
+ */
47
+ struct zsv_cell {
48
+ /**
49
+ * address of cell contents (not null-terminated)
50
+ */
51
+ unsigned char *str;
52
+
53
+ /**
54
+ * length of cell contents
55
+ */
56
+ size_t len;
57
+
58
+ /**
59
+ * bitfield values for `quoted` flags
60
+ */
61
+ #define ZSV_PARSER_QUOTE_NONE 0 /* content does not need to be quoted */
62
+ #define ZSV_PARSER_QUOTE_UNCLOSED 1 /* only used internally by parser */
63
+ #define ZSV_PARSER_QUOTE_CLOSED 2 /* value was quoted */
64
+ #define ZSV_PARSER_QUOTE_NEEDED 4 /* value contains delimiter or dbl-quote */
65
+ #define ZSV_PARSER_QUOTE_EMBEDDED 8 /* value contains dbl-quote */
66
+ #define ZSV_PARSER_QUOTE_PENDING 16 /* only used internally by parser */
67
+ #define ZSV_PARSER_QUOTE_PENDING_LF 32 /* only used internally by parser */
68
+ /**
69
+ * quoted flags enable additional efficiency, in particular when input data will
70
+ * be output as text (csv, json etc), by indicating whether the cell contents may
71
+ * require special handling. For example, if the caller will output the cell value as
72
+ * CSV and quoted == 0, the caller need not scan the cell contents to check if
73
+ * quoting or escaping will be required
74
+ */
75
+ char quoted;
76
+ unsigned char overwritten : 1;
77
+ };
78
+
79
+ typedef size_t (*zsv_generic_write)(const void *restrict, size_t, size_t, void *restrict);
80
+ typedef size_t (*zsv_generic_read)(void *restrict, size_t n, size_t size, void *restrict);
81
+ typedef int (*zsv_generic_seek)(void *, long, int);
82
+
83
+ #define zsv_generic_fprintf (int (*)(void *, const char *, ...)) fprintf;
84
+ #define zsv_generic_fclose (int (*)(void *)) fclose;
85
+
86
+ #ifdef ZSV_EXTRAS
87
+ /**
88
+ * progress callback function signature
89
+ * @param context pointer set in parser opts.progress.ctx
90
+ * @param cumulative_row_count number of input rows read so far
91
+ * @return zero to continue processing, non-zero to cancel parse
92
+ */
93
+ typedef int (*zsv_progress_callback)(void *ctx, size_t cumulative_row_count);
94
+
95
+ /**
96
+ * completed callback function signature
97
+ * @param context pointer set in parser opts.progress.ctx
98
+ * @param exit code
99
+ */
100
+ typedef void (*zsv_completed_callback)(void *ctx, int code);
101
+
102
+ /**
103
+ * Data can be "overwritten" on-the-fly by providing custom callbacks
104
+ * data from the calling code is passed to the zsv library
105
+ * via the `zsv_overwrite_data` structure
106
+ */
107
+ struct zsv_overwrite_data {
108
+ size_t row_ix; // 0-based
109
+ size_t col_ix; // 0-based
110
+ size_t timestamp;
111
+ struct zsv_cell val;
112
+ struct zsv_cell author;
113
+ struct zsv_cell old_value;
114
+ char have; // 1 = we have unprocessed overwrites
115
+ };
116
+
117
+ struct zsv_opt_overwrite {
118
+ void *ctx;
119
+ enum zsv_status (*open)(void *ctx);
120
+ enum zsv_status (*next)(void *ctx, struct zsv_overwrite_data *odata);
121
+ enum zsv_status (*close)(void *ctx);
122
+ char cancel; // explicitly cancel application of overwrites
123
+ };
124
+
125
+ #endif
126
+
127
+ struct zsv_opts {
128
+ /**
129
+ * Callback that is called for each row that is parsed. In most use cases,
130
+ * this is where most of the code logic resides
131
+ */
132
+ void (*row_handler)(void *ctx);
133
+
134
+ /**
135
+ * Callback that is called immediately after a cell is parsed.
136
+ * The most common usage pattern is to omit the cell handler, and just loop
137
+ * through each cell in the `row_handler`. But if you prefer, you can use
138
+ * only a cell handler, or both a cell handler and a row handler.
139
+ */
140
+ void (*cell_handler)(void *ctx, unsigned char *utf8_value, size_t len);
141
+
142
+ /**
143
+ * If a row was too long to fit in the allocated memory, then
144
+ * if `overflow_row_handler` is set, it will be called after the remaining
145
+ * portion of the row is parsed. For example, if a row consists of
146
+ * XXXXX,YYYYY and there is only enough memory to hold XXXX
147
+ * then `row_handler()` will be called after parsing `XXXX,` and
148
+ * `overflow_row_handler()` called twice, after parsing `X,YY` and `YYY`,
149
+ * before the subsequent row is parsed
150
+ *
151
+ * Note: we considered adding a callback that would be called before the initial
152
+ * `row_handler()` call, in the event that a subsequent `overflow_row_handler()`
153
+ * call was anticipated. Because this scenario occurs so infrequently, we
154
+ * decided to keep it simple with a single callback. But we may reconsider
155
+ * if there is demand for that (or another) alternative approach
156
+ */
157
+ void (*overflow_row_handler)(void *ctx);
158
+
159
+ /**
160
+ * The context that is passed to each of our handlers
161
+ */
162
+ void *ctx;
163
+
164
+ /**
165
+ * Caller can specify its own read function for fetching data to be parsed
166
+ * If not specified, the default value is `fread()`
167
+ */
168
+ zsv_generic_read read;
169
+
170
+ /**
171
+ * Caller can specify its own seek function for setting the file position
172
+ * with zsv_index_seek. If not specified, the default value is `fseek()`
173
+ */
174
+ zsv_generic_seek seek;
175
+
176
+ /**
177
+ * Caller can specify its own stream that is passed to the read function
178
+ * If not specified, the default value is stdin
179
+ */
180
+ void *stream;
181
+
182
+ /**
183
+ * Caller can specify its own buffer for the parser to use of at least
184
+ * ZSV_MIN_SCANNER_BUFFSIZE (4096) in size. If not provided, an internal
185
+ * buffer is allocated
186
+ */
187
+ unsigned char *buff;
188
+
189
+ /**
190
+ * If caller specifies its own buffer, this should be its size
191
+ * Otherwise, this can be specified as the size of the internal buffer that
192
+ * will be created, subject to increase if/as appropriate if max_row_size
193
+ * is specified. Defaults to 256k
194
+ *
195
+ * cli option: -B,--buff-size
196
+ */
197
+ size_t buffsize;
198
+
199
+ /**
200
+ * Maximum number of columns to parse. defaults to 1024
201
+ *
202
+ * cli option: -c,--max-column-count
203
+ */
204
+ unsigned max_columns;
205
+
206
+ /**
207
+ * maximum row size can be used as an alternative way to specify the
208
+ * internal buffer size, which will be at least as large as max_row_size * 2
209
+ *
210
+ * cli option: -r,--max-row-size
211
+ */
212
+ unsigned max_row_size;
213
+
214
+ /**
215
+ * delimiter: typically a comma or tab
216
+ * can be any char other than newline, form feed or quote
217
+ * defaults to comma
218
+ *
219
+ * cli option: -t,--tab-delim or -O,--other-delim <delim>
220
+ */
221
+ char delimiter;
222
+
223
+ /**
224
+ * no_quotes: if > 0, this flag indicates that the parser should treat double-quotes
225
+ * just like any ordinary character
226
+ * defaults to 0
227
+ *
228
+ * cli option: -q,--no-quote
229
+ */
230
+ char no_quotes;
231
+
232
+ #ifndef ZSV_NO_ONLY_CRLF
233
+ /**
234
+ * only_crlf_rowend: if non-zero, *only* accept CRLF as row end
235
+ *
236
+ * cli option: --only-crlf
237
+ */
238
+ char only_crlf_rowend;
239
+ #endif
240
+ /**
241
+ * scan engine: 0 = default, 3 = fast (branchless SIMD)
242
+ *
243
+ * cli option: --parser <default|fast|compat>
244
+ */
245
+ unsigned char scan_engine;
246
+
247
+ /**
248
+ * flag to print more verbose messages to the console
249
+ * cli option: -v,--verbose
250
+ */
251
+ char verbose;
252
+
253
+ /**
254
+ * if the actual data does not have a header row with column names, the caller
255
+ * should provide one (in CSV format) which will be treated as if it was the
256
+ * first row of data
257
+ *
258
+ * cli option: -0,--header-row
259
+ */
260
+ const char *insert_header_row;
261
+
262
+ /**
263
+ * number of rows that the header row spans. If 0 or 1, header is assumed to span 1 row
264
+ * otherwise, set to number > 1 to span multiple rows
265
+ */
266
+ unsigned int header_span;
267
+
268
+ /**
269
+ * number of rows to ignore before the initial row is processed
270
+ */
271
+ unsigned int rows_to_ignore;
272
+
273
+ /**
274
+ * by default, zsv ignores empty header rows; the number of ignored rows
275
+ * can be fetched via `zsv_get_empty_header_rows()`). To disable this
276
+ * behavior, set `keep_empty_header_rows` to 1
277
+ */
278
+ unsigned char keep_empty_header_rows;
279
+
280
+ /**
281
+ * by default, zsv ignores malformed UTF8; set malformed_utf8_replace to
282
+ * a value between 1 and 127 to replace malformed UTF8 with that single
283
+ * char, to ZSV_MALFORMED_UTF8_REMOVE to remove
284
+ * or ZSV_MALFORMED_UTF8_DO_NOT_REPLACE to explicitly leave untouched
285
+ */
286
+ #define ZSV_MALFORMED_UTF8_DO_NOT_REPLACE -2
287
+ #define ZSV_MALFORMED_UTF8_REMOVE -1
288
+ char malformed_utf8_replace;
289
+
290
+ /**
291
+ * `overrides` is a bitfield that indicates what ZSV options, if any, were
292
+ * specifically set in the command invocation and is used to ensure
293
+ * that option values set in the command invocation take priority over
294
+ * default values, or values saved in related property values such as
295
+ * .zsv/data/<filename>/props.json
296
+ *
297
+ * For example, if a file has a saved header row span of 2, but the
298
+ * command-line arguments explicitly included `--header-row-span 3`,
299
+ * then setting header_span to 3 and setting overrides.header_row_span
300
+ * ensures that the value of 3 is used
301
+ */
302
+ struct {
303
+ unsigned char header_row_span : 1;
304
+ unsigned char skip_head : 1;
305
+ unsigned char max_column_count : 1;
306
+ unsigned char malformed_utf8_replacement : 1;
307
+ unsigned char _ : 4;
308
+ } option_overrides;
309
+
310
+ /**
311
+ * Optional file path to be treated as the input's path when locating
312
+ * cached file properties (.zsv/data/<filepath>/). Applied only to an
313
+ * input that has no path of its own (e.g. stdin); an input read from an
314
+ * actual file keeps its own property lookup. Consumed when loading cached
315
+ * properties (by zsv_new_with_properties(), and directly by `sql` for
316
+ * buffered stdin input); ignored by zsv_new(). Has no effect on which
317
+ * data is parsed
318
+ *
319
+ * cli option: --stdin-filename <path>
320
+ */
321
+ const char *stdin_filename;
322
+
323
+ int (*errprintf)(void *ctx, const char *format, ...);
324
+ void *errf;
325
+ int (*errclose)(void *ctx);
326
+
327
+ #ifdef ZSV_EXTRAS
328
+ struct {
329
+ /**
330
+ * min number of rows between progress callback calls
331
+ */
332
+ size_t rows_interval;
333
+
334
+ /**
335
+ * min number of seconds b/w callback calls
336
+ */
337
+ unsigned int seconds_interval;
338
+
339
+ /**
340
+ * Progress callback, called periodically to provide progress updates
341
+ */
342
+ zsv_progress_callback callback;
343
+
344
+ /**
345
+ * Context passed to the callback, when the callback is invoked
346
+ */
347
+ void *ctx;
348
+ } progress;
349
+
350
+ struct {
351
+ /**
352
+ * Optional callback. If set, it is called by zsv_finish()
353
+ */
354
+ zsv_completed_callback callback;
355
+ /**
356
+ * Context passed to the callback, when the callback is invoked
357
+ */
358
+ void *ctx;
359
+ } completed;
360
+
361
+ /**
362
+ * maximum number of rows to parse (including any header rows)
363
+ */
364
+ size_t max_rows;
365
+
366
+ /**
367
+ * If non-zero, automatically apply overwrites located in
368
+ * /path/to/.zsv/data/my-data.csv/overwrite.sqlite3 for a given
369
+ * input /path/to/my-data.csv
370
+ *
371
+ * This flag is only used by zsv_new_with_properties()
372
+ * if using zsv_new(), this flag is ignored (use the `overwrite` structure instead)
373
+ */
374
+ char overwrite_auto;
375
+
376
+ /**
377
+ * Optional cell-level values that overwrite data returned to the caller by the API
378
+ * Use when not using overwrite_auto together with zsv_new_with_properties()
379
+ */
380
+ struct zsv_opt_overwrite overwrite;
381
+
382
+ #endif /* ZSV_EXTRAS */
383
+
384
+ /**
385
+ * optional handler invoked when a cell contains malformed UTF8, whatever
386
+ * `malformed_utf8_replace` says to do about it: called at most once per
387
+ * cell, with the cell's index in the current row and the number of
388
+ * malformed sequences scanned. Not invoked for cells past the row's cell
389
+ * limit (overflow), nor in fixed-width mode.
390
+ * Last in the struct so consumers built against the prior layout keep
391
+ * their field offsets (a size change still requires a rebuild)
392
+ */
393
+ void (*malformed_utf8_handler)(void *ctx, size_t cell_ix, size_t count);
394
+ void *malformed_utf8_handler_ctx;
395
+ };
396
+
397
+ #endif
@@ -0,0 +1,62 @@
1
+ /*
2
+ * Copyright (C) 2021 Liquidaty and the zsv/lib contributors
3
+ * All rights reserved
4
+ *
5
+ * This file is part of zsv/lib, distributed under the license defined at
6
+ * https://opensource.org/licenses/MIT
7
+ */
8
+
9
+ #ifndef ZSV_EXT_PRIVATE_H
10
+ #define ZSV_EXT_PRIVATE_H
11
+
12
+ #include <zsv/ext.h>
13
+
14
+ /**
15
+ * @file zsv_ext.h
16
+ * @brief ZSV extension implementation specification
17
+ * @defgroup zsv_extension implementation specification
18
+ * @ingroup ZSV
19
+ * @{
20
+ */
21
+
22
+ /**
23
+ * Overridable compiler flag ZSV_EXT=1 indicates that we are compiling a ZSV
24
+ * extension
25
+ */
26
+ #ifndef ZSV_EXT
27
+ #define ZSV_EXT 1
28
+ #endif
29
+
30
+ ZSV_BEGIN_DECL
31
+
32
+ /**
33
+ * To build a zsv extension:
34
+ * - implement the following required functions:
35
+ * `zsv_ext_id`
36
+ * `zsv_ext_init`
37
+ * `zsv_ext_main`
38
+ *
39
+ * - optionally, implement the following recommended functions:
40
+ * `zsv_ext_help`
41
+ * `zsv_ext_errstr`
42
+ * `zsv_ext_version`
43
+ * `zsv_ext_license`
44
+ *
45
+ * - on Windows, be sure to decorate your function definitions
46
+ * with ZSV_EXT_EXPORT
47
+ */
48
+
49
+ #ifdef _WIN32
50
+ #define ZSV_EXT_EXPORT __declspec(dllexport)
51
+ #elif __EMSCRIPTEN__
52
+ #include <emscripten.h>
53
+ #define ZSV_EXT_EXPORT EMSCRIPTEN_KEEPALIVE
54
+ #else
55
+ #define ZSV_EXT_EXPORT
56
+ #endif
57
+
58
+ #include "implementation_private.h"
59
+
60
+ /** @} */
61
+ ZSV_END_DECL
62
+ #endif
@@ -0,0 +1,113 @@
1
+ /*
2
+ * Copyright (C) 2021 Liquidaty and the zsv/lib contributors
3
+ * All rights reserved
4
+ *
5
+ * This file is part of zsv/lib, distributed under the license defined at
6
+ * https://opensource.org/licenses/MIT
7
+ */
8
+
9
+ /**
10
+ * @file zsv_ext_private.h
11
+ * @brief ZSV extension implementation specification
12
+ * @defgroup zsv_extension implementation specification
13
+ * @ingroup ZSV
14
+ * @{
15
+ */
16
+
17
+ /**
18
+ * Return a module identifier, which must be a 2-char string
19
+ *
20
+ * Required. Any sub-command that starts with this id followed by a dash
21
+ * will be passed on to this module
22
+ *
23
+ * Your DLL or shared lib filename must correspondingly be "zsvext<id>"
24
+ *
25
+ * For example, to implement sub-commands that begin with "my-":
26
+ * - your function zsv_ext_id() would return "my"
27
+ * - your library would be named zsvextmy.dll (or .so or .dylib)
28
+ */
29
+ ZSV_EXT_EXPORT
30
+ const char *zsv_ext_id(void);
31
+
32
+ /**
33
+ * Initialize your module
34
+ *
35
+ * Called once, when your library is loaded
36
+ *
37
+ * @param callbacks Pointer to struct holding zsvlib function pointers
38
+ * @return Zero on success, non-zero on fail
39
+ */
40
+ ZSV_EXT_EXPORT
41
+ enum zsv_ext_status zsv_ext_init(struct zsv_ext_callbacks *callbacks, zsv_execution_context ctx);
42
+
43
+ /**
44
+ * Get your extension's internal error code
45
+ *
46
+ * In the case that any of your module functions return zsv_ext_status_error
47
+ * this function is called to obtain your extension's internal error code
48
+ *
49
+ * @param context Execution context
50
+ * @return Error code
51
+ */
52
+ ZSV_EXT_EXPORT
53
+ int zsv_ext_errcode(zsv_execution_context context);
54
+
55
+ /**
56
+ * Get an error message
57
+ *
58
+ * In the case that any of your module functions return zsv_ext_status_error,
59
+ * this function is called to obtain the message corresponding to the internal
60
+ * error code returned by zsv_ext_errcode()
61
+ *
62
+ * @param context Execution context
63
+ * @param int Return code from zsv_ext_errcode()
64
+ * @return Error message to display
65
+ */
66
+ ZSV_EXT_EXPORT
67
+ char *zsv_ext_errstr(zsv_execution_context context, int err);
68
+
69
+ /**
70
+ * Free an error message
71
+ *
72
+ * Called after obtaining any non-NULL result from `zsv_ext_errstr()`
73
+ *
74
+ * @param errstr The string returned from zsv_ext_errstr()
75
+ */
76
+ ZSV_EXT_EXPORT
77
+ void zsv_ext_errfree(char *errstr);
78
+
79
+ /**
80
+ * Exit your module
81
+ *
82
+ * Called once, when your library is unloaded
83
+ *
84
+ * @return Zero on success, non-zero on fail
85
+ */
86
+ ZSV_EXT_EXPORT
87
+ enum zsv_ext_status zsv_ext_exit(void);
88
+
89
+ /**
90
+ * Help message. Displayed when user enters any command beginning with
91
+ * `zsv help <module-id>`
92
+ *
93
+ * @param argc Number of arguments
94
+ * @param argv Arguments
95
+ */
96
+ ZSV_EXT_EXPORT
97
+ const char *const *zsv_ext_help(int argc, const char *argv[]);
98
+
99
+ /**
100
+ * License message. Displayed when user enters any command beginning with
101
+ * `zsv license <module-id>`
102
+ *
103
+ */
104
+ ZSV_EXT_EXPORT
105
+ const char *const *zsv_ext_license(void);
106
+
107
+ /**
108
+ * Version message. Displayed when user enters any command beginning with
109
+ * `zsv version <module-id>`
110
+ *
111
+ */
112
+ ZSV_EXT_EXPORT
113
+ const char *const *zsv_ext_version(void);
@@ -0,0 +1,80 @@
1
+ #ifndef ZSVSHEET_H
2
+ #define ZSVSHEET_H
3
+
4
+ /* custom sheet handler id */
5
+ typedef int zsvsheet_proc_id_t;
6
+
7
+ typedef struct zsvsheet_proc_context *zsvsheet_proc_context_t;
8
+
9
+ typedef enum zsvsheet_status {
10
+ zsvsheet_status_ok = 0,
11
+ zsvsheet_status_error,
12
+ zsvsheet_status_ignore,
13
+ zsvsheet_status_duplicate,
14
+ zsvsheet_status_memory,
15
+ zsvsheet_status_exit,
16
+ zsvsheet_status_busy,
17
+ zsvsheet_status_no_data
18
+ } zsvsheet_status;
19
+
20
+ typedef struct zsvsheet_context *zsvsheet_context_t;
21
+ typedef struct zsvsheet_subcommand_context *zsvsheet_subcommand_context_t;
22
+
23
+ typedef void *zsvsheet_buffer_t;
24
+ // int zsvsheet_ext_keypress(zsvsheet_proc_context_t);
25
+
26
+ typedef struct zsvsheet_transformation *zsvsheet_transformation;
27
+ /**
28
+ * Transformation options passed to zsvsheet_push_transformation
29
+ */
30
+ struct zsvsheet_buffer_transformation_opts {
31
+ /**
32
+ * Caller supplied context; can be retrieved with ext_sheet_transformation_user_context(trn).
33
+ *
34
+ * This is free'd by the library after on_done is called unless it is NULL. That holds
35
+ * for every outcome, including zsvsheet_status_busy -- so a caller that retries must
36
+ * build a fresh context rather than reuse the opts it just passed.
37
+ */
38
+ void *user_context;
39
+ /**
40
+ * This is called each time a row is parsed and available.
41
+ *
42
+ * It can be used to write out a new row immediately or contribute to a calculation
43
+ * where the partial results are stored in the context.
44
+ *
45
+ * Note that when doing a reduction which does not produce output until the end;
46
+ * it is best to write out a header row in the row_handler and flush the writer. Otherwise the
47
+ * main thread will be blocked waiting for something to display.
48
+ *
49
+ * Once some data has been written to the output file execution is moved to a background thread.
50
+ *
51
+ * The parser can be retrieved with ext_sheet_transformation_parser(trn),
52
+ * the output file writer can be retrieved with ext_sheet_transformation_writer(trn),
53
+ * the context can be retrieved with ext_sheet_transformation_user_context(trn),
54
+ * and so on
55
+ */
56
+ void (*row_handler)(zsvsheet_transformation trn);
57
+ /**
58
+ * Called when the parser has no more data or was cancelled.
59
+ *
60
+ * This can be used to free resources, complete a calculation or to write out one
61
+ * or more final rows.
62
+ *
63
+ * For small input files this may be executed in the main thread, for larger ones
64
+ * it will be done in a background thread. So if an operation done inside this handler
65
+ * can take a long time even on small inputs then it could block the main thread.
66
+ *
67
+ * Called exactly once. If the transformation failed before it was created, trn is
68
+ * a stub: its parser, writer, filename and buffer are all NULL, and
69
+ * ext_sheet_transformation_user_context(trn) may itself be NULL. So this handler
70
+ * must not dereference anything it did not itself allocate.
71
+ */
72
+ void (*on_done)(zsvsheet_transformation trn);
73
+ };
74
+
75
+ struct zsvsheet_rowcol {
76
+ size_t row;
77
+ size_t col;
78
+ };
79
+
80
+ #endif