]> sigrok.org Git - sigrok-cli.git/commitdiff
Reduce reliance on globals
authorBert Vermeulen <redacted>
Sun, 17 Nov 2013 17:51:15 +0000 (18:51 +0100)
committerBert Vermeulen <redacted>
Sun, 17 Nov 2013 17:51:15 +0000 (18:51 +0100)
decode.c
main.c
sigrok-cli.h

index 19112a922575b04edfbb5ec8e6e5aae6bc6709a7..28b156b45c03050931cd6f11e915fd632192248d 100644 (file)
--- a/decode.c
+++ b/decode.c
@@ -32,11 +32,6 @@ static GHashTable *pd_binary_visible = NULL;
 
 extern struct srd_session *srd_sess;
 extern gint opt_loglevel;
-extern gchar *opt_pds;
-extern gchar *opt_pd_stack;
-extern gchar *opt_pd_annotations;
-extern gchar *opt_pd_meta;
-extern gchar *opt_pd_binary;
 
 
 static int opts_to_gvar(struct srd_decoder *dec, GHashTable *hash,
@@ -126,7 +121,7 @@ static int probes_to_gvar(struct srd_decoder *dec, GHashTable *hash,
  * That will instantiate two SPI decoders on the clock but different data
  * lines.
  */
-int register_pds(const char *pdstring)
+int register_pds(const char *opt_pds, char *opt_pd_annotations)
 {
        struct srd_decoder *dec;
        GHashTable *pd_opthash, *options, *probes;
@@ -140,7 +135,7 @@ int register_pds(const char *pdstring)
        ret = 0;
        pd_name = NULL;
        pd_opthash = options = probes = NULL;
-       pdtokens = g_strsplit(pdstring, ",", 0);
+       pdtokens = g_strsplit(opt_pds, ",", 0);
        for (pdtok = pdtokens; *pdtok; pdtok++) {
                if (!(pd_opthash = parse_generic_arg(*pdtok, TRUE))) {
                        g_critical("Invalid protocol decoder option '%s'.", *pdtok);
@@ -207,7 +202,7 @@ int register_pds(const char *pdstring)
        return ret;
 }
 
-int setup_pd_stack(void)
+int setup_pd_stack(char *opt_pds, char *opt_pd_stack, char *opt_pd_annotations)
 {
        struct srd_decoder_inst *di_from, *di_to;
        int ret, i;
@@ -266,7 +261,7 @@ int setup_pd_stack(void)
        return 0;
 }
 
-int setup_pd_annotations(void)
+int setup_pd_annotations(char *opt_pd_annotations)
 {
        GSList *l;
        struct srd_decoder *dec;
@@ -314,7 +309,7 @@ int setup_pd_annotations(void)
        return 0;
 }
 
-int setup_pd_meta(void)
+int setup_pd_meta(char *opt_pd_meta)
 {
        struct srd_decoder *dec;
        char **pds, **pdtok;
@@ -335,7 +330,7 @@ int setup_pd_meta(void)
        return 0;
 }
 
-int setup_pd_binary(void)
+int setup_pd_binary(char *opt_pd_binary)
 {
        GSList *l;
        struct srd_decoder *dec;
diff --git a/main.c b/main.c
index 50826a5f31c2a51625e8d96823c1e2e7ac068dc6..abacea964830707dbe30a5fc34f0006e078b3731 100644 (file)
--- a/main.c
+++ b/main.c
@@ -43,10 +43,10 @@ gchar *opt_probe_group = NULL;
 gchar *opt_triggers = NULL;
 gchar *opt_pds = NULL;
 #ifdef HAVE_SRD
-gchar *opt_pd_stack = NULL;
-gchar *opt_pd_annotations = NULL;
-gchar *opt_pd_meta = NULL;
-gchar *opt_pd_binary = NULL;
+static gchar *opt_pd_stack = NULL;
+static gchar *opt_pd_annotations = NULL;
+static gchar *opt_pd_meta = NULL;
+static gchar *opt_pd_binary = NULL;
 #endif
 gchar *opt_input_format = NULL;
 gchar *opt_output_format = NULL;
@@ -226,27 +226,27 @@ int main(int argc, char **argv)
                        g_critical("Failed to create new decode session.");
                        goto done;
                }
-               if (register_pds(opt_pds) != 0)
+               if (register_pds(opt_pds, opt_pd_annotations) != 0)
                        goto done;
-               if (setup_pd_stack() != 0)
+               if (setup_pd_stack(opt_pds, opt_pd_stack, opt_pd_annotations) != 0)
                        goto done;
 
                /* Only one output type is ever shown. */
                if (opt_pd_binary) {
-                       if (setup_pd_binary() != 0)
+                       if (setup_pd_binary(opt_pd_binary) != 0)
                                goto done;
                        if (srd_pd_output_callback_add(srd_sess, SRD_OUTPUT_BINARY,
                                        show_pd_binary, NULL) != SRD_OK)
                                goto done;
                } else if (opt_pd_meta) {
-                       if (setup_pd_meta() != 0)
+                       if (setup_pd_meta(opt_pd_meta) != 0)
                                goto done;
                        if (srd_pd_output_callback_add(srd_sess, SRD_OUTPUT_META,
                                        show_pd_meta, NULL) != SRD_OK)
                                goto done;
                } else {
                        if (opt_pd_annotations)
-                               if (setup_pd_annotations() != 0)
+                               if (setup_pd_annotations(opt_pd_annotations) != 0)
                                        goto done;
                        if (srd_pd_output_callback_add(srd_sess, SRD_OUTPUT_ANN,
                                        show_pd_annotations, NULL) != SRD_OK)
index 32981e3b13949d421e630e1edc1bb84fea0f84dc..74e4fdaa36dbc97fcac327abd8c9d31e5646b682 100644 (file)
@@ -52,11 +52,11 @@ void run_session(void);
 void load_input_file(void);
 
 /* decode.c */
-int register_pds(const char *pdstring);
-int setup_pd_stack(void);
-int setup_pd_annotations(void);
-int setup_pd_meta(void);
-int setup_pd_binary(void);
+int register_pds(const char *opt_pds, char *opt_pd_annotations);
+int setup_pd_stack(char *opt_pds, char *opt_pd_stack, char *opt_pd_annotations);
+int setup_pd_annotations(char *opt_pd_annotations);
+int setup_pd_meta(char *opt_pd_meta);
+int setup_pd_binary(char *opt_pd_binary);
 void show_pd_annotations(struct srd_proto_data *pdata, void *cb_data);
 void show_pd_meta(struct srd_proto_data *pdata, void *cb_data);
 void show_pd_binary(struct srd_proto_data *pdata, void *cb_data);