Update of /cvsroot/monetdb/sql/src/backends/monet5/merovingian
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv25081

Modified Files:
        properties.c properties.h 
Log Message:
add buffer equivalents of readProps and writeProps

U properties.h
Index: properties.h
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/properties.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- properties.h        9 Sep 2009 19:11:24 -0000       1.4
+++ properties.h        16 Sep 2009 13:45:41 -0000      1.5
@@ -26,7 +26,9 @@
 
 confkeyval *getDefaultProps(void);
 void writeProps(confkeyval *ckv, char *path);
+void writePropsBuf(confkeyval *ckv, char **buf);
 void readProps(confkeyval *ckv, char *path);
+void readPropsBuf(confkeyval *ckv, char *buf);
 char *setProp(char *path, char *key, char *val);
 
 #endif

U properties.c
Index: properties.c
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/merovingian/properties.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- properties.c        9 Sep 2009 19:11:24 -0000       1.10
+++ properties.c        16 Sep 2009 13:45:40 -0000      1.11
@@ -82,6 +82,36 @@
 }
 
 /**
+ * Writes the given key-value list to a buffer and sets its pointer to
+ * buf.  This function deals with the allocation of the buffer, hence
+ * the caller should free it.
+ */
+inline void
+writePropsBuf(confkeyval *ckv, char **buf)
+{
+       confkeyval *w;
+       size_t len = sizeof(MEROPROPFILEHEADER);
+       char *p;
+
+       w = ckv;
+       while (w->key != NULL) {
+               if (w->val != NULL)
+                       len += strlen(w->key) + 1 + strlen(w->val) + 1;
+               w++;
+       }
+
+       p = *buf = malloc(sizeof(char) * len + 1);
+       memcpy(p, MEROPROPFILEHEADER, sizeof(MEROPROPFILEHEADER));
+       p += sizeof(MEROPROPFILEHEADER);
+       w = ckv;
+       while (w->key != NULL) {
+               if (w->val != NULL)
+                       p += sprintf(p, "%s=%s\n", w->key, w->val);
+               w++;
+       }
+}
+
+/**
  * Read a property file, filling in the requested key-values.
  */
 inline void
@@ -98,6 +128,30 @@
 }
 
 /**
+ * Read properties from buf, filling in the requested key-values.
+ */
+inline void
+readPropsBuf(confkeyval *ckv, char *buf)
+{
+       confkeyval *t;
+       char *p;
+       char *err;
+       char *lasts;
+       size_t len;
+
+       while((p = strtok_r(buf, "\n", &lasts)) != NULL) {
+               buf = NULL; /* strtok */
+               for (t = ckv; t->key != NULL; t++) {
+                       len = strlen(t->key);
+                       if (strncmp(p, t->key, len) == 0 && p[len] == '=') {
+                               if ((err = setConfVal(t, p + len + 1)) != NULL)
+                                       GDKfree(err); /* ignore, just fall back 
to default */
+                       }
+               }
+       }
+}
+
+/**
  * Sets a single property, performing all necessary checks to validate
  * the key and associated value.
  */


------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to