summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2013-10-22 11:28:02 +0200
committerGravatar Christian Hesse <mail@eworm.de>2013-10-22 11:28:02 +0200
commit33bc696af012d386d334be5ee4b90c718e2475cf (patch)
tree1ffffed4b55ffb415e5e82c44582061451fbed6c
parente793219fbae56376ed77bef87040a163dfb8dd36 (diff)
downloadmpd-notification-33bc696af012d386d334be5ee4b90c718e2475cf.tar.gz
mpd-notification-33bc696af012d386d334be5ee4b90c718e2475cf.tar.zst
parse command line options for host and port
-rw-r--r--mpd-notification.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/mpd-notification.c b/mpd-notification.c
index a2e2295..d439157 100644
--- a/mpd-notification.c
+++ b/mpd-notification.c
@@ -47,6 +47,7 @@ int main(int argc, char ** argv) {
unsigned mpd_port = MPD_PORT, mpd_timeout = MPD_TIMEOUT;
struct mpd_connection * conn = NULL;
struct mpd_song * song = NULL;
+ unsigned int i;
program = argv[0];
@@ -60,6 +61,32 @@ 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;
+ printf("%s: using host %s\n", program, mpd_host);
+ break;
+ default:
+ fprintf(stderr, "%s: unknown option: '%s'\n", program, argv[i]);
+ return EXIT_FAILURE;
+ }
+ 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);
if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) {