chiark / gitweb /
wip compile
[inn-innduct.git] / frontends / innconfval.c
1 /*  $Id: innconfval.c 5962 2002-12-08 19:52:13Z rra $
2 **
3 **  Get a config value from INN.
4 */
5
6 #include "config.h"
7 #include "clibrary.h"
8
9 #include "inn/innconf.h"
10 #include "inn/messages.h"
11 #include "libinn.h"
12
13 /*
14 **  Print the INN version string with appropriate quoting.
15 */
16 static void
17 print_version(FILE *file, enum innconf_quoting quoting)
18 {
19     switch (quoting) {
20     case INNCONF_QUOTE_NONE:
21         fprintf(file, "%s\n", inn_version_string);
22         break;
23     case INNCONF_QUOTE_SHELL:
24         fprintf(file, "VERSION='%s'; export VERSION\n", inn_version_string);
25         break;
26     case INNCONF_QUOTE_PERL:
27         fprintf(file, "$version = '%s';\n", inn_version_string);
28         break;
29     case INNCONF_QUOTE_TCL:
30         fprintf(file, "set inn_version \"%s\"\n", inn_version_string);
31         break;
32     }
33 }
34
35
36 /*
37 **  Main routine.  Most of the real work is done by the innconf library
38 **  routines.
39 */
40 int
41 main(int argc, char *argv[])
42 {
43     int option, i;
44     char *file = NULL;
45     enum innconf_quoting quoting = INNCONF_QUOTE_NONE;
46     bool okay = true;
47     bool version = false;
48     bool checking = false;
49
50     message_program_name = "innconfval";
51
52     while ((option = getopt(argc, argv, "Ci:pstv")) != EOF)
53         switch (option) {
54         default:
55             die("usage error");
56             break;
57         case 'C':
58             checking = true;
59             break;
60         case 'i':
61             file = optarg;
62             break;
63         case 'p':
64             quoting = INNCONF_QUOTE_PERL;
65             break;
66         case 's':
67             quoting = INNCONF_QUOTE_SHELL;
68             break;
69         case 't':
70             quoting = INNCONF_QUOTE_TCL;
71             break;
72         case 'v':
73             version = true;
74             break;
75         }
76     argc -= optind;
77     argv += optind;
78
79     if (version) {
80         print_version(stdout, quoting);
81         exit(0);
82     }
83     if (checking)
84         exit(innconf_check(file) ? 0 : 1);
85
86     /* Read in the inn.conf file specified. */
87     if (!innconf_read(file))
88         exit(1);
89
90     /* Perform the specified action. */
91     if (argv[0] == NULL) {
92         innconf_dump(stdout, quoting);
93         print_version(stdout, quoting);
94     } else {
95         for (i = 0; i < argc; i++)
96             if (strcmp(argv[i], "version") == 0)
97                 print_version(stdout, quoting);
98             else if (!innconf_print_value(stdout, argv[i], quoting))
99                 okay = false;
100     }
101     exit(okay ? 0 : 1);
102 }