sc/ini/sc_ini.h

78 lines
3.0 KiB
C
Raw Normal View History

2020-11-11 01:19:49 +03:00
/*
* BSD-3-Clause
2020-11-11 01:19:49 +03:00
*
* Copyright 2021 Ozan Tezcan
* All rights reserved.
2020-11-11 01:19:49 +03:00
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
2020-11-11 01:19:49 +03:00
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
2020-11-11 01:19:49 +03:00
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
2020-11-11 01:19:49 +03:00
*/
#ifndef SC_INI_H
#define SC_INI_H
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
2021-04-13 22:36:50 +03:00
#define SC_INI_VERSION "2.0.0"
2021-02-14 16:19:26 +03:00
2021-02-06 21:36:18 +03:00
// Set max line length. If a line is longer, it will be truncated silently.
2020-11-11 01:19:49 +03:00
#define SC_INI_MAX_LINE_LEN 1024
/**
2021-02-03 08:09:50 +03:00
* @param arg user arg
* @param line current line number
2021-02-03 08:09:50 +03:00
* @param section section
* @param key key
* @param value value
2020-11-11 01:19:49 +03:00
* @return Return '0' on success, any other value will make parser
2021-02-03 08:09:50 +03:00
* stop and return error
2020-11-11 01:19:49 +03:00
*/
typedef int (*sc_ini_on_item)(void *arg, int line, const char *section,
const char *key, const char *value);
2020-11-11 01:19:49 +03:00
/**
2021-02-03 08:09:50 +03:00
* @param arg user data to be passed to 'on_item' callback
* @param on_item callback
* @param filename filename
2020-11-11 01:19:49 +03:00
* @return - '0' on success,
* - '-1' on file IO error.
* - positive line number on parsing error
* - 'on_item' return value if it returns other than '0'
*/
int sc_ini_parse_file(void *arg, sc_ini_on_item on_item, const char *filename);
/**
2021-02-03 08:09:50 +03:00
* @param arg user data to be passed to 'on_item' callback.
* @param on_item callback
* @param str string to parse
2020-11-11 01:19:49 +03:00
* @return - '0' on success,
* - positive line number on parsing error
2021-02-03 08:09:50 +03:00
* - "on_item's return value" if it returns other than '0'
2020-11-11 01:19:49 +03:00
*/
int sc_ini_parse_string(void *arg, sc_ini_on_item on_item, const char *str);
#endif