A simple .ini file interface.

Dependents:   Smart-WiFly-WebServer SignalGenerator WattEye X10Svr

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Sat Mar 31 23:36:47 2018 +0000
Parent:
22:1ad96fcc5731
Child:
24:ba5fa9548f59
Commit message:
ReadString - now defaults as intended if the file is not found, but a default string is provided.

Changed in this revision

IniManager.cpp Show annotated file Show diff for this revision Revisions of this file
IniManager.h Show annotated file Show diff for this revision Revisions of this file
--- a/IniManager.cpp	Sat Mar 31 21:07:53 2018 +0000
+++ b/IniManager.cpp	Sat Mar 31 23:36:47 2018 +0000
@@ -207,7 +207,9 @@
     INFO("ReadString from %s", iniFile);
     FILE * fp = fopen(iniFile,"rt");
     if (!fp) {
-        return RetXLate[INI_FILE_NOT_FOUND][version];
+        if (defaultString == NULL) {
+            return RetXLate[INI_FILE_NOT_FOUND][version];
+        }
     } else {
         char buf[INTERNAL_BUF_SIZE];
         bool inSection = (section == NULL) ? true : false;
--- a/IniManager.h	Sat Mar 31 21:07:53 2018 +0000
+++ b/IniManager.h	Sat Mar 31 23:36:47 2018 +0000
@@ -25,9 +25,24 @@
 *
 * Also, an internal stack-frame buffer is used to manage the read operations. As
 * such, no single record in the file can exceed this buffer size (compile time set
-* with a default of 250 bytes). A single record for a section is surrounded with
-* '[' and ']' and a new line appended. A single record for an entry within a
-* section for a key, value pair is separated with an '=' and a new line appended.
+* with a default of 250 bytes). 
+*
+* @code
+* INI ini("/local/settings.ini");
+* ...
+* char buf[10];
+* sprintf_s(buf, 10, "%d", daymask);
+* if (INI::INI_SUCCESS == ini.WriteString("Alarm", "Daymask", buf)) {
+*     ...
+* }
+* ...
+* uint8_t x = (uint8_t)ReadLongInt("Alarm", "Daymask", 0);
+* ...
+* @endcode 
+*
+* A single record for a section is surrounded with '[' and ']' and a new line 
+* appended. A single record for an entry within a section for a key, value pair 
+* is separated with an '=' and a new line appended.
 * @code
 * [section name]
 * Key name=value for Key name