MiniGUI API Reference (MiniGUI-Processes)  v5.0.6
A mature and proven cross-platform GUI system for embedded and smart IoT devices
Data Structures | Macros | Typedefs | Functions | Variables
Configuration file operations

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: More...

Data Structures

struct  _ETCSECTION
 
struct  _ETC_S
 

Macros

#define ETC_MAXLINE   1024
 The max line number of etc file. More...
 
#define ETC_FILENOTFOUND   -1
 No found etc file. More...
 
#define ETC_SECTIONNOTFOUND   -2
 No found section in etc file. More...
 
#define ETC_KEYNOTFOUND   -3
 No found key in etc file. More...
 
#define ETC_TMPFILEFAILED   -4
 Create tmpfile failed. More...
 
#define ETC_FILEIOFAILED   -5
 IO operation failed to etc file. More...
 
#define ETC_INTCONV   -6
 Convert the value string to an integer failed. More...
 
#define ETC_INVALIDOBJ   -7
 Invalid object to etc file. More...
 
#define ETC_READONLYOBJ   -8
 Read only to etc file. More...
 
#define ETC_OK   0
 Operate success to etc file. More...
 
#define SetValueToEtc(hEtc, pSection, pKey, pValue)   GetValueFromEtc(hEtc, pSection, pKey, pValue, -1)
 Set the value in the etc object. More...
 

Typedefs

typedef struct _ETCSECTION ETCSECTION
 
typedef ETCSECTIONPETCSECTION
 
typedef struct _ETC_S ETC_S
 

Functions

MG_EXPORT int GUIAPI GetValueFromEtcFile (const char *pEtcFile, const char *pSection, const char *pKey, char *pValue, int iLen)
 Get value from a configuration file. More...
 
MG_EXPORT int GUIAPI GetIntValueFromEtcFile (const char *pEtcFile, const char *pSection, const char *pKey, int *value)
 Get integer value from a configuration file. More...
 
MG_EXPORT int GUIAPI SetValueToEtcFile (const char *pEtcFile, const char *pSection, const char *pKey, char *pValue)
 Set a value in a configuration file. More...
 
MG_EXPORT int GUIAPI RemoveSectionInEtcFile (const char *pEtcFile, const char *pSection)
 Removes a section in an etc file. More...
 
MG_EXPORT int GUIAPI SaveSectionToEtcFile (const char *pEtcFile, PETCSECTION psect)
 Saves a section to an etc file. More...
 
MG_EXPORT GHANDLE GUIAPI LoadEtcFile (const char *pEtcFile)
 Loads an etc file into memory. More...
 
MG_EXPORT int GUIAPI SaveEtcToFile (GHANDLE hEtc, const char *file_name)
 Saves an ETC object into a file. More...
 
MG_EXPORT int GUIAPI UnloadEtcFile (GHANDLE hEtc)
 Unloads an etc file. More...
 
MG_EXPORT int GUIAPI GetValueFromEtc (GHANDLE hEtc, const char *pSection, const char *pKey, char *pValue, int iLen)
 Get value from a configuration etc object. More...
 
MG_EXPORT int GUIAPI GetIntValueFromEtc (GHANDLE hEtc, const char *pSection, const char *pKey, int *pValue)
 Get the integer value from a configuration etc object. More...
 
MG_EXPORT GHANDLE GUIAPI FindSectionInEtc (GHANDLE hEtc, const char *pSection, BOOL bCreateNew)
 Finds/Creates a section from an etc object. More...
 
MG_EXPORT int GUIAPI GetValueFromEtcSec (GHANDLE hSect, const char *pKey, char *pValue, int iLen)
 Get value from an etc section object. More...
 
MG_EXPORT int GUIAPI GetIntValueFromEtcSec (GHANDLE hSect, const char *pKey, int *pValue)
 Get an integer value from an etc section object. More...
 
MG_EXPORT int GUIAPI SetValueToEtcSec (GHANDLE hSect, const char *pKey, char *pValue)
 Set the value in the etc section object. More...
 
MG_EXPORT int GUIAPI RemoveSectionInEtc (GHANDLE hEtc, const char *pSection)
 Removes a section in etc object. More...
 
static int GetMgEtcValue (const char *pSection, const char *pKey, char *pValue, int iLen)
 Get value from MiniGUI configuration etc object. More...
 

Variables

MG_EXPORT char ETCFILEPATH []
 The path name of MiniGUI configuration file. More...
 

Detailed Description

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:

[system]
# GAL engine
gal_engine=fbcon
# IAL engine
ial_engine=console
mdev=/dev/mouse
mtype=PS2
[fbcon]
defaultmode=1024x768-16bpp
[qvfb]
defaultmode=640x480-16bpp
display=0

