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.
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
);
41 main(int argc
, char *argv
[])
44 char *confpath
= NULL
;
45 const char *homedir
= NULL
;
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]))
60 confpath
= argv
[2], args_ok
= 1;
62 eprint("-c option requires a file name\n");
65 exit_help(EXIT_FAILURE
);
68 exit_help(EXIT_FAILURE
);
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
)))
85 perror("awesome: parsing configuration file failed");
88 cfg_error(cfg
, "awesome: parsing configuration file %s failed.\n", confpath
);
94 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80