From: Bert Vermeulen Date: Sun, 17 Nov 2013 17:51:15 +0000 (+0100) Subject: Reduce reliance on globals X-Git-Tag: sigrok-cli-0.5.0~62 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=26c63758bd4e5676cb6c987668ca46053c5e82bb;p=sigrok-cli.git Reduce reliance on globals --- diff --git a/decode.c b/decode.c index 19112a9..28b156b 100644 --- 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 50826a5..abacea9 100644 --- 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) diff --git a/sigrok-cli.h b/sigrok-cli.h index 32981e3..74e4fda 100644 --- a/sigrok-cli.h +++ b/sigrok-cli.h @@ -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);