From dcb451cadcf0871bf8c92896bc95c1bed5919d8f Mon Sep 17 00:00:00 2001 From: Sascha Kruse Date: Thu, 14 Jun 2012 15:45:09 +0200 Subject: [PATCH] Only parse cmdline once This also fixes a bug where the geometry is parsed incorrectly. --- dunst.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/dunst.c b/dunst.c index ea36251..0b8e1a8 100644 --- a/dunst.c +++ b/dunst.c @@ -706,8 +706,8 @@ parse_cmdline(int argc, char *argv[]) { {"format", required_argument, NULL, 'f'}, {"key", required_argument, NULL, 'k'}, {"geometry", required_argument, NULL, 'g'}, - {"mod", required_argument, NULL, 'M'}, {"config", required_argument, NULL, 'r'}, + {"mod", required_argument, NULL, 'M'}, {"ns", no_argument, NULL, 'x'}, {0,0,0,0} }; @@ -799,15 +799,16 @@ parse_cmdline(int argc, char *argv[]) { case 's': sort = True; break; + case 'r': + /* this option is parsed elsewhere. This is just to supress + * error message */ + break; case 'x': sort = False; break; case 'v': verbosity++; break; - case 'r': - config_file = optarg; - break; default: usage(EXIT_FAILURE); break; @@ -990,6 +991,19 @@ parse_dunstrc(void) { } +void +parse_cmdline_for_config_file(int argc, char *argv[]) { + int i; + for (i = 0; i < argc; i++) { + if(strstr(argv[i], "-config") != 0) { + if (i + 1 == argc) { + printf("Invalid commandline: -config needs argument\n"); + } + config_file = argv[++i]; + return; + } + } +} int main(int argc, char *argv[]) { @@ -1000,12 +1014,7 @@ main(int argc, char *argv[]) { &geometry.x, &geometry.y, &geometry.w, &geometry.h); - /* FIXME: we need to parse the cmdline to get the -config option - * in order to read the config file. After reading the config file - * we have to parse the cmdline again, to override the OPTIONS - * read from the config file. - */ - parse_cmdline(argc, argv); + parse_cmdline_for_config_file(argc, argv); parse_dunstrc(); parse_cmdline(argc, argv); key = key_string ? XStringToKeysym(key_string) : NoSymbol;