-
Notifications
You must be signed in to change notification settings - Fork 1
/
bsv.c
37 lines (30 loc) · 830 Bytes
/
bsv.c
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
#include "csv.h"
#include "dump.h"
#define DESCRIPTION "convert csv to bsv\n\n"
#define USAGE "... | bsv\n\n"
#define EXAMPLE ">> echo a,b,c | bsv | bcut 3,2,1 | csv\nc,b,a\n"
int main(int argc, char **argv) {
// setup bsv
SETUP();
// setup input
CSV_INIT();
// setup output
writebuf_t wbuf = wbuf_init((FILE*[]){stdout}, 1, false);
// setup state
row_t row;
// process input row by row
while (1) {
CSV_READ_LINE(stdin);
if (csv_stop)
break;
if (csv_max > 0 || csv_sizes[0] > 0) {
row.max = csv_max;
for (i32 i = 0; i <= row.max; i++) {
row.columns[i] = csv_columns[i];
row.sizes[i] = csv_sizes[i];
}
dump(&wbuf, &row, 0);
}
}
dump_flush(&wbuf, 0);
}