Skip to content

Commit

Permalink
Reduce reliance on globals
Browse files Browse the repository at this point in the history
  • Loading branch information
biot committed Nov 17, 2013
1 parent 2be182e commit 26c6375
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
17 changes: 6 additions & 11 deletions decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions sigrok-cli.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 26c6375

Please sign in to comment.