The code from https://github.com/vpcola/Nucleo
ini.h@0:5464d5e415e5, 2014-10-08 (annotated)
- Committer:
- sinrab
- Date:
- Wed Oct 08 11:00:24 2014 +0000
- Revision:
- 0:5464d5e415e5
The code from https://github.com/vpcola/Nucleo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sinrab | 0:5464d5e415e5 | 1 | /* inih -- simple .INI file parser |
sinrab | 0:5464d5e415e5 | 2 | |
sinrab | 0:5464d5e415e5 | 3 | inih is released under the New BSD license (see LICENSE.txt). Go to the project |
sinrab | 0:5464d5e415e5 | 4 | home page for more info: |
sinrab | 0:5464d5e415e5 | 5 | |
sinrab | 0:5464d5e415e5 | 6 | http://code.google.com/p/inih/ |
sinrab | 0:5464d5e415e5 | 7 | |
sinrab | 0:5464d5e415e5 | 8 | */ |
sinrab | 0:5464d5e415e5 | 9 | |
sinrab | 0:5464d5e415e5 | 10 | #ifndef __INI_H__ |
sinrab | 0:5464d5e415e5 | 11 | #define __INI_H__ |
sinrab | 0:5464d5e415e5 | 12 | |
sinrab | 0:5464d5e415e5 | 13 | /* Make this header file easier to include in C++ code */ |
sinrab | 0:5464d5e415e5 | 14 | #ifdef __cplusplus |
sinrab | 0:5464d5e415e5 | 15 | extern "C" { |
sinrab | 0:5464d5e415e5 | 16 | #endif |
sinrab | 0:5464d5e415e5 | 17 | |
sinrab | 0:5464d5e415e5 | 18 | #include <stdio.h> |
sinrab | 0:5464d5e415e5 | 19 | |
sinrab | 0:5464d5e415e5 | 20 | /* Parse given INI-style file. May have [section]s, name=value pairs |
sinrab | 0:5464d5e415e5 | 21 | (whitespace stripped), and comments starting with ';' (semicolon). Section |
sinrab | 0:5464d5e415e5 | 22 | is "" if name=value pair parsed before any section heading. name:value |
sinrab | 0:5464d5e415e5 | 23 | pairs are also supported as a concession to Python's ConfigParser. |
sinrab | 0:5464d5e415e5 | 24 | |
sinrab | 0:5464d5e415e5 | 25 | For each name=value pair parsed, call handler function with given user |
sinrab | 0:5464d5e415e5 | 26 | pointer as well as section, name, and value (data only valid for duration |
sinrab | 0:5464d5e415e5 | 27 | of handler call). Handler should return nonzero on success, zero on error. |
sinrab | 0:5464d5e415e5 | 28 | |
sinrab | 0:5464d5e415e5 | 29 | Returns 0 on success, line number of first error on parse error (doesn't |
sinrab | 0:5464d5e415e5 | 30 | stop on first error), -1 on file open error, or -2 on memory allocation |
sinrab | 0:5464d5e415e5 | 31 | error (only when INI_USE_STACK is zero). |
sinrab | 0:5464d5e415e5 | 32 | */ |
sinrab | 0:5464d5e415e5 | 33 | int ini_parse(const char* filename, |
sinrab | 0:5464d5e415e5 | 34 | int (*handler)(void* user, const char* section, |
sinrab | 0:5464d5e415e5 | 35 | const char* name, const char* value), |
sinrab | 0:5464d5e415e5 | 36 | void* user); |
sinrab | 0:5464d5e415e5 | 37 | |
sinrab | 0:5464d5e415e5 | 38 | /* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't |
sinrab | 0:5464d5e415e5 | 39 | close the file when it's finished -- the caller must do that. */ |
sinrab | 0:5464d5e415e5 | 40 | int ini_parse_file(FILE* file, |
sinrab | 0:5464d5e415e5 | 41 | int (*handler)(void* user, const char* section, |
sinrab | 0:5464d5e415e5 | 42 | const char* name, const char* value), |
sinrab | 0:5464d5e415e5 | 43 | void* user); |
sinrab | 0:5464d5e415e5 | 44 | |
sinrab | 0:5464d5e415e5 | 45 | /* Nonzero to allow multi-line value parsing, in the style of Python's |
sinrab | 0:5464d5e415e5 | 46 | ConfigParser. If allowed, ini_parse() will call the handler with the same |
sinrab | 0:5464d5e415e5 | 47 | name for each subsequent line parsed. */ |
sinrab | 0:5464d5e415e5 | 48 | #ifndef INI_ALLOW_MULTILINE |
sinrab | 0:5464d5e415e5 | 49 | #define INI_ALLOW_MULTILINE 1 |
sinrab | 0:5464d5e415e5 | 50 | #endif |
sinrab | 0:5464d5e415e5 | 51 | |
sinrab | 0:5464d5e415e5 | 52 | /* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of |
sinrab | 0:5464d5e415e5 | 53 | the file. See http://code.google.com/p/inih/issues/detail?id=21 */ |
sinrab | 0:5464d5e415e5 | 54 | #ifndef INI_ALLOW_BOM |
sinrab | 0:5464d5e415e5 | 55 | #define INI_ALLOW_BOM 1 |
sinrab | 0:5464d5e415e5 | 56 | #endif |
sinrab | 0:5464d5e415e5 | 57 | |
sinrab | 0:5464d5e415e5 | 58 | /* Nonzero to use stack, zero to use heap (malloc/free). */ |
sinrab | 0:5464d5e415e5 | 59 | #ifndef INI_USE_STACK |
sinrab | 0:5464d5e415e5 | 60 | #define INI_USE_STACK 1 |
sinrab | 0:5464d5e415e5 | 61 | #endif |
sinrab | 0:5464d5e415e5 | 62 | |
sinrab | 0:5464d5e415e5 | 63 | /* Stop parsing on first error (default is to keep parsing). */ |
sinrab | 0:5464d5e415e5 | 64 | #ifndef INI_STOP_ON_FIRST_ERROR |
sinrab | 0:5464d5e415e5 | 65 | #define INI_STOP_ON_FIRST_ERROR 0 |
sinrab | 0:5464d5e415e5 | 66 | #endif |
sinrab | 0:5464d5e415e5 | 67 | |
sinrab | 0:5464d5e415e5 | 68 | /* Maximum line length for any line in INI file. */ |
sinrab | 0:5464d5e415e5 | 69 | #ifndef INI_MAX_LINE |
sinrab | 0:5464d5e415e5 | 70 | #define INI_MAX_LINE 200 |
sinrab | 0:5464d5e415e5 | 71 | #endif |
sinrab | 0:5464d5e415e5 | 72 | |
sinrab | 0:5464d5e415e5 | 73 | #ifdef __cplusplus |
sinrab | 0:5464d5e415e5 | 74 | } |
sinrab | 0:5464d5e415e5 | 75 | #endif |
sinrab | 0:5464d5e415e5 | 76 | |
sinrab | 0:5464d5e415e5 | 77 | #endif /* __INI_H__ */ |
sinrab | 0:5464d5e415e5 | 78 |