]> sigrok.org Git - libsigrok.git/blob - src/input/csv.c
db6f46767e9688a5eb8c4483f1d693f00a9c6542
[libsigrok.git] / src / input / csv.c
1 /*
2  * This file is part of the libsigrok project.
3  *
4  * Copyright (C) 2013 Marc Schink <sigrok-dev@marcschink.de>
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 #include <config.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <glib.h>
24 #include <libsigrok/libsigrok.h>
25 #include "libsigrok-internal.h"
26
27 #define LOG_PREFIX "input/csv"
28
29 /*
30  * The CSV input module has the following options:
31  *
32  * single-column: Specifies the column number which stores the sample data for
33  *                single column mode and enables single column mode. Multi
34  *                column mode is used if this parameter is omitted.
35  *
36  * numchannels:   Specifies the number of channels to use. In multi column mode
37  *                the number of channels are the number of columns and in single
38  *                column mode the number of bits (LSB first) beginning at
39  *                'first-channel'.
40  *
41  * delimiter:     Specifies the delimiter for columns. Must be at least one
42  *                character. Comma is used as default delimiter.
43  *
44  * format:        Specifies the format of the sample data in single column mode.
45  *                Available formats are: 'bin', 'hex' and 'oct'. The binary
46  *                format is used by default. This option has no effect in multi
47  *                column mode.
48  *
49  * comment:       Specifies the prefix character(s) for comments. No prefix
50  *                characters are used by default which disables removing of
51  *                comments.
52  *
53  * samplerate:    Samplerate which the sample data was captured with. Default
54  *                value is 0.
55  *
56  * first-channel: Column number of the first channel in multi column mode and
57  *                position of the bit for the first channel in single column mode.
58  *                Default value is 0.
59  *
60  * header:        Determines if the first line should be treated as header
61  *                and used for channel names in multi column mode. Empty header
62  *                names will be replaced by the channel number. If enabled in
63  *                single column mode the first line will be skipped. Usage of
64  *                header is disabled by default.
65  *
66  * startline:     Line number to start processing sample data. Must be greater
67  *                than 0. The default line number to start processing is 1.
68  */
69
70 /* Single column formats. */
71 enum {
72         FORMAT_BIN,
73         FORMAT_HEX,
74         FORMAT_OCT
75 };
76
77 struct context {
78         gboolean started;
79
80         /* Current selected samplerate. */
81         uint64_t samplerate;
82
83         /* Number of channels. */
84         unsigned int num_channels;
85
86         /* Column delimiter character(s). */
87         GString *delimiter;
88
89         /* Comment prefix character(s). */
90         GString *comment;
91
92         /* Termination character(s) used in current stream. */
93         char *termination;
94
95         /* Determines if sample data is stored in multiple columns. */
96         gboolean multi_column_mode;
97
98         /* Column number of the sample data in single column mode. */
99         unsigned int single_column;
100
101         /*
102          * Number of the first column to parse. Equivalent to the number of the
103          * first channel in multi column mode and the single column number in
104          * single column mode.
105          */
106         unsigned int first_column;
107
108         /*
109          * Column number of the first channel in multi column mode and position of
110          * the bit for the first channel in single column mode.
111          */
112         unsigned int first_channel;
113
114         /* Line number to start processing. */
115         size_t start_line;
116
117         /*
118          * Determines if the first line should be treated as header and used for
119          * channel names in multi column mode.
120          */
121         gboolean header;
122
123         /* Format sample data is stored in single column mode. */
124         int format;
125
126         /* Size of the sample buffer. */
127         size_t sample_buffer_size;
128
129         /* Buffer to store sample data. */
130         uint8_t *sample_buffer;
131
132         /* Current line number. */
133         size_t line_number;
134 };
135
136 static void strip_comment(char *buf, const GString *prefix)
137 {
138         char *ptr;
139
140         if (!prefix->len)
141                 return;
142
143         if ((ptr = strstr(buf, prefix->str)))
144                 *ptr = '\0';
145 }
146
147 static int parse_binstr(const char *str, struct context *inc)
148 {
149         gsize i, j, length;
150
151         length = strlen(str);
152
153         if (!length) {
154                 sr_err("Column %u in line %zu is empty.", inc->single_column,
155                         inc->line_number);
156                 return SR_ERR;
157         }
158
159         /* Clear buffer in order to set bits only. */
160         memset(inc->sample_buffer, 0, (inc->num_channels + 7) >> 3);
161
162         i = inc->first_channel;
163
164         for (j = 0; i < length && j < inc->num_channels; i++, j++) {
165                 if (str[length - i - 1] == '1') {
166                         inc->sample_buffer[j / 8] |= (1 << (j % 8));
167                 } else if (str[length - i - 1] != '0') {
168                         sr_err("Invalid value '%s' in column %u in line %zu.",
169                                 str, inc->single_column, inc->line_number);
170                         return SR_ERR;
171                 }
172         }
173
174         return SR_OK;
175 }
176
177 static int parse_hexstr(const char *str, struct context *inc)
178 {
179         gsize i, j, k, length;
180         uint8_t value;
181         char c;
182
183         length = strlen(str);
184
185         if (!length) {
186                 sr_err("Column %u in line %zu is empty.", inc->single_column,
187                         inc->line_number);
188                 return SR_ERR;
189         }
190
191         /* Clear buffer in order to set bits only. */
192         memset(inc->sample_buffer, 0, (inc->num_channels + 7) >> 3);
193
194         /* Calculate the position of the first hexadecimal digit. */
195         i = inc->first_channel / 4;
196
197         for (j = 0; i < length && j < inc->num_channels; i++) {
198                 c = str[length - i - 1];
199
200                 if (!g_ascii_isxdigit(c)) {
201                         sr_err("Invalid value '%s' in column %u in line %zu.",
202                                 str, inc->single_column, inc->line_number);
203                         return SR_ERR;
204                 }
205
206                 value = g_ascii_xdigit_value(c);
207
208                 k = (inc->first_channel + j) % 4;
209
210                 for (; j < inc->num_channels && k < 4; k++) {
211                         if (value & (1 << k))
212                                 inc->sample_buffer[j / 8] |= (1 << (j % 8));
213
214                         j++;
215                 }
216         }
217
218         return SR_OK;
219 }
220
221 static int parse_octstr(const char *str, struct context *inc)
222 {
223         gsize i, j, k, length;
224         uint8_t value;
225         char c;
226
227         length = strlen(str);
228
229         if (!length) {
230                 sr_err("Column %u in line %zu is empty.", inc->single_column,
231                         inc->line_number);
232                 return SR_ERR;
233         }
234
235         /* Clear buffer in order to set bits only. */
236         memset(inc->sample_buffer, 0, (inc->num_channels + 7) >> 3);
237
238         /* Calculate the position of the first octal digit. */
239         i = inc->first_channel / 3;
240
241         for (j = 0; i < length && j < inc->num_channels; i++) {
242                 c = str[length - i - 1];
243
244                 if (c < '0' || c > '7') {
245                         sr_err("Invalid value '%s' in column %u in line %zu.",
246                                 str, inc->single_column, inc->line_number);
247                         return SR_ERR;
248                 }
249
250                 value = g_ascii_xdigit_value(c);
251
252                 k = (inc->first_channel + j) % 3;
253
254                 for (; j < inc->num_channels && k < 3; k++) {
255                         if (value & (1 << k))
256                                 inc->sample_buffer[j / 8] |= (1 << (j % 8));
257
258                         j++;
259                 }
260         }
261
262         return SR_OK;
263 }
264
265 static char **parse_line(char *buf, struct context *inc, int max_columns)
266 {
267         const char *str, *remainder;
268         GSList *list, *l;
269         char **columns;
270         char *column;
271         gsize n, k;
272
273         n = 0;
274         k = 0;
275         list = NULL;
276
277         remainder = buf;
278         str = strstr(remainder, inc->delimiter->str);
279
280         while (str && max_columns) {
281                 if (n >= inc->first_column) {
282                         column = g_strndup(remainder, str - remainder);
283                         list = g_slist_prepend(list, g_strstrip(column));
284
285                         max_columns--;
286                         k++;
287                 }
288
289                 remainder = str + inc->delimiter->len;
290                 str = strstr(remainder, inc->delimiter->str);
291                 n++;
292         }
293
294         if (buf[0] && max_columns && n >= inc->first_column) {
295                 column = g_strdup(remainder);
296                 list = g_slist_prepend(list, g_strstrip(column));
297                 k++;
298         }
299
300         if (!(columns = g_try_new(char *, k + 1)))
301                 return NULL;
302
303         columns[k--] = NULL;
304
305         for (l = list; l; l = l->next)
306                 columns[k--] = l->data;
307
308         g_slist_free(list);
309
310         return columns;
311 }
312
313 static int parse_multi_columns(char **columns, struct context *inc)
314 {
315         gsize i;
316         char *column;
317
318         /* Clear buffer in order to set bits only. */
319         memset(inc->sample_buffer, 0, (inc->num_channels + 7) >> 3);
320
321         for (i = 0; i < inc->num_channels; i++) {
322                 column = columns[i];
323                 if (column[0] == '1') {
324                         inc->sample_buffer[i / 8] |= (1 << (i % 8));
325                 } else if (!strlen(column)) {
326                         sr_err("Column %zu in line %zu is empty.",
327                                 inc->first_channel + i, inc->line_number);
328                         return SR_ERR;
329                 } else if (column[0] != '0') {
330                         sr_err("Invalid value '%s' in column %zu in line %zu.",
331                                 column, inc->first_channel + i,
332                                 inc->line_number);
333                         return SR_ERR;
334                 }
335         }
336
337         return SR_OK;
338 }
339
340 static int parse_single_column(const char *column, struct context *inc)
341 {
342         int res;
343
344         res = SR_ERR;
345
346         switch (inc->format) {
347         case FORMAT_BIN:
348                 res = parse_binstr(column, inc);
349                 break;
350         case FORMAT_HEX:
351                 res = parse_hexstr(column, inc);
352                 break;
353         case FORMAT_OCT:
354                 res = parse_octstr(column, inc);
355                 break;
356         }
357
358         return res;
359 }
360
361 static int send_samples(const struct sr_dev_inst *sdi, uint8_t *buffer,
362                 gsize buffer_size, gsize count)
363 {
364         struct sr_datafeed_packet packet;
365         struct sr_datafeed_logic logic;
366         int res;
367         gsize i;
368
369         packet.type = SR_DF_LOGIC;
370         packet.payload = &logic;
371         logic.unitsize = buffer_size;
372         logic.length = buffer_size;
373         logic.data = buffer;
374
375         for (i = 0; i < count; i++) {
376                 res = sr_session_send(sdi, &packet);
377                 if (res != SR_OK)
378                         return res;
379         }
380
381         return SR_OK;
382 }
383
384 static int init(struct sr_input *in, GHashTable *options)
385 {
386         struct context *inc;
387         const char *s;
388
389         in->sdi = g_malloc0(sizeof(struct sr_dev_inst));
390         in->priv = inc = g_malloc0(sizeof(struct context));
391
392         inc->single_column = g_variant_get_int32(g_hash_table_lookup(options, "single-column"));
393         inc->multi_column_mode = inc->single_column == 0;
394
395         inc->num_channels = g_variant_get_int32(g_hash_table_lookup(options, "numchannels"));
396
397         inc->delimiter = g_string_new(g_variant_get_string(
398                         g_hash_table_lookup(options, "delimiter"), NULL));
399         if (inc->delimiter->len == 0) {
400                 sr_err("Delimiter must be at least one character.");
401                 return SR_ERR_ARG;
402         }
403
404         s = g_variant_get_string(g_hash_table_lookup(options, "format"), NULL);
405         if (!g_ascii_strncasecmp(s, "bin", 3)) {
406                 inc->format = FORMAT_BIN;
407         } else if (!g_ascii_strncasecmp(s, "hex", 3)) {
408                 inc->format = FORMAT_HEX;
409         } else if (!g_ascii_strncasecmp(s, "oct", 3)) {
410                 inc->format = FORMAT_OCT;
411         } else {
412                 sr_err("Invalid format: '%s'", s);
413                 return SR_ERR_ARG;
414         }
415
416         inc->comment = g_string_new(g_variant_get_string(
417                         g_hash_table_lookup(options, "comment"), NULL));
418         if (g_string_equal(inc->comment, inc->delimiter)) {
419                 /* That's never going to work. Likely the result of the user
420                  * setting the delimiter to ; -- the default comment. Clearing
421                  * the comment setting will work in that case. */
422                 g_string_truncate(inc->comment, 0);
423         }
424
425         inc->samplerate = g_variant_get_uint64(g_hash_table_lookup(options, "samplerate"));
426
427         inc->first_channel = g_variant_get_int32(g_hash_table_lookup(options, "first-channel"));
428
429         inc->header = g_variant_get_boolean(g_hash_table_lookup(options, "header"));
430
431         inc->start_line = g_variant_get_int32(g_hash_table_lookup(options, "startline"));
432         if (inc->start_line < 1) {
433                 sr_err("Invalid start line %zu.", inc->start_line);
434                 return SR_ERR_ARG;
435         }
436
437         if (inc->multi_column_mode)
438                 inc->first_column = inc->first_channel;
439         else
440                 inc->first_column = inc->single_column;
441
442         if (!inc->multi_column_mode && !inc->num_channels) {
443                 sr_err("Number of channels needs to be specified in single column mode.");
444                 return SR_ERR_ARG;
445         }
446
447         return SR_OK;
448 }
449
450 static const char *get_line_termination(GString *buf)
451 {
452         const char *term;
453
454         term = NULL;
455         if (g_strstr_len(buf->str, buf->len, "\r\n"))
456                 term = "\r\n";
457         else if (memchr(buf->str, '\n', buf->len))
458                 term = "\n";
459         else if (memchr(buf->str, '\r', buf->len))
460                 term = "\r";
461
462         return term;
463 }
464
465 static int initial_parse(const struct sr_input *in, GString *buf)
466 {
467         struct context *inc;
468         GString *channel_name;
469         unsigned int num_columns, i;
470         size_t line_number, l;
471         int ret;
472         char **lines, *line, **columns, *column;
473
474         ret = SR_OK;
475         inc = in->priv;
476         columns = NULL;
477
478         line_number = 0;
479         lines = g_strsplit_set(buf->str, "\r\n", 0);
480         for (l = 0; lines[l]; l++) {
481                 line_number++;
482                 line = lines[l];
483                 if (inc->start_line > line_number) {
484                         sr_spew("Line %zu skipped.", line_number);
485                         continue;
486                 }
487                 if (line[0] == '\0') {
488                         sr_spew("Blank line %zu skipped.", line_number);
489                         continue;
490                 }
491                 strip_comment(line, inc->comment);
492                 if (line[0] == '\0') {
493                         sr_spew("Comment-only line %zu skipped.", line_number);
494                         continue;
495                 }
496
497                 /* Reached first proper line. */
498                 break;
499         }
500         if (!lines[l]) {
501                 /* Not enough data for a proper line yet. */
502                 ret = SR_ERR_NA;
503                 goto out;
504         }
505
506         /*
507          * In order to determine the number of columns parse the current line
508          * without limiting the number of columns.
509          */
510         columns = parse_line(line, inc, -1);
511         if (!columns) {
512                 sr_err("Error while parsing line %zu.", line_number);
513                 ret = SR_ERR;
514                 goto out;
515         }
516         num_columns = g_strv_length(columns);
517
518         /* Ensure that the first column is not out of bounds. */
519         if (!num_columns) {
520                 sr_err("Column %u in line %zu is out of bounds.",
521                         inc->first_column, line_number);
522                 ret = SR_ERR;
523                 goto out;
524         }
525
526         if (inc->multi_column_mode) {
527                 /*
528                  * Detect the number of channels in multi column mode
529                  * automatically if not specified.
530                  */
531                 if (!inc->num_channels) {
532                         inc->num_channels = num_columns;
533                         sr_dbg("Number of auto-detected channels: %u.",
534                                 inc->num_channels);
535                 }
536
537                 /*
538                  * Ensure that the number of channels does not exceed the number
539                  * of columns in multi column mode.
540                  */
541                 if (num_columns < inc->num_channels) {
542                         sr_err("Not enough columns for desired number of channels in line %zu.",
543                                 line_number);
544                         ret = SR_ERR;
545                         goto out;
546                 }
547         }
548
549         channel_name = g_string_sized_new(64);
550         for (i = 0; i < inc->num_channels; i++) {
551                 column = columns[i];
552                 if (inc->header && inc->multi_column_mode && column[0] != '\0')
553                         g_string_assign(channel_name, column);
554                 else
555                         g_string_printf(channel_name, "%u", i);
556                 sr_channel_new(in->sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name->str);
557         }
558         g_string_free(channel_name, TRUE);
559
560         /*
561          * Calculate the minimum buffer size to store the sample data of the
562          * channels.
563          */
564         inc->sample_buffer_size = (inc->num_channels + 7) >> 3;
565         inc->sample_buffer = g_malloc(inc->sample_buffer_size);
566
567 out:
568         if (columns)
569                 g_strfreev(columns);
570         g_strfreev(lines);
571
572         return ret;
573 }
574
575 static int initial_receive(const struct sr_input *in)
576 {
577         struct context *inc;
578         GString *new_buf;
579         int len, ret;
580         char *p;
581         const char *termination;
582
583         inc = in->priv;
584
585         termination = get_line_termination(in->buf);
586         if (!termination)
587                 /* Don't have a full line yet. */
588                 return SR_ERR_NA;
589
590         p = g_strrstr_len(in->buf->str, in->buf->len, termination);
591         if (!p)
592                 /* Don't have a full line yet. */
593                 return SR_ERR_NA;
594         len = p - in->buf->str - 1;
595         new_buf = g_string_new_len(in->buf->str, len);
596         g_string_append_c(new_buf, '\0');
597
598         inc->termination = g_strdup(termination);
599
600         if (in->buf->str[0] != '\0')
601                 ret = initial_parse(in, new_buf);
602         else
603                 ret = SR_OK;
604
605         g_string_free(new_buf, TRUE);
606
607         return ret;
608 }
609
610 static int process_buffer(struct sr_input *in)
611 {
612         struct sr_datafeed_packet packet;
613         struct sr_datafeed_meta meta;
614         struct sr_config *src;
615         struct context *inc;
616         gsize num_columns;
617         uint64_t samplerate;
618         int max_columns, ret, l;
619         char *p, **lines, *line, **columns;
620
621         inc = in->priv;
622         if (!inc->started) {
623                 std_session_send_df_header(in->sdi);
624
625                 if (inc->samplerate) {
626                         packet.type = SR_DF_META;
627                         packet.payload = &meta;
628                         samplerate = inc->samplerate;
629                         src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(samplerate));
630                         meta.config = g_slist_append(NULL, src);
631                         sr_session_send(in->sdi, &packet);
632                         g_slist_free(meta.config);
633                         sr_config_free(src);
634                 }
635
636                 inc->started = TRUE;
637         }
638
639         p = g_strrstr_len(in->buf->str, in->buf->len, inc->termination);
640         if (!p)
641                 /* Don't have a full line. */
642                 return SR_ERR;
643
644         *p = '\0';
645         g_strstrip(in->buf->str);
646
647         /* Limit the number of columns to parse. */
648         if (inc->multi_column_mode)
649                 max_columns = inc->num_channels;
650         else
651                 max_columns = 1;
652
653         ret = SR_OK;
654         lines = g_strsplit_set(in->buf->str, "\r\n", 0);
655         for (l = 0; lines[l]; l++) {
656                 inc->line_number++;
657                 line = lines[l];
658                 if (line[0] == '\0') {
659                         sr_spew("Blank line %zu skipped.", inc->line_number);
660                         continue;
661                 }
662
663                 /* Remove trailing comment. */
664                 strip_comment(line, inc->comment);
665                 if (line[0] == '\0') {
666                         sr_spew("Comment-only line %zu skipped.", inc->line_number);
667                         continue;
668                 }
669
670                 /* Skip the header line, its content was used as the channel names. */
671                 if (inc->header) {
672                         sr_spew("Header line %zu skipped.", inc->line_number);
673                         inc->header = FALSE;
674                         continue;
675                 }
676
677                 columns = parse_line(line, inc, max_columns);
678                 if (!columns) {
679                         sr_err("Error while parsing line %zu.", inc->line_number);
680                         return SR_ERR;
681                 }
682                 num_columns = g_strv_length(columns);
683                 if (!num_columns) {
684                         sr_err("Column %u in line %zu is out of bounds.",
685                                 inc->first_column, inc->line_number);
686                         g_strfreev(columns);
687                         return SR_ERR;
688                 }
689                 /*
690                  * Ensure that the number of channels does not exceed the number
691                  * of columns in multi column mode.
692                  */
693                 if (inc->multi_column_mode && num_columns < inc->num_channels) {
694                         sr_err("Not enough columns for desired number of channels in line %zu.",
695                                 inc->line_number);
696                         g_strfreev(columns);
697                         return SR_ERR;
698                 }
699
700                 if (inc->multi_column_mode)
701                         ret = parse_multi_columns(columns, inc);
702                 else
703                         ret = parse_single_column(columns[0], inc);
704                 if (ret != SR_OK) {
705                         g_strfreev(columns);
706                         return SR_ERR;
707                 }
708
709                 /* Send sample data to the session bus. */
710                 ret = send_samples(in->sdi, inc->sample_buffer,
711                         inc->sample_buffer_size, 1);
712                 if (ret != SR_OK) {
713                         sr_err("Sending samples failed.");
714                         return SR_ERR;
715                 }
716                 g_strfreev(columns);
717         }
718         g_strfreev(lines);
719         g_string_erase(in->buf, 0, p - in->buf->str + 1);
720
721         return ret;
722 }
723
724 static int receive(struct sr_input *in, GString *buf)
725 {
726         struct context *inc;
727         int ret;
728
729         g_string_append_len(in->buf, buf->str, buf->len);
730
731         inc = in->priv;
732         if (!inc->termination) {
733                 ret = initial_receive(in);
734                 if (ret == SR_ERR_NA)
735                         /* Not enough data yet. */
736                         return SR_OK;
737                 else if (ret != SR_OK)
738                         return SR_ERR;
739
740                 /* sdi is ready, notify frontend. */
741                 in->sdi_ready = TRUE;
742                 return SR_OK;
743         }
744
745         ret = process_buffer(in);
746
747         return ret;
748 }
749
750 static int end(struct sr_input *in)
751 {
752         struct context *inc;
753         int ret;
754
755         if (in->sdi_ready)
756                 ret = process_buffer(in);
757         else
758                 ret = SR_OK;
759
760         inc = in->priv;
761         if (inc->started)
762                 std_session_send_df_end(in->sdi);
763
764         return ret;
765 }
766
767 static void cleanup(struct sr_input *in)
768 {
769         struct context *inc;
770
771         inc = in->priv;
772
773         if (inc->delimiter)
774                 g_string_free(inc->delimiter, TRUE);
775
776         if (inc->comment)
777                 g_string_free(inc->comment, TRUE);
778
779         g_free(inc->termination);
780         g_free(inc->sample_buffer);
781 }
782
783 static int reset(struct sr_input *in)
784 {
785         struct context *inc = in->priv;
786
787         cleanup(in);
788         inc->started = FALSE;
789         g_string_truncate(in->buf, 0);
790
791         return SR_OK;
792 }
793
794 static struct sr_option options[] = {
795         { "single-column", "Single column", "Enable/specify single column", NULL, NULL },
796         { "numchannels", "Max channels", "Number of channels", NULL, NULL },
797         { "delimiter", "Delimiter", "Column delimiter", NULL, NULL },
798         { "format", "Format", "Numeric format", NULL, NULL },
799         { "comment", "Comment", "Comment prefix character", NULL, NULL },
800         { "samplerate", "Samplerate", "Samplerate used during capture", NULL, NULL },
801         { "first-channel", "First channel", "Column number of first channel", NULL, NULL },
802         { "header", "Header", "Treat first line as header with channel names", NULL, NULL },
803         { "startline", "Start line", "Line number at which to start processing samples", NULL, NULL },
804         ALL_ZERO
805 };
806
807 static const struct sr_option *get_options(void)
808 {
809         if (!options[0].def) {
810                 options[0].def = g_variant_ref_sink(g_variant_new_int32(0));
811                 options[1].def = g_variant_ref_sink(g_variant_new_int32(0));
812                 options[2].def = g_variant_ref_sink(g_variant_new_string(","));
813                 options[3].def = g_variant_ref_sink(g_variant_new_string("bin"));
814                 options[4].def = g_variant_ref_sink(g_variant_new_string(";"));
815                 options[5].def = g_variant_ref_sink(g_variant_new_uint64(0));
816                 options[6].def = g_variant_ref_sink(g_variant_new_int32(0));
817                 options[7].def = g_variant_ref_sink(g_variant_new_boolean(FALSE));
818                 options[8].def = g_variant_ref_sink(g_variant_new_int32(1));
819         }
820
821         return options;
822 }
823
824 SR_PRIV struct sr_input_module input_csv = {
825         .id = "csv",
826         .name = "CSV",
827         .desc = "Comma-separated values",
828         .exts = (const char*[]){"csv", NULL},
829         .options = get_options,
830         .init = init,
831         .receive = receive,
832         .end = end,
833         .cleanup = cleanup,
834         .reset = reset,
835 };