You've already forked M5Stack_Linux_Libs
mirror of
https://github.com/m5stack/M5Stack_Linux_Libs.git
synced 2026-05-20 11:01:38 -07:00
164 lines
5.1 KiB
C
164 lines
5.1 KiB
C
#ifdef ENABLE_OPENMV_INI
|
|
/*
|
|
* This file is part of the OpenMV project.
|
|
*
|
|
* Copyright (c) 2013-2021 Ibrahim Abdelkader <iabdalkader@openmv.io>
|
|
* Copyright (c) 2013-2021 Kwabena W. Agyeman <kwagyeman@openmv.io>
|
|
*
|
|
* This work is licensed under the MIT license, see the file LICENSE for details.
|
|
*
|
|
* Initialization file parser.
|
|
* inih library is released under the New BSD license (see LICENSE.txt).
|
|
* For more details see the following: https://github.com/benhoyt/inih
|
|
*/
|
|
#ifndef __INI_H__
|
|
#define __INI_H__
|
|
|
|
|
|
|
|
/* Make this header file easier to include in C++ code */
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
int ini_atoi(const char *string);
|
|
bool ini_is_true(const char *value);
|
|
|
|
#include "ff_wrapper.h"
|
|
|
|
/* Nonzero if ini_handler callback should accept lineno parameter. */
|
|
#ifndef INI_HANDLER_LINENO
|
|
#define INI_HANDLER_LINENO 0
|
|
#endif
|
|
|
|
/* Typedef for prototype of handler function. */
|
|
#if INI_HANDLER_LINENO
|
|
typedef int (*ini_handler)(void* user, const char* section,
|
|
const char* name, const char* value,
|
|
int lineno);
|
|
#else
|
|
typedef int (*ini_handler)(void* user, const char* section,
|
|
const char* name, const char* value);
|
|
#endif
|
|
|
|
/* Typedef for prototype of fgets-style reader function. */
|
|
typedef char* (*ini_reader)(char* str, int num, void* stream);
|
|
|
|
/* Parse given INI-style file. May have [section]s, name=value pairs
|
|
(whitespace stripped), and comments starting with ';' (semicolon). Section
|
|
is "" if name=value pair parsed before any section heading. name:value
|
|
pairs are also supported as a concession to Python's configparser.
|
|
|
|
For each name=value pair parsed, call handler function with given user
|
|
pointer as well as section, name, and value (data only valid for duration
|
|
of handler call). Handler should return nonzero on success, zero on error.
|
|
|
|
Returns 0 on success, line number of first error on parse error (doesn't
|
|
stop on first error), -1 on file open error, or -2 on memory allocation
|
|
error (only when INI_USE_STACK is zero).
|
|
*/
|
|
int ini_parse(FATFS *fs, const char* filename, ini_handler handler, void* user);
|
|
|
|
/* Same as ini_parse(), but takes a FIL* instead of filename. This doesn't
|
|
close the file when it's finished -- the caller must do that. */
|
|
int ini_parse_file(FIL* file, ini_handler handler, void* user);
|
|
|
|
/* Same as ini_parse(), but takes an ini_reader function pointer instead of
|
|
filename. Used for implementing custom or string-based I/O (see also
|
|
ini_parse_string). */
|
|
int ini_parse_stream(ini_reader reader, void* stream, ini_handler handler,
|
|
void* user);
|
|
|
|
/* Same as ini_parse(), but takes a zero-terminated string with the INI data
|
|
instead of a file. Useful for parsing INI data from a network socket or
|
|
already in memory. */
|
|
int ini_parse_string(const char* string, ini_handler handler, void* user);
|
|
|
|
/* Nonzero to allow multi-line value parsing, in the style of Python's
|
|
configparser. If allowed, ini_parse() will call the handler with the same
|
|
name for each subsequent line parsed. */
|
|
#ifndef INI_ALLOW_MULTILINE
|
|
#define INI_ALLOW_MULTILINE 1
|
|
#endif
|
|
|
|
/* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
|
|
the file. See http://code.google.com/p/inih/issues/detail?id=21 */
|
|
#ifndef INI_ALLOW_BOM
|
|
#define INI_ALLOW_BOM 1
|
|
#endif
|
|
|
|
/* Nonzero to allow inline comments (with valid inline comment characters
|
|
specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match
|
|
Python 3.2+ configparser behaviour. */
|
|
#ifndef INI_ALLOW_INLINE_COMMENTS
|
|
#define INI_ALLOW_INLINE_COMMENTS 1
|
|
#endif
|
|
#ifndef INI_INLINE_COMMENT_PREFIXES
|
|
#define INI_INLINE_COMMENT_PREFIXES ";"
|
|
#endif
|
|
|
|
/* Nonzero to use stack for line buffer, zero to use heap (malloc/free). */
|
|
#ifndef INI_USE_STACK
|
|
#define INI_USE_STACK 1
|
|
#endif
|
|
|
|
/* Maximum line length for any line in INI file (stack or heap). Note that
|
|
this must be 3 more than the longest line (due to '\r', '\n', and '\0'). */
|
|
#ifndef INI_MAX_LINE
|
|
#define INI_MAX_LINE 200
|
|
#endif
|
|
|
|
/* Nonzero to allow heap line buffer to grow via realloc(), zero for a
|
|
fixed-size buffer of INI_MAX_LINE bytes. Only applies if INI_USE_STACK is
|
|
zero. */
|
|
#ifndef INI_ALLOW_REALLOC
|
|
#define INI_ALLOW_REALLOC 0
|
|
#endif
|
|
|
|
/* Initial size in bytes for heap line buffer. Only applies if INI_USE_STACK
|
|
is zero. */
|
|
#ifndef INI_INITIAL_ALLOC
|
|
#define INI_INITIAL_ALLOC 200
|
|
#endif
|
|
|
|
/* Stop parsing on first error (default is to keep parsing). */
|
|
#ifndef INI_STOP_ON_FIRST_ERROR
|
|
#define INI_STOP_ON_FIRST_ERROR 0
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* __INI_H__ */
|
|
|
|
#else
|
|
/**
|
|
* Copyright (c) 2016 rxi
|
|
*
|
|
* This library is free software; you can redistribute it and/or modify it
|
|
* under the terms of the MIT license. See `ini.c` for details.
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INI_H
|
|
#define INI_H
|
|
|
|
#define INI_VERSION "0.1.1"
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
typedef struct ini_t ini_t;
|
|
|
|
ini_t* ini_load(const char *filename);
|
|
void ini_free(ini_t *ini);
|
|
const char* ini_get(ini_t *ini, const char *section, const char *key);
|
|
int ini_sget(ini_t *ini, const char *section, const char *key, const char *scanfmt, void *dst);
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
#endif |