diff --git a/awesome.c b/awesome.c index df6123ca..0c6644cf 100644 --- a/awesome.c +++ b/awesome.c @@ -270,6 +270,7 @@ int main(int argc, char *argv[]) { char *p; + const char *confpath = NULL; int r, xfd, e_dummy; fd_set rd; XEvent ev; @@ -281,13 +282,23 @@ main(int argc, char *argv[]) Atom netatom[NetLast]; event_handler **handler; - if(argc == 2 && !a_strcmp("-v", argv[1])) + if(argc >= 2) { - printf("awesome-" VERSION " © 2007 Julien Danjou\n"); - return EXIT_SUCCESS; + if(!a_strcmp("-v", argv[1])) + { + printf("awesome-" VERSION " © 2007 Julien Danjou\n"); + return EXIT_SUCCESS; + } + else if(!a_strcmp("-c", argv[1])) + { + if(a_strlen(argv[2])) + confpath = argv[2]; + else + eprint("awesome: -c require a file\n"); + } + else + eprint("usage: awesome [-v | -c configfile]\n"); } - else if(argc != 1) - eprint("usage: awesome [-v]\n"); /* Tag won't be printed otherwised */ setlocale(LC_CTYPE, ""); @@ -317,7 +328,7 @@ main(int argc, char *argv[]) for(screen = 0; screen < ScreenCount(dpy); screen++) { - parse_config(dpy, screen, &dc[screen], &awesomeconf[screen]); + parse_config(dpy, screen, &dc[screen], confpath, &awesomeconf[screen]); setup(dpy, screen, &dc[screen], &awesomeconf[screen]); XChangeProperty(dpy, RootWindow(dpy, screen), netatom[NetSupported], XA_ATOM, 32, PropModeReplace, (unsigned char *) netatom, NetLast); diff --git a/config.c b/config.c index 2b9bf016..439b2697 100644 --- a/config.c +++ b/config.c @@ -164,7 +164,7 @@ name_func_lookup(const char *funcname, const NameFuncLink * list) * \param drawcontext Draw context */ void -parse_config(Display * disp, int scr, DC * drawcontext, awesome_config *awesomeconf) +parse_config(Display * disp, int scr, DC * drawcontext, const char *confpatharg, awesome_config *awesomeconf) { /* Main configuration object for parsing*/ config_t awesomelibconf; @@ -179,12 +179,17 @@ parse_config(Display * disp, int scr, DC * drawcontext, awesome_config *awesomec KeySym tmp_key; ssize_t confpath_len; - homedir = getenv("HOME"); - confpath_len = a_strlen(homedir) + a_strlen(AWESOME_CONFIG_FILE) + 2; - confpath = p_new(char, confpath_len); - a_strcpy(confpath, confpath_len, homedir); - a_strcat(confpath, confpath_len, "/"); - a_strcat(confpath, confpath_len, AWESOME_CONFIG_FILE); + if(confpatharg) + confpath = a_strdup(confpatharg); + else + { + homedir = getenv("HOME"); + confpath_len = a_strlen(homedir) + a_strlen(AWESOME_CONFIG_FILE) + 2; + confpath = p_new(char, confpath_len); + a_strcpy(confpath, confpath_len, homedir); + a_strcat(confpath, confpath_len, "/"); + a_strcat(confpath, confpath_len, AWESOME_CONFIG_FILE); + } config_init(&awesomelibconf); diff --git a/config.h b/config.h index 9b3ea4a9..c568788d 100644 --- a/config.h +++ b/config.h @@ -159,6 +159,6 @@ struct awesome_config Bool have_randr; }; -void parse_config(Display *, int, DC *, awesome_config *); /* parse configuration file */ +void parse_config(Display *, int, DC *, const char *, awesome_config *); /* parse configuration file */ #endif