change prev_selected
[awesome.git] / awesome-check.c
blob308d0681b82c43fa1896c8358630114ff6d211bd
1 /*
2 * awesome-check.c - awesome configuration file testing
4 * Copyright © 2008 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <confuse.h>
24 #include "common/awesome-version.h"
25 #include "common/util.h"
26 #include "common/configopts.h"
28 #define PROGNAME "awesome-check"
30 /** Print help and exit(2) with given exit_code.
32 static void __attribute__ ((noreturn))
33 exit_help(int exit_code)
35 FILE *outfile = (exit_code == EXIT_SUCCESS) ? stdout : stderr;
36 fprintf(outfile, "Usage: %s [-v | -h | -c configfile]\n", PROGNAME);
37 exit(exit_code);
40 int
41 main(int argc, char *argv[])
43 cfg_t *cfg;
44 char *confpath = NULL;
45 const char *homedir = NULL;
46 int args_ok = 1, ret;
47 ssize_t confpath_len;
49 /* check args */
50 if(argc >= 2)
52 args_ok = 0;
53 if(!a_strcmp("-v", argv[1]) || !a_strcmp("--version", argv[1]))
54 eprint_version(PROGNAME);
55 else if(!a_strcmp("-h", argv[1]) || !a_strcmp("--help", argv[1]))
56 exit_help(EXIT_SUCCESS);
57 else if(!a_strcmp("-c", argv[1]))
59 if(a_strlen(argv[2]))
60 confpath = argv[2], args_ok = 1;
61 else
62 eprint("-c option requires a file name\n");
64 else
65 exit_help(EXIT_FAILURE);
67 if(!args_ok)
68 exit_help(EXIT_FAILURE);
70 if(!confpath)
72 homedir = getenv("HOME");
73 confpath_len = a_strlen(homedir) + a_strlen(AWESOME_CONFIG_FILE) + 2;
74 confpath = p_new(char, confpath_len);
75 a_strcpy(confpath, confpath_len, homedir);
76 a_strcat(confpath, confpath_len, "/");
77 a_strcat(confpath, confpath_len, AWESOME_CONFIG_FILE);
80 cfg = cfg_init(opts, CFGF_NONE);
82 switch((ret = cfg_parse(cfg, confpath)))
84 case CFG_FILE_ERROR:
85 perror("awesome: parsing configuration file failed");
86 break;
87 case CFG_PARSE_ERROR:
88 cfg_error(cfg, "awesome: parsing configuration file %s failed.\n", confpath);
89 break;
92 return ret;
94 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80