Add dstate_getflags() to the interface, allowing flag interrogation.

Add status_set_uniq() working similary to status_set() but making sure
that the added status word is not duplicated.

Signed-off-by: Michal Soltys <[email protected]>
---
 drivers/dstate.c |   21 +++++++++++++++++++++
 drivers/dstate.h |    2 ++
 2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/drivers/dstate.c b/drivers/dstate.c
index b95cec9..0cb5896 100644
--- a/drivers/dstate.c
+++ b/drivers/dstate.c
@@ -691,6 +691,11 @@ const char *dstate_getinfo(const char *var)
        return state_getinfo(dtree_root, var);
 }
 
+int dstate_getflags(const char *var)
+{
+       return state_getflags(dtree_root, var);
+}
+
 void dstate_addcmd(const char *cmdname)
 {
        int     ret;
@@ -806,6 +811,22 @@ void status_set(const char *buf)
        }
 }
 
+/* add a status element, making sure it's not already present */
+void status_set_uniq(const char *buf)
+{
+       const char *ptr = status_buf;
+       int len = strlen(buf);
+
+       /* make sure it's on a word boundary */
+       while ((ptr = strstr(ptr, buf))) {
+               if ((!ptr[len] || ptr[len] == ' ') && (ptr == status_buf || 
ptr[-1] == ' '))
+                       return;
+               ptr += len;
+       }
+
+       status_set(buf);
+}
+
 /* write the status_buf into the externally visible dstate storage */
 void status_commit(void)
 {
diff --git a/drivers/dstate.h b/drivers/dstate.h
index 7ffe899..91bf873 100644
--- a/drivers/dstate.h
+++ b/drivers/dstate.h
@@ -48,6 +48,7 @@ int dstate_addenum(const char *var, const char *fmt, ...)
 void dstate_setflags(const char *var, int flags);
 void dstate_setaux(const char *var, int aux);
 const char *dstate_getinfo(const char *var);
+int dstate_getflags(const char *var);
 void dstate_addcmd(const char *cmdname);
 int dstate_delinfo(const char *var);
 int dstate_delenum(const char *var, const char *val);
@@ -66,6 +67,7 @@ void status_init(void);
 
 /* add a status element */
 void status_set(const char *buf);
+void status_set_uniq(const char *buf);
 
 /* write the temporary status_buf into ups.status */
 void status_commit(void);
-- 
1.7.2.1


_______________________________________________
Nut-upsdev mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/nut-upsdev

Reply via email to