Reformat a bit
[yaz-moved-to-github.git] / src / cqltransform.c
index e38fe05..3163775 100644 (file)
@@ -1,8 +1,7 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2008 Index Data
+ * Copyright (C) 1995-2011 Index Data
  * See the file LICENSE for details.
  */
-
 /**
  * \file cqltransform.c
  * \brief Implements CQL transform (CQL to RPN conversion).
  * index
  * relationModifier
  */
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <assert.h>
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <yaz/rpn2cql.h>
 #include <yaz/xmalloc.h>
 #include <yaz/diagsrw.h>
@@ -107,7 +108,7 @@ static int cql_transform_parse_tok_line(cql_transform_t ct,
             t = yaz_tok_move(tp);
         }
         elem->attributeType = nmem_intdup(ct->nmem, 0);
-        if (sscanf(wrbuf_cstr(type_str), "%d", elem->attributeType)
+        if (sscanf(wrbuf_cstr(type_str), ODR_INT_PRINTF, elem->attributeType)
             != 1)
         {
             wrbuf_destroy(type_str);
@@ -136,7 +137,7 @@ static int cql_transform_parse_tok_line(cql_transform_t ct,
             break;
         }
         value_str = yaz_tok_parse_string(tp);
-        if (isdigit(*value_str))
+        if (yaz_isdigit(*value_str))
         {
             elem->which = Z_AttributeValue_numeric;
             elem->value.numeric =
@@ -350,7 +351,7 @@ const char *cql_lookup_reverse(cql_transform_t ct,
                     
             }
             if (i == e->attr_list.num_attributes)
-                return e->pattern;
+                return e->pattern + clen;
         }
     }
     return 0;
@@ -435,7 +436,7 @@ int cql_pr_attr_uri(cql_transform_t ct, const char *category,
             int i;
             while (*cp1 && *cp1 != ' ')
                 cp1++;
-            if (cp1 - cp0 >= sizeof(buf))
+            if (cp1 - cp0 >= (ptrdiff_t) sizeof(buf))
                 break;
             memcpy(buf, cp0, cp1 - cp0);
             buf[cp1-cp0] = 0;
@@ -607,11 +608,11 @@ static int has_modifier(struct cql_node *cn, const char *name) {
 }
 
 
-void emit_term(cql_transform_t ct,
-               struct cql_node *cn,
-               const char *term, int length,
-               void (*pr)(const char *buf, void *client_data),
-               void *client_data)
+static void emit_term(cql_transform_t ct,
+                      struct cql_node *cn,
+                      const char *term, int length,
+                      void (*pr)(const char *buf, void *client_data),
+                      void *client_data)
 {
     int i;
     const char *ns = cn->u.st.index_uri;
@@ -733,7 +734,7 @@ void emit_term(cql_transform_t ct,
     }
 
     (*pr)("\"", client_data);
-    for (i = 0; i<length; i++)
+    for (i = 0; i < length; i++)
     {
         /* pr(int) each character */
         /* we do not need to deal with \-sequences because the
@@ -748,11 +749,11 @@ void emit_term(cql_transform_t ct,
     xfree(z3958_mem);
 }
 
-void emit_terms(cql_transform_t ct,
-                struct cql_node *cn,
-                void (*pr)(const char *buf, void *client_data),
-                void *client_data,
-                const char *op)
+static void emit_terms(cql_transform_t ct,
+                       struct cql_node *cn,
+                       void (*pr)(const char *buf, void *client_data),
+                       void *client_data,
+                       const char *op)
 {
     struct cql_node *ne = cn->u.st.extra_terms;
     if (ne)
@@ -776,11 +777,11 @@ void emit_terms(cql_transform_t ct,
     }
 }
 
-void emit_wordlist(cql_transform_t ct,
-                   struct cql_node *cn,
-                   void (*pr)(const char *buf, void *client_data),
-                   void *client_data,
-                   const char *op)
+static void emit_wordlist(cql_transform_t ct,
+                          struct cql_node *cn,
+                          void (*pr)(const char *buf, void *client_data),
+                          void *client_data,
+                          const char *op)
 {
     const char *cp0 = cn->u.st.term;
     const char *cp1;
@@ -875,7 +876,9 @@ void cql_transform_r(cql_transform_t ct,
         cql_transform_r(ct, cn->u.boolean.left, pr, client_data);
         cql_transform_r(ct, cn->u.boolean.right, pr, client_data);
         break;
-
+    case CQL_NODE_SORT:
+        cql_transform_r(ct, cn->u.sort.search, pr, client_data);
+        break;
     default:
         fprintf(stderr, "Fatal: impossible CQL node-type %d\n", cn->which);
         abort();
@@ -911,7 +914,8 @@ int cql_transform_FILE(cql_transform_t ct, struct cql_node *cn, FILE *f)
     return cql_transform(ct, cn, cql_fputs, f);
 }
 
-int cql_transform_buf(cql_transform_t ct, struct cql_node *cn, char *out, int max)
+int cql_transform_buf(cql_transform_t ct, struct cql_node *cn,
+                      char *out, int max)
 {
     struct cql_buf_write_info info;
     int r;
@@ -951,6 +955,7 @@ void cql_transform_set_error(cql_transform_t ct, int error, const char *addinfo)
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab