doc: Remove superfluous comment already described in footnotes.
[mpd-mk.git] / src / cmdline.c
blob606f266747795bcdf133c447a985a0748325b5dc
1 /*
2 * Copyright (C) 2003-2009 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "cmdline.h"
21 #include "path.h"
22 #include "log.h"
23 #include "conf.h"
24 #include "decoder_list.h"
25 #include "config.h"
26 #include "output_list.h"
27 #include "ls.h"
29 #ifdef ENABLE_ARCHIVE
30 #include "archive_list.h"
31 #endif
33 #include <glib.h>
35 #include <stdio.h>
36 #include <stdlib.h>
38 #define USER_CONFIG_FILE_LOCATION1 ".mpdconf"
39 #define USER_CONFIG_FILE_LOCATION2 ".mpd/mpd.conf"
41 G_GNUC_NORETURN
42 static void version(void)
44 puts(PACKAGE " (MPD: Music Player Daemon) " VERSION " \n"
45 "\n"
46 "Copyright (C) 2003-2007 Warren Dukes <warren.dukes@gmail.com>\n"
47 "Copyright (C) 2008 Max Kellermann <max@duempel.org>\n"
48 "This is free software; see the source for copying conditions. There is NO\n"
49 "warranty; not even MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
50 "\n"
51 "Supported decoders:\n");
53 decoder_plugin_init_all();
54 decoder_plugin_print_all_decoders(stdout);
56 puts("\n"
57 "Supported outputs:\n");
58 audio_output_plugin_print_all_types(stdout);
60 #ifdef ENABLE_ARCHIVE
61 puts("\n"
62 "Supported archives:\n");
63 archive_plugin_init_all();
64 archive_plugin_print_all_suffixes(stdout);
65 #endif
67 puts("\n"
68 "Supported protocols:\n");
69 print_supported_uri_schemes_to_fp(stdout);
71 exit(EXIT_SUCCESS);
74 #if GLIB_CHECK_VERSION(2,12,0)
75 static const char *summary =
76 "Music Player Daemon - a daemon for playing music.";
77 #endif
79 void parse_cmdline(int argc, char **argv, struct options *options)
81 GError *error = NULL;
82 GOptionContext *context;
83 bool ret;
84 static gboolean option_version,
85 option_create_db, option_no_create_db, option_no_daemon,
86 option_no_config;
87 const GOptionEntry entries[] = {
88 { "create-db", 0, 0, G_OPTION_ARG_NONE, &option_create_db,
89 "force (re)creation of database", NULL },
90 { "kill", 0, 0, G_OPTION_ARG_NONE, &options->kill,
91 "kill the currently running mpd session", NULL },
92 { "no-config", 0, 0, G_OPTION_ARG_NONE, &option_no_config,
93 "don't read from config", NULL },
94 { "no-create-db", 0, 0, G_OPTION_ARG_NONE, &option_no_create_db,
95 "don't create database, even if it doesn't exist", NULL },
96 { "no-daemon", 0, 0, G_OPTION_ARG_NONE, &option_no_daemon,
97 "don't detach from console", NULL },
98 { "stdout", 0, 0, G_OPTION_ARG_NONE, &options->log_stderr,
99 NULL, NULL },
100 { "stderr", 0, 0, G_OPTION_ARG_NONE, &options->log_stderr,
101 "print messages to stderr", NULL },
102 { "verbose", 'v', 0, G_OPTION_ARG_NONE, &options->verbose,
103 "verbose logging", NULL },
104 { "version", 'V', 0, G_OPTION_ARG_NONE, &option_version,
105 "print version number", NULL },
106 { .long_name = NULL }
109 options->kill = false;
110 options->daemon = true;
111 options->log_stderr = false;
112 options->verbose = false;
113 options->create_db = 0;
115 context = g_option_context_new("[path/to/mpd.conf]");
116 g_option_context_add_main_entries(context, entries, NULL);
118 #if GLIB_CHECK_VERSION(2,12,0)
119 g_option_context_set_summary(context, summary);
120 #endif
122 ret = g_option_context_parse(context, &argc, &argv, &error);
123 g_option_context_free(context);
125 if (!ret) {
126 g_error("option parsing failed: %s\n", error->message);
127 exit(1);
130 if (option_version)
131 version();
133 /* initialize the logging library, so the configuration file
134 parser can use it already */
135 log_early_init(options->verbose);
137 if (option_create_db && option_no_create_db)
138 g_error("Cannot use both --create-db and --no-create-db\n");
140 if (option_no_create_db)
141 options->create_db = -1;
142 else if (option_create_db)
143 options->create_db = 1;
145 options->daemon = !option_no_daemon;
147 if (option_no_config) {
148 g_debug("Ignoring config, using daemon defaults\n");
149 } else if (argc <= 1) {
150 /* default configuration file path */
151 char *path1;
152 char *path2;
154 path1 = g_build_filename(g_get_home_dir(),
155 USER_CONFIG_FILE_LOCATION1, NULL);
156 path2 = g_build_filename(g_get_home_dir(),
157 USER_CONFIG_FILE_LOCATION2, NULL);
158 if (g_file_test(path1, G_FILE_TEST_IS_REGULAR))
159 config_read_file(path1);
160 else if (g_file_test(path2, G_FILE_TEST_IS_REGULAR))
161 config_read_file(path2);
162 else if (g_file_test(SYSTEM_CONFIG_FILE_LOCATION,
163 G_FILE_TEST_IS_REGULAR))
164 config_read_file(SYSTEM_CONFIG_FILE_LOCATION);
165 g_free(path1);
166 g_free(path2);
167 } else if (argc == 2) {
168 /* specified configuration file */
169 config_read_file(argv[1]);
170 } else
171 g_error("too many arguments");