Added a utility res_clear which removes/clears all items in a
[idzebra-moved-to-github.git] / util / res.c
index 6ce039c..15e65e5 100644 (file)
@@ -1,6 +1,6 @@
-/* $Id: res.c,v 1.38 2004-11-19 10:27:18 heikki Exp $
-   Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
-   Index Data Aps
+/* $Id: res.c,v 1.44 2005-08-17 21:28:07 adam Exp $
+   Copyright (C) 1995-2005
+   Index Data ApS
 
 This file is part of the Zebra server.
 
@@ -26,12 +26,13 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <assert.h>
 #ifdef WIN32
 #include <io.h>
-#else
+#endif
+#if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
-#include <zebrautl.h>
 #include <yaz/yaz-util.h>
+#include <idzebra/res.h>
 
 struct res_entry {
     char *name;
@@ -270,10 +271,8 @@ Res res_open (const char *name, Res def_res, Res over_res)
     return r;
 }
 
-void res_close (Res r)
+void res_clear (Res r)
 {
-    if (!r)
-        return;
     if (r->init)
     {
         struct res_entry *re, *re1;
@@ -287,6 +286,16 @@ void res_close (Res r)
             xfree (re);
         }
     }
+    r->init = 0;
+    r->first = r->last = NULL;
+}
+
+void res_close (Res r)
+{
+    if (!r)
+        return;
+    res_clear(r);
+
     xfree (r->name);
     xfree (r);
 }
@@ -455,3 +464,14 @@ int res_write (Res r)
     return 0;
 }
 
+ZEBRA_RES res_get_int(Res r, const char *name, int *val)
+{
+    const char *cp = res_get(r, name);
+    if (cp)
+    {
+       if (sscanf(cp, "%d", val) == 1)
+           return ZEBRA_OK;
+       yaz_log(YLOG_WARN, "Expected integer for resource %s", name);
+    }
+    return ZEBRA_FAIL;
+}