From: v1ne Date: Wed, 1 Apr 2020 20:14:39 +0000 (+0200) Subject: output/ascii: Also print trigger marker for "short" data lines X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=cc835205cdc372de86b233afe3d826371a028901;p=libsigrok.git output/ascii: Also print trigger marker for "short" data lines The trigger position would be missing in the output text when the number of available samples is less than the configured text line length. Do flush the trigger marker for the last chunk of accumulated samples, too. How to reproduce: $ sigrok-cli -d ... --samples 32 -O ascii:width=128 [ gsi: rephrased commit message ] --- diff --git a/src/output/ascii.c b/src/output/ascii.c index c82c5973..6f38c80f 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -154,6 +154,23 @@ static GString *gen_header(const struct sr_output *o) return header; } +static void maybe_add_trigger(struct context *ctx, GString *out) { + if (ctx->trigger <= -1) + return; + + int offset = ctx->trigger; + + /* + * Sample data lines have one character per bit and + * no separator between bytes. Align trigger marker + * to this layout. + */ + g_string_append_printf(out, "%*sT:%*s^ %d\n", ctx->max_namelen - 1, "", offset, "", offset); + + ctx->trigger = -1; +} + + static int receive(const struct sr_output *o, const struct sr_datafeed_packet *packet, GString **out) { @@ -162,7 +179,7 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p const struct sr_config *src; GSList *l; struct context *ctx; - int idx, offset, curbit, prevbit; + int idx, curbit, prevbit; uint64_t i, j; gchar *p, c; size_t charidx; @@ -214,16 +231,8 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p /* Flush line buffers. */ g_string_append_len(*out, ctx->lines[j]->str, ctx->lines[j]->len); g_string_append_c(*out, '\n'); - if (j == ctx->num_enabled_channels - 1 && ctx->trigger > -1) { - /* - * Sample data lines have one character per bit and - * no separator between bytes. Align trigger marker - * to this layout. - */ - offset = ctx->trigger; - g_string_append_printf(*out, "%*sT:%*s^ %d\n", ctx->max_namelen - 1, "", offset, "", ctx->trigger); - ctx->trigger = -1; - } + if (j == ctx->num_enabled_channels - 1) + maybe_add_trigger(ctx, *out); g_string_printf(ctx->lines[j], "%s:", ctx->channel_names[j]->str); } } @@ -241,6 +250,7 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p g_string_append_len(*out, ctx->lines[i]->str, ctx->lines[i]->len); g_string_append_c(*out, '\n'); } + maybe_add_trigger(ctx, *out); } break; }