1 /**
2  * @namespace   biewlib
3  * @file        biewlib/file_ini.h
4  * @brief       This file contains prototypes of .ini file services.
5  * @version     -
6  * @remark      this source file is part of Binary vIEW project (BIEW).
7  *              The Binary vIEW (BIEW) is copyright (C) 1995 Nickols_K.
8  *              All rights reserved. This software is redistributable under the
9  *              licence given in the file "Licence.en" ("Licence.ru" in russian
10  *              translation) distributed in the BIEW archive.
11  * @note        Requires POSIX compatible development system
12  *
13  * @author      Nickols_K
14  * @since       1995
15  * @note        Development, fixes and improvements
16  * @warning     All internal functions is undocumented
17  * @todo        To document internal functions
18 **/
19 #ifndef __FILE_INI_RUNTIME_SUPPORT_SYSTEM__
20 #define __FILE_INI_RUNTIME_SUPPORT_SYSTEM__ 1
21 
22 #ifndef __BBIO_H
23 #include "biewlib/bbio.h"
24 #endif
25 
26 /**
27     List of possible errors that are generic
28 */
29 
30 #define __FI_NOERRORS      0 /**< No errors */
31 #define __FI_BADFILENAME  -1 /**< Can not open file */
32 #define __FI_TOOMANY      -2 /**< Too many opened files */
33 #define __FI_NOTMEM       -3 /**< Memory exhausted */
34 #define __FI_OPENCOND     -4 /**< Opened 'if' (missing '#endif') */
35 #define __FI_IFNOTFOUND   -5 /**< Missing 'if' for 'endif' statement */
36 #define __FI_ELSESTAT     -6 /**< Missing 'if' for 'else' statement */
37 #define __FI_UNRECOGN     -7 /**< Unknown '#' directive */
38 #define __FI_BADCOND      -8 /**< Syntax error in 'if' statement */
39 #define __FI_OPENSECT     -9 /**< Expected opened section or subsection or invalid string */
40 #define __FI_BADCHAR      -10 /**< Bad character on line (possible lost comment) */
41 #define __FI_BADVAR       -11 /**< Bad variable in 'set' or 'delete' statement */
42 #define __FI_BADVAL       -12 /**< Bad value of variable in 'set' statement */
43 #define __FI_NOVAR        -13 /**< Unrecognized name of variable in 'delete' statement */
44 #define __FI_NODEFVAR     -14 /**< Detected undefined variable (case sensitivity?) */
45 #define __FI_ELIFSTAT     -15 /**< Missing 'if' for 'elif' statement */
46 #define __FI_OPENVAR      -16 /**< Opened variable on line (use even number of '%' characters) */
47 #define __FI_NOTEQU       -17 /**< Lost or mismatch character '=' in assigned expression */
48 #define __FI_USER         -18 /**< User defined message */
49 #define __FI_FIUSER       -19 /**< User error */
50 
51 /**
52     possible answers to the errors
53 */
54 
55 #define __FI_IGNORE   0 /**< Ignore error and continue */
56 #define __FI_EXITPROC 1 /**< Terminate the program execution */
57 
58 /**
59     return constants for FiSearch
60 */
61 
62 #define __FI_NOTFOUND   0 /**< Required string is not found */
63 #define __FI_SECTION    1 /**< Required string is section */
64 #define __FI_SUBSECTION 2 /**< required string is subsection */
65 #define __FI_ITEM       3 /**< required string is item */
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
71 typedef BGLOBAL FiHandler; /**< This is the data type used to represent ini stream objects */
72 
73 /** Contains information about current record in ini file */
74 typedef struct tagIniInfo
75 {
76   const char * section;      /**< section name */
77   const char * subsection;   /**< subsection name */
78   const char * item;         /**< item name */
79   const char * value;        /**< value of item */
80 }IniInfo;
81 
82                    /** Pointer to a user supplied function that receive readed record from ini file.
83                      * @return                For continue of scaning - False
84                                               For terminating scaning - True (means: all done)
85                      * @param info            pointers to current record from inni file
86                     **/
87 typedef tBool      (__FASTCALL__ *FiUserFunc)(IniInfo * info);
88 
89 /******************************************************\
90 * You can exchange all this pointers to self routines  *
91 *    and release virtual access to the methods         *
92 *                                                      *
93 * Chematic disgramm :                                  *
94 *                                                      *
95 *   FiFileProcessor   -- call --> FiStringProcessor    *
96 *   FiStringProcessor -- call --> FiCommandProcessor   *
97 *   FiCommandProcessor - call --> FiFileProcessor &    *
98 *                                 FiStringProcessor    *
99 \******************************************************/
100 
101 extern  int    (__FASTCALL__ *FiError)(int nError,int row,const char *addinfo); /**< Default error handler */
102 extern  void   (__FASTCALL__ *FiFileProcessor)(const char *fname); /**< Default file processor */
103 extern  tBool  (__FASTCALL__ *FiStringProcessor)(char * curr_str); /**< Default string processor */
104 extern  tBool  (__FASTCALL__ *FiCommandProcessor)(const char * cmd); /**< Default command processor */
105 extern  tBool  (__FASTCALL__ *FiGetCondition)(const char * cond);    /**< Default processor of conditions */
106 
107 #define FI_MAXSTRLEN 255 /**< Specifies maximal length of string, that can be readed from ini file */
108 
109                    /** Decodes error of ini library and return it string equivalent.
110                      * @return                String, that described error
111                      * @param nError          Specifies error number
112                     **/
113 extern const char *  __FASTCALL__ FiDecodeError(int nError);
114 extern tBool         FiAllWantInput ; /**< Flags indicating, that all input exclude commentaries, i.e. carriage return and line feed and space characters will be returned */
115 extern char *        FiUserMessage;   /**< Pointer to user defined message string */
116 extern char          FiOpenComment;   /**< Character to be used as opening comment. @note comment always start with FiOpenComment symbol and termonated at end of line */
117 
118                    /** Creates file with error description.
119                      * @return                none
120                      * @param nError          Specifies error number
121                      * @param row             Specifies row at which error occured
122                      * @see                   FiAErrorCL
123                     **/
124 void         __FASTCALL__ FiAError(int nError,int row,const char *addinfo);
125 
126                    /** Creates file with error description and treated error as occured at current line.
127                      * @return                none
128                      * @param nError          Specifies error number
129                      * @see                   FiAError
130                     **/
131 void         __FASTCALL__ FiAErrorCL(int nError); /**< error in curent line */
132 
133 /********************************************************************\
134 * High Level procedure                                               *
135 *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*
136 * Use only this function.                                            *
137 * This function calls UserFunc as CALLBACK routine.                  *
138 * All internal variables will be expanded, and command processor     *
139 * will be done. Unknown instruction and hotkeys should be ignored.   *
140 \********************************************************************/
141 
142                    /** Performs ini-file scanning.
143                      * @return                none
144                      * @param filename        Specifies name of file to be processed
145                      * @param fuser           Specifies user-defined callback function
146                      * @note                  Before calling user-defined function
147                      *                        all internal variables will be expanded,
148                      *                        and command processor will be done.
149                      *                        Unknown instruction and hotkeys should
150                      *                        be ignored.
151                      * @see                   FiUserFunc
152                     **/
153 void          __FASTCALL__ FiProgress(const char * filename,FiUserFunc fuser);
154 
155 /******************************************************************\
156 * Low level routines                                               *
157 \******************************************************************/
158 
159 FiHandler     __FASTCALL__ FiOpen( const char * filename );
160 void          __FASTCALL__ FiClose( FiHandler h );
161 int           __FASTCALL__ FiSearch( FiHandler h, const char * Name );
162 void          __FASTCALL__ FiSeekTo( FiHandler h, int nSection, int nSubSection, int nItem );
163 char *        __FASTCALL__ FiGetNextString( FiHandler h, char * store, unsigned int len, char *original );
164 unsigned int  __FASTCALL__ FiGetNumberOfSections( FiHandler h);
165 unsigned int  __FASTCALL__ FiGetTotalNumberOfSubSections( FiHandler h );
166 unsigned int  __FASTCALL__ FiGetLocalNumberOfSubSections( FiHandler h, int nSection );
167 unsigned int  __FASTCALL__ FiGetTotalNumberOfItems( FiHandler h);
168 unsigned int  __FASTCALL__ FiGetLocalNumberOfItems( FiHandler h,int nSection , int nSubSection);
169 
170 tBool         __FASTCALL__ FiisSection( const char * str );
171 tBool         __FASTCALL__ FiisSubSection( const char * str );
172 tBool         __FASTCALL__ FiisItem( const char * str);
173 tBool         __FASTCALL__ FiisCommand( const char * str);
174 
175 unsigned int  __FASTCALL__ FiGetLengthSection( const char * src );
176 unsigned int  __FASTCALL__ FiGetLengthSubSection( const char * src );
177 unsigned int  __FASTCALL__ FiGetLengthItem( const char * src );
178 unsigned int  __FASTCALL__ FiGetLengthValue( const char * src );
179 unsigned int  __FASTCALL__ FiGetLengthCommandString( const char * src );
180 
181 char *        __FASTCALL__ FiGetSectionName(const char * src,char * store);
182 char *        __FASTCALL__ FiGetSubSectionName(const char * src, char * store);
183 char *        __FASTCALL__ FiGetItemName(const char * src, char * store);
184 char *        __FASTCALL__ FiGetValueOfItem(const char * src, char * store);
185 char *        __FASTCALL__ FiGetCommandString(const char * src, char * store);
186 
187 void          __FASTCALL__ FiFileProcessorStd( const char * filename );
188 tBool         __FASTCALL__ FiStringProcessorStd( char * string );
189 tBool         __FASTCALL__ FiCommandProcessorStd( const char * cmd );
190 
191 /**
192     WORD processor
193 */
194 
195 typedef struct tagSTRING
196 {
197   const char * str;
198   unsigned int iptr;
199 }STRING;
200 
201 unsigned int  __FASTCALL__ FiGetLengthBracketString( const char * src );
202 char *        __FASTCALL__ FiGetBracketString(const char * str, char * store);
203 int           __FASTCALL__ FiisLegal(const char * illegal,char c);
204 unsigned int  __FASTCALL__ FiGetLengthNextWord( STRING * str, const char * illegal_symbols);
205 char *        __FASTCALL__ FiGetNextWord( STRING * str,const char * illegal_symbols,char * store );
206 
207 /**
208     variables set
209 */
210 
211 typedef struct tagVar
212 {
213   char * variables;
214   char * associate;
215   struct tagVar * next;
216   struct tagVar * prev;
217 }Var;
218 
219 typedef Var * pVar;
220 
221 pVar            __FASTCALL__ FiConstructVar(const char *v,const char *a);
222 void            __FASTCALL__ FiDeleteVar(pVar pp);
223 void            __FASTCALL__ FiDeleteAllVar( void );
224 const char    * __FASTCALL__ FiExpandVariables(const char * var);
225 tBool           __FASTCALL__ FiExpandAllVar(const char * value,char * store);
226 void            __FASTCALL__ FiAddVariables(const char * var,const char * associate);
227 void            __FASTCALL__ FiRemoveVariables(const char * var);
228 
229 tBool           __FASTCALL__ FiGetConditionStd( const char *condstr);
230 
231 /**
232     High level routines (similar to MS WIN SDK)
233 */
234 
235 #define HINI_FULLCACHED 0x0001
236 #define HINI_UPDATED    0x0002
237 
238 typedef struct tag_iniProfile
239 {
240    FiHandler     handler;
241    char *        fname;
242    void *        cache;
243    unsigned      flags;
244 }hIniProfile;
245 
246 /** For internal purposes */
247 extern void __FASTCALL__ hlFiProgress(hIniProfile *ini,FiUserFunc usrproc);
248 
249 /* For public use */
250                    /** Opens ini file for using with iniReadProfileString and iniWriteProfileString functions.
251                      * @return                handle of opened stream
252                      * @param filename        Specifies name of file to be open
253                      * @param has_error       Pointer to the memory where will be stored error if occured
254                      * @warning               You must not call any other function
255                      *                        If error occured and has_error assigned
256                      *                        non NULL value.
257                      * @see                   iniCloseFile
258                     **/
259 extern hIniProfile*    __FASTCALL__ iniOpenFile(const char *fname,tBool *has_error);
260 
261                    /** Closes ini file stream.
262                      * @return                none
263                      * @param ini             handle of opened stream
264                      * @see                   iniOpenFile
265                     **/
266 extern void            __FASTCALL__ iniCloseFile(hIniProfile *ini);
267 
268                    /** Performs search of given item in ini file and reads it value if found.
269                      * @return                length of readed value
270                      * @param ini             handle of opened stream
271                      * @param section         specifies section name
272                      * @param subsection      specifies subsection name
273                      * @param _item           specifies item name
274                      * @param def_value       specifies default return value
275                      * @param buffer          specifies buffer where will be stored readed value
276                      * @param cbBuffer        specifies size of buffer.
277                      * @note                  if given item is not present in
278                      *                        ini file, then default value will
279                      *                        returned.
280                      * @see                   iniWriteProfileString
281                     **/
282 extern unsigned __FASTCALL__ iniReadProfileString(hIniProfile *ini,
283                                      const char *section,
284                                      const char *subsection,
285                                      const char *_item,
286                                      const char *def_value,
287                                      char *buffer,
288                                      unsigned cbBuffer);
289 
290                    /** Writes given item to ini file.
291                      * @return                True if operation performed successfully
292                      * @param ini             handle of opened stream
293                      * @param section         specifies section name
294                      * @param subsection      specifies subsection name
295                      * @param item            specifies item name
296                      * @param value           specifies value of item
297                      * @see                   iniReadProfileString
298                     **/
299 extern tBool __FASTCALL__ iniWriteProfileString(hIniProfile *ini,
300                                      const char *section,
301                                      const char *subsection,
302                                      const char *item,
303                                      const char *value);
304 
305 #ifdef __cplusplus
306 }
307 #endif
308 
309 #endif
310 
311 
312 
313 
314