changeset 11:e467b3586e4d

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 01 Jan 2010 05:43:28 +0200
parents a25f5d22483e
children 83f7c71e4772
files th_config.h th_util.c th_util.h
diffstat 3 files changed, 65 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/th_config.h	Mon Apr 20 00:01:43 2009 +0300
+++ b/th_config.h	Fri Jan 01 05:43:28 2010 +0200
@@ -20,38 +20,39 @@
  */
 enum ITEM_TYPE {
     ITEM_BLOCK = 1,
+    ITEM_COMMENT,
     ITEM_STRING,
     ITEM_INT,
     ITEM_UINT,
     ITEM_BOOL,
-    ITEM_FLOAT
+    ITEM_FLOAT,
+    ITEM_HEX_TRIPLET
 };
 
 
 typedef struct _cfgitem_t {
-    char *name;     /* Config item name */
-    int  type;      /* Type of the item */
-    void *data;     /* Data / value */
-
+    char *name;
+    int  type;
+    void *data;
     BOOL (*validate)(struct _cfgitem_t *);
-
+    
     struct _cfgitem_t *next, *prev;
 } cfgitem_t;
 
 
 /* Functions
  */
-cfgitem_t * th_config_new(void);
-int         th_config_read(char *, cfgitem_t **);
-void        th_config_free(cfgitem_t *);
-int         th_config_write(FILE *, cfgitem_t *);
+int     th_config_read(FILE *, char *, cfgitem_t *);
+void    th_config_free(cfgitem_t *);
+int     th_config_write(FILE *, char *, cfgitem_t *);
 
-int th_config_add_block(cfgitem_t *cfg, char *name, BOOL (*validate)(cfgitem_t *));
-int th_config_add_int(cfgitem_t *cfg, char *name, BOOL (*validate)(cfgitem_t *), int *data, int itemDef);
-int th_config_add_uint(cfgitem_t *cfg, char *name, BOOL (*validate)(cfgitem_t *), unsigned int *data, unsigned int itemDef);
-int th_config_add_str(cfgitem_t *cfg, char *name, BOOL (*validate)(cfgitem_t *), char **data, char *itemDef);
-int th_config_add_bool(cfgitem_t *cfg, char *name, BOOL (*validate)(cfgitem_t *), BOOL *data, BOOL itemDef);
-int th_config_add_float(cfgitem_t *cfg, char *name, BOOL (*validate)(cfgitem_t *), float *data, float itemDef);
+int     th_config_add_section(cfgitem_t **cfg, char *name, cfgitem_t *data);
+int     th_config_add_comment(cfgitem_t **cfg, char *comment);
+int     th_config_add_int(cfgitem_t **cfg, char *name, BOOL (*validate)(cfgitem_t *), int *data, int itemDef);
+int     th_config_add_uint(cfgitem_t **cfg, char *name, BOOL (*validate)(cfgitem_t *), unsigned int *data, unsigned int itemDef);
+int     th_config_add_string(cfgitem_t **cfg, char *name, BOOL (*validate)(cfgitem_t *), char **data, char *itemDef);
+int     th_config_add_bool(cfgitem_t **cfg, char *name, BOOL (*validate)(cfgitem_t *), BOOL *data, BOOL itemDef);
+int     th_config_add_float(cfgitem_t **cfg, char *name, BOOL (*validate)(cfgitem_t *), float *data, float itemDef);
 
 #ifdef __cplusplus
 }
--- a/th_util.c	Mon Apr 20 00:01:43 2009 +0300
+++ b/th_util.c	Fri Jan 01 05:43:28 2010 +0200
@@ -48,44 +48,66 @@
 /* Print formatted error, warning and information messages
  * TODO: Implement th_vfprintf() and friends?
  */
-void THERR(const char *pcFormat, ...)
+void THERR_V(const char *fmt, va_list ap)
+{
+    assert(th_initialized == TRUE);
+
+    fprintf(stderr, "%s: ", th_prog_name);
+    vfprintf(stderr, fmt, ap);
+}
+
+
+void THMSG_V(int level, const char *fmt, va_list ap)
+{
+    assert(th_initialized == TRUE);
+
+    if (th_verbosityLevel >= level) {
+        fprintf(stderr, "%s: ", th_prog_name);
+        vfprintf(stderr, fmt, ap);
+    }
+}
+
+
+void THPRINT_V(int level, const char *fmt, va_list ap)
+{
+    assert(th_initialized == TRUE);
+
+    if (th_verbosityLevel >= level) {
+        vfprintf(stderr, fmt, ap);
+    }
+}
+
+
+void THERR(const char *fmt, ...)
 {
     va_list ap;
-    assert(th_initialized);
+    assert(th_initialized == TRUE);
 
-    va_start(ap, pcFormat);
-    fprintf(stderr, "%s: ", th_prog_name);
-    vfprintf(stderr, pcFormat, ap);
+    va_start(ap, fmt);
+    THERR_V(fmt, ap);
     va_end(ap);
 }
 
 
-void THMSG(int verbLevel, const char *pcFormat, ...)
+void THMSG(int level, const char *fmt, ...)
 {
     va_list ap;
-    assert(th_initialized);
+    assert(th_initialized == TRUE);
 
-    /* Check if the current verbosity level is enough */
-    if (th_verbosityLevel >= verbLevel) {
-        va_start(ap, pcFormat);
-        fprintf(stderr, "%s: ", th_prog_name);
-        vfprintf(stderr, pcFormat, ap);
-        va_end(ap);
-    }
+    va_start(ap, fmt);
+    THMSG_V(level, fmt, ap);
+    va_end(ap);
 }
 
 
-void THPRINT(int verbLevel, const char *pcFormat, ...)
+void THPRINT(int level, const char *fmt, ...)
 {
     va_list ap;
-    assert(th_initialized);
+    assert(th_initialized == TRUE);
 
-    /* Check if the current verbosity level is enough */
-    if (th_verbosityLevel >= verbLevel) {
-        va_start(ap, pcFormat);
-        vfprintf(stderr, pcFormat, ap);
-        va_end(ap);
-    }
+    va_start(ap, fmt);
+    THPRINT_V(level, fmt, ap);
+    va_end(ap);
 }
 
 
--- a/th_util.h	Mon Apr 20 00:01:43 2009 +0300
+++ b/th_util.h	Fri Jan 01 05:43:28 2010 +0200
@@ -68,6 +68,10 @@
 void    THMSG(int, const char *, ...);
 void    THPRINT(int, const char *, ...);
 
+void    THERR_V(const char *, va_list);
+void    THMSG_V(int, const char *, va_list);
+void    THPRINT_V(int, const char *, va_list);
+
 void    *th_malloc(size_t);
 void    *th_calloc(size_t, size_t);
 void    *th_realloc(void *, size_t);