2 * Copyright (C) 2003-2010 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.
25 #include "decoder_list.h"
26 #include "decoder_plugin.h"
27 #include "output_list.h"
31 #include "encoder_list.h"
35 #include "archive_list.h"
44 #define CONFIG_FILE_LOCATION "\\mpd\\mpd.conf"
45 #else /* G_OS_WIN32 */
46 #define USER_CONFIG_FILE_LOCATION1 ".mpdconf"
47 #define USER_CONFIG_FILE_LOCATION2 ".mpd/mpd.conf"
53 return g_quark_from_static_string("cmdline");
57 print_all_decoders(FILE *fp
)
59 for (unsigned i
= 0; decoder_plugins
[i
] != NULL
; ++i
) {
60 const struct decoder_plugin
*plugin
= decoder_plugins
[i
];
61 const char *const*suffixes
;
63 fprintf(fp
, "[%s]", plugin
->name
);
65 for (suffixes
= plugin
->suffixes
;
66 suffixes
!= NULL
&& *suffixes
!= NULL
;
68 fprintf(fp
, " %s", *suffixes
);
76 static void version(void)
78 puts(PACKAGE
" (MPD: Music Player Daemon) " VERSION
" \n"
80 "Copyright (C) 2003-2007 Warren Dukes <warren.dukes@gmail.com>\n"
81 "Copyright (C) 2008-2010 Max Kellermann <max@duempel.org>\n"
82 "This is free software; see the source for copying conditions. There is NO\n"
83 "warranty; not even MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
85 "Supported decoders:\n");
87 print_all_decoders(stdout
);
90 "Supported outputs:\n");
91 audio_output_plugin_print_all_types(stdout
);
95 "Supported encoders:\n");
96 encoder_plugin_print_all_types(stdout
);
100 #ifdef ENABLE_ARCHIVE
102 "Supported archives:\n");
103 archive_plugin_init_all();
104 archive_plugin_print_all_suffixes(stdout
);
108 "Supported protocols:\n");
109 print_supported_uri_schemes_to_fp(stdout
);
114 static const char *summary
=
115 "Music Player Daemon - a daemon for playing music.";
118 parse_cmdline(int argc
, char **argv
, struct options
*options
,
121 GError
*error
= NULL
;
122 GOptionContext
*context
;
124 static gboolean option_version
,
127 const GOptionEntry entries
[] = {
128 { "kill", 0, 0, G_OPTION_ARG_NONE
, &options
->kill
,
129 "kill the currently running mpd session", NULL
},
130 { "no-config", 0, 0, G_OPTION_ARG_NONE
, &option_no_config
,
131 "don't read from config", NULL
},
132 { "no-daemon", 0, 0, G_OPTION_ARG_NONE
, &option_no_daemon
,
133 "don't detach from console", NULL
},
134 { "stdout", 0, 0, G_OPTION_ARG_NONE
, &options
->log_stderr
,
136 { "stderr", 0, 0, G_OPTION_ARG_NONE
, &options
->log_stderr
,
137 "print messages to stderr", NULL
},
138 { "verbose", 'v', 0, G_OPTION_ARG_NONE
, &options
->verbose
,
139 "verbose logging", NULL
},
140 { "version", 'V', 0, G_OPTION_ARG_NONE
, &option_version
,
141 "print version number", NULL
},
142 { .long_name
= NULL
}
145 options
->kill
= false;
146 options
->daemon
= true;
147 options
->log_stderr
= false;
148 options
->verbose
= false;
150 context
= g_option_context_new("[path/to/mpd.conf]");
151 g_option_context_add_main_entries(context
, entries
, NULL
);
153 g_option_context_set_summary(context
, summary
);
155 ret
= g_option_context_parse(context
, &argc
, &argv
, &error
);
156 g_option_context_free(context
);
159 g_error("option parsing failed: %s\n", error
->message
);
166 /* initialize the logging library, so the configuration file
167 parser can use it already */
168 log_early_init(options
->verbose
);
170 options
->daemon
= !option_no_daemon
;
172 if (option_no_config
) {
173 g_debug("Ignoring config, using daemon defaults\n");
175 } else if (argc
<= 1) {
176 /* default configuration file path */
180 path1
= g_build_filename(g_get_user_config_dir(),
181 CONFIG_FILE_LOCATION
, NULL
);
182 if (g_file_test(path1
, G_FILE_TEST_IS_REGULAR
))
183 ret
= config_read_file(path1
, error_r
);
186 char *system_path
= NULL
;
187 const char * const *system_config_dirs
;
189 system_config_dirs
= g_get_system_config_dirs();
191 while(system_config_dirs
[i
] != NULL
) {
192 system_path
= g_build_filename(system_config_dirs
[i
],
193 CONFIG_FILE_LOCATION
,
195 if(g_file_test(system_path
,
196 G_FILE_TEST_IS_REGULAR
)) {
197 ret
= config_read_file(system_path
,error_r
);
199 g_free(&system_config_dirs
);
205 g_free(&system_config_dirs
);
207 #else /* G_OS_WIN32 */
209 path1
= g_build_filename(g_get_home_dir(),
210 USER_CONFIG_FILE_LOCATION1
, NULL
);
211 path2
= g_build_filename(g_get_home_dir(),
212 USER_CONFIG_FILE_LOCATION2
, NULL
);
213 if (g_file_test(path1
, G_FILE_TEST_IS_REGULAR
))
214 ret
= config_read_file(path1
, error_r
);
215 else if (g_file_test(path2
, G_FILE_TEST_IS_REGULAR
))
216 ret
= config_read_file(path2
, error_r
);
217 else if (g_file_test(SYSTEM_CONFIG_FILE_LOCATION
,
218 G_FILE_TEST_IS_REGULAR
))
219 ret
= config_read_file(SYSTEM_CONFIG_FILE_LOCATION
,
229 } else if (argc
== 2) {
230 /* specified configuration file */
231 return config_read_file(argv
[1], error_r
);
233 g_set_error(error_r
, cmdline_quark(), 0,
234 "too many arguments");