1 /*
2     INI LIBRARY
3 
4     Header file for the internal constants for the INI interface.
5 
6     Copyright (C) Dmitri Pal <dpal@redhat.com> 2010
7 
8     INI Library is free software: you can redistribute it and/or modify
9     it under the terms of the GNU Lesser General Public License as published by
10     the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12 
13     INI Library is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU Lesser General Public License for more details.
17 
18     You should have received a copy of the GNU Lesser General Public License
19     along with INI Library.  If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #ifndef INI_DEFINES_H
23 #define INI_DEFINES_H
24 
25 #include <stdint.h>
26 
27 #define NAME_OVERHEAD   10
28 
29 #define SLASH           "/"
30 
31 
32 /* Name of the special collection used to store parsing errors */
33 #define FILE_ERROR_SET  "ini_file_error_set"
34 
35 /* Text error strings used when errors are printed out */
36 #define WARNING_TXT         _("Warning")
37 #define ERROR_TXT           _("Error")
38 /* For parse errors */
39 #define WRONG_COLLECTION    _("Passed in list is not a list of parse errors.\n")
40 #define FAILED_TO_PROCCESS  _("Internal Error. Failed to process error list.\n")
41 #define ERROR_HEADER        _("Parsing errors and warnings in file: %s\n")
42 /* For grammar errors */
43 #define WRONG_GRAMMAR       _("Passed in list is not a list of grammar errors.\n")
44 #define FAILED_TO_PROC_G    _("Internal Error. Failed to process list of grammar errors.\n")
45 #define ERROR_HEADER_G      _("Logical errors and warnings in file: %s\n")
46 /* For validation errors */
47 #define WRONG_VALIDATION    _("Passed in list is not a list of validation errors.\n")
48 #define FAILED_TO_PROC_V    _("Internal Error. Failed to process list of validation errors.\n")
49 #define ERROR_HEADER_V      _("Validation errors and warnings in file: %s\n")
50 
51 #define LINE_FORMAT         _("%s (%d) on line %d: %s")
52 #define MAX_ERROR_LINE      120
53 
54 /* Codes that parsing function can return */
55 #define RET_PAIR        0
56 #define RET_COMMENT     1
57 #define RET_SECTION     2
58 #define RET_INVALID     3
59 #define RET_EMPTY       4
60 #define RET_EOF         5
61 #define RET_ERROR       6
62 
63 #define INI_ERROR       "errors"
64 #define INI_METADATA    "meta"
65 #define INI_ERROR_NAME  "errname"
66 #define INI_CONFIG_NAME "INI"
67 
68 #define INI_SECTION_KEY "["
69 
70 /* Internal sizes. MAX_KEY is defined in config.h */
71 #define MAX_VALUE       PATH_MAX
72 #define BUFFER_SIZE     MAX_KEY + MAX_VALUE + 3
73 
74 /* Beffer length used for int to string conversions */
75 #define CONVERSION_BUFFER 80
76 
77 /* Size of the block for a value */
78 #define INI_VALUE_BLOCK   100
79 
80 /* Default boundary */
81 #define INI_WRAP_BOUNDARY 80
82 
83 /* This constant belongs here. */
84 #define COL_CLASS_INI_BASE        20000
85 #define COL_CLASS_INI_CONFIG      COL_CLASS_INI_BASE + 0
86 #define COL_CLASS_INI_SECTION     COL_CLASS_INI_BASE + 1
87 
88 /**
89  * @brief Name of the default section.
90  *
91  * This is the name of the implied section where orphan key-value
92  * pairs will be put.
93  */
94 #define INI_DEFAULT_SECTION "default"
95 
96 /**
97  * @brief A one level collection of parse errors.
98  *
99  * Collection stores \ref parse_error structures.
100  */
101 #define COL_CLASS_INI_PERROR      COL_CLASS_INI_BASE + 2
102 
103 /**
104  * @brief Collection of metadata.
105  *
106  * Collection that stores metadata.
107  */
108 #define COL_CLASS_INI_META        COL_CLASS_INI_BASE + 4
109 
110 /* Family of errors */
111 #define INI_FAMILY_PARSING      0
112 #define INI_FAMILY_VALIDATION   1
113 #define INI_FAMILY_GRAMMAR      2
114 
115 #define INI_MV1S_MASK      0x000F /* Merge values options mask
116                                    * for one section */
117 #define INI_MV2S_MASK      0x00F0 /* Merge values options mask
118                                    * for two sections. */
119 #define INI_MS_MASK        0x0F00 /* Merge section options mask */
120 #define INI_MS_MODE_MASK   0x0300 /* Merge section merge mode mask */
121 
122 
123 /* Different error string functions can be passed as callbacks */
124 typedef const char * (*error_fn)(int error);
125 
126 int ini_flags_have(uint32_t flag, uint32_t flags);
127 
128 #endif
129