]> sigrok.org Git - sigrok-cli.git/blobdiff - sigrok-cli.c
cli: removed obsolete debugging, setup for proper stderr logging
[sigrok-cli.git] / sigrok-cli.c
index 560cbc5d08e7d18caef4208f802bdb64cf26aa03..b02312042e9da03ff2ba617efc31088b8c9f18be 100644 (file)
@@ -38,7 +38,6 @@
 
 extern struct sr_hwcap_option sr_hwcap_options[];
 
-static gboolean debug = 0;
 static uint64_t limit_samples = 0;
 static struct sr_output_format *output_format = NULL;
 static int default_output_format = FALSE;
@@ -979,15 +978,10 @@ static void logger(const gchar *log_domain, GLogLevelFlags log_level,
         * All messages, warnings, errors etc. go to stderr (not stdout) in
         * order to not mess up the CLI tool data output, e.g. VCD output.
         */
-       if (log_level & (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_WARNING)) {
+       if (log_level & (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_WARNING)
+                       || opt_loglevel > SR_LOG_WARN) {
                fprintf(stderr, "%s\n", message);
                fflush(stderr);
-       } else {
-               if ((log_level & G_LOG_LEVEL_MESSAGE && debug == 1)
-                   || debug == 2) {
-                       printf("%s\n", message);
-                       fflush(stderr);
-               }
        }
 }
 
@@ -1004,8 +998,6 @@ int main(int argc, char **argv)
        char *fmtspec, **pds;
 
        g_log_set_default_handler(logger, NULL);
-       if (getenv("SIGROK_DEBUG"))
-               debug = strtol(getenv("SIGROK_DEBUG"), NULL, 10);
 
        error = NULL;
        context = g_option_context_new(NULL);
@@ -1047,33 +1039,39 @@ int main(int argc, char **argv)
                        printf("Failed to register protocol decoder callback\n");
                        return 1;
                }
-       }
 
-       if (opt_pd_stack) {
-               pds = g_strsplit(opt_pd_stack, ",", 0);
-               if (g_strv_length(pds) < 2) {
-                       printf("Specify at least two protocol decoders to stack.\n");
-                       return 1;
-               }
+               pds = g_strsplit(opt_pds, ",", 0);
+               if (g_strv_length(pds) > 1) {
+                       if (opt_pd_stack) {
+                               /* A stack setup was specified, use that. */
+                               g_strfreev(pds);
+                               pds = g_strsplit(opt_pd_stack, ",", 0);
+                               if (g_strv_length(pds) < 2) {
+                                       g_strfreev(pds);
+                                       printf("Specify at least two protocol decoders to stack.\n");
+                                       return 1;
+                               }
+                       }
 
-               if (!(di_from = srd_inst_find_by_id(pds[0]))) {
-                       printf("Cannot stack protocol decoder '%s': instance not found.\n", pds[0]);
-                       return 1;
-               }
-               for (i = 1; pds[i]; i++) {
-                       if (!(di_to = srd_inst_find_by_id(pds[i]))) {
-                               printf("Cannot stack protocol decoder '%s': instance not found.\n", pds[i]);
+                       if (!(di_from = srd_inst_find_by_id(pds[0]))) {
+                               printf("Cannot stack protocol decoder '%s': instance not found.\n", pds[0]);
                                return 1;
                        }
-                       if ((ret = srd_inst_stack(di_from, di_to)) != SRD_OK)
-                               return ret;
+                       for (i = 1; pds[i]; i++) {
+                               if (!(di_to = srd_inst_find_by_id(pds[i]))) {
+                                       printf("Cannot stack protocol decoder '%s': instance not found.\n", pds[i]);
+                                       return 1;
+                               }
+                               if ((ret = srd_inst_stack(di_from, di_to)) != SRD_OK)
+                                       return ret;
 
-                       /* Don't show annotation from this PD. Only the last PD in
-                        * the stack will be left on the annotation list.
-                        */
-                       g_datalist_remove_data(&pd_ann_visible, di_from->inst_id);
+                               /* Don't show annotation from this PD. Only the last PD in
+                                * the stack will be left on the annotation list.
+                                */
+                               g_datalist_remove_data(&pd_ann_visible, di_from->inst_id);
 
-                       di_from = di_to;
+                               di_from = di_to;
+                       }
                }
                g_strfreev(pds);
        }