Assume that the configuration file named my.cfg, if you want get the value of mdev in system section, you can call GetValueFromEtcFile in the following way:

char buffer [51];
GetValueFromEtcFile ("my.cfg", "system", "mdev", buffer, 51);

Example:

/*
* The following code is used by MDE to get the applications information.
*
* It gets the information from a INI-like configuration file.
*/
#define APP_INFO_FILE "mginit.rc"
static BOOL get_app_info (void)
{
int i;
APPITEM* item;
/* Get the number of the applications */
if (GetIntValueFromEtcFile (APP_INFO_FILE, "mginit", "nr", &app_info.nr_apps) != ETC_OK)
return FALSE;
if (app_info.nr_apps <= 0)
return FALSE;
/* Get the index of the autostart application. */
GetIntValueFromEtcFile (APP_INFO_FILE, "mginit", "autostart", &app_info.autostart);
if (app_info.autostart >= app_info.nr_apps || app_info.autostart < 0)
app_info.autostart = 0;
/* Allocate application information structures. */
if ((app_info.app_items = (APPITEM*)calloc (app_info.nr_apps, sizeof (APPITEM))) == NULL) {
return FALSE;
}
/* Get the path, name, and icon of every application. */
item = app_info.app_items;
for (i = 0; i < app_info.nr_apps; i++, item++) {
char section [10];
sprintf (section, "app%d", i);
if (GetValueFromEtcFile (APP_INFO_FILE, section, "path", item->path, PATH_MAX) != ETC_OK)
goto error;
if (GetValueFromEtcFile (APP_INFO_FILE, section, "name", item->name, NAME_MAX) != ETC_OK)
goto error;
if (GetValueFromEtcFile (APP_INFO_FILE, section, "layer", item->layer, LEN_LAYER_NAME) != ETC_OK)
goto error;
if (GetValueFromEtcFile (APP_INFO_FILE, section, "tip", item->tip, TIP_MAX) != ETC_OK)
goto error;
strsubchr (item->tip, '&', ' ');
if (GetValueFromEtcFile (APP_INFO_FILE, section, "icon", item->bmp_path, PATH_MAX + NAME_MAX) != ETC_OK)
goto error;
if (LoadBitmap (HDC_SCREEN, &item->bmp, item->bmp_path) != ERR_BMP_OK)
goto error;
item->cdpath = TRUE;
}
return TRUE;
error:
free_app_info ();
return FALSE;
}

Macro Definition Documentation

◆ ETC_FILEIOFAILED

#define ETC_FILEIOFAILED   -5

IO operation failed to etc file.

Definition at line 2888 of file minigui.h.

◆ ETC_FILENOTFOUND

#define ETC_FILENOTFOUND   -1

No found etc file.

Definition at line 2868 of file minigui.h.

◆ ETC_INTCONV

#define ETC_INTCONV   -6

Convert the value string to an integer failed.

Definition at line 2893 of file minigui.h.

◆ ETC_INVALIDOBJ

#define ETC_INVALIDOBJ   -7

Invalid object to etc file.

Definition at line 2898 of file minigui.h.

◆ ETC_KEYNOTFOUND

#define ETC_KEYNOTFOUND   -3

No found key in etc file.

Definition at line 2878 of file minigui.h.

◆ ETC_MAXLINE

#define ETC_MAXLINE   1024

The max line number of etc file.

Definition at line 2862 of file minigui.h.

◆ ETC_OK

#define ETC_OK   0

Operate success to etc file.

Definition at line 2908 of file minigui.h.

◆ ETC_READONLYOBJ

#define ETC_READONLYOBJ   -8

Read only to etc file.

Definition at line 2903 of file minigui.h.

◆ ETC_SECTIONNOTFOUND

#define ETC_SECTIONNOTFOUND   -2

No found section in etc file.

Definition at line 2873 of file minigui.h.

◆ ETC_TMPFILEFAILED

#define ETC_TMPFILEFAILED   -4

Create tmpfile failed.

Definition at line 2883 of file minigui.h.

◆ SetValueToEtc

#define SetValueToEtc (   hEtc,
  pSection,
  pKey,
  pValue 
)    GetValueFromEtc(hEtc, pSection, pKey, pValue, -1)

Set the value in the etc object.

This fuctions sets the value in the etc object, somewhat similiar to

See also
SetValueToEtcFile.
SetValueToEtcFile, GetValueFromEtc

Definition at line 3204 of file minigui.h.

Typedef Documentation

