ini.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* inih -- simple .INI file parser
  2. inih is released under the New BSD license (see LICENSE.txt). Go to the project
  3. home page for more info:
  4. https://github.com/benhoyt/inih
  5. */
  6. #ifndef __INI_H__
  7. #define __INI_H__
  8. /* Make this header file easier to include in C++ code */
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #include <stdio.h>
  13. /* Typedef for prototype of handler function. */
  14. typedef int (*ini_handler)(void *user,
  15. const char *section,
  16. const char *name,
  17. const char *value);
  18. /* Typedef for prototype of fgets-style reader function. */
  19. typedef char *(*ini_reader)(char *str, int num, void *stream);
  20. /* Parse given INI-style file. May have [section]s, name=value pairs
  21. (whitespace stripped), and comments starting with ';' (semicolon). Section
  22. is "" if name=value pair parsed before any section heading. name:value
  23. pairs are also supported as a concession to Python's configparser.
  24. For each name=value pair parsed, call handler function with given user
  25. pointer as well as section, name, and value (data only valid for duration
  26. of handler call). Handler should return nonzero on success, zero on error.
  27. Returns 0 on success, line number of first error on parse error (doesn't
  28. stop on first error), -1 on file open error, or -2 on memory allocation
  29. error (only when INI_USE_STACK is zero).
  30. */
  31. int ini_parse(const char *filename, ini_handler handler, void *user);
  32. /* Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
  33. close the file when it's finished -- the caller must do that. */
  34. int ini_parse_file(FILE *file, ini_handler handler, void *user);
  35. /* Same as ini_parse(), but takes an ini_reader function pointer instead of
  36. filename. Used for implementing custom or string-based I/O. */
  37. int
  38. ini_parse_stream(ini_reader reader, void *stream, ini_handler handler, void *user);
  39. /* Nonzero to allow multi-line value parsing, in the style of Python's
  40. configparser. If allowed, ini_parse() will call the handler with the same
  41. name for each subsequent line parsed. */
  42. #ifndef INI_ALLOW_MULTILINE
  43. #define INI_ALLOW_MULTILINE 1
  44. #endif
  45. /* Nonzero to allow a UTF-8 BOM sequence (0xEF 0xBB 0xBF) at the start of
  46. the file. See http://code.google.com/p/inih/issues/detail?id=21 */
  47. #ifndef INI_ALLOW_BOM
  48. #define INI_ALLOW_BOM 1
  49. #endif
  50. /* Nonzero to allow inline comments (with valid inline comment characters
  51. specified by INI_INLINE_COMMENT_PREFIXES). Set to 0 to turn off and match
  52. Python 3.2+ configparser behaviour. */
  53. #ifndef INI_ALLOW_INLINE_COMMENTS
  54. #define INI_ALLOW_INLINE_COMMENTS 1
  55. #endif
  56. #ifndef INI_INLINE_COMMENT_PREFIXES
  57. #define INI_INLINE_COMMENT_PREFIXES ";"
  58. #endif
  59. /* Nonzero to use stack, zero to use heap (malloc/free). */
  60. #ifndef INI_USE_STACK
  61. #define INI_USE_STACK 1
  62. #endif
  63. /* Stop parsing on first error (default is to keep parsing). */
  64. #ifndef INI_STOP_ON_FIRST_ERROR
  65. #define INI_STOP_ON_FIRST_ERROR 0
  66. #endif
  67. /* Maximum line length for any line in INI file. */
  68. #ifndef INI_MAX_LINE
  69. #define INI_MAX_LINE 2000
  70. #endif
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. #endif /* __INI_H__ */