remove awesome-check, move that to an -k option to awesome

This commit is contained in:
Julien Danjou 2008-01-31 10:21:03 +01:00
parent 0c8f75b26b
commit f2e64adb59
6 changed files with 60 additions and 116 deletions

View File

@ -154,14 +154,6 @@ awesome_message_SOURCES = \
awesome_message_LDADD = $(XFT_LIBS) $(X_LIBS) $(CAIRO_LIBS) 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 EXTRA_DIST += awesome.1.txt
man_MANS += awesome.1 man_MANS += awesome.1

View File

@ -1,97 +0,0 @@
/*
* awesome-check.c - awesome configuration file testing
*
* Copyright © 2008 Julien Danjou <julien@danjou.info>
*
* 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 <confuse.h>
#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

View File

@ -43,8 +43,12 @@ OPTIONS
------- -------
-v | --version:: -v | --version::
prints version information to standard output, then exits. prints version information to standard output, then exits.
-h | --help::
prints help information, then exits.
-c:: -c::
use an alternate configuration file instead of $HOME/.awesomerc. use an alternate configuration file instead of $HOME/.awesomerc.
-k::
check configuration file syntax.
DEFAULTS MOUSE BINDINGS DEFAULTS MOUSE BINDINGS
----------------------- -----------------------

View File

@ -189,7 +189,7 @@ static void __attribute__ ((noreturn))
exit_help(int exit_code) exit_help(int exit_code)
{ {
FILE *outfile = (exit_code == EXIT_SUCCESS) ? stdout : stderr; 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); exit(exit_code);
} }
@ -216,6 +216,7 @@ main(int argc, char *argv[])
int args_ok = 1; int args_ok = 1;
/* check args */ /* check args */
/* XXX switch to getopt */
if(argc >= 2) if(argc >= 2)
{ {
args_ok = 0; args_ok = 0;
@ -230,6 +231,8 @@ main(int argc, char *argv[])
else else
eprint("-c option requires a file name\n"); eprint("-c option requires a file name\n");
} }
else if(!a_strcmp("-k", argv[1]))
return config_check(confpath);
else else
exit_help(EXIT_FAILURE); exit_help(EXIT_FAILURE);
} }

View File

@ -428,6 +428,55 @@ config_parse_screen(cfg_t *cfg, int screen)
virtscreen->padding.right = cfg_getint(cfg_padding, "right"); 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 /** Parse configuration file and initialize some stuff
* \param confpatharg Path to configuration file * \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; cfg_t *cfg, *cfg_rules, *cfg_keys, *cfg_mouse, *cfgsectmp;
int ret, screen, i; int ret, screen, i;
const char *homedir;
char *confpath; char *confpath;
ssize_t confpath_len;
Rule *rule = NULL; Rule *rule = NULL;
FILE *defconfig = NULL; FILE *defconfig = NULL;
if(confpatharg) if(confpatharg)
confpath = a_strdup(confpatharg); confpath = a_strdup(confpatharg);
else else
{ confpath = config_file();
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);
}
globalconf.configpath = a_strdup(confpath); globalconf.configpath = a_strdup(confpath);

View File

@ -26,6 +26,8 @@
DO_SLIST(Key, key, p_delete); DO_SLIST(Key, key, p_delete);
DO_SLIST(Button, button, p_delete); DO_SLIST(Button, button, p_delete);
int config_check(const char *);
void config_parse(const char *); void config_parse(const char *);
#endif #endif