◆ ETC_S

typedef struct _ETC_S ETC_S

ETC_S The current config file information

◆ ETCSECTION

typedef struct _ETCSECTION ETCSECTION

Etc The current config section information

◆ PETCSECTION

Data type of pointer to a ETCSECTION

Definition at line 2925 of file minigui.h.

Function Documentation

◆ FindSectionInEtc()

GHANDLE GUIAPI FindSectionInEtc ( GHANDLE  hEtc,
const char *  pSection,
BOOL  bCreateNew 
)

Finds/Creates a section from an etc object.

This function look for a section named pSection from the etc object hEtc. If there is no such section in the etc object and bCreateNew is TRUE, the function will create an empty section.

Parameters
hEtcHandle to the etc object.
pSectionThe name of the section.
bCreateNewIndicate whether to create a new section.
Returns
The handle to the section, 0 if not found or creatation failed.
See also
GetValueFromEtcSec, GetIntValueFromEtcSec, SetValueInEtcSec

◆ GetIntValueFromEtc()

int GUIAPI GetIntValueFromEtc ( GHANDLE  hEtc,
const char *  pSection,
const char *  pKey,
int *  pValue 
)

Get the integer value from a configuration etc object.

See also
GetValueFromEtc, GetIntValueFromEtcFile

◆ GetIntValueFromEtcFile()

int GUIAPI GetIntValueFromEtcFile ( const char *  pEtcFile,
const char *  pSection,
const char *  pKey,
int *  value 
)

Get integer value from a configuration file.

This function gets the integer value of the key pKey in the section pSection of the configuration file pEtcFile, and returns the integer value through the buffer pointed to by value.

Parameters
pEtcFileThe path name of the configuration file.
pSectionThe section name in which the value located.
pKeyThe key name of the value.
valueThe integer value will be saved in this buffer.
Returns
ETC_OK on success, < 0 on error.
Return values
ETC_OKGet value successfullly.
ETC_FILENOTFOUNDCan not find the specified configuration file.
ETC_SECTIONNOTFOUNDCan not find the specified section in the configuration file.
ETC_KEYNOTFOUNDCan not find the specified key in the section.
ETC_FILEIOFAILEDFile I/O operation error occurred.
ETC_INTCONVCan not convert the value string to an integer.
Note
MiniGUI uses strtol to convert the string value to an integer, and pass the base as 0. Thus, the valid string value can be converted to integer should be in the following forms:
  • [+|-]0x[0-9|A-F]*
    Will be read in base 16.
  • [+|-]0[0-7]*
    Will be read in base 8.
  • [+|-][1-9][0-9]*
    Will be read in base 10.
See also
GetValueFromEtcFile, SetValueToEtcFile, strtol(3)

◆ GetIntValueFromEtcSec()

int GUIAPI GetIntValueFromEtcSec ( GHANDLE  hSect,
const char *  pKey,
int *  pValue 
)

Get an integer value from an etc section object.

This function gets an integer value from an etc section object, similar to GetIntValueFromEtc. It gets the value of the key pKey in the section hSect, and saves the value to the buffer pointed to by pValue.

Parameters
hSectThe handle to the section.
pKeyThe key name of the value.
pValueThe value will be saved in this buffer.
Returns
ETC_OK on success, < 0 on error.
Return values
ETC_OKGet value successfullly.
ETC_INVALIDOBJInvalid etc object.
ETC_KEYNOTFOUNDCan not find the specified key in the section.
ETC_INTCONVCan not convert the value string to an integer.
See also
GetValueFromEtcFile, GetValueFromEtc, FindSectionInEtc

◆ GetMgEtcValue()

static inline int GetMgEtcValue ( const char *  pSection,
const char *  pKey,
char *  pValue,
int  iLen 
)
inlinestatic

Get value from MiniGUI configuration etc object.

This fuctions gets the value from MiniGUi configuration etc object, somewhat similiar to GetValueFromEtcFile and GetValueFromEtc

See also
GetValueFromEtcFile
GetValueFromEtc.

Definition at line 3328 of file minigui.h.

◆ GetValueFromEtc()

int GUIAPI GetValueFromEtc ( GHANDLE  hEtc,
const char *  pSection,
const char *  pKey,
char *  pValue,
int  iLen 
)

Get value from a configuration etc object.

This function gets value from an etc object, similar to GetValueFromEtcFile. This function gets the value of the key pKey in the section pSection of the etc object hEtc, and saves the value to the buffer pointed to by pValue.

