summaryrefslogtreecommitdiffstats
path: root/mpd-notification.c
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2014-05-06 21:47:28 +0200
committerGravatar Christian Hesse <mail@eworm.de>2014-05-06 21:47:28 +0200
commit141eae4f7a173de22695759a7237042f56beebfe (patch)
treeec82550dffcf38adfd4e5e4f2d4009abf4aa398f /mpd-notification.c
parent1ade5fa16a18d20ec39b2ed0f37f86094b321c46 (diff)
downloadmpd-notification-141eae4f7a173de22695759a7237042f56beebfe.tar.gz
mpd-notification-141eae4f7a173de22695759a7237042f56beebfe.tar.zst
use getopt for command line parsing
Diffstat (limited to 'mpd-notification.c')
-rw-r--r--mpd-notification.c40
1 files changed, 13 insertions, 27 deletions
diff --git a/mpd-notification.c b/mpd-notification.c
index 7ad3aa0..0ea2a5c 100644
--- a/mpd-notification.c
+++ b/mpd-notification.c
@@ -62,35 +62,21 @@ int main(int argc, char ** argv) {
printf("%s: Started with PID %d\n", program, getpid());
# endif
- for (i = 1; i < argc; i++) {
- switch ((int)argv[i][0]) {
- case '-':
- switch ((int)argv[i][1]) {
- case 'p':
- mpd_port = atoi(argv[i] + 2);
- printf("%s: using port %d\n", program, mpd_port);
- break;
- case 'h':
- fprintf(stderr, "usage: %s [-pPORT] [-h] [-HHOST]\n", program);
- return EXIT_SUCCESS;
- case 'H':
- mpd_host = argv[i] + 2;
- if (strlen(mpd_host) == 0) {
- fprintf(stderr, "No host given!\n");
- return EXIT_FAILURE;
- }
- printf("%s: using host %s\n", program, mpd_host);
- break;
- default:
- fprintf(stderr, "%s: unknown option: '%s'\n", program, argv[i]);
- return EXIT_FAILURE;
- }
+ /* get command line options */
+ while ((i = getopt(argc, argv, "hH:p:")) != -1)
+ switch (i) {
+ case 'h':
+ fprintf(stderr, "usage: %s [-h] [-H HOST] [-p PORT]\n", program);
+ return EXIT_SUCCESS;
+ case 'p':
+ mpd_port = atoi(optarg);
+ printf("%s: using port %d\n", program, mpd_port);
+ break;
+ case 'H':
+ mpd_host = optarg;
+ printf("%s: using host %s\n", program, mpd_host);
break;
- default:
- fprintf(stderr, "%s: unknown command line argument: '%s'\n", program, argv[i]);
- return EXIT_FAILURE;
}
- }
conn = mpd_connection_new(mpd_host, mpd_port, mpd_timeout);