Check-in [53df9990ae]
Overview
Comment:Made dysfunctional configuration elements return -1. Made conf_section work correctly.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 53df9990ae57b7dba6c78c293cf9f8fece12fe8e
User & Date: rkeene on 2004-10-22 23:59:18
Other Links: manifest | tags
Context
2004-10-24
14:26
Lots of improvements to libconfig: We now process the command line arguments ourselves rather than using getopt(). We now process Apache-style config files. Began work on documentation. Many more bug fixes check-in: 6a0a10a0ab user: rkeene tags: trunk
2004-10-22
23:59
Made dysfunctional configuration elements return -1. Made conf_section work correctly. check-in: 53df9990ae user: rkeene tags: trunk
23:42
Created libconfig project. check-in: 0334619956 user: rkeene tags: trunk
Changes

Modified conf_apache.c from [8278d1aa65] to [9b123ca764].

1
2
3
4
5
6
7
#include "libconfig.h"
#include "libconfig_private.h"
#include "conf_apache.h"

int lc_process_conf_apache(const char *appname, const char *configfile) {
	return(0);
}





|

1
2
3
4
5
6
7
#include "libconfig.h"
#include "libconfig_private.h"
#include "conf_apache.h"

int lc_process_conf_apache(const char *appname, const char *configfile) {
	return(-1);
}

Modified conf_colon.c from [8a37e64caa] to [8274083490].

1
2
3
4
5
6
7
#include "libconfig.h"
#include "libconfig_private.h"
#include "conf_colon.h"

int lc_process_conf_colon(const char *appname, const char *configfile) {
	return(0);
}





|

1
2
3
4
5
6
7
#include "libconfig.h"
#include "libconfig_private.h"
#include "conf_colon.h"

int lc_process_conf_colon(const char *appname, const char *configfile) {
	return(-1);
}

Modified conf_equal.c from [714d70ff07] to [71a1e5dba4].

1
2
3
4
5
6
7
#include "libconfig.h"
#include "libconfig_private.h"
#include "conf_equal.h"

int lc_process_conf_equal(const char *appname, const char *configfile) {
	return(0);
}





|

1
2
3
4
5
6
7
#include "libconfig.h"
#include "libconfig_private.h"
#include "conf_equal.h"

int lc_process_conf_equal(const char *appname, const char *configfile) {
	return(-1);
}

Modified conf_section.c from [e0f704afa3] to [97302025c7].

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <string.h>
#endif

int lc_process_conf_section(const char *appname, const char *configfile) {
	FILE *configfp = NULL;
	char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL;
	char qualifbuf[LC_LINEBUF_LEN] = {0};
	char *cmd = NULL, *value = NULL, *sep = NULL;
	char *currsection = NULL;
	char *fgetsret = NULL;
	int lcpvret = -1;

	if (appname == NULL || configfile == NULL) {
		return(-1);
	}







|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <string.h>
#endif

int lc_process_conf_section(const char *appname, const char *configfile) {
	FILE *configfp = NULL;
	char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL;
	char qualifbuf[LC_LINEBUF_LEN] = {0};
	char *cmd = NULL, *value = NULL, *sep = NULL, *cmdend = NULL;
	char *currsection = NULL;
	char *fgetsret = NULL;
	int lcpvret = -1;

	if (appname == NULL || configfile == NULL) {
		return(-1);
	}
46
47
48
49
50
51
52


53
54
55
56
57
58
59


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

79












80
81

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96


97
98
99
100
101
102

103
104
105
106
107
108
109
110
111
112
113
114
			*linebuf_ptr--;
		}

		/* Handle section header. */
		if (linebuf[0] == '[' && linebuf[strlen(linebuf) - 1] == ']') {
			linebuf[strlen(linebuf) - 1] = '\0';
			linebuf_ptr = &linebuf[1];


			if (currsection != NULL) {
				lcpvret = lc_process_var(currsection, NULL, NULL, LC_FLAGS_SECTIONEND);
				if (lcpvret < 0) {
					PRINTERR_D("Invalid section terminating: \"%s\"", currsection);
				}
				free(currsection);
			}


			currsection = strdup(linebuf_ptr);
			lcpvret = lc_process_var(currsection, NULL, NULL, LC_FLAGS_SECTIONSTART);
			if (lcpvret < 0) {
				PRINTERR_D("Invalid section: \"%s\"", currsection);
			}
			continue;
		}

		/* Remove leading spaces. */
		linebuf_ptr = &linebuf[0];
		while (*linebuf_ptr == ' ') {
			*linebuf_ptr++;
		}

		/* Drop comments and blank lines. */
		if (*linebuf_ptr == ';' || *linebuf_ptr == '\0') {
			continue;
		}


		sep = strpbrk(linebuf_ptr, " \t");












		cmd = linebuf_ptr;
		if (sep != NULL) {

			*sep = '\0';
			*sep++;
			while (*sep == ' ' || *sep == '\t') {
				*sep++;
			}
			value = sep;
		} else {
			value = NULL;
		}

		if (currsection == NULL) {
			strncpy(qualifbuf, cmd, sizeof(qualifbuf) - 1);
		} else {
			snprintf(qualifbuf, sizeof(qualifbuf) - 1, "%s.%s", currsection, cmd);
		}


		lcpvret = lc_process_var(qualifbuf, NULL, value, LC_FLAGS_VAR);
		if (lcpvret < 0) {
			PRINTERR_D("Invalid command: \"%s\"", qualifbuf);
		}
	}


	if (currsection != NULL) {
		lcpvret = lc_process_var(currsection, NULL, NULL, LC_FLAGS_SECTIONEND);
		if (lcpvret < 0) {
			PRINTERR_D("Invalid section terminating: \"%s\"", currsection);
		}
		free(currsection);
	}

	fclose(configfp);

	return(0);
}







