Diff

Differences From Artifact [3e4ac1b9da]:

To Artifact [d4be221f35]:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "compat.h"
#include "libconfig.h"

int help_cmd(const char *partarg, const char *arg, const char *argarg, const char *val, lc_flags_t flags, void *extra) {
	printf("Usage info goes here\n");
	printf("\n");

	exit(EXIT_FAILURE);
}
int sally_cmd(const char *partarg, const char *arg, const char *argarg, const char *val, lc_flags_t flags, void *extra) {
	PRINTERR("%s sets value: \"%s\" (flags=%i)", arg, val, flags);
	return(0);
}

int cmd_ifmodule(const char *partarg, const char *arg, const char *argarg, const char *val, lc_flags_t flags, void *extra) {
	if (flags == LC_FLAGS_SECTIONEND) {
		return(LC_CBRET_OKAY);
	}
	if (flags != LC_FLAGS_SECTIONSTART) {
		PRINTERR("IfModule can only be used as a section.");
		return(LC_CBRET_ERROR);
	}
	if (argarg == NULL) {
		PRINTERR("You must specify an argument to IfModule.");
		return(LC_CBRET_ERROR);
	}

	PRINTERR("IfModule (%s)", argarg);
	return(LC_CBRET_IGNORESECTION);
}

int main(int argc, char **argv) {
	char *joeval = NULL;
	long long xval = -1;
	int onoff = -1;










|








|



|



|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "compat.h"
#include "libconfig.h"

int help_cmd(const char *partarg, const char *arg, const char *argarg, const char *val, lc_flags_t flags, void *extra) {
	printf("Usage info goes here\n");
	printf("\n");

	exit(EXIT_FAILURE);
}
int sally_cmd(const char *partarg, const char *arg, const char *argarg, const char *val, lc_flags_t flags, void *extra) {
	fprintf(stderr, "%s sets value: \"%s\" (flags=%i)\n", arg, val, flags);
	return(0);
}

int cmd_ifmodule(const char *partarg, const char *arg, const char *argarg, const char *val, lc_flags_t flags, void *extra) {
	if (flags == LC_FLAGS_SECTIONEND) {
		return(LC_CBRET_OKAY);
	}
	if (flags != LC_FLAGS_SECTIONSTART) {
		fprintf(stderr, "IfModule can only be used as a section.\n");
		return(LC_CBRET_ERROR);
	}
	if (argarg == NULL) {
		fprintf(stderr, "You must specify an argument to IfModule.\n");
		return(LC_CBRET_ERROR);
	}

	fprintf(stderr, "IfModule (%s)\n", argarg);
	return(LC_CBRET_IGNORESECTION);
}

int main(int argc, char **argv) {
	char *joeval = NULL;
	long long xval = -1;
	int onoff = -1;
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
	lc_register_var("Somesection.Free", LC_VAR_BOOL, &onoff, 0);
	lc_register_var("long", LC_VAR_BOOL_BY_EXISTANCE, &onoff2, 'l');
	lc_register_callback("sally", 0, LC_VAR_STRING, sally_cmd, NULL);
	lc_register_callback("HELP", 'h', LC_VAR_NONE, help_cmd, NULL);
	lc_register_callback("*.ifmodule", 0, LC_VAR_NONE, cmd_ifmodule, NULL);
	lcpret = lc_process(argc, argv, "testapp", LC_CONF_APACHE, "test.cfg");
	if (lcpret < 0) {
		PRINTERR("Error processing config file: %s", lc_geterrstr());
		return(EXIT_FAILURE);
	}

	if (joeval != NULL) {
		PRINTERR("joeval = \"%s\"", joeval);
	} else {
		PRINTERR("joeval = \"(null)\"");
	}
	PRINTERR("xval = %lli", xval);
	PRINTERR("onoff = %i", onoff);
	PRINTERR("long = %i", onoff2);
	for (i = lc_optind; i < argc; i++) {
		PRINTERR("argv[%i] = \"%s\"", i, argv[i]);
	}

	return(0);
}







|




|

|

|
|
|

|




45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
	lc_register_var("Somesection.Free", LC_VAR_BOOL, &onoff, 0);
	lc_register_var("long", LC_VAR_BOOL_BY_EXISTANCE, &onoff2, 'l');
	lc_register_callback("sally", 0, LC_VAR_STRING, sally_cmd, NULL);
	lc_register_callback("HELP", 'h', LC_VAR_NONE, help_cmd, NULL);
	lc_register_callback("*.ifmodule", 0, LC_VAR_NONE, cmd_ifmodule, NULL);
	lcpret = lc_process(argc, argv, "testapp", LC_CONF_APACHE, "test.cfg");
	if (lcpret < 0) {
		fprintf(stderr, "Error processing config file: %s\n", lc_geterrstr());
		return(EXIT_FAILURE);
	}

	if (joeval != NULL) {
		fprintf(stderr, "joeval = \"%s\"\n", joeval);
	} else {
		fprintf(stderr, "joeval = \"(null)\"\n");
	}
	fprintf(stderr, "xval = %lli\n", xval);
	fprintf(stderr, "onoff = %i\n", onoff);
	fprintf(stderr, "long = %i\n", onoff2);
	for (i = lc_optind; i < argc; i++) {
		fprintf(stderr, "argv[%i] = \"%s\"\n", i, argv[i]);
	}

	return(0);
}