Skip to content

Commit

Permalink
support XDG Base Directory Specification.
Browse files Browse the repository at this point in the history
  • Loading branch information
naihe2010 committed Dec 8, 2021
1 parent 38198fd commit ed0e011
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/main.cc
Expand Up @@ -35,6 +35,7 @@
#ifndef WIN32
#include <getopt.h>
#endif
#include <glib.h>
#include <gtk/gtk.h>
#include <iostream>

Expand Down Expand Up @@ -73,6 +74,29 @@ version_exit ()
}
#endif

static char *
get_xdg_or_home_ini (void)
{
const gchar *xdgdir, *homedir;
gchar *configpath;

xdgdir = g_getenv ("XDG_CONFIG_DIR");
homedir = g_getenv ("HOME");
if (xdgdir != nullptr)
{
configpath = g_strdup_printf ("%s/apvlv/apvlvrc", xdgdir);
}
else if (homedir != nullptr)
{
configpath = g_strdup_printf ("%s/.config/apvlv/apvlvrc", homedir);
}

if (configpath && g_file_test (configpath, G_FILE_TEST_IS_REGULAR))
return configpath;
else
return nullptr;
}

static int
parse_options (int argc, char *argv[])
{
Expand Down Expand Up @@ -120,8 +144,11 @@ parse_options (int argc, char *argv[])

if (ini == nullptr)
{
ini = absolutepath (inifile.c_str ());
ini = get_xdg_or_home_ini ();
if (ini == nullptr)
ini = absolutepath (inifile.c_str ());
}
debug ("using config: %s", ini);

/*
* load the global sys conf file
Expand Down

0 comments on commit ed0e011

Please sign in to comment.