X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=blobdiff_plain;f=sigrok-cli.c;h=4af47d2da2a3fe0470fee124af052e62fbcff140;hp=aeffeaa8d42f659aac62fde3d31d642e175cc138;hb=f1f703bf0dc63e2b6149f4cfba294253991d04f7;hpb=11b62b6f90e9c65beb1b6880c7e254551e296ae2 diff --git a/sigrok-cli.c b/sigrok-cli.c index aeffeaa..4af47d2 100644 --- a/sigrok-cli.c +++ b/sigrok-cli.c @@ -256,16 +256,16 @@ static void print_dev_line(const struct sr_dev_inst *sdi) if (sdi->probes) { if (g_slist_length(sdi->probes) == 1) { probe = sdi->probes->data; - printf("with 1 probe: %s\n", probe->name); + printf("with 1 probe: %s", probe->name); } else { - printf("with %d probes:\n", g_slist_length(sdi->probes)); + printf("with %d probes:", g_slist_length(sdi->probes)); for (l = sdi->probes; l; l = l->next) { probe = l->data; - printf(" %s\n", probe->name); + printf(" %s", probe->name); } } - } else - printf("\n"); + } + printf("\n"); } static void show_dev_list(void) @@ -821,7 +821,6 @@ static int register_pds(struct sr_dev *dev, const char *pdstring) int ret; char **pdtokens, **pdtok, *pd_name; - /* Avoid compiler warnings. */ (void)dev; ret = 0; @@ -1062,31 +1061,23 @@ void show_pd_annotations(struct srd_proto_data *pdata, void *cb_data) static int select_probes(struct sr_dev_inst *sdi) { - char **probelist; - int max_probes, i; + struct sr_probe *probe; + GSList *selected_probes, *l; if (!opt_probes) return SR_OK; - /* - * This only works because a device by default initializes - * and enables all its probes. - */ - max_probes = g_slist_length(sdi->probes); - probelist = parse_probestring(max_probes, opt_probes); - if (!probelist) { + if (!(selected_probes = parse_probestring(sdi, opt_probes))) return SR_ERR; - } - for (i = 0; i < max_probes; i++) { - if (probelist[i]) { - sr_dev_probe_name_set(sdi, i, probelist[i]); - g_free(probelist[i]); - } else { - sr_dev_probe_enable(sdi, i, FALSE); - } + for (l = sdi->probes; l; l = l->next) { + probe = l->data; + if (g_slist_find(selected_probes, probe)) + probe->enabled = TRUE; + else + probe->enabled = FALSE; } - g_free(probelist); + g_slist_free(selected_probes); return SR_OK; } @@ -1466,7 +1457,6 @@ static void run_session(void) static void logger(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer cb_data) { - /* Avoid compiler warnings. */ (void)log_domain; (void)cb_data; @@ -1483,8 +1473,10 @@ static void logger(const gchar *log_domain, GLogLevelFlags log_level, int main(int argc, char **argv) { + int ret = 1; GOptionContext *context; GError *error; + struct sr_context *sr_ctx = NULL; g_log_set_default_handler(logger, NULL); @@ -1494,36 +1486,36 @@ int main(int argc, char **argv) if (!g_option_context_parse(context, &argc, &argv, &error)) { g_critical("%s", error->message); - return 1; + goto done; } /* Set the loglevel (amount of messages to output) for libsigrok. */ if (sr_log_loglevel_set(opt_loglevel) != SR_OK) - return 1; + goto done; /* Set the loglevel (amount of messages to output) for libsigrokdecode. */ if (srd_log_loglevel_set(opt_loglevel) != SRD_OK) - return 1; + goto done; - if (sr_init() != SR_OK) - return 1; + if (sr_init(&sr_ctx) != SR_OK) + goto done; if (opt_pds) { if (srd_init(NULL) != SRD_OK) - return 1; + goto done; if (register_pds(NULL, opt_pds) != 0) - return 1; + goto done; if (srd_pd_output_callback_add(SRD_OUTPUT_ANN, show_pd_annotations, NULL) != SRD_OK) - return 1; + goto done; if (setup_pd_stack() != 0) - return 1; + goto done; if (setup_pd_annotations() != 0) - return 1; + goto done; } if (setup_output_format() != 0) - return 1; + goto done; if (opt_version) show_version(); @@ -1543,8 +1535,13 @@ int main(int argc, char **argv) if (opt_pds) srd_exit(); + ret = 0; + +done: + if (sr_ctx) + sr_exit(sr_ctx); + g_option_context_free(context); - sr_exit(); - return 0; + return ret; }