diff options
author | Simon Gomizelj <simongmzlj@gmail.com> | 2012-08-13 11:25:56 -0400 |
---|---|---|
committer | Simon Gomizelj <simongmzlj@gmail.com> | 2012-08-13 15:21:22 -0400 |
commit | 7dbdac3b192f20bb6885254ed097fb18bcbc0d5e (patch) | |
tree | e28a693ee284d13b68b4e6d59459291f4570e0e3 | |
parent | 77e694d96c59ec8228b69a6d3cbc7161c9993df4 (diff) | |
download | mirror-ponymix-7dbdac3b192f20bb6885254ed097fb18bcbc0d5e.tar.gz mirror-ponymix-7dbdac3b192f20bb6885254ed097fb18bcbc0d5e.tar.bz2 mirror-ponymix-7dbdac3b192f20bb6885254ed097fb18bcbc0d5e.zip |
refactor main with a switch
-rw-r--r-- | pulsemix.c | 56 |
1 files changed, 31 insertions, 25 deletions
@@ -803,48 +803,54 @@ int main(int argc, char *argv[]) errx(EXIT_FAILURE, "missing value for action '%s'", argv[optind - 1]); else arg = argv[optind]; + break; default: + break; } /* initialize connection */ if (pulse_init(&pulse) != 0) return 1; - if (verb == ACTION_DEFAULTS) { + switch (verb) { + case ACTION_DEFAULTS: get_default_sink(&pulse); get_default_source(&pulse); print_all(&pulse); - } else if (verb == ACTION_LIST) { + goto done; + case ACTION_LIST: populate_sinks(&pulse, mode); populate_sources(&pulse, mode); print_all(&pulse); - } else { - /* determine sink */ - if (id && fn_get_by_name) { - if (fn_get_by_name(&pulse, id, mode) != 0) - goto done; - } else if (!mode && verb != ACTION_SETDEFAULT && fn_get_default) { - if (fn_get_default(&pulse) != 0) - goto done; - } + goto done; + default: + break; + } + + if (id && fn_get_by_name) { + if (fn_get_by_name(&pulse, id, mode) != 0) + goto done; + } else if (!mode && verb != ACTION_SETDEFAULT && fn_get_default) { + if (fn_get_default(&pulse) != 0) + goto done; + } - if (pulse.head == NULL) { - if (mode && !id) { - warnx("%s id not set, no default operations", pp_name); - rc = 1; - goto done; - } else { - warnx("%s not found: %s", pp_name, id ? id : "default"); - rc = 1; - goto done; - } + if (pulse.head == NULL) { + if (mode && !id) { + warnx("%s id not set, no default operations", pp_name); + rc = 1; + goto done; + } else { + warnx("%s not found: %s", pp_name, id ? id : "default"); + rc = 1; + goto done; } + } - if (arg && fn_get_by_name) - fn_get_by_name(&pulse, arg, MODE_DEVICE); + if (arg && fn_get_by_name) + fn_get_by_name(&pulse, arg, MODE_DEVICE); - rc = do_verb(&pulse, verb, value); - } + rc = do_verb(&pulse, verb, value); done: /* shut down */ |