Path: blob/a-new-beginning/SharedDependencies/Sources/inih/include/ini.h
2 views
/* inih -- simple .INI file parser12SPDX-License-Identifier: BSD-3-Clause34Copyright (C) 2009-2025, Ben Hoyt56inih is released under the New BSD license (see LICENSE.txt). Go to the project7home page for more info:89https://github.com/benhoyt/inih1011*/1213#ifndef INI_H14#define INI_H1516/* Make this header file easier to include in C++ code */17#ifdef __cplusplus18extern "C" {19#endif2021#include <stdio.h>2223/* Nonzero if ini_handler callback should accept lineno parameter. */24#ifndef INI_HANDLER_LINENO25#define INI_HANDLER_LINENO 026#endif2728/* Visibility symbols, required for Windows DLLs */29#ifndef INI_API30#if defined _WIN32 || defined __CYGWIN__31# ifdef INI_SHARED_LIB32# ifdef INI_SHARED_LIB_BUILDING33# define INI_API __declspec(dllexport)34# else35# define INI_API __declspec(dllimport)36# endif37# else38# define INI_API39# endif40#else41# if defined(__GNUC__) && __GNUC__ >= 442# define INI_API __attribute__ ((visibility ("default")))43# else44# define INI_API45# endif46#endif47#endif4849/* Typedef for prototype of handler function.5051Note that even though the value parameter has type "const char*", the user52may cast to "char*" and modify its content, as the value is not used again53after the call to ini_handler. This is not true of section and name --54those must not be modified.55*/56#if INI_HANDLER_LINENO57typedef int (*ini_handler)(void* user, const char* section,58const char* name, const char* value,59int lineno);60#else61typedef int (*ini_handler)(void* user, const char* section,62const char* name, const char* value);63#endif6465/* Typedef for prototype of fgets-style reader function. */66typedef char* (*ini_reader)(char* str, int num, void* stream);6768/* Parse given INI-style file. May have [section]s, name=value pairs69(whitespace stripped), and comments starting with ';' (semicolon). Section70is "" if name=value pair parsed before any section heading. name:value71pairs are also supported as a concession to Python's configparser.7273For each name=value pair parsed, call handler function with given user74pointer as well as section, name, and value (data only valid for duration75of handler call). Handler should return nonzero on success, zero on error.7677Returns 0 on success, line number of first error on parse error (doesn't78stop on first error), -1 on file open error, or -2 on memory allocation79error (only when INI_USE_STACK is zero).80*/81INI_API int ini_parse(const char* filename, ini_handler handler, void* user);8283/* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't84close the file when it's finished -- the caller must do that. */85INI_API int ini_parse_file(FILE* file, ini_handler handler, void* user);8687/* Same as ini_parse(), but takes an ini_reader function pointer instead of88filename. Used for implementing custom or string-based I/O (see also89ini_parse_string). */90INI_API int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,91void* user);9293/* Same as ini_parse(), but takes a zero-terminated string with the INI data94instead of a file. Useful for parsing INI data from a network socket or95which is already in memory. */96INI_API int ini_parse_string(const char* string, ini_handler handler, void* user);9798/* Same as ini_parse_string(), but takes a string and its length, avoiding99strlen(). Useful for parsing INI data from a network socket or which is100already in memory, or interfacing with C++ std::string_view. */101INI_API int ini_parse_string_length(const char* string, size_t length, ini_handler handler, void* user);102103/* Nonzero to allow multi-line value parsing, in the style of Python's104configparser. If allowed, ini_parse() will call the handler with the same105name for each subsequent line parsed. */106#ifndef INI_ALLOW_MULTILINE107#define INI_ALLOW_MULTILINE 1108#endif109110/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of111the file. See https://github.com/benhoyt/inih/issues/21 */112#ifndef INI_ALLOW_BOM113#define INI_ALLOW_BOM 1114#endif115116/* Chars that begin a start-of-line comment. Per Python configparser, allow117both ; and # comments at the start of a line by default. */118#ifndef INI_START_COMMENT_PREFIXES119#define INI_START_COMMENT_PREFIXES ";#"120#endif121122/* Nonzero to allow inline comments (with valid inline comment characters123specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match124Python 3.2+ configparser behaviour. */125#ifndef INI_ALLOW_INLINE_COMMENTS126#define INI_ALLOW_INLINE_COMMENTS 1127#endif128#ifndef INI_INLINE_COMMENT_PREFIXES129#define INI_INLINE_COMMENT_PREFIXES ";"130#endif131132/* Nonzero to use stack for line buffer, zero to use heap (malloc/free). */133#ifndef INI_USE_STACK134#define INI_USE_STACK 1135#endif136137/* Maximum line length for any line in INI file (stack or heap). Note that138this must be 3 more than the longest line (due to '\r', '\n', and '\0'). */139#ifndef INI_MAX_LINE140#define INI_MAX_LINE 200141#endif142143/* Nonzero to allow heap line buffer to grow via realloc(), zero for a144fixed-size buffer of INI_MAX_LINE bytes. Only applies if INI_USE_STACK is145zero. */146#ifndef INI_ALLOW_REALLOC147#define INI_ALLOW_REALLOC 0148#endif149150/* Initial size in bytes for heap line buffer. Only applies if INI_USE_STACK151is zero. */152#ifndef INI_INITIAL_ALLOC153#define INI_INITIAL_ALLOC 200154#endif155156/* Stop parsing on first error (default is to keep parsing). */157#ifndef INI_STOP_ON_FIRST_ERROR158#define INI_STOP_ON_FIRST_ERROR 0159#endif160161/* Nonzero to call the handler at the start of each new section (with162name and value NULL). Default is to only call the handler on163each name=value pair. */164#ifndef INI_CALL_HANDLER_ON_NEW_SECTION165#define INI_CALL_HANDLER_ON_NEW_SECTION 0166#endif167168/* Nonzero to allow a name without a value (no '=' or ':' on the line) and169call the handler with value NULL in this case. Default is to treat170no-value lines as an error. */171#ifndef INI_ALLOW_NO_VALUE172#define INI_ALLOW_NO_VALUE 0173#endif174175/* Nonzero to use custom ini_malloc, ini_free, and ini_realloc memory176allocation functions (INI_USE_STACK must also be 0). These functions must177have the same signatures as malloc/free/realloc and behave in a similar178way. ini_realloc is only needed if INI_ALLOW_REALLOC is set. */179#ifndef INI_CUSTOM_ALLOCATOR180#define INI_CUSTOM_ALLOCATOR 0181#endif182183184#ifdef __cplusplus185}186#endif187188#endif /* INI_H */189190191