X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Foutput%2Fcsv.c;h=426cb6ed344ed3040bb7adb9a84f6c3844695ab1;hb=aa0979482f6e7c269609bb2c22d7d75a2845ac75;hp=dd94f28d694f61a039e95e1114f2cdeea129f5e8;hpb=7e7d7bc074fd92d54c2851ad64ed443fdd58fc28;p=libsigrok.git diff --git a/src/output/csv.c b/src/output/csv.c index dd94f28d..426cb6ed 100644 --- a/src/output/csv.c +++ b/src/output/csv.c @@ -216,7 +216,7 @@ static GString *gen_header(const struct sr_output *o, struct sr_channel *ch; GVariant *gvar; GString *header; - GSList *l; + GSList *channels, *l; unsigned int num_channels, i; uint64_t samplerate = 0, sr; char *samplerate_s; @@ -256,18 +256,20 @@ static GString *gen_header(const struct sr_output *o, ctx->title, ctime(&hdr->starttime.tv_sec)); /* Columns / channels */ - num_channels = g_slist_length(o->sdi->channels); + channels = o->sdi ? o->sdi->channels : NULL; + num_channels = g_slist_length(channels); g_string_append_printf(header, "%s Channels (%d/%d):", ctx->comment, ctx->num_analog_channels + ctx->num_logic_channels, num_channels); - for (i = 0, l = o->sdi->channels; l; l = l->next, i++) { + for (l = channels; l; l = l->next) { ch = l->data; if (ch->enabled) g_string_append_printf(header, " %s,", ch->name); } - if (o->sdi->channels) + if (channels) { /* Drop last separator. */ g_string_truncate(header, header->len - 1); + } g_string_append_printf(header, "\n"); if (samplerate != 0) { samplerate_s = sr_samplerate_string(samplerate); @@ -380,7 +382,7 @@ static void process_logic(struct context *ctx, if (ctx->channels[j].ch->type == SR_CHANNEL_LOGIC) { for (i = 0; i < num_samples; i++) { sample = logic->data + i * logic->unitsize; - idx = ctx->channels[ch].ch->index; + idx = ctx->channels[j].ch->index; if (ctx->label_do && !ctx->label_names) ctx->channels[j].label = "logic"; ctx->logic_samples[i * ctx->num_logic_channels + ch] = sample[idx / 8] & (1 << (idx % 8)); @@ -578,7 +580,7 @@ static int receive(const struct sr_output *o, break; case SR_DF_FRAME_BEGIN: *out = g_string_new(ctx->frame); - /* And then fall through to... */ + /* Fallthrough */ case SR_DF_END: /* Got to end of frame/session with part of the data. */ if (ctx->channels_seen) @@ -623,7 +625,7 @@ static struct sr_option options[] = { {"scale", "scale", "Scale gnuplot graphs", NULL, NULL}, {"value", "Value separator", "Character to print between values", NULL, NULL}, {"record", "Record separator", "String to print between records", NULL, NULL}, - {"frame", "Frame seperator", "String to print between frames", NULL, NULL}, + {"frame", "Frame separator", "String to print between frames", NULL, NULL}, {"comment", "Comment start string", "String used at start of comment lines", NULL, NULL}, {"header", "Output header", "Output header comment with capture metdata", NULL, NULL}, {"label", "Label values", "Type of column labels", NULL, NULL},