aboutsummaryrefslogtreecommitdiffstats
path: root/src/CommandLine.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-08-10 18:02:44 +0200
committerMax Kellermann <max@duempel.org>2013-09-04 18:14:22 +0200
commit29030b54c98b0aee65fbc10ebf7ba36bed98c02c (patch)
tree79766830b55ebca38ddbce84d8d548227eedb69e /src/CommandLine.cxx
parentc9fcc7f14860777458153eb2d13c773ccfa1daa2 (diff)
downloadmpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.tar.gz
mpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.tar.xz
mpd-29030b54c98b0aee65fbc10ebf7ba36bed98c02c.zip
util/Error: new error passing library
Replaces GLib's GError.
Diffstat (limited to 'src/CommandLine.cxx')
-rw-r--r--src/CommandLine.cxx36
1 files changed, 16 insertions, 20 deletions
diff --git a/src/CommandLine.cxx b/src/CommandLine.cxx
index 89575a13f..71395fd0c 100644
--- a/src/CommandLine.cxx
+++ b/src/CommandLine.cxx
@@ -33,6 +33,8 @@
#include "mpd_error.h"
#include "fs/Path.hxx"
#include "fs/FileSystem.hxx"
+#include "util/Error.hxx"
+#include "util/Domain.hxx"
#ifdef ENABLE_ENCODER
#include "EncoderList.hxx"
@@ -57,11 +59,7 @@
#define USER_CONFIG_FILE_LOCATION_XDG "mpd/mpd.conf"
#endif
-static GQuark
-cmdline_quark(void)
-{
- return g_quark_from_static_string("cmdline");
-}
+static constexpr Domain cmdline_domain("cmdline");
gcc_noreturn
static void version(void)
@@ -147,9 +145,8 @@ PathBuildChecked(const Path &a, Path::const_pointer b)
bool
parse_cmdline(int argc, char **argv, struct options *options,
- GError **error_r)
+ Error &error)
{
- GError *error = NULL;
GOptionContext *context;
bool ret;
static gboolean option_version,
@@ -183,11 +180,12 @@ parse_cmdline(int argc, char **argv, struct options *options,
g_option_context_set_summary(context, summary);
- ret = g_option_context_parse(context, &argc, &argv, &error);
+ GError *gerror = nullptr;
+ ret = g_option_context_parse(context, &argc, &argv, &gerror);
g_option_context_free(context);
if (!ret)
- MPD_ERROR("option parsing failed: %s\n", error->message);
+ MPD_ERROR("option parsing failed: %s\n", gerror->message);
if (option_version)
version();
@@ -208,7 +206,7 @@ parse_cmdline(int argc, char **argv, struct options *options,
Path path = PathBuildChecked(Path::FromUTF8(g_get_user_config_dir()),
CONFIG_FILE_LOCATION);
if (!path.IsNull() && FileExists(path))
- return ReadConfigFile(path, error_r);
+ return ReadConfigFile(path, error);
const char *const*system_config_dirs =
g_get_system_config_dirs();
@@ -217,38 +215,36 @@ parse_cmdline(int argc, char **argv, struct options *options,
path = PathBuildChecked(Path::FromUTF8(system_config_dirs[i]),
CONFIG_FILE_LOCATION);
if (!path.IsNull() && FileExists(path))
- return ReadConfigFile(path, error_r);
+ return ReadConfigFile(path, error);
}
#else /* G_OS_WIN32 */
Path path = PathBuildChecked(Path::FromUTF8(g_get_user_config_dir()),
USER_CONFIG_FILE_LOCATION_XDG);
if (!path.IsNull() && FileExists(path))
- return ReadConfigFile(path, error_r);
+ return ReadConfigFile(path, error);
path = PathBuildChecked(Path::FromUTF8(g_get_home_dir()),
USER_CONFIG_FILE_LOCATION1);
if (!path.IsNull() && FileExists(path))
- return ReadConfigFile(path, error_r);
+ return ReadConfigFile(path, error);
path = PathBuildChecked(Path::FromUTF8(g_get_home_dir()),
USER_CONFIG_FILE_LOCATION2);
if (!path.IsNull() && FileExists(path))
- return ReadConfigFile(path, error_r);
+ return ReadConfigFile(path, error);
path = Path::FromUTF8(SYSTEM_CONFIG_FILE_LOCATION);
if (!path.IsNull() && FileExists(path))
- return ReadConfigFile(path, error_r);
+ return ReadConfigFile(path, error);
#endif
- g_set_error(error_r, cmdline_quark(), 0,
- "No configuration file found");
+ error.Set(cmdline_domain, "No configuration file found");
return false;
} else if (argc == 2) {
/* specified configuration file */
- return ReadConfigFile(Path::FromFS(argv[1]), error_r);
+ return ReadConfigFile(Path::FromFS(argv[1]), error);
} else {
- g_set_error(error_r, cmdline_quark(), 0,
- "too many arguments");
+ error.Set(cmdline_domain, "too many arguments");
return false;
}
}