added version markers to settings, option to disable INI comments

This commit is contained in:
2017-12-28 18:16:39 +01:00
parent d3d8b20095
commit 0af90eccbf
14 changed files with 265 additions and 170 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ static void *userdata = NULL; //!< Currently assigned user data for the callback
// Buffers
static char keybuf[INI_KEY_MAX];
static char secbuf[INI_KEY_MAX];
static char secbuf[INI_KEY_MAX+10];
static char valbuf[INI_VALUE_MAX];
// See header for doxygen!
+11
View File
@@ -2,6 +2,7 @@
// Created by MightyPork on 2017/12/01.
//
#include <framework/system_settings.h>
#include "platform.h"
#include "ini_writer.h"
@@ -65,12 +66,22 @@ void iw_section(IniWriter *iw, const char *format, ...)
void iw_comment(IniWriter *iw, const char *format, ...)
{
if (iw->count == 0) return;
if (!SystemSettings.ini_comments) return;
iw_string(iw, "# ");
IW_VPRINTF();
iw_newline(iw);
}
void iw_hdr_comment(IniWriter *iw, const char *format, ...)
{
if (iw->count == 0) return;
iw_string(iw, "## ");
IW_VPRINTF();
iw_newline(iw);
}
void iw_entry(IniWriter *iw, const char *key, const char *format, ...)
{
if (iw->count == 0) return;
+9
View File
@@ -46,6 +46,9 @@ static inline void iw_string(IniWriter *iw, const char *str)
}
#define iw_newline(iw) iw_string(iw, "\r\n")
#define iw_cmt_newline(iw) do { \
if (SystemSettings.ini_comments) iw_string(iw, "\r\n"); \
} while (0)
/**
* Try to snprintf to the file
@@ -77,6 +80,12 @@ void iw_section(IniWriter *iw, const char *format, ...)
void iw_comment(IniWriter *iw, const char *format, ...)
__attribute__((format(printf,2,3)));
/**
* Same as iw_comment(), but ignores the systemsettings option to disable comments
*/
void iw_hdr_comment(IniWriter *iw, const char *format, ...)
__attribute__((format(printf,2,3)));
/**
* Try to write a key-value entry
*
+11
View File
@@ -17,6 +17,17 @@ bool pb_buf(PayloadBuilder *pb, const uint8_t *buf, uint32_t len)
return true;
}
/** Add some zeros */
bool pb_reserve(PayloadBuilder *pb, uint32_t len)
{
pb_check_capacity(pb, len);
if (!pb->ok) return false;
memset(pb->current, 0, len);
pb->current += len;
return true;
}
/** Write s zero terminated string */
bool pb_string(PayloadBuilder *pb, const char *str)
{
+3
View File
@@ -71,6 +71,9 @@ struct PayloadBuilder_ {
/** Write from a buffer */
bool pb_buf(PayloadBuilder *pb, const uint8_t *buf, uint32_t len);
/** Write zeros */
bool pb_reserve(PayloadBuilder *pb, uint32_t len);
/** Write a zero terminated string */
bool pb_string(PayloadBuilder *pb, const char *str);