mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
ini.hpp
Go to the documentation of this file.
1 /** \file ini.hpp
2  * \author Jared R. Males
3  * \brief The inih ini-style, file parser modified for mxlib.
4  *
5  * \ingroup mxApp_files
6  *
7  */
8 
9 //***********************************************************************//
10 // Copyright 2015, 2016, 2017, 2018 Jared R. Males (jaredmales@gmail.com)
11 //
12 // This file is part of mxlib.
13 //
14 // mxlib is free software: you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation, either version 3 of the License, or
17 // (at your option) any later version.
18 //
19 // mxlib is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with mxlib. If not, see <http://www.gnu.org/licenses/>.
26 //***********************************************************************//
27 
28 // This file was originally ini.c
29 // Modifications made by jaredmales@gmail.com to support inclusion
30 // in a c++ library and other features:
31 // #ifdef protection
32 // made comment character configurable at compile time by adding INI_COMMENT_CHAR
33 // copied defines from ini.h
34 // copied documentation from ini.h, and updated for doxygen
35 // commented out ini.h
36 // NOTE: original ini.h and ini.c are in the inih directory
37 
38 
39 #ifndef ini_hpp
40 #define ini_hpp
41 
42 
43 /* inih -- simple .INI file parser
44 
45 inih is released under the New BSD license (see LICENSE.txt). Go to the project
46 home page for more info:
47 
48 http://code.google.com/p/inih/
49 
50 */
51 
52 #include <stdio.h>
53 #include <ctype.h>
54 #include <string.h>
55 
56 //#include "ini.h"
57 
58 /// Parse ini file
59 /** Same as ini_parse(), but takes a FILE* instead of filename. This doesn't
60  close the file when it's finished -- the caller must do that. */
61 int ini_parse_file(FILE* file,
62  int (*handler)(void*, const char*, const char*,
63  const char*),
64  void* user
65  );
66 
67 /// Parse given INI-style file.
68 /** May have [section]s, name=value pairs
69  (whitespace stripped), and comments. By default comments start with ';' (semicolon)
70  but this can be configured with the INI_COMMENT_CHAR macro. Section
71  is "" if name=value pair parsed before any section heading. name:value
72  pairs are also supported as a concession to Python's ConfigParser.
73 
74  For each name=value pair parsed, call handler function with given user
75  pointer as well as section, name, and value (data only valid for duration
76  of handler call). Handler should return nonzero on success, zero on error.
77 
78  Returns 0 on success, line number of first error on parse error (doesn't
79  stop on first error), -1 on file open error, or -2 on memory allocation
80  error (only when INI_USE_STACK is zero).
81 */
82 int ini_parse(const char* filename,
83  int (*handler)(void*, const char*, const char*, const char*),
84  void* user
85  );
86 
87 #endif //ini_hpp
int ini_parse_file(FILE *file, int(*handler)(void *, const char *, const char *, const char *), void *user)
Parse ini file.
Definition: ini.cpp:88
int ini_parse(const char *filename, int(*handler)(void *, const char *, const char *, const char *), void *user)
Parse given INI-style file.
Definition: ini.cpp:193