aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@users.noreply.github.com>2024-08-07 13:52:10 -0400
committerGitHub <noreply@github.com>2024-08-07 13:52:10 -0400
commit1d5e5f26014ceefd824382acec732f326d8d6ce2 (patch)
tree2d329c1a76e1bb5a13a84659465a60d2c6e99cd2 /include
parent202e69c8951a38187489c66e994dd593755d62cb (diff)
downloadstasis-1d5e5f26014ceefd824382acec732f326d8d6ce2.tar.gz
Refactor ini getter and setter usage (#19)
* Add handler for space-delimited lists * This needs attention, however. The INI writer has no way to know a list with spaces is a list; this happens in the value conversion functions. * Add type_hint member to INIData structure. At some point support with be added for all INIVAL_TYPE_* defines. Right now it's only used with arrays. * Zero out line buffer in ini_open after each iteration * Do not strip raw INI data. Let the conversion functions handle it * Add spaces to key value pairs in rendered INI output. * Add ini_getvar_TYPE() functions * These replace the functionality of static conv_TYPE() functions in delivery.c * Add support for missing types: U/CHAR, U/SHORT, STRLIST * ini_getval: expand template variables immediately before processing the output * Strip leading space to avoid issues with string comparisons against the result * ini_getval: Return copies, not the original. * This forces one to use ini_setval to replace/append values to the data array(s). It's safer this way. * fix_tox_conf(): Use ini_getval and ini_setval instead of modifying the original pointers directly * Tests: Free resources * Replace ini_getval(), ini_getval_required() and conv_*() usage * Now using ini_getval_TYPE() functions and ini_setval() * Remove unused helper functions and variables * download() returns long, not int * actions: update apt cache
Diffstat (limited to 'include')
-rw-r--r--include/ini.h52
1 files changed, 40 insertions, 12 deletions
diff --git a/include/ini.h b/include/ini.h
index 7167cad..5c840f5 100644
--- a/include/ini.h
+++ b/include/ini.h
@@ -14,24 +14,32 @@
#define INI_SEARCH_SUBSTR 2
///< expanded to preserve runtime state.
-#define INIVAL_TYPE_INT 1 ///< Integer
-#define INIVAL_TYPE_UINT 2 ///< Unsigned integer
-#define INIVAL_TYPE_LONG 3 ///< Long integer
-#define INIVAL_TYPE_ULONG 4 ///< Unsigned long integer
-#define INIVAL_TYPE_LLONG 5 ///< Long long integer
-#define INIVAL_TYPE_ULLONG 6 ///< Unsigned long long integer
-#define INIVAL_TYPE_DOUBLE 7 ///< Double precision float
-#define INIVAL_TYPE_FLOAT 8 ///< Single precision float
-#define INIVAL_TYPE_STR 9 ///< String
-#define INIVAL_TYPE_STR_ARRAY 10 ///< String Array
-#define INIVAL_TYPE_BOOL 11 ///< Boolean
+#define INIVAL_TYPE_CHAR 1 ///< Byte
+#define INIVAL_TYPE_UCHAR 2 ///< Unsigned byte
+#define INIVAL_TYPE_SHORT 3 ///< Short integer
+#define INIVAL_TYPE_USHORT 4 ///< Unsigned short integer
+#define INIVAL_TYPE_INT 5 ///< Integer
+#define INIVAL_TYPE_UINT 6 ///< Unsigned integer
+#define INIVAL_TYPE_LONG 7 ///< Long integer
+#define INIVAL_TYPE_ULONG 8 ///< Unsigned long integer
+#define INIVAL_TYPE_LLONG 9 ///< Long long integer
+#define INIVAL_TYPE_ULLONG 10 ///< Unsigned long long integer
+#define INIVAL_TYPE_DOUBLE 11 ///< Double precision float
+#define INIVAL_TYPE_FLOAT 12 ///< Single precision float
+#define INIVAL_TYPE_STR 13 ///< String
+#define INIVAL_TYPE_STR_ARRAY 14 ///< String Array
+#define INIVAL_TYPE_BOOL 15 ///< Boolean
#define INIVAL_TO_LIST 1 << 1
/*! \union INIVal
- * \brief Consolidation possible value types
+ * \brief Consolidate possible value types
*/
union INIVal {
+ char as_char; ///< Byte
+ unsigned char as_uchar; ///< Unsigned byte
+ short as_short; ///< Short integer
+ unsigned short as_ushort; ///< Unsigned short integer
int as_int; ///< Integer
unsigned as_uint; ///< Unsigned integer
long as_long; ///< Long integer
@@ -52,6 +60,7 @@ union INIVal {
struct INIData {
char *key; ///< INI variable name
char *value; ///< INI variable value
+ unsigned type_hint;
};
/*! \struct INISection
@@ -225,4 +234,23 @@ int ini_write(struct INIFILE *ini, FILE **stream, unsigned mode);
* @param ini
*/
void ini_free(struct INIFILE **ini);
+
+int ini_getval_int(struct INIFILE *ini, char *section_name, char *key, int *state);
+unsigned int ini_getval_uint(struct INIFILE *ini, char *section_name, char *key, int *state);
+long ini_getval_long(struct INIFILE *ini, char *section_name, char *key, int *state);
+unsigned long ini_getval_ulong(struct INIFILE *ini, char *section_name, char *key, int *state);
+long long ini_getval_llong(struct INIFILE *ini, char *section_name, char *key, int *state);
+unsigned long long ini_getval_ullong(struct INIFILE *ini, char *section_name, char *key, int *state);
+float ini_getval_float(struct INIFILE *ini, char *section_name, char *key, int *state);
+double ini_getval_double(struct INIFILE *ini, char *section_name, char *key, int *state);
+bool ini_getval_bool(struct INIFILE *ini, char *section_name, char *key, int *state);
+short ini_getval_short(struct INIFILE *ini, char *section_name, char *key, int *state);
+unsigned short ini_getval_ushort(struct INIFILE *ini, char *section_name, char *key, int *state);
+char ini_getval_char(struct INIFILE *ini, char *section_name, char *key, int *state);
+unsigned char ini_getval_uchar(struct INIFILE *ini, char *section_name, char *key, int *state);
+char *ini_getval_char_p(struct INIFILE *ini, char *section_name, char *key, int *state);
+char *ini_getval_str(struct INIFILE *ini, char *section_name, char *key, int *state);
+char **ini_getval_char_array_p(struct INIFILE *ini, char *section_name, char *key, int *state);
+char **ini_getval_str_array(struct INIFILE *ini, char *section_name, char *key, int *state);
+struct StrList *ini_getval_strlist(struct INIFILE *ini, char *section_name, char *key, char *tok, int *state);
#endif //STASIS_INI_H