]> sigrok.org Git - libsigrok.git/commitdiff
input/protocoldata: also accept comma separated data values
authorGerhard Sittig <redacted>
Sun, 30 Jul 2023 08:10:12 +0000 (10:10 +0200)
committerGerhard Sittig <redacted>
Sun, 30 Jul 2023 08:35:54 +0000 (10:35 +0200)
Frame format specs in the header section accepted space and comma
separators already (though comma separated frame format details are
considered unusual). Protocol values in non-comment (text mode) lines
assumed strictly space separated fields.

Accept comma and semicolon too as data value separators for maximum user
convenience. Simplifies the import of post processed other text formats,
only requires the addition of headers and decoration (select control,
text to number conversion base), but allows re-use of all existing
values. Reduces diffs before and after manipulating original text into
protocoldata which sigrok can import.

These separators silently get ignored. They don't have a meaning in the
sense of interpreting "1, , 3" as three values. There is no concept of
empty fields in the sequence of data values. This is pure convenience.

src/input/protocoldata.c

index 1438f6f4ca7942e5dfd723949e795b9c024a8e3d..e8591b22296cec68b53ae6e2884fff3dbe0a0b10 100644 (file)
@@ -2878,8 +2878,7 @@ static int process_textline(struct sr_input *in, char *line)
        struct context *inc;
        const struct proto_handler_t *handler;
        gboolean is_comm, is_pseudo;
        struct context *inc;
        const struct proto_handler_t *handler;
        gboolean is_comm, is_pseudo;
-       char *word;
-       char *endp;
+       char *p, *word, *endp;
        unsigned long value;
        int ret;
 
        unsigned long value;
        int ret;
 
@@ -2931,11 +2930,16 @@ static int process_textline(struct sr_input *in, char *line)
        /*
         * Non-empty non-comment lines carry protocol values.
         * (Empty lines are handled transparently when they get here.)
        /*
         * Non-empty non-comment lines carry protocol values.
         * (Empty lines are handled transparently when they get here.)
+        * Accept comma and semicolon separators for user convenience.
         * Convert text according to previously received instructions.
         * Pass the values to the protocol handler. Flush waveforms
         * when handlers state that their construction has completed.
         */
        sr_spew("got values line: %s", line);
         * Convert text according to previously received instructions.
         * Pass the values to the protocol handler. Flush waveforms
         * when handlers state that their construction has completed.
         */
        sr_spew("got values line: %s", line);
+       for (p = line; *p; p++) {
+               if (*p == ',' || *p == ';')
+                       *p = ' ';
+       }
        while (line) {
                word = sr_text_next_word(line, &line);
                if (!word)
        while (line) {
                word = sr_text_next_word(line, &line);
                if (!word)