etienne herbin / FileIni
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FileIni.h Source File

FileIni.h

Go to the documentation of this file.
00001 #ifndef FILEINI_INCLUDED
00002 #define FILEINI_INCLUDED
00003 
00004 #define MAX_PATH 256
00005 
00006 /** 
00007   * @file
00008   */
00009 typedef struct INIKEY INIKEY;
00010 typedef struct INIKEY* LPINIKEY;
00011 
00012 
00013 /**  A structure that stores a configuration key node. */
00014 struct INIKEY {
00015     char* ptrKeyName;
00016     char* ptrValue;
00017     LPINIKEY lpikNext;
00018 };
00019 
00020 
00021 typedef struct INI INI;
00022 typedef struct INI* LPINI;
00023 
00024 /** A structure that represent a section node */
00025 struct INI {
00026     char* ptrSectionName;
00027     LPINIKEY lpikKey;
00028     LPINI lpinNext;
00029 };
00030 
00031 /** Sets string characters to upper case.
00032   * @param ptrSource A pointer to the string to transform to upper case.
00033   */
00034 int _strupr(char* ptrSource);
00035 
00036 /** @memberof INI
00037   * Loads and parses an Ini file into memory.
00038   * @param ptrFile A pointer to a NULL-terminated string that contains the name of the file to load.
00039   * If this parameters is NULL, the function create a void Ini file in memory.
00040   * @return Returns a pointer to an INI structure that represents the loaded file. If a error occurs, the return value is NULL.
00041   */
00042 LPINI IniLoad (char* ptrFileName);
00043 
00044 /** @memberof INI
00045   * Gets a pointer to a section.
00046   * @param ptrSectionFile A pointer to a NULL-terminated string that stores the name of the needed section.
00047   * @param lpinIni A pointer to an INI structure created with IniLoad().
00048   * @return Returns a pointer to an INI structure that represents the needed section. If a error occurs, the return value is NULL.
00049   */
00050 LPINI IniGetSection (char* ptrSectionName, LPINI lpinIni);
00051 
00052 LPINIKEY IniGetKey(char* ptrVarName, LPINI lpinSection);
00053 /** \fn LPINIKEY IniGetKey(char* ptrVarName, LPINI lpinSection);
00054     @memberof INI
00055     \brief Gets a pointer to a key.
00056     \param[in] ptrVarName A pointer to a NULL-terminated string that stores the name of the needed key.
00057     \param[in] lpinSection A pointer to an INI structure that represents a section (opened with IniGetSection() or IniCreateSection()).
00058     \return Returns a pointer to an INIKEY structure that represents the needed key. If a error occurs, the return value is NULL.
00059 */
00060 
00061 int IniGetValue(char* ptrValue, int iLength, LPINIKEY lpikIniKey);
00062 /** \fn int IniGetValue(char* ptrValue, int iLength, LPINIKEY lpikIniKey);
00063     @memberof INIKEY
00064     \brief Gets a key value.
00065     \param[out] ptrValue A pointer to a buffer that will receive the key content.
00066     \param[in] iLenght The length of the buffer pointed by ptrValue.
00067     \param[in] lpikIniKey A pointer to an INIKEY structure that represents a key (opened with IniGetKey() or IniCreateKey()).
00068     \return Returns 0 if no error occurs, 1 else.
00069 */
00070 
00071 int IniSetValue(char* ptrValue, LPINIKEY lpikIniKey);
00072 /** \fn int IniSetValue(char* ptrValue, LPINIKEY lpikIniKey);
00073     @memberof INIKEY
00074     \brief Sets a key value.
00075     \param[in] ptrValue A pointer to a NULL-terminated string that stores the value to be set.
00076     \param[in] lpikIniKey A pointer to an INIKEY structure that represents a key (opened with IniGetKey() or IniCreateKey()).
00077     \return Returns 0 if no error occurs, 1 else.
00078 */
00079 LPINIKEY IniCreateKey(char* ptrKeyName, char* ptrValue, LPINI lpinSection);
00080 /** @extends INIKEY
00081     \fn LPINIKEY IniCreateKey(char* ptrKeyName, char* ptrValue, LPINI lpinSection);
00082     \brief Creates a key.
00083     \param[in] ptrKeyName A pointer to a NULL-terminated string that stores the name of the key to be created.
00084     \param[in] ptrValue The length of the NULL-terminated string that stores the value of the key to be created.
00085     \param[in] lpinSection A pointer to an INI structure that represents a section (opened with IniGetSection() or IniCreateSection()).
00086     \return Returns a pointer to an INIKEY structure that represents the created key. If a error occurs, the return value is NULL.
00087 */
00088 LPINI IniCreateSection(char* ptrSectionName, LPINI lpinIni);
00089 /** @extends INI
00090     \fn LPINI IniCreateSection(char* ptrSectionName, LPINI lpinIni);
00091     \brief Creates a section.
00092     \param[in] ptrSectionName A pointer to a NULL-terminated string that stores the name of the section to be created.
00093     \param[in] lpinIni A pointer to an INI structure that represents a file (opened with IniLoad()).
00094     \return Returns a pointer to an INI structure that represents the created section. If a error occurs, the return value is NULL.
00095 */
00096 int IniSave(char* ptrFileName, LPINI lpinIni);
00097 /** @extends INI
00098     \fn int IniSave(char* ptrFileName, LPINI lpinIni);
00099     \brief Saves an Ini file .
00100     \param[in] ptrFileName A pointer to a NULL-terminated string that stores the name of the file to be saved.
00101     \param[in] lpinIni A pointer to an INI structure that represents a file (opened with IniLoad()).
00102     \returnsReturns 0 if no error occurs, 1 else.
00103 */
00104 void IniDeleteSection(LPINI lpinSection);
00105 /** @extends INI
00106     \fn void IniDeleteSection(LPINI lpinSection);
00107     \brief Deletes a section.
00108     \param[in] lpinSection A pointer to an INI structure that represents the section to be deleted (opened with IniGetSection() or IniCreateSection()).
00109     \returns No return value avaliable.
00110 */
00111 void IniDeleteKey(LPINIKEY lpikKey);
00112 /** @extends INIKEY
00113     \fn void IniDeleteKey(LPINIKEY lpikKey);
00114   *  \brief Deletes a key.
00115   *  \param[in] lpinSection A pointer to an INI structure that represents the key to be deleted (opened with IniGetKey() or IniCreateKey()).
00116   *  \return No return value avaliable.
00117   */
00118 void IniFree(LPINI lpinIni);
00119 /** @extends INI
00120      \fn void IniFree(LPINI lpinIni);
00121   *  \brief Frees an Ini file.
00122   * \param[in] lpinIni A pointer to an INI structure that represents the file (opened with IniLoad()) to be freed.
00123   *  \return No return value avaliable.
00124   */
00125 
00126 #define INI_ZERO(a) a->ptrSectionName=NULL; \
00127         a->lpikKey=NULL; \
00128         a->lpinNext=NULL
00129 
00130 #define INIKEY_ZERO(a) a->ptrKeyName=NULL; \
00131         a->ptrValue=NULL; \
00132         a->lpikNext=NULL
00133 
00134 #define EXIT_FREE {fclose(ptrFile);return 0;}
00135 
00136 #endif
00137