Diff

Differences From Artifact [f6fa72ff6b]:

To Artifact [291ca9d7b9]:


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
36
37
38
39
40
41
42
43
44
45


46
47
48
49
50
51
52
#endif

#ifdef HAVE_STRING_H
#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;
	int invalid_section = 1, ignore_section = 0;

	int retval = 0;
	lc_err_t save_lc_errno = LC_ERR_NONE;




	if (appname == NULL || configfile == NULL) {


		lc_errno = LC_ERR_INVDATA;
		return(-1);
	}

	configfp = lc_fopen(configfile, "r");

	if (configfp == NULL) {


		lc_errno = LC_ERR_CANTOPEN;
		return(-1);
	}

	while (1) {
		fgetsret = fgets(linebuf, sizeof(linebuf) - 1, configfp);
		if (fgetsret == NULL) {
			break;
		}
		if (feof(configfp)) {
			break;
		}



		/* Remove trailing crap (but not spaces). */
		linebuf_ptr = &linebuf[strlen(linebuf) - 1];
		while (*linebuf_ptr < ' ' && linebuf_ptr >= linebuf) {
			*linebuf_ptr = '\0';
			linebuf_ptr--;
		}







|
>







>



>
>
>

>
>







>
>





|



|


>
>







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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#endif

#ifdef HAVE_STRING_H
#include <string.h>
#endif

int lc_process_conf_section(const char *appname, const char *configfile) {
	LC_FILE *configfp = NULL;
	const char *local_lc_errfile;
	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;
	int invalid_section = 1, ignore_section = 0;
	int local_lc_errline;
	int retval = 0;
	lc_err_t save_lc_errno = LC_ERR_NONE;

	local_lc_errfile = configfile;
	local_lc_errline = 0;

	if (appname == NULL || configfile == NULL) {
		lc_errfile = local_lc_errfile;
		lc_errline = local_lc_errline;
		lc_errno = LC_ERR_INVDATA;
		return(-1);
	}

	configfp = lc_fopen(configfile, "r");

	if (configfp == NULL) {
		lc_errfile = local_lc_errfile;
		lc_errline = local_lc_errline;
		lc_errno = LC_ERR_CANTOPEN;
		return(-1);
	}

	while (1) {
		fgetsret = lc_fgets(linebuf, sizeof(linebuf) - 1, configfp);
		if (fgetsret == NULL) {
			break;
		}
		if (lc_feof(configfp)) {
			break;
		}

		local_lc_errline++;

		/* Remove trailing crap (but not spaces). */
		linebuf_ptr = &linebuf[strlen(linebuf) - 1];
		while (*linebuf_ptr < ' ' && linebuf_ptr >= linebuf) {
			*linebuf_ptr = '\0';
			linebuf_ptr--;
		}
71
72
73
74
75
76
77


78
79
80
81
82
83
84
			currsection = strdup(linebuf_ptr);
			lcpvret = lc_process_var(currsection, NULL, NULL, LC_FLAGS_SECTIONSTART);
			if (lcpvret < 0) {
#ifdef DEBUG
				fprintf(stderr, "Invalid section: \"%s\"\n", currsection);
#endif
				invalid_section = 1;


				lc_errno = LC_ERR_INVSECTION;
				retval = -1;
			} else {
				invalid_section = 0;
				ignore_section = 0;
			}








>
>







82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
			currsection = strdup(linebuf_ptr);
			lcpvret = lc_process_var(currsection, NULL, NULL, LC_FLAGS_SECTIONSTART);
			if (lcpvret < 0) {
#ifdef DEBUG
				fprintf(stderr, "Invalid section: \"%s\"\n", currsection);
#endif
				invalid_section = 1;
				lc_errfile = local_lc_errfile;
				lc_errline = local_lc_errline;
				lc_errno = LC_ERR_INVSECTION;
				retval = -1;
			} else {
				invalid_section = 0;
				ignore_section = 0;
			}

159
160
161
162
163
164
165


166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#endif
				lc_errno = LC_ERR_INVCMD;
			} else {
#ifdef DEBUG
				fprintf(stderr, "Error processing command (command was valid, but an error occured, errno was set)\n");
#endif
			}


			retval = -1;
		} else {
			lc_errno = save_lc_errno;
		}
	}

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

	fclose(configfp);

	return(retval);
}







>
>

















|



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#endif
				lc_errno = LC_ERR_INVCMD;
			} else {
#ifdef DEBUG
				fprintf(stderr, "Error processing command (command was valid, but an error occured, errno was set)\n");
#endif
			}
			lc_errfile = local_lc_errfile;
			lc_errline = local_lc_errline;
			retval = -1;
		} else {
			lc_errno = save_lc_errno;
		}
	}

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

	lc_fclose(configfp);

	return(retval);
}