Parameters
hEtcHandle to the etc object.
pSectionThe section name in which the value located.
pKeyThe key name of the value.
pValueThe value will be saved in this buffer.
iLenThe length in bytes of the buffer. This function will set value if the iLen is less than 1.
Returns
ETC_OK on success, < 0 on error.
Return values
ETC_OKGet value successfullly.
ETC_INVALIDOBJInvalid etc object.
ETC_SECTIONNOTFOUNDCan not find the specified section in the configuration file.
ETC_KEYNOTFOUNDCan not find the specified key in the section.
ETC_READONLYOBJThe etc object is read-only.
See also
GetValueFromEtcFile, LoadEtcFile, UnloadEtcFile

◆ GetValueFromEtcFile()

int GUIAPI GetValueFromEtcFile ( const char *  pEtcFile,
const char *  pSection,
const char *  pKey,
char *  pValue,
int  iLen 
)

Get value from a configuration file.

This function gets the value of the key pKey in the section pSection of the configuration file pEtcFile, and saves the value to the buffer pointed to by pValue.

Parameters
pEtcFileThe path name of the configuration file.
pSectionThe section name in which the value located.
pKeyThe key name of the value.
pValueThe value will be saved in this buffer.
iLenThe length in bytes of the buffer.
Returns
ETC_OK on success, < 0 on error.
Return values
ETC_OKGet value successfullly.
ETC_FILENOTFOUNDCan not find the specified configuration file.
ETC_SECTIONNOTFOUNDCan not find the specified section in the configuration file.
ETC_KEYNOTFOUNDCan not find the specified key in the section.
ETC_FILEIOFAILEDFile I/O operation error occurred.
Note
MiniGUI use strncpy to copy actual value to pValue. Thus, if the length of the actual value is larger than iLen, the result copied to pValue will NOT be null-terminated.
See also
GetIntValueFromEtcFile, SetValueToEtcFile, strncpy(3)

◆ GetValueFromEtcSec()

int GUIAPI GetValueFromEtcSec ( GHANDLE  hSect,
const char *  pKey,
char *  pValue,
int  iLen 
)

Get value from an etc section object.

This function gets value from an etc section object, similar to GetValueFromEtc. It gets the value of the key pKey in the section hSect, and saves the value to the buffer pointed to by pValue.

Parameters
hSectThe handle to the section.
pKeyThe key name of the value.
pValueThe value will be saved in this buffer.
iLenThe length in bytes of the buffer. This function will set value if the iLen is less than 1.
Returns
ETC_OK on success, < 0 on error.
Return values
ETC_OKGet value successfullly.
ETC_INVALIDOBJInvalid etc object.
ETC_KEYNOTFOUNDCan not find the specified key in the section.
ETC_READONLYOBJThe section object is read-only.
See also
GetValueFromEtcFile, GetValueFromEtc, FindSectionInEtc

◆ LoadEtcFile()

GHANDLE GUIAPI LoadEtcFile ( const char *  pEtcFile)

Loads an etc file into memory.

This function loads the content of an etc file into the memory, later, you can visit the content using GetValueFromEtc function.

Parameters
pEtcFileThe path name of the configuration file. If pEtcFile is NULL, the function will create an empty ETC object.
Returns
Handle of the etc object on success, NULL on error.
See also
UnloadEtcFile, GetValueFromEtc

◆ RemoveSectionInEtc()

int GUIAPI RemoveSectionInEtc ( GHANDLE  hEtc,
const char *  pSection 
)

Removes a section in etc object.

This function removes a section named pSection from the etc object hEtc.

Parameters
hEtcThe handle to the etc object.
pSectionThe name of the pSection;
Returns
ETC_OK on success, < 0 on error.
Return values
ETC_OKGet value successfullly.
ETC_INVALIDOBJInvalid etc object.
ETC_READONLYOBJThe etc object is read-only.
ETC_SECTIONNOTFOUNDCan not find the specified section in the etc object.
See also
RemoveSectionInEtcFile

◆ RemoveSectionInEtcFile()

int GUIAPI RemoveSectionInEtcFile ( const char *  pEtcFile,
const char *  pSection 
)

Removes a section in an etc file.

This function removes a section named pSection from the etc file named pEtcFile.

Parameters
pEtcFileThe name of the etc file.
pSectionThe name of the pSection;
Returns
ETC_OK on success, < 0 on error.
Return values
ETC_OKGet value successfullly.
ETC_FILEIOFAILEDFile I/O operation error occurred.
ETC_SECTIONNOTFOUNDCan not find the specified section in the etc object.
See also
RemoveSectionInEtc

◆ SaveEtcToFile()

int GUIAPI SaveEtcToFile ( GHANDLE  hEtc,
const char *  file_name 
)

