📄 group__etc__fns.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>MiniGUI V1.6.10 API Reference: Configuration file operations</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.2 --><div class="qindex"><a class="qindex" href="index.htm">Main Page</a> | <a class="qindex" href="modules.htm">Modules</a> | <a class="qindex" href="classes.htm">Alphabetical List</a> | <a class="qindex" href="annotated.htm">Data Structures</a> | <a class="qindex" href="dirs.htm">Directories</a> | <a class="qindex" href="files.htm">File List</a> | <a class="qindex" href="functions.htm">Data Fields</a> | <a class="qindex" href="globals.htm">Globals</a> | <a class="qindex" href="pages.htm">Related Pages</a></div><h1>Configuration file operations<br><small>[<a class="el" href="group__lite__fns.htm">MiniGUI-Processes specific functions</a>]</small></h1><h2>Data Structures</h2><ul><li>struct <a class="el" href="struct__ETCSECTION.htm">_ETCSECTION</a><li>struct <a class="el" href="struct__ETC__S.htm">_ETC_S</a></ul><h2>Defines</h2><ul><li>#define <a class="el" href="group__etc__fns.htm#ga21">ETC_MAXLINE</a> 1024<dl class="el"><dd class="mdescRight">The max line number of etc file. <a href="#ga21"></a><br></dl><li>#define <a class="el" href="group__etc__fns.htm#ga22">ETC_FILENOTFOUND</a> -1<dl class="el"><dd class="mdescRight">No found etc file. <a href="#ga22"></a><br></dl><li>#define <a class="el" href="group__etc__fns.htm#ga23">ETC_SECTIONNOTFOUND</a> -2<dl class="el"><dd class="mdescRight">No found section in etc file. <a href="#ga23"></a><br></dl><li>#define <a class="el" href="group__etc__fns.htm#ga24">ETC_KEYNOTFOUND</a> -3<dl class="el"><dd class="mdescRight">No found key in etc file. <a href="#ga24"></a><br></dl><li>#define <a class="el" href="group__etc__fns.htm#ga25">ETC_TMPFILEFAILED</a> -4<dl class="el"><dd class="mdescRight">Create tmpfile failed. <a href="#ga25"></a><br></dl><li>#define <a class="el" href="group__etc__fns.htm#ga26">ETC_FILEIOFAILED</a> -5<dl class="el"><dd class="mdescRight">IO operation failed to etc file. <a href="#ga26"></a><br></dl><li>#define <a class="el" href="group__etc__fns.htm#ga27">ETC_INTCONV</a> -6<dl class="el"><dd class="mdescRight">Convert the value string to an integer failed. <a href="#ga27"></a><br></dl><li>#define <a class="el" href="group__etc__fns.htm#ga28">ETC_INVALIDOBJ</a> -7<dl class="el"><dd class="mdescRight">Invalid object to etc file. <a href="#ga28"></a><br></dl><li>#define <a class="el" href="group__etc__fns.htm#ga29">ETC_READONLYOBJ</a> -8<dl class="el"><dd class="mdescRight">Read only to etc file. <a href="#ga29"></a><br></dl><li>#define <a class="el" href="group__etc__fns.htm#ga30">ETC_OK</a> 0<dl class="el"><dd class="mdescRight">Operate success to etc file. <a href="#ga30"></a><br></dl><li>#define <a class="el" href="group__etc__fns.htm#ga31">SetValueToEtc</a>(hEtc, pSection, pKey, pValue) GetValueFromEtc(hEtc, pSection, pKey, pValue, -1)<dl class="el"><dd class="mdescRight">Sets the value in the etc object. <a href="#ga31"></a><br></dl></ul><h2>Typedefs</h2><ul><li>typedef <a class="el" href="struct__ETCSECTION.htm">_ETCSECTION</a> <a class="el" href="group__etc__fns.htm#ga0">ETCSECTION</a><li>typedef <a class="el" href="struct__ETCSECTION.htm">ETCSECTION</a> * <a class="el" href="group__etc__fns.htm#ga1">PETCSECTION</a><li>typedef <a class="el" href="struct__ETC__S.htm">_ETC_S</a> <a class="el" href="group__etc__fns.htm#ga2">ETC_S</a></ul><h2>Functions</h2><ul><li>MG_EXPORT int GUIAPI <a class="el" href="group__etc__fns.htm#ga5">GetValueFromEtcFile</a> (const char *pEtcFile, const char *pSection, const char *pKey, char *pValue, int iLen)<dl class="el"><dd class="mdescRight">Gets value from a configuration file. <a href="#ga5"></a><br></dl><li>MG_EXPORT int GUIAPI <a class="el" href="group__etc__fns.htm#ga6">GetIntValueFromEtcFile</a> (const char *pEtcFile, const char *pSection, const char *pKey, int *value)<dl class="el"><dd class="mdescRight">Gets integer value from a configuration file. <a href="#ga6"></a><br></dl><li>MG_EXPORT int GUIAPI <a class="el" href="group__etc__fns.htm#ga7">SetValueToEtcFile</a> (const char *pEtcFile, const char *pSection, const char *pKey, char *pValue)<dl class="el"><dd class="mdescRight">Sets a value in a configuration file. <a href="#ga7"></a><br></dl><li>MG_EXPORT int GUIAPI <a class="el" href="group__etc__fns.htm#ga8">RemoveSectionInEtcFile</a> (const char *pEtcFile, const char *pSection)<dl class="el"><dd class="mdescRight">Removes a section in an etc file. <a href="#ga8"></a><br></dl><li>MG_EXPORT <a class="el" href="group__handles.htm#ga0">GHANDLE</a> GUIAPI <a class="el" href="group__etc__fns.htm#ga9">LoadEtcFile</a> (const char *pEtcFile)<dl class="el"><dd class="mdescRight">Loads an etc file into memory. <a href="#ga9"></a><br></dl><li>MG_EXPORT int GUIAPI <a class="el" href="group__etc__fns.htm#ga10">SaveEtcToFile</a> (<a class="el" href="group__handles.htm#ga0">GHANDLE</a> hEtc, const char *file_name)<dl class="el"><dd class="mdescRight">Saves an ETC object into a file. <a href="#ga10"></a><br></dl><li>MG_EXPORT int GUIAPI <a class="el" href="group__etc__fns.htm#ga11">UnloadEtcFile</a> (<a class="el" href="group__handles.htm#ga0">GHANDLE</a> hEtc)<dl class="el"><dd class="mdescRight">Unloads an etc file. <a href="#ga11"></a><br></dl><li>MG_EXPORT int GUIAPI <a class="el" href="group__etc__fns.htm#ga12">GetValueFromEtc</a> (<a class="el" href="group__handles.htm#ga0">GHANDLE</a> hEtc, const char *pSection, const char *pKey, char *pValue, int iLen)<dl class="el"><dd class="mdescRight">Gets value from a configuration etc object. <a href="#ga12"></a><br></dl><li>MG_EXPORT int GUIAPI <a class="el" href="group__etc__fns.htm#ga13">GetIntValueFromEtc</a> (<a class="el" href="group__handles.htm#ga0">GHANDLE</a> hEtc, const char *pSection, const char *pKey, int *pValue)<dl class="el"><dd class="mdescRight">Gets the integer value from a configuration etc object. <a href="#ga13"></a><br></dl><li>MG_EXPORT <a class="el" href="group__handles.htm#ga0">GHANDLE</a> GUIAPI <a class="el" href="group__etc__fns.htm#ga14">FindSectionInEtc</a> (<a class="el" href="group__handles.htm#ga0">GHANDLE</a> hEtc, const char *pSection, <a class="el" href="group__simple__types.htm#ga0">BOOL</a> bCreateNew)<dl class="el"><dd class="mdescRight">Finds/Creates a section from an etc object. <a href="#ga14"></a><br></dl><li>MG_EXPORT int GUIAPI <a class="el" href="group__etc__fns.htm#ga15">GetValueFromEtcSec</a> (<a class="el" href="group__handles.htm#ga0">GHANDLE</a> hSect, const char *pKey, char *pValue, int iLen)<dl class="el"><dd class="mdescRight">Gets value from an etc section object. <a href="#ga15"></a><br></dl><li>MG_EXPORT int GUIAPI <a class="el" href="group__etc__fns.htm#ga16">GetIntValueFromEtcSec</a> (<a class="el" href="group__handles.htm#ga0">GHANDLE</a> hSect, const char *pKey, int *pValue)<dl class="el"><dd class="mdescRight">Gets an integer value from an etc section object. <a href="#ga16"></a><br></dl><li>MG_EXPORT int GUIAPI <a class="el" href="group__etc__fns.htm#ga17">SetValueToEtcSec</a> (<a class="el" href="group__handles.htm#ga0">GHANDLE</a> hSect, const char *pKey, char *pValue)<dl class="el"><dd class="mdescRight">Sets the value in the etc section object. <a href="#ga17"></a><br></dl><li>MG_EXPORT int GUIAPI <a class="el" href="group__etc__fns.htm#ga18">RemoveSectionInEtc</a> (<a class="el" href="group__handles.htm#ga0">GHANDLE</a> hEtc, const char *pSection)<dl class="el"><dd class="mdescRight">Removes a section in etc object. <a href="#ga18"></a><br></dl><li>static int <a class="el" href="group__etc__fns.htm#ga19">GetMgEtcValue</a> (const char *pSection, const char *pKey, char *pValue, int iLen)<dl class="el"><dd class="mdescRight">Gets value from MiniGUI configuration etc object. <a href="#ga19"></a><br></dl><li>static int <a class="el" href="group__etc__fns.htm#ga20">GetMgEtcIntValue</a> (const char *pSection, const char *pKey, int *value)<dl class="el"><dd class="mdescRight">Gets integer value from MiniGUI configuration etc object. <a href="#ga20"></a><br></dl></ul><h2>Variables</h2><ul><li>MG_EXPORT char <a class="el" href="group__etc__fns.htm#ga3">ETCFILEPATH</a> []<dl class="el"><dd class="mdescRight">The path name of MiniGUI configuration file. <a href="#ga3"></a><br></dl></ul><hr><a name="_details"></a><h2>Detailed Description</h2>The configuration file used by MiniGUI have a similiar format as M$ Windows INI file, i.e. the file consists of sections, and the section consists of key-value pairs, like this:<p><div class="fragment"><pre class="fragment"> [system]<span class="preprocessor"> # GAL engine</span><span class="preprocessor"></span> gal_engine=fbcon<span class="preprocessor"> # IAL engine</span><span class="preprocessor"></span> ial_engine=console mdev=/dev/mouse mtype=PS2 [fbcon] defaultmode=1024x768-16bpp [qvfb] defaultmode=640x480-16bpp display=0</pre></div><p>Assume that the configuration file named <em>my.cfg</em>, if you want get the value of <em>mdev</em> in <em>system</em> section, you can call <em>GetValueFromEtcFile</em> in the following way:<p><div class="fragment"><pre class="fragment"> <span class="keywordtype">char</span> buffer [51]; <a class="code" href="group__etc__fns.htm#ga5">GetValueFromEtcFile</a> (<span class="stringliteral">"my.cfg"</span>, <span class="stringliteral">"system"</span>, <span class="stringliteral">"mdev"</span>, buffer, 51);</pre></div><p>Example:<p><div class="fragment"><pre class="fragment"><span class="comment">/*</span><span class="comment"> * The following code is used by MDE to get the applications information.</span><span class="comment"> *</span><span class="comment"> * It gets the information from a INI-like configuration file.</span><span class="comment"> */</span><span class="preprocessor">#define APP_INFO_FILE "mginit.rc"</span><span class="preprocessor"></span><span class="keyword">static</span> <a class="code" href="group__simple__types.htm#ga0">BOOL</a> get_app_info (<span class="keywordtype">void</span>){ <span class="keywordtype">int</span> i; APPITEM* item; <span class="comment">/* Get the number of the applications */</span> <span class="keywordflow">if</span> (<a class="code" href="group__etc__fns.htm#ga6">GetIntValueFromEtcFile</a> (APP_INFO_FILE, <span class="stringliteral">"mginit"</span>, <span class="stringliteral">"nr"</span>, &app_info.nr_apps) != <a class="code" href="group__etc__fns.htm#ga30">ETC_OK</a>) <span class="keywordflow">return</span> <a class="code" href="group__simple__types.htm#ga1">FALSE</a>; <span class="keywordflow">if</span> (app_info.nr_apps <= 0) <span class="keywordflow">return</span> <a class="code" href="group__simple__types.htm#ga1">FALSE</a>; <span class="comment">/* Get the index of the autostart application. */</span> <a class="code" href="group__etc__fns.htm#ga6">GetIntValueFromEtcFile</a> (APP_INFO_FILE, <span class="stringliteral">"mginit"</span>, <span class="stringliteral">"autostart"</span>, &app_info.autostart); <span class="keywordflow">if</span> (app_info.autostart >= app_info.nr_apps || app_info.autostart < 0) app_info.autostart = 0; <span class="comment">/* Allocate application information structures. */</span> <span class="keywordflow">if</span> ((app_info.app_items = (APPITEM*)calloc (app_info.nr_apps, sizeof (APPITEM))) == <a class="code" href="group__simple__types.htm#ga3">NULL</a>) { <span class="keywordflow">return</span> <a class="code" href="group__simple__types.htm#ga1">FALSE</a>; } <span class="comment">/* Get the path, name, and icon of every application. */</span> item = app_info.app_items; <span class="keywordflow">for</span> (i = 0; i < app_info.nr_apps; i++, item++) { <span class="keywordtype">char</span> section [10]; sprintf (section, <span class="stringliteral">"app%d"</span>, i); <span class="keywordflow">if</span> (<a class="code" href="group__etc__fns.htm#ga5">GetValueFromEtcFile</a> (APP_INFO_FILE, section, <span class="stringliteral">"path"</span>, item->path, PATH_MAX) != <a class="code" href="group__etc__fns.htm#ga30">ETC_OK</a>) <span class="keywordflow">goto</span> error; <span class="keywordflow">if</span> (<a class="code" href="group__etc__fns.htm#ga5">GetValueFromEtcFile</a> (APP_INFO_FILE, section, <span class="stringliteral">"name"</span>, item->name, NAME_MAX) != <a class="code" href="group__etc__fns.htm#ga30">ETC_OK</a>) <span class="keywordflow">goto</span> error; <span class="keywordflow">if</span> (<a class="code" href="group__etc__fns.htm#ga5">GetValueFromEtcFile</a> (APP_INFO_FILE, section, <span class="stringliteral">"layer"</span>, item->layer, LEN_LAYER_NAME) != <a class="code" href="group__etc__fns.htm#ga30">ETC_OK</a>) <span class="keywordflow">goto</span> error; <span class="keywordflow">if</span> (<a class="code" href="group__etc__fns.htm#ga5">GetValueFromEtcFile</a> (APP_INFO_FILE, section, <span class="stringliteral">"tip"</span>, item->tip, TIP_MAX) != <a class="code" href="group__etc__fns.htm#ga30">ETC_OK</a>) <span class="keywordflow">goto</span> error; strsubchr (item->tip, <span class="charliteral">'&'</span>, <span class="charliteral">' '</span>); <span class="keywordflow">if</span> (<a class="code" href="group__etc__fns.htm#ga5">GetValueFromEtcFile</a> (APP_INFO_FILE, section, <span class="stringliteral">"icon"</span>, item->bmp_path, PATH_MAX + NAME_MAX) != <a class="code" href="group__etc__fns.htm#ga30">ETC_OK</a>) <span class="keywordflow">goto</span> error; <span class="keywordflow">if</span> (<a class="code" href="group__bmp__load__fns.htm#ga63">LoadBitmap</a> (<a class="code" href="group__dc__fns.htm#ga22">HDC_SCREEN</a>, &item->bmp, item->bmp_path) != ERR_BMP_OK) <span class="keywordflow">goto</span> error; item->cdpath = <a class="code" href="group__simple__types.htm#ga2">TRUE</a>; } <span class="keywordflow">return</span> <a class="code" href="group__simple__types.htm#ga2">TRUE</a>;error: free_app_info (); <span class="keywordflow">return</span> <a class="code" href="group__simple__types.htm#ga1">FALSE</a>;}</pre></div> <hr><h2>Define Documentation</h2><a class="anchor" name="ga26" doxytag="minigui.h::ETC_FILEIOFAILED"></a><p><table class="mdTable" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top">#define ETC_FILEIOFAILED -5 </td> </tr> </table> </td> </tr></table><table cellspacing="5" cellpadding="0" border="0"> <tr> <td> </td> <td><p>IO operation failed to etc file. <p><p>Definition at line <a class="el" href="minigui_8h-source.htm#l01645">1645</a> of file <a class="el" href="minigui_8h-source.htm">minigui.h</a>. </td> </tr></table><a class="anchor" name="ga22" doxytag="minigui.h::ETC_FILENOTFOUND"></a><p><table class="mdTable" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top">#define ETC_FILENOTFOUND -1 </td> </tr> </table> </td> </tr></table><table cellspacing="5" cellpadding="0" border="0"> <tr> <td> </td> <td><p>No found etc file. <p><p>Definition at line <a class="el" href="minigui_8h-source.htm#l01625">1625</a> of file <a class="el" href="minigui_8h-source.htm">minigui.h</a>. </td> </tr></table><a class="anchor" name="ga27" doxytag="minigui.h::ETC_INTCONV"></a><p><table class="mdTable" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top">#define ETC_INTCONV -6 </td> </tr> </table> </td> </tr></table><table cellspacing="5" cellpadding="0" border="0"> <tr> <td> </td> <td><p>Convert the value string to an integer failed. <p><p>Definition at line <a class="el" href="minigui_8h-source.htm#l01650">1650</a> of file <a class="el" href="minigui_8h-source.htm">minigui.h</a>. </td> </tr></table><a class="anchor" name="ga28" doxytag="minigui.h::ETC_INVALIDOBJ"></a><p><table class="mdTable" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top">#define ETC_INVALIDOBJ -7 </td> </tr> </table> </td> </tr></table><table cellspacing="5" cellpadding="0" border="0"> <tr> <td> </td> <td><p>Invalid object to etc file. <p><p>Definition at line <a class="el" href="minigui_8h-source.htm#l01655">1655</a> of file <a class="el" href="minigui_8h-source.htm">minigui.h</a>. </td> </tr></table><a class="anchor" name="ga24" doxytag="minigui.h::ETC_KEYNOTFOUND"></a><p><table class="mdTable" cellpadding="2" cellspacing="0"> <tr> <td class="mdRow"> <table cellpadding="0" cellspacing="0" border="0"> <tr> <td class="md" nowrap valign="top">#define ETC_KEYNOTFOUND -3 </td> </tr> </table> </td> </tr></table><table cellspacing="5" cellpadding="0" border="0"> <tr> <td> </td> <td><p>No found key in etc file. <p><p>Definition at line <a class="el" href="minigui_8h-source.htm#l01635">1635</a> of file <a class="el" href="minigui_8h-source.htm">minigui.h</a>. </td> </tr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -