|
int | parsefile (struct confsection *params, int nparams, char *filename) |
| Parse a configuration file. More...
|
|
static char * | getparamline (char *pline, FILE *stream) |
|
static int | parseline (struct confsection *params, int nparams, char *pline) |
|
static int | parsesection (struct confsection *params, int nparams, char *pline) |
|
static int | validatesection (struct confsection *params, int nparams, char *section) |
|
static int | parseparam (char *pline) |
|
static int | isolatekey (char *pline, char *endkey, char *key) |
|
static int | isolatevalue (char *startvalue, char *endvalue, char *value) |
|
static int | validatekeyvalue (char *key, char *value) |
|
static int | chkmandatories (struct confsection *params, int nparams) |
|
static int | chkkeys (struct confsection *section) |
|
static int | chkfileerr (FILE *fp) |
|
Configuration file processing.
configfile library source to process configuration files consisting of sections and parameters of key / value pairs.
Whitespace lines and empty lines are ignored.
Lines with a '#' as the first non-whitespace character are ignored as comment lines.
The first parameter line must be a section header.
Section headers are enclosed in [], [ must be the first non-whitespace character on the line and anything after the first ] is ignored.
All other lines are assumed to be parameter lines and after any initial whitespace characters they must have a parameter name, optional whitespace, a mandatory '=', optional whitespace and finishing with an optional word of characters and / or numbers.
e.g.
# Section General
[General]
# pollint is the polling interval in seconds.
pollint=5 <== This is legal.
large pollint=5 <== This is legal.
pollint = <== This is legal.
pollint <== This is illegal.
If a parameter is repeated then the last occurrence prevails.
An array of struct confsection's is provided by the library user to specify valid parameters and whether they are mandatory. A mandatory Key / Value pair for an optional Section is only enforced if the Section does appear, (is defined), in the config file.
- Author
- Copyright (C) 2015-2019 Mark Grant
Released under the GPLv3 only.
SPDX-License-Identifier: GPL-3.0
- Version
- v1.0.12 ==== 30/10/2019