Saves an ETC object into a file.

This function saves the etc object into the file named file_name;

Parameters
hEtcHandle to the etc object.
file_nameThe name of the target file.
Returns
ETC_OK on success, 0 < on error.
Return values
ETC_OKSet the etc object successfullly.
ETC_INVALIDOBJInvalid etc object.
ETC_FILEIOFAILEDFile I/O operation error occurred.
See also
LoadEtcFile

◆ SaveSectionToEtcFile()

int GUIAPI SaveSectionToEtcFile ( const char *  pEtcFile,
PETCSECTION  psect 
)

Saves a section to an etc file.

This function saves a section named psect to the etc file named pEtcFile.

Parameters
pEtcFileThe name of the etc file.
psectThe name of the psect;
Returns
ETC_OK on success, < 0 on error.
Return values
ETC_OKGet value successfullly.
ETC_FILEIOFAILEDFile I/O operation error occurred.
ETC_SECTIONNOTFOUNDCan not find the specified section in the etc object.

◆ SetValueToEtcFile()

int GUIAPI SetValueToEtcFile ( const char *  pEtcFile,
const char *  pSection,
const char *  pKey,
char *  pValue 
)

Set a value in a configuration file.

This function sets the value of the key pKey in the section pSection of the configuration file pEtcFile to be the string pointed to by pValue.

Parameters
pEtcFileThe path name of the configuration file.
pSectionThe section name in which the value located.
pKeyThe key name of the value.
pValueThe null-terminated value string.
Returns
ETC_OK on success, < 0 on error.
Return values
ETC_OKSet value successfullly.
ETC_FILEIOFAILEDFile I/O operation error occurred.
ETC_TMPFILEFAILEDCan not create temporary file.
Note
If the specified configuration file does not exist, MiniGUI will try to create this file.
See also
GetValueFromEtcFile, GetIntValueFromEtcFile

◆ SetValueToEtcSec()

int GUIAPI SetValueToEtcSec ( GHANDLE  hSect,
const char *  pKey,
char *  pValue 
)

Set the value in the etc section object.

This fuctions sets the value in the etc section object hSect, somewhat similiar to SetValueToEtc

See also
SetValueToEtc.
GetValueFromEtc, FindSectionInEtc

◆ UnloadEtcFile()

GUIAPI UnloadEtcFile ( GHANDLE  hEtc)

Unloads an etc file.

This function unloads the etc object generated by using

See also
LoadEtcFile function.
Parameters
hEtcHandle of the etc object.
Returns
Returns 0 on success, -1 on error.
See also
LoadEtcFile, GetValueFromEtc

Variable Documentation

◆ ETCFILEPATH

char * ETCFILEPATH

The path name of MiniGUI configuration file.

By default, the configuration file of MiniGUI must be installed in /etc, /usr/local/etc or your home directory. When you install it in your home directory, the name should be ".MiniGUI.cfg".

MiniGUI will try to use MiniGUI.cfg in the current directory, ~/.MiniGUI.cfg, then /usr/local/etc/MiniGUI.cfg, and /etc/MiniGUI.cfg last.

If MiniGUI can not find any MiniGUI.cfg file, or find a bad formated configure file, the initialzation of MiniGUI will be canceled.

NULL
#define NULL
A value indicates null pointer.
Definition: common.h:369
FALSE
#define FALSE
FALSE value, defined as 0 by MiniGUI.
Definition: common.h:351
LoadBitmap
#define LoadBitmap
An alias of LoadBitmapFromFile.
Definition: gdi.h:11407
BOOL
int BOOL
A type definition for boolean value.
Definition: common.h:343
GetIntValueFromEtcFile
MG_EXPORT int GUIAPI GetIntValueFromEtcFile(const char *pEtcFile, const char *pSection, const char *pKey, int *value)
Get integer value from a configuration file.
GetValueFromEtcFile
MG_EXPORT int GUIAPI GetValueFromEtcFile(const char *pEtcFile, const char *pSection, const char *pKey, char *pValue, int iLen)
Get value from a configuration file.
ETC_OK
#define ETC_OK
Operate success to etc file.
Definition: minigui.h:2908
LEN_LAYER_NAME
#define LEN_LAYER_NAME
The maximum length of name of layer in MiniGUI-Processes.
Definition: minigui.h:259
TRUE
#define TRUE
TRUE value, defined as 1 by MiniGUI.
Definition: common.h:358
HDC_SCREEN
#define HDC_SCREEN
Handle to the device context of the whole screen or the fake screen when MiniGUI is running under Min...
Definition: gdi.h:1358