2 * augparse.c: utility for parsing config files and seeing what's happening
4 * Copyright (C) 2007-2016 David Lutterkort
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * Author: David Lutterkort <dlutter@redhat.com>
33 bool print_version = false;
35 __attribute__((noreturn))
36 static void usage(void) {
37 fprintf(stderr, "Usage: %s [OPTIONS] MODULE\n", progname);
38 fprintf(stderr, "Evaluate MODULE. Generally, MODULE should contain unit tests.\n");
39 fprintf(stderr, "\nOptions:\n\n");
40 fprintf(stderr, " -I, --include DIR search DIR for modules; can be given multiple times\n");
41 fprintf(stderr, " -t, --trace trace module loading\n");
42 fprintf(stderr, " --nostdinc do not search the builtin default directories for modules\n");
43 fprintf(stderr, " --notypecheck do not typecheck lenses\n");
44 fprintf(stderr, " --version print version information and exit\n");
49 static void print_version_info(struct augeas *aug) {
53 r = aug_get(aug, "/augeas/version", &version);
57 fprintf(stderr, "augparse %s <http://augeas.net/>\n", version);
58 fprintf(stderr, "Copyright (C) 2007-2016 David Lutterkort\n");
59 fprintf(stderr, "License LGPLv2+: GNU LGPL version 2.1 or later\n");
60 fprintf(stderr, " <http://www.gnu.org/licenses/lgpl-2.1.html>\n");
61 fprintf(stderr, "This is free software: you are free to change and redistribute it.\n");
62 fprintf(stderr, "There is NO WARRANTY, to the extent permitted by law.\n\n");
63 fprintf(stderr, "Written by David Lutterkort\n");
66 fprintf(stderr, "Something went terribly wrong internally - please file a bug\n");
69 int main(int argc, char **argv) {
72 char *loadpath = NULL;
73 size_t loadpathlen = 0;
75 VAL_NO_STDINC = CHAR_MAX + 1,
76 VAL_NO_TYPECHECK = VAL_NO_STDINC + 1,
77 VAL_VERSION = VAL_NO_TYPECHECK + 1
79 struct option options[] = {
80 { "help", 0, 0, 'h' },
81 { "include", 1, 0, 'I' },
82 { "trace", 0, 0, 't' },
83 { "nostdinc", 0, 0, VAL_NO_STDINC },
84 { "notypecheck", 0, 0, VAL_NO_TYPECHECK },
85 { "version", 0, 0, VAL_VERSION },
89 unsigned int flags = AUG_TYPE_CHECK|AUG_NO_MODL_AUTOLOAD;
92 setlocale(LC_ALL, "");
93 while ((opt = getopt_long(argc, argv, "hI:t", options, &idx)) != -1) {
96 argz_add(&loadpath, &loadpathlen, optarg);
99 flags |= AUG_TRACE_MODULE_LOADING;
105 flags |= AUG_NO_STDINC;
107 case VAL_NO_TYPECHECK:
108 flags &= ~(AUG_TYPE_CHECK);
111 print_version = true;
119 if (!print_version && optind >= argc) {
120 fprintf(stderr, "Expected .aug file\n");
124 argz_stringify(loadpath, loadpathlen, PATH_SEP_CHAR);
125 aug = aug_init(NULL, loadpath, flags);
127 fprintf(stderr, "Memory exhausted\n");
132 print_version_info(aug);
137 if (__aug_load_module_file(aug, argv[optind]) == -1) {
138 fprintf(stderr, "%s\n", aug_error_message(aug));
139 const char *s = aug_error_details(aug);
141 fprintf(stderr, "%s\n", s);
153 * indent-tabs-mode: nil