settings.c revision 6bfd8baac71b2c4ab7191834da36e843ae0dbd14
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
#include "istream.h"
#include "strescape.h"
#include "settings.h"
#include <stdio.h>
#include <fcntl.h>
{
else
return NULL;
}
{
int num;
return NULL;
}
const char *
{
struct setting_def *def;
case SET_STR:
return NULL;
case SET_INT:
/* use %i so we can handle eg. 0600
as octal value with umasks */
case SET_BOOL:
}
}
}
}
{
const char *errormsg, *next_section;
if (fd < 0) {
return FALSE;
}
t_push();
skip = 0;
next_section = NULL;
} else {
skip = 1;
}
for (;;) {
/* EOF. Also handle the last line even if it doesn't
contain LF. */
const unsigned char *data;
if (size == 0)
break;
}
linenum++;
/* @UNSAFE: line is modified */
/* skip whitespace */
line++;
/* ignore comments or empty lines */
continue;
/* strip away comments. pretty kludgy way really.. */
for (p = line; *p != '\0'; p++) {
if (*p == '\'' || *p == '"') {
quote = *p;
for (p++; *p != quote && *p != '\0'; p++) {
if (*p == '\\' && p[1] != '\0')
p++;
}
if (*p == '\0')
break;
} else if (*p == '#') {
*p = '\0';
break;
}
}
/* remove whitespace from end of line */
len--;
/* a) key = value
b) section_type [section_name] {
c) } */
line++;
*line++ = '\0';
}
if (*line == '=') {
/* a) */
*line++ = '\0';
if (len > 0 &&
}
/* b) + errors */
if (*line == '{')
name = "";
else {
line++;
if (*line != '\0') {
*line++ = '\0';
line++;
}
}
if (*line != '{')
errormsg = "Expecting '='";
else {
sections++;
if (next_section != NULL &&
if (*section == '\0') {
skip = 0;
next_section = NULL;
} else {
section++;
}
}
if (skip > 0)
skip++;
else {
&errormsg);
}
}
} else {
/* c) */
if (sections == 0)
errormsg = "Unexpected '}'";
else {
if (skip > 0)
skip--;
else {
&errormsg);
if (root_section == sections &&
/* we found the section,
now quit */
break;
}
}
sections--;
}
}
i_error("Error in configuration file %s line %d: %s",
break;
}
}
t_pop();
}