>
>







>
>



















>
|
>
>
>
>
>
>
>
>
>
>
>
>

|
>
|
|
|
|
|
|
<
<
|
|





>
>






>












46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105


106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
			*linebuf_ptr--;
		}

		/* Handle section header. */
		if (linebuf[0] == '[' && linebuf[strlen(linebuf) - 1] == ']') {
			linebuf[strlen(linebuf) - 1] = '\0';
			linebuf_ptr = &linebuf[1];

			/* If a section was open, close it. */
			if (currsection != NULL) {
				lcpvret = lc_process_var(currsection, NULL, NULL, LC_FLAGS_SECTIONEND);
				if (lcpvret < 0) {
					PRINTERR_D("Invalid section terminating: \"%s\"", currsection);
				}
				free(currsection);
			}

			/* Open new section. */
			currsection = strdup(linebuf_ptr);
			lcpvret = lc_process_var(currsection, NULL, NULL, LC_FLAGS_SECTIONSTART);
			if (lcpvret < 0) {
				PRINTERR_D("Invalid section: \"%s\"", currsection);
			}
			continue;
		}

		/* Remove leading spaces. */
		linebuf_ptr = &linebuf[0];
		while (*linebuf_ptr == ' ') {
			*linebuf_ptr++;
		}

		/* Drop comments and blank lines. */
		if (*linebuf_ptr == ';' || *linebuf_ptr == '\0') {
			continue;
		}

		/* Find the command and the data in the line. */
		cmdend = sep = strpbrk(linebuf_ptr, "=");
		if (sep == NULL) {
			PRINTERR("Invalid line: \"%s\"", linebuf);
			continue;
		}

		/* Delete space at the end of the command. */
		*cmdend--; /* It currently derefs to the seperator.. */
		while (*cmdend <= ' ') {
			*cmdend = '\0';
			*cmdend--;
		}

		cmd = linebuf_ptr;

		/* Delete the seperator char and any leading space. */
		*sep = '\0';
		*sep++;
		while (*sep == ' ' || *sep == '\t') {
			*sep++;
		}
		value = sep;



		/* Create the fully qualified variable name. */
		if (currsection == NULL) {
			strncpy(qualifbuf, cmd, sizeof(qualifbuf) - 1);
		} else {
			snprintf(qualifbuf, sizeof(qualifbuf) - 1, "%s.%s", currsection, cmd);
		}

		/* Call the parent and tell them we have data. */
		lcpvret = lc_process_var(qualifbuf, NULL, value, LC_FLAGS_VAR);
		if (lcpvret < 0) {
			PRINTERR_D("Invalid command: \"%s\"", qualifbuf);
		}
	}

	/* Close any open section, and clean-up. */
	if (currsection != NULL) {
		lcpvret = lc_process_var(currsection, NULL, NULL, LC_FLAGS_SECTIONEND);
		if (lcpvret < 0) {
			PRINTERR_D("Invalid section terminating: \"%s\"", currsection);
		}
		free(currsection);
	}

	fclose(configfp);

	return(0);
}

Modified conf_xml.c from [ec8b9126f9] to [d7313fb75f].

1
2
3
4
5
6
7
#include "libconfig.h"
#include "libconfig_private.h"
#include "conf_xml.h"

int lc_process_conf_xml(const char *appname, const char *configfile) {
	return(0);
}





|

1
2
3
4
5
6
7
#include "libconfig.h"
#include "libconfig_private.h"
#include "conf_xml.h"

int lc_process_conf_xml(const char *appname, const char *configfile) {
	return(-1);
}