From 778a37e7c80c96f87a5baea355ab21da879cf9ac Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Thu, 4 Apr 2013 17:26:24 +0200 Subject: [PATCH] Allow to specify custom config file via cli option (#12). --- doc/vimb.1.txt | 3 +++ src/main.c | 19 ++++++++++++++++--- src/main.h | 1 + 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/doc/vimb.1.txt b/doc/vimb.1.txt index eaa8f6c..785e26d 100644 --- a/doc/vimb.1.txt +++ b/doc/vimb.1.txt @@ -14,6 +14,9 @@ browsing-experience. .SH OPTIONS Mandatory arguments to long options are mandatory for short options too. .TP +.BI "-c, --config " "CONFIG-FILE" +Use custom configuration given as \fICONFIG-FILE\fP. +.TP .BI "-e, --embed " "WINID" .I WINID of an XEmbed-aware application, that PROJECT will use as its parent. diff --git a/src/main.c b/src/main.c index 221cd48..d5cece1 100644 --- a/src/main.c +++ b/src/main.c @@ -171,7 +171,7 @@ gboolean vb_load_uri(const Arg *arg) if (arg->i == VB_TARGET_NEW) { guint i = 0; - char *cmd[5], xid[64]; + char *cmd[7], xid[64]; cmd[i++] = *args; if (vb.embed) { @@ -179,6 +179,10 @@ gboolean vb_load_uri(const Arg *arg) snprintf(xid, LENGTH(xid), "%u", (int)vb.embed); cmd[i++] = xid; } + if (vb.custom_config) { + cmd[i++] = "-c"; + cmd[i++] = vb.custom_config; + } cmd[i++] = uri; cmd[i++] = NULL; @@ -824,8 +828,14 @@ static void vb_init_files(void) { char *path = util_get_config_dir(); - vb.files[FILES_CONFIG] = g_build_filename(path, "config", NULL); - util_create_file_if_not_exists(vb.files[FILES_CONFIG]); + if (vb.custom_config) { + char *rp = realpath(vb.custom_config, NULL); + vb.files[FILES_CONFIG] = g_strdup(rp); + free(rp); + } else { + vb.files[FILES_CONFIG] = g_build_filename(path, "config", NULL); + util_create_file_if_not_exists(vb.files[FILES_CONFIG]); + } vb.files[FILES_COOKIE] = g_build_filename(path, "cookies", NULL); util_create_file_if_not_exists(vb.files[FILES_COOKIE]); @@ -1027,8 +1037,11 @@ int main(int argc, char *argv[]) static char *winid = NULL; static gboolean ver = false, dump = false; static GError *err; + + vb.custom_config = NULL; static GOptionEntry opts[] = { {"version", 'v', 0, G_OPTION_ARG_NONE, &ver, "Print version", NULL}, + {"config", 'c', 0, G_OPTION_ARG_STRING, &vb.custom_config, "Custom cufiguration file", NULL}, {"embed", 'e', 0, G_OPTION_ARG_STRING, &winid, "Reparents to window specified by xid", NULL}, {"dump-config", 'd', 0, G_OPTION_ARG_NONE, &dump, "Dump out the default configuration to stdout", NULL}, {NULL} diff --git a/src/main.h b/src/main.h index 75f0e95..0c20a36 100644 --- a/src/main.h +++ b/src/main.h @@ -315,6 +315,7 @@ typedef struct { Window embed; #else GdkNativeWindow embed; + char *custom_config; #endif } VbCore; -- 2.20.1