3 #include "libconfig_private.h"
4 #include "conf_space.h"
14 int lc_process_conf_space(const char *appname, const char *configfile) {
15 LC_FILE *configfp = NULL;
16 const char *local_lc_errfile;
17 char linebuf[LC_LINEBUF_LEN] = {0}, *linebuf_ptr = NULL;
18 char *cmd = NULL, *value = NULL, *sep = NULL;
19 char *fgetsret = NULL;
23 lc_err_t save_lc_errno = LC_ERR_NONE;
25 local_lc_errfile = configfile;
28 if (appname == NULL || configfile == NULL) {
29 lc_errfile = local_lc_errfile;
30 lc_errline = local_lc_errline;
31 lc_errno = LC_ERR_INVDATA;
35 configfp = lc_fopen(configfile, "r");
37 if (configfp == NULL) {
38 lc_errfile = local_lc_errfile;
39 lc_errline = local_lc_errline;
40 lc_errno = LC_ERR_CANTOPEN;
45 fgetsret = lc_fgets(linebuf, sizeof(linebuf) - 1, configfp);
46 if (fgetsret == NULL) {
49 if (lc_feof(configfp)) {
55 linebuf_ptr = &linebuf[strlen(linebuf) - 1];
56 while (*linebuf_ptr < ' ' && linebuf_ptr >= linebuf) {
61 linebuf_ptr = &linebuf[0];
62 while (*linebuf_ptr == ' ') {
66 if (*linebuf_ptr == '#' || *linebuf_ptr == '\0') {
71 sep = strpbrk(linebuf_ptr, " \t");
76 while (*sep == ' ' || *sep == '\t') {
84 save_lc_errno = lc_errno;
85 lc_errno = LC_ERR_NONE;
86 lcpvret = lc_process_var(cmd, NULL, value, LC_FLAGS_VAR);
88 if (lc_errno == LC_ERR_NONE) {
90 fprintf(stderr, "Invalid command: \"%s\"\n", cmd);
92 lc_errno = LC_ERR_INVCMD;
95 fprintf(stderr, "Error processing command (command was valid, but an error occured, errno was set)\n");
98 lc_errfile = local_lc_errfile;
99 lc_errline = local_lc_errline;
102 lc_errno = save_lc_errno;