Fix return values for cql_to_ccl_buf
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 10 Jun 2011 12:30:32 +0000 (14:30 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 10 Jun 2011 12:30:32 +0000 (14:30 +0200)
include/yaz/cql.h
src/cql2ccl.c

index 148a9e0..60d9d5c 100644 (file)
@@ -264,7 +264,9 @@ void cql_to_ccl_stdio(struct cql_node *cn, FILE *f);
     \param cn CQL node (tree)
     \param out buffer
     \param max size of buffer (max chars to write)
     \param cn CQL node (tree)
     \param out buffer
     \param max size of buffer (max chars to write)
-    \returns length of resulting buffer
+    \retval 0 OK
+    \retval -1 conversion error
+    \retval -2 buffer too small (truncated)
  */
 YAZ_EXPORT
 int cql_to_ccl_buf(struct cql_node *cn, char *out, int max);
  */
 YAZ_EXPORT
 int cql_to_ccl_buf(struct cql_node *cn, char *out, int max);
index 90ee5d6..48bb284 100644 (file)
@@ -3,7 +3,7 @@
  * See the file LICENSE for details.
  */
 /**
  * See the file LICENSE for details.
  */
 /**
- * \file xcqlutil.c
+ * \file cql2ccl.c
  * \brief Implements CQL to XCQL conversion.
  */
 #if HAVE_CONFIG_H
  * \brief Implements CQL to XCQL conversion.
  */
 #if HAVE_CONFIG_H
@@ -21,8 +21,8 @@ static int cql_to_ccl_r(struct cql_node *cn,
                         void *client_data);
 
 static void pr_term(struct cql_node *cn,
                         void *client_data);
 
 static void pr_term(struct cql_node *cn,
-                void (*pr)(const char *buf, void *client_data),
-                void *client_data)
+                    void (*pr)(const char *buf, void *client_data),
+                    void *client_data)
 {
     while (cn)
     {
 {
     while (cn)
     {
@@ -111,7 +111,6 @@ static int node(struct cql_node *cn,
             pr(split_op, client_data);
             pr(" ", client_data);            
         }
             pr(split_op, client_data);
             pr(" ", client_data);            
         }
-        return -1;
     }
     return 0;
 }
     }
     return 0;
 }
@@ -171,13 +170,16 @@ void cql_to_ccl_stdio(struct cql_node *cn, FILE *f)
 int cql_to_ccl_buf(struct cql_node *cn, char *out, int max)
 {
     struct cql_buf_write_info info;
 int cql_to_ccl_buf(struct cql_node *cn, char *out, int max)
 {
     struct cql_buf_write_info info;
+    int r;
     info.off = 0;
     info.max = max;
     info.buf = out;
     info.off = 0;
     info.max = max;
     info.buf = out;
-    cql_to_ccl(cn, cql_buf_write_handler, &info);
+    r = cql_to_ccl(cn, cql_buf_write_handler, &info);
     if (info.off >= 0)
         info.buf[info.off] = '\0';
     if (info.off >= 0)
         info.buf[info.off] = '\0';
-    return info.off;
+    else
+        return -2; /* buffer overflow */
+    return r;
 }
 
 /*
 }
 
 /*