diff --git a/Makefile.am b/Makefile.am index 411f28a52..af0e45864 100644 --- a/Makefile.am +++ b/Makefile.am @@ -154,14 +154,6 @@ awesome_message_SOURCES = \ awesome_message_LDADD = $(XFT_LIBS) $(X_LIBS) $(CAIRO_LIBS) -bin_PROGRAMS += awesome-check -awesome_check_SOURCES = \ - awesome-check.c common/configopts.h \ - common/util.h common/util.c \ - common/awesome-version.h common/awesome-version.c - -awesome_check_LDADD = $(CONFUSE_LIBS) - EXTRA_DIST += awesome.1.txt man_MANS += awesome.1 diff --git a/awesome-check.c b/awesome-check.c deleted file mode 100644 index 5c7375cdc..000000000 --- a/awesome-check.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * awesome-check.c - awesome configuration file testing - * - * Copyright © 2008 Julien Danjou - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - */ - -#include - -#include "common/awesome-version.h" -#include "common/util.h" -#include "common/configopts.h" - -#define PROGNAME "awesome-check" - -/** Print help and exit(2) with given exit_code. - */ -static void __attribute__ ((noreturn)) -exit_help(int exit_code) -{ - FILE *outfile = (exit_code == EXIT_SUCCESS) ? stdout : stderr; - fprintf(outfile, "Usage: %s [-v | -h | -c configfile]\n", PROGNAME); - exit(exit_code); -} - -int -main(int argc, char *argv[]) -{ - cfg_t *cfg; - char *confpath = NULL; - const char *homedir = NULL; - int args_ok = 1, ret; - ssize_t confpath_len; - - /* check args */ - if(argc >= 2) - { - args_ok = 0; - if(!a_strcmp("-v", argv[1]) || !a_strcmp("--version", argv[1])) - eprint_version(PROGNAME); - else if(!a_strcmp("-h", argv[1]) || !a_strcmp("--help", argv[1])) - exit_help(EXIT_SUCCESS); - else if(!a_strcmp("-c", argv[1])) - { - if(a_strlen(argv[2])) - confpath = argv[2], args_ok = 1; - else - eprint("-c option requires a file name\n"); - } - else - exit_help(EXIT_FAILURE); - } - if(!args_ok) - exit_help(EXIT_FAILURE); - - if(!confpath) - { - 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); - } - - cfg = cfg_init(opts, CFGF_NONE); - - switch((ret = cfg_parse(cfg, confpath))) - { - case CFG_FILE_ERROR: - perror("awesome: parsing configuration file failed"); - break; - case CFG_PARSE_ERROR: - cfg_error(cfg, "awesome: parsing configuration file %s failed.\n", confpath); - break; - case CFG_SUCCESS: - printf("Configuration file OK.\n"); - break; - } - - return ret; -} -// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/awesome.1.txt b/awesome.1.txt index bfc951b9d..597e65062 100644 --- a/awesome.1.txt +++ b/awesome.1.txt @@ -43,8 +43,12 @@ OPTIONS ------- -v | --version:: prints version information to standard output, then exits. +-h | --help:: + prints help information, then exits. -c:: use an alternate configuration file instead of $HOME/.awesomerc. +-k:: + check configuration file syntax. DEFAULTS MOUSE BINDINGS ----------------------- diff --git a/awesome.c b/awesome.c index 77118f913..cc85ddf4e 100644 --- a/awesome.c +++ b/awesome.c @@ -189,7 +189,7 @@ static void __attribute__ ((noreturn)) exit_help(int exit_code) { FILE *outfile = (exit_code == EXIT_SUCCESS) ? stdout : stderr; - fprintf(outfile, "Usage: awesome [-v | -h | -c configfile]\n"); + fprintf(outfile, "Usage: awesome [ -v | -h | -c configfile | -k ]\n"); exit(exit_code); } @@ -216,6 +216,7 @@ main(int argc, char *argv[]) int args_ok = 1; /* check args */ + /* XXX switch to getopt */ if(argc >= 2) { args_ok = 0; @@ -230,6 +231,8 @@ main(int argc, char *argv[]) else eprint("-c option requires a file name\n"); } + else if(!a_strcmp("-k", argv[1])) + return config_check(confpath); else exit_help(EXIT_FAILURE); } diff --git a/config.c b/config.c index 4bffae514..c8663aa84 100644 --- a/config.c +++ b/config.c @@ -428,6 +428,55 @@ config_parse_screen(cfg_t *cfg, int screen) virtscreen->padding.right = cfg_getint(cfg_padding, "right"); } +static char * +config_file(void) +{ + const char *homedir; + char * confpath; + 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); + + return confpath; +} + +int +config_check(const char *confpatharg) +{ + cfg_t *cfg; + int ret; + char *confpath; + + cfg = cfg_init(opts, CFGF_NONE); + + if(confpatharg) + confpath = a_strdup(confpatharg); + else + confpath = config_file(); + + switch((ret = cfg_parse(cfg, confpath))) + { + case CFG_FILE_ERROR: + perror("awesome: parsing configuration file failed"); + break; + case CFG_PARSE_ERROR: + cfg_error(cfg, "awesome: parsing configuration file %s failed.\n", confpath); + break; + case CFG_SUCCESS: + printf("Configuration file OK.\n"); + break; + } + + p_delete(&confpath); + + return ret; +} + /** Parse configuration file and initialize some stuff * \param confpatharg Path to configuration file */ @@ -436,23 +485,14 @@ config_parse(const char *confpatharg) { cfg_t *cfg, *cfg_rules, *cfg_keys, *cfg_mouse, *cfgsectmp; int ret, screen, i; - const char *homedir; char *confpath; - ssize_t confpath_len; Rule *rule = NULL; FILE *defconfig = NULL; 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); - } + confpath = config_file(); globalconf.configpath = a_strdup(confpath); diff --git a/config.h b/config.h index bc2c5d5fc..01bcea4ad 100644 --- a/config.h +++ b/config.h @@ -26,6 +26,8 @@ DO_SLIST(Key, key, p_delete); DO_SLIST(Button, button, p_delete); + +int config_check(const char *); void config_parse(const char *); #endif