regify utility  2.0.0-0
Ini File Handling

This section contains ini file handling support. More...

Typedefs

typedef void * ruIni
 An opaque type representing an ini object. More...
 

Functions

RUAPI ruIni ruIniFree (ruIni ini)
 Frees the given ini object and its members. More...
 
RUAPI ruIni ruIniNew (void)
 Create a new empty ini object. More...
 
RUAPI int32_t ruIniWrite (ruIni iniOb, trans_chars filename)
 Writes given ini object into given filename. More...
 
RUAPI int32_t ruIniRead (trans_chars filename, ruIni *iniOb)
 Parse given INI-style file. May have [section]s, name=value pairs (whitespace stripped), and comments starting with ';' (semicolon). Section is "" if name=value pair parsed before any section heading. name:value pairs are also supported as a concession to Python's configparser. More...
 
RUAPI int32_t ruIniSections (ruIni iniOb, ruList *sections)
 Returns a list of sections from the given ini object. More...
 
RUAPI int32_t ruIniKeys (ruIni iniOb, trans_chars section, ruList *keys)
 Returns a list of keys from given section or global. More...
 
RUAPI perm_chars ruIniGetDef (ruIni iniOb, trans_chars section, trans_chars key, trans_chars def, int32_t *code)
 Retrieves a value or given default from the given ini object. More...
 
RUAPI int32_t ruIniGet (ruIni iniOb, trans_chars section, trans_chars key, perm_chars *value)
 Retrieves a value from the given ini object. More...
 
RUAPI int32_t ruIniSet (ruIni iniOb, trans_chars section, trans_chars key, trans_chars value)
 Set a value in the given ini object. More...
 

Detailed Description

This section contains ini file handling support.

Example:

ruIni cf = NULL;
const char* inipath = "/path/to/file.ini";
// We are going to ignore some return codes for brevity.
int32_t ret = ruIniRead(inipath, &cf);
const char* name = NULL;
ret = ruIniGet(cf, NULL, "username", &name);
printf("Username: %s", name);
// make some changes
ret = ruIniSet(cf, NULL, "password", "secret");
ret = ruIniWrite(cf, inipath);
cf = ruIniFree(cf);
RUAPI int32_t ruIniSet(ruIni iniOb, trans_chars section, trans_chars key, trans_chars value)
Set a value in the given ini object.
RUAPI int32_t ruIniGet(ruIni iniOb, trans_chars section, trans_chars key, perm_chars *value)
Retrieves a value from the given ini object.
RUAPI int32_t ruIniWrite(ruIni iniOb, trans_chars filename)
Writes given ini object into given filename.
RUAPI ruIni ruIniFree(ruIni ini)
Frees the given ini object and its members.
void * ruIni
An opaque type representing an ini object.
Definition: ini.h:56
RUAPI int32_t ruIniRead(trans_chars filename, ruIni *iniOb)
Parse given INI-style file. May have [section]s, name=value pairs (whitespace stripped),...

Typedef Documentation

◆ ruIni

typedef void* ruIni

An opaque type representing an ini object.

Function Documentation

◆ ruIniFree()

RUAPI ruIni ruIniFree ( ruIni  ini)

Frees the given ini object and its members.

Parameters
iniobject to free
Returns
NULL

◆ ruIniGet()

RUAPI int32_t ruIniGet ( ruIni  iniOb,
trans_chars  section,
trans_chars  key,
perm_chars value 
)

Retrieves a value from the given ini object.

Parameters
iniObObject to get value from
sectionSection to get value from. NULL for no section.
keyKey name.
valueWhere the value will be stored. Caller should copy as needed
Returns
RUE_OK on success else an error code

◆ ruIniGetDef()

RUAPI perm_chars ruIniGetDef ( ruIni  iniOb,
trans_chars  section,
trans_chars  key,
trans_chars  def,
int32_t *  code 
)

Retrieves a value or given default from the given ini object.

Parameters
iniObObject to get value from
sectionSection to get value from. NULL for no section.
keyKey name.
defWill be returned if not NULL and value is NULL or empty string.
codeOptional, where to store the return code of the operation
Returns
The found value or def if the value was not found or blank.

◆ ruIniKeys()

RUAPI int32_t ruIniKeys ( ruIni  iniOb,
trans_chars  section,
ruList keys 
)

Returns a list of keys from given section or global.

Parameters
iniObObject to get sections from
sectionSection to get keys from or NULL for global keys
keysList of keys to be freed by caller after use.
Returns
RUE_OK on success else an error code

◆ ruIniNew()

RUAPI ruIni ruIniNew ( void  )

Create a new empty ini object.

Returns
The object

◆ ruIniRead()

RUAPI int32_t ruIniRead ( trans_chars  filename,
ruIni iniOb 
)

Parse given INI-style file. May have [section]s, name=value pairs (whitespace stripped), and comments starting with ';' (semicolon). Section is "" if name=value pair parsed before any section heading. name:value pairs are also supported as a concession to Python's configparser.

For each name=value pair parsed, call handler function with given user pointer as well as section, name, and value (data only valid for duration of handler call). Handler should return nonzero on success, zero on error.

Parameters
filenamepath to file to parse
iniObWhere the result ruIni object will be stored. Free with ruIniFree.
Returns
RUE_OK on success else an error code

◆ ruIniSections()

RUAPI int32_t ruIniSections ( ruIni  iniOb,
ruList sections 
)

Returns a list of sections from the given ini object.

Parameters
iniObObject to get sections from
sectionsList of sections to be freed by caller after use.
Returns
RUE_OK on success else an error code

◆ ruIniSet()

RUAPI int32_t ruIniSet ( ruIni  iniOb,
trans_chars  section,
trans_chars  key,
trans_chars  value 
)

Set a value in the given ini object.

Parameters
iniObObject to set value in
sectionSection to set value in. NULL for no section.
keyKey name
valueThe value to set. Use blank for an empty entry and NULL to remove
Returns
RUE_OK on success else an error code

◆ ruIniWrite()

RUAPI int32_t ruIniWrite ( ruIni  iniOb,
trans_chars  filename 
)

Writes given ini object into given filename.

Parameters
iniObIni object to write
filenamePath to ini file
Returns
RUE_OK on success else an error code