From: Peter Stuge Date: Sun, 21 Oct 2012 18:52:41 +0000 (+0200) Subject: Change main() to have only one exit code flow, used also on errors X-Git-Tag: sigrok-cli-0.4.0~70 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=198f4c6c8d8e572aed41dfc3f7d3fe413e421770;p=sigrok-cli.git Change main() to have only one exit code flow, used also on errors --- diff --git a/sigrok-cli.c b/sigrok-cli.c index 805e219..2f6c59d 100644 --- a/sigrok-cli.c +++ b/sigrok-cli.c @@ -1475,6 +1475,7 @@ static void logger(const gchar *log_domain, GLogLevelFlags log_level, int main(int argc, char **argv) { + int ret = 1; GOptionContext *context; GError *error; @@ -1486,36 +1487,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_noexit; } /* Set the loglevel (amount of messages to output) for libsigrok. */ if (sr_log_loglevel_set(opt_loglevel) != SR_OK) - return 1; + goto done_noexit; /* Set the loglevel (amount of messages to output) for libsigrokdecode. */ if (srd_log_loglevel_set(opt_loglevel) != SRD_OK) - return 1; + goto done_noexit; if (sr_init() != SR_OK) - return 1; + goto done_noexit; 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(); @@ -1535,8 +1536,13 @@ int main(int argc, char **argv) if (opt_pds) srd_exit(); + ret = 0; + +done: sr_exit(); + +done_noexit: g_option_context_free(context); - return 0; + return ret; }