Debian Codegraph @

include/toolcfg.h

raw symbols SCIP
1 // ****************************************************************************
2 // Project: libguytools
3 // ****************************************************************************
4 // Programmer: Guy Voncken
5 // Police Grand-Ducale
6 // Service de Police Judiciaire
7 // Section Nouvelles Technologies
8 // ****************************************************************************
9 // Module: Configuration utility
10 // ****************************************************************************
11
12 // Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
13 // 2018, 2019
14 // Guy Voncken
15 //
16 // This file is part of libguytools.
17 //
18 // libguytools is free software: you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation, either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 // libguytools is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 // GNU General Public License for more details.
27 //
28 // You should have received a copy of the GNU General Public License
29 // along with libguytools. If not, see <http://www.gnu.org/licenses/>.
30
31 #ifndef __TOOLCFG_H__
32 #define __TOOLCFG_H__
33
34 /* ------------------------------ */
35 /* Type & structure definitions */
36 /* ------------------------------ */
37
38 typedef enum
39 {
40 CFGTYPE_PRESENCE,
41 CFGTYPE_INTEGER,
42 CFGTYPE_DOUBLE,
43 CFGTYPE_STRING,
44 CFGTYPE_SET,
45 CFGTYPE_HMS,
46 CFGTYPE_NULL
47 } t_ToolCfgType;
48
49
50 typedef enum
51 {
52 CFGASN_SOURCE = 0x0000000F,
53 CFGASN_CMD = 0x00000001,
54 CFGASN_CFG = 0x00000002,
55
56 CFGASN_COUNT = 0x000000F0,
57 CFGASN_ONCE = 0x00000010,
58 CFGASN_TWICE = 0x00000020,
59 CFGASN_MULTIPLE = 0x00000030,
60
61 CFGASN_OPTIONAL = 0x00000100
62 } t_ToolCfgAssignment;
63
64
65 #define CFGASSIGN_CMD ((t_ToolCfgAssignment)(CFGASN_CMD | CFGASN_MULTIPLE ))
66 #define CFGASSIGN_CFG_ONCE ((t_ToolCfgAssignment)(CFGASN_CFG | CFGASN_ONCE ))
67 #define CFGASSIGN_CFG_MULTIPLE ((t_ToolCfgAssignment)(CFGASN_CFG | CFGASN_MULTIPLE ))
68 #define CFGASSIGN_BOTH_ONCE ((t_ToolCfgAssignment)(CFGASN_CMD | CFGASN_CFG | CFGASN_ONCE ))
69 #define CFGASSIGN_BOTH_TWICE ((t_ToolCfgAssignment)(CFGASN_CMD | CFGASN_CFG | CFGASN_TWICE ))
70 #define CFGASSIGN_BOTH_MULTIPLE ((t_ToolCfgAssignment)(CFGASN_CMD | CFGASN_CFG | CFGASN_MULTIPLE ))
71 #define CFGASSIGN_OPTIONAL ((t_ToolCfgAssignment)(CFGASN_CMD | CFGASN_CFG | CFGASN_MULTIPLE | CFGASN_OPTIONAL))
72
73 typedef struct
74 {
75 t_pcchar pSetString;
76 t_int SetValue;
77 } t_ToolCfgSet, *t_pToolCfgSet;
78
79 typedef struct
80 {
81 t_pcchar pName; /* The last one in the table must have pName set to NULL */
82 t_ToolCfgType CfgType;
83 long DestAddr; /* For Params: the destination address: For table columns: the offset from the baseaddress */
84 t_int DestLen; /* for strings, this length DOES NOT include the trailing '\0' */
85 t_double MinValue;
86 t_double MaxValue;
87 t_pToolCfgSet pSetArray;
88 } t_ToolCfgDataDesc, *t_pToolCfgDataDesc;
89
90 /* ------------------------------------- */
91 /* Structure to describe one parameter */
92 /* ------------------------------------- */
93
94 typedef struct _t_ToolCfgParamDesc *t_pToolCfgParamDesc;
95
96 typedef APIRET (* t_pToolCfgCallOnInitFn)(t_pToolCfgParamDesc pCfgParamDesc, t_pcchar *ppErrorText);
97
98 typedef struct _t_ToolCfgParamDesc
99 {
100 t_ToolCfgAssignment Assign;
101 t_pToolCfgCallOnInitFn pCallOnInitFn;
102 t_ToolCfgDataDesc DataDesc;
103
104 /* The following two elements will be filled by the configuration scanner CfgScanConfiguration */
105 /* and do not need to be set by the calling function. */
106
107 t_int CmdAssignments;
108 t_int CfgAssignments;
109 } t_ToolCfgParamDesc;
110
111 #define CFG_FILLUP_FORLINT 0,0
112
113 /* ------------------------------- */
114 /* Structure to describe a table */
115 /* ------------------------------- */
116
117 typedef APIRET (* t_pTableStartFn )(t_pchar pTableName, long *pBaseAddr, t_pcchar *ppErrorText);
118 typedef APIRET (* t_pTableSaveAndNextFn)( long *pBaseAddr, t_pcchar *ppErrorText);
119 typedef APIRET (* t_pTableEndFn )( t_pcchar *ppErrorText);
120
121 typedef struct
122 {
123 t_pcchar pTableType;
124 t_pTableStartFn pStartFn;
125 t_pTableSaveAndNextFn pSaveAndNextFn;
126 t_pTableEndFn pEndFn;
127 t_pToolCfgDataDesc pDataDescArray; /* Pointer to array of data descriptors (one for each column) */
128 } t_ToolCfgTableDesc, *t_pToolCfgTableDesc;
129
130 /* Prototype of the user's logfunction */
131
132 typedef void (* t_pToolCfgUserLogFn)(t_pcchar pFileName, t_pcchar pFunction, t_int LineNr, t_pcchar pFormat, va_list pArguments);
133
134 /* ----------------- */
135 /* Prototypes */
136 /* ----------------- */
137
138 #ifdef __cplusplus
139 #define EXTERN extern "C"
140 #elif __STDC__
141 #define EXTERN extern
142 #else
143 #error Unknown C compiler mode
144 #endif
145
146 EXTERN APIRET ToolCfgInit (int argc, char *argv[]);
147 EXTERN APIRET ToolCfgDeInit (void);
148 EXTERN APIRET ToolCfgUseAdjustedCommandLine (int argc, char *argv[]);
149 EXTERN APIRET ToolCfgSetLogFn (t_pToolCfgUserLogFn pUserLogFn);
150 EXTERN APIRET ToolCfgGetCmdLineOption (t_pcchar pParamName, t_pcchar *ppValue);
151 EXTERN APIRET ToolCfgAddGlobalSectionName (t_pcchar pSectionName);
152 EXTERN APIRET ToolCfgDelGlobalSectionName (t_pcchar pSectionName);
153 EXTERN APIRET ToolCfgScanConfiguration (t_pcchar pFileName, t_pcchar pSectionName, t_ToolCfgParamDesc *pParamDescArray, t_ToolCfgTableDesc *pTableDescArray);
154 EXTERN APIRET ToolCfgBuildTemplate (t_pcchar pFileName, t_pcchar pComment, t_pcchar pSectionName, t_ToolCfgParamDesc *pParamDescArray, t_ToolCfgTableDesc *pTableDescArray);
155 EXTERN APIRET ToolCfgLogConfiguration (t_pToolCfgParamDesc pParamDescArray);
156 EXTERN APIRET ToolCfgPrintParamContents (t_pToolCfgParamDesc pParamDescArray, t_pchar pName, t_pchar pBuff);
157 EXTERN APIRET ToolCfgGetSetString (t_pToolCfgSet pSetArray, int SetValue, const char **ppSetString);
158
159 /* CfgGetCommandLineOption is useful to the params that cannot be contained in the configuration file */
160 /* file itself, as for example the name of the cfg file. */
161 /* Use CfgScanConfiguration to read a certain section of the cfg file. The two arrays pParamDescArray */
162 /* and pTableDescArray specify the expected parameters and tables found in the indicated section. */
163
164 /* ------------------------------ */
165 /* Error codes */
166 /* ------------------------------ */
167
168 static const APIRET TOOLCFG_ERROR_OPEN_FAILED = ERROR_BASE_TOOL_CFG + 1;
169 static const APIRET TOOLCFG_ERROR_READ_FAILED = ERROR_BASE_TOOL_CFG + 2;
170 static const APIRET TOOLCFG_ERROR_CLOSE_FAILED = ERROR_BASE_TOOL_CFG + 3;
171 static const APIRET TOOLCFG_ERROR_FILE_NOT_FOUND = ERROR_BASE_TOOL_CFG + 4;
172 static const APIRET TOOLCFG_ERROR_SEEKEND_FAILED = ERROR_BASE_TOOL_CFG + 5;
173 static const APIRET TOOLCFG_ERROR_SEEKSET_FAILED = ERROR_BASE_TOOL_CFG + 6;
174 static const APIRET TOOLCFG_ERROR_INVALID_STATE = ERROR_BASE_TOOL_CFG + 7;
175 static const APIRET TOOLCFG_ERROR_NAME_TOO_LONG = ERROR_BASE_TOOL_CFG + 8;
176 static const APIRET TOOLCFG_ERROR_INCLUDE_NESTING_OVERFLOW = ERROR_BASE_TOOL_CFG + 9;
177 static const APIRET TOOLCFG_ERROR_CONFIG_ERROR = ERROR_BASE_TOOL_CFG + 10;
178 static const APIRET TOOLCFG_ERROR_INVALID_ASSIGNMENT_OPTION = ERROR_BASE_TOOL_CFG + 11;
179 static const APIRET TOOLCFG_ERROR_INVALID_CFGTYPE = ERROR_BASE_TOOL_CFG + 12;
180 static const APIRET TOOLCFG_ERROR_TEMPLATE_OPEN_FAILED = ERROR_BASE_TOOL_CFG + 13;
181 static const APIRET TOOLCFG_ERROR_FPRINTF_FAILED = ERROR_BASE_TOOL_CFG + 14;
182 static const APIRET TOOLCFG_ERROR_CMDLINE_OPTION_NOT_FOUND = ERROR_BASE_TOOL_CFG + 15;
183 static const APIRET TOOLCFG_ERROR_SETBUF_FAILED = ERROR_BASE_TOOL_CFG + 16;
184 static const APIRET TOOLCFG_ERROR_MALLOC_FAILED = ERROR_BASE_TOOL_CFG + 17;
185 static const APIRET TOOLCFG_ERROR_SECTIONNAME_TOO_LONG = ERROR_BASE_TOOL_CFG + 18;
186 static const APIRET TOOLCFG_ERROR_TOO_MANY_SECTIONNAMES = ERROR_BASE_TOOL_CFG + 19;
187 static const APIRET TOOLCFG_ERROR_SECTIONNAME_NOTFOUND = ERROR_BASE_TOOL_CFG + 20;
188 static const APIRET TOOLCFG_ERROR_UNKNOWN_PARAMETER = ERROR_BASE_TOOL_CFG + 21;
189 static const APIRET TOOLCFG_ERROR_UNEXPECTED_EOL = ERROR_BASE_TOOL_CFG + 22;
190
191 #endif
192