Lely core libraries 2.3.4
config_ini.c File Reference

This file is part of the utilities library; it contains the implementation of the INI parser for configuration structs. More...

#include "util.h"
#include <lely/util/config.h>
#include <lely/util/diag.h>
#include <lely/util/frbuf.h>
#include <lely/util/fwbuf.h>
#include <lely/util/lex.h>
#include <lely/util/membuf.h>
#include <lely/util/print.h>
#include <assert.h>
Include dependency graph for config_ini.c:

Go to the source code of this file.

Functions

size_t config_parse_ini_file (config_t *config, const char *filename)
 Parses an INI file and adds the keys to a configuration struct. More...
 
size_t config_parse_ini_text (config_t *config, const char *begin, const char *end, struct floc *at)
 Parses a string in INI-format and adds the keys to a configuration struct. More...
 
size_t config_print_ini_file (const config_t *config, const char *filename)
 Prints a configuration struct to an INI file. More...
 
size_t config_print_ini_text (const config_t *config, char **pbegin, char *end)
 Prints a configuration struct in INI-format to a memory buffer. More...
 

Detailed Description

This file is part of the utilities library; it contains the implementation of the INI parser for configuration structs.

See also
lely/util/config.h
Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file config_ini.c.

Function Documentation

◆ config_parse_ini_file()

size_t config_parse_ini_file ( config_t config,
const char *  filename 
)

Parses an INI file and adds the keys to a configuration struct.

Returns
the number of characters read, or 0 on error. I/O and parsing errors are reported with diag_at().
See also
config_parse_ini_text()

Definition at line 50 of file config_ini.c.

◆ config_parse_ini_text()

size_t config_parse_ini_text ( config_t config,
const char *  begin,
const char *  end,
struct floc at 
)

Parses a string in INI-format and adds the keys to a configuration struct.

Parameters
configa pointer to a configuration struct.
begina pointer to the first character in the string.
enda pointer to one past the last character in the string (can be NULL if the string is null-terminated).
atan optional pointer to the file location of begin (used for diagnostic purposes). On exit, if at != NULL, *at points to one past the last character parsed.
Returns
the number of characters read. Parsing errors are reported with diag() and diag_at(), respectively.
See also
config_parse_ini_file()

Definition at line 78 of file config_ini.c.

◆ config_print_ini_file()

size_t config_print_ini_file ( const config_t config,
const char *  filename 
)

Prints a configuration struct to an INI file.

Returns
the number of characters written, or 0 on error. I/O errors are reported with diag().
See also
config_print_ini_text()

Definition at line 182 of file config_ini.c.

◆ config_print_ini_text()

size_t config_print_ini_text ( const config_t config,
char **  pbegin,
char *  end 
)

Prints a configuration struct in INI-format to a memory buffer.

Note that the output is not null-terminated.

Parameters
configa pointer to a configuration struct.
pbeginthe address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written.
enda pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated.
Returns
the number of characters that would have been written had the buffer been sufficiently large.
See also
config_print_ini_file()

Definition at line 216 of file config_ini.c.