apcups plugin: Warn about the irritating name `apcups_charge_pct'.
[collectd.git] / src / libconfig / test-lc.c
1 #include "compat.h"
2 #include "libconfig.h"
3
4 int help_cmd(const char *partarg, const char *arg, const char *argarg, const char *val, lc_flags_t flags, void *extra) {
5         printf("Usage info goes here\n");
6         printf("\n");
7
8         exit(EXIT_FAILURE);
9 }
10 int sally_cmd(const char *partarg, const char *arg, const char *argarg, const char *val, lc_flags_t flags, void *extra) {
11         fprintf(stderr, "%s sets value: \"%s\" (flags=%i)\n", arg, val, flags);
12         return(0);
13 }
14
15 int cmd_ifmodule(const char *partarg, const char *arg, const char *argarg, const char *val, lc_flags_t flags, void *extra) {
16         if (flags == LC_FLAGS_SECTIONEND) {
17                 return(LC_CBRET_OKAY);
18         }
19         if (flags != LC_FLAGS_SECTIONSTART) {
20                 fprintf(stderr, "IfModule can only be used as a section.\n");
21                 return(LC_CBRET_ERROR);
22         }
23         if (argarg == NULL) {
24                 fprintf(stderr, "You must specify an argument to IfModule.\n");
25                 return(LC_CBRET_ERROR);
26         }
27
28         fprintf(stderr, "IfModule (%s)\n", argarg);
29         return(LC_CBRET_IGNORESECTION);
30 }
31
32 int main(int argc, char **argv) {
33         char *joeval = NULL;
34         size_t xval = -1;
35         int onoff = -1;
36         int lcpret = -1;
37         int i = 0;
38         int onoff2 = 0;
39         uint32_t ipaddr = 0;
40
41         lc_register_var("Section", LC_VAR_SECTION, NULL, 0);
42         lc_register_var("Somesection", LC_VAR_SECTION, NULL, 0);
43         lc_register_var("Section.Test", LC_VAR_STRING, &joeval, 'j');
44         lc_register_var("bob", LC_VAR_SIZE_SIZE_T, &xval, 's');
45         lc_register_var("Somesection.Free", LC_VAR_BOOL, &onoff, 0);
46         lc_register_var("long", LC_VAR_BOOL_BY_EXISTANCE, &onoff2, 'l');
47         lc_register_var("ipaddr", LC_VAR_IP, &ipaddr, 'i');
48         lc_register_callback("sally", 0, LC_VAR_STRING, sally_cmd, NULL);
49         lc_register_callback("HELP", 'h', LC_VAR_NONE, help_cmd, NULL);
50         lc_register_callback("*.ifmodule", 0, LC_VAR_NONE, cmd_ifmodule, NULL);
51         lcpret = lc_process_file("testapp", "build/test.conf", LC_CONF_APACHE);
52         if (lcpret < 0) {
53                 fprintf(stderr, "Error processing config file: %s\n", lc_geterrstr());
54                 return(EXIT_FAILURE);
55         }
56
57         lcpret = lc_process(argc, argv, "testapp", LC_CONF_APACHE, "test.cfg");
58         if (lcpret < 0) {
59                 fprintf(stderr, "Error processing config file: %s\n", lc_geterrstr());
60                 return(EXIT_FAILURE);
61         }
62
63         lc_cleanup();
64
65         if (joeval != NULL) {
66                 fprintf(stderr, "joeval = \"%s\"\n", joeval);
67         } else {
68                 fprintf(stderr, "joeval = \"(null)\"\n");
69         }
70         fprintf(stderr, "xval = %llu\n", (unsigned long long) xval);
71         fprintf(stderr, "onoff = %i\n", onoff);
72         fprintf(stderr, "long = %i\n", onoff2);
73         fprintf(stderr, "ip = %08lx\n", (unsigned long) ipaddr);
74         for (i = lc_optind; i < argc; i++) {
75                 fprintf(stderr, "argv[%i] = \"%s\"\n", i, argv[i]);
76         }
77
78         return(0);
79 }