Many public functions returns ZEBRA_RES rather than int to avoid
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 15 Apr 2005 10:47:47 +0000 (10:47 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 15 Apr 2005 10:47:47 +0000 (10:47 +0000)
confusions about succeeded/failed requests. Query parser more picky
about unsupported relation attributes.

25 files changed:
bfile/bfile.c
bfile/cfile.c
bfile/commit.c
bfile/mfile.c
dfa/grepper.c
dfa/imalloc.c
dict/dictext.c
dict/dicttest.c
include/idzebra/api.h
include/idzebra/isamc.h
include/idzebra/util.h
include/rset.h
index/extract.c
index/index.h
index/recindex.c
index/zebraapi.c
index/zrpn.c
index/zserver.c
index/zsets.c
isamb/isamb.c
test/api/t3.c
test/api/t5.c
test/api/testlib.c
test/api/testlib.h
util/res.c

index facec01..347a2a3 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: bfile.c,v 1.40 2005-03-30 09:25:23 adam Exp $
+/* $Id: bfile.c,v 1.41 2005-04-15 10:47:47 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -30,6 +30,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <unistd.h>
 #endif
 
+#include <yaz/xmalloc.h>
 #include <idzebra/util.h>
 #include <idzebra/bfile.h>
 #include "mfile.h"
index d2d1add..94875e6 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: cfile.c,v 1.34 2005-03-30 09:25:23 adam Exp $
+/* $Id: cfile.c,v 1.35 2005-04-15 10:47:47 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -25,6 +25,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <string.h>
 
 #include <idzebra/util.h>
+#include <yaz/yaz-util.h>
 #include "mfile.h"
 #include "cfile.h"
 
index 2461834..91debc1 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: commit.c,v 1.24 2005-03-30 09:25:23 adam Exp $
+/* $Id: commit.c,v 1.25 2005-04-15 10:47:47 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -25,6 +25,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <stdlib.h>
 
 #include <idzebra/util.h>
+#include <yaz/xmalloc.h>
 #include "mfile.h"
 #include "cfile.h"
 
index 69a062a..5d86ef1 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mfile.c,v 1.59 2005-03-30 09:25:23 adam Exp $
+/* $Id: mfile.c,v 1.60 2005-04-15 10:47:47 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -44,6 +44,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 
 #include <zebra-lock.h>
 #include <idzebra/util.h>
+#include <yaz/yaz-util.h>
 #include "mfile.h"
 
 static int scan_areadef(MFile_area ma, const char *ad, const char *base)
index 03553a6..94a13ad 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: grepper.c,v 1.13 2005-03-30 09:25:23 adam Exp $
+/* $Id: grepper.c,v 1.14 2005-04-15 10:47:47 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -28,6 +28,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <assert.h>
 
 #include <idzebra/util.h>
+#include <yaz/yaz-util.h>
 #include <dfa.h>
 #include "imalloc.h"
 
index 0561d89..cf1e504 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: imalloc.c,v 1.12 2005-03-30 09:25:23 adam Exp $
+/* $Id: imalloc.c,v 1.13 2005-04-15 10:47:47 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -26,6 +26,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <stdlib.h>
 
 #include <idzebra/util.h>
+#include <yaz/xmalloc.h>
 #include "imalloc.h"
 
 #if MEMDEBUG
index 124e461..b2bda3a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: dictext.c,v 1.12 2005-03-30 09:25:23 adam Exp $
+/* $Id: dictext.c,v 1.13 2005-04-15 10:47:48 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -29,6 +29,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <ctype.h>
 
 #include <idzebra/util.h>
+#include <yaz/yaz-util.h>
 
 char *prog;
 
@@ -42,7 +43,7 @@ int main (int argc, char **argv)
     char ipf_buf[1024];
 
     prog = *argv;
-    while ((ret = options ("8vh", argv, argc, &arg)) != -2)
+    while ((ret = options("8vh", argv, argc, &arg)) != -2)
     {
         if (ret == 0)
         {
index e923565..053d586 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: dicttest.c,v 1.33 2005-03-30 09:25:23 adam Exp $
+/* $Id: dicttest.c,v 1.34 2005-04-15 10:47:48 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -28,6 +28,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <idzebra/dict.h>
 #include <idzebra/util.h>
 #include <idzebra/res.h>
+#include <yaz/yaz-util.h>
 
 char *prog;
 static Dict dict;
index 0c139d0..d2226b4 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: api.h,v 1.17 2005-04-13 08:52:26 adam Exp $
+/* $Id: api.h,v 1.18 2005-04-15 10:47:48 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -100,14 +100,14 @@ YAZ_EXPORT
 ZebraService zebra_start_res(const char *configName,
                             Res def_res, Res over_res);
 
-/** \fn int zebra_stop(ZebraService zs)
+/** \fn ZEBRA_RES zebra_stop(ZebraService zs)
     \brief stops a Zebra service.
     \param zs service handle
     
     Frees resources used by the service.
 */
 YAZ_EXPORT
-int zebra_stop(ZebraService zs);
+ZEBRA_RES zebra_stop(ZebraService zs);
 
 /** \fn void zebra_filter_info(ZebraService zs, void *cd,
     void(*cb)(void *cd, const char *name))
@@ -135,7 +135,7 @@ YAZ_EXPORT ZebraHandle zebra_open(ZebraService zs);
     \brief destroys Zebra session handle.
     \param zh zebra session handle.
  */
-YAZ_EXPORT int zebra_close(ZebraHandle zh);
+YAZ_EXPORT ZEBRA_RES zebra_close(ZebraHandle zh);
 
 /** \fn int zebra_errCode(ZebraHandle zh)
     \brief returns error code for last error
@@ -169,7 +169,7 @@ YAZ_EXPORT int zebra_result(ZebraHandle zh, int *code, char **addinfo);
  */
 YAZ_EXPORT void zebra_clearError(ZebraHandle zh);
 
-/** \fn int zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
+/** \fn ZEBRA_RES zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
     const char *setname, int *hits)
     \brief Search using PQF Query 
     \param zh session handle
@@ -177,10 +177,10 @@ YAZ_EXPORT void zebra_clearError(ZebraHandle zh);
     \param setname name of resultset
     \param hits of hits is returned
  */
-YAZ_EXPORT int zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
-                               const char *setname, zint *hits);
+YAZ_EXPORT ZEBRA_RES zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
+                                     const char *setname, zint *hits);
 
-/** \fn int zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
+/** \fn ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
     const char *setname, zint *hits)
     \brief Search using RPN Query 
     \param zh session handle
@@ -189,11 +189,11 @@ YAZ_EXPORT int zebra_search_PQF(ZebraHandle zh, const char *pqf_query,
     \param setname name of resultset
     \param hits number of hits is returned
  */
-YAZ_EXPORT int zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
-                               const char *setname, zint *hits);
+YAZ_EXPORT ZEBRA_RES zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
+                                     const char *setname, zint *hits);
 
 /** 
-    \fn int zebra_records_retrieve(ZebraHandle zh, ODR stream,
+    \fn ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
     const char *setname, Z_RecordComposition *comp, oid_value input_format,
     int num_recs, ZebraRetrievalRecord *recs)
     \brief retrieve records from result set (after search)
@@ -205,11 +205,13 @@ YAZ_EXPORT int zebra_search_RPN(ZebraHandle zh, ODR o, Z_RPNQuery *query,
     \param num_recs number of records to retrieve
     \param recs store records in this structure (size is num_recs)
 */
-YAZ_EXPORT int zebra_records_retrieve(ZebraHandle zh, ODR stream,
-                      const char *setname, Z_RecordComposition *comp,
-                      oid_value input_format,
-                      int num_recs, ZebraRetrievalRecord *recs);
-
+YAZ_EXPORT
+ZEBRA_RES zebra_records_retrieve(ZebraHandle zh, ODR stream,
+                                const char *setname,
+                                Z_RecordComposition *comp,
+                                oid_value input_format,
+                                int num_recs,
+                                ZebraRetrievalRecord *recs);
 /**
    \fn int zebra_deleteResultSet(ZebraHandle zh, int function,
    int num_setnames, char **setnames, int *statuses)
@@ -220,12 +222,13 @@ YAZ_EXPORT int zebra_records_retrieve(ZebraHandle zh, ODR stream,
    \param setnames result set names
    \param statuses status result
 */
-YAZ_EXPORT int zebra_deleteResultSet(ZebraHandle zh, int function,
-                                    int num_setnames, char **setnames,
-                                    int *statuses);
+YAZ_EXPORT
+int zebra_deleteResultSet(ZebraHandle zh, int function,
+                         int num_setnames, char **setnames,
+                         int *statuses);
 
 /**
-   \fn int zebra_scan(ZebraHandle zh, ODR stream,
+   \fn ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream,
    Z_AttributesPlusTerm *zapt, oid_value attributeset,
    int *position, int *num_entries, ZebraScanEntry **list, int *is_partial)
    \brief performs Scan (Z39.50 style)
@@ -238,15 +241,15 @@ YAZ_EXPORT int zebra_deleteResultSet(ZebraHandle zh, int function,
    \param list list of resulting terms (ODR allocated)
    \param is_partial upon return 1=partial, 0=complete
 */
-YAZ_EXPORT int zebra_scan(ZebraHandle zh, ODR stream,
-                         Z_AttributesPlusTerm *zapt,
-                         oid_value attributeset,
-                         int *position, int *num_entries,
-                         ZebraScanEntry **list,
-                         int *is_partial);
+YAZ_EXPORT ZEBRA_RES zebra_scan(ZebraHandle zh, ODR stream,
+                               Z_AttributesPlusTerm *zapt,
+                               oid_value attributeset,
+                               int *position, int *num_entries,
+                               ZebraScanEntry **list,
+                               int *is_partial);
 
 /**
-   \fn int zebra_scan_PQF(ZebraHandle zh, ODR stream,
+   \fn ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream,
    const char *query, int *position, int *num_entries, ZebraScanEntry **list, int *is_partial)
    \brief performs Scan (taking PQF string)
    \param zh session handle
@@ -257,20 +260,20 @@ YAZ_EXPORT int zebra_scan(ZebraHandle zh, ODR stream,
    \param list list of resulting terms (ODR allocated)
    \param is_partial upon return 1=partial, 0=complete
 */
-YAZ_EXPORT int zebra_scan_PQF(ZebraHandle zh, ODR stream,
-                             const char *query,
-                             int *position, int *num_entries,
-                             ZebraScanEntry **entries,
-                             int *is_partial);
+YAZ_EXPORT ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream,
+                                   const char *query,
+                                   int *position, int *num_entries,
+                                   ZebraScanEntry **entries,
+                                   int *is_partial);
 /**
-   \fn int zebra_auth(ZebraHandle zh, const char *user, const char *pass)
+   \fn ZEBRA_RES zebra_auth(ZebraHandle zh, const char *user, const char *pass)
    \brief authenticate user. Returns 0 if OK, != 0 on failure
    \param zh session handle
    \param user user name
    \param pass password
  */
-YAZ_EXPORT int zebra_auth(ZebraHandle zh, const char *user, const char *pass);
-
+YAZ_EXPORT ZEBRA_RES zebra_auth(ZebraHandle zh,
+                               const char *user, const char *pass);
 
 /**
    \fn int zebra_string_norm(ZebraHandle zh, unsigned reg_id,
@@ -289,12 +292,12 @@ YAZ_EXPORT int zebra_string_norm(ZebraHandle zh, unsigned reg_id,
                                  char *output_str, int output_len);
 
 /**
-   \fn int zebra_create_database(ZebraHandle zh, const char *db)
+   \fn ZEBRA_RES zebra_create_database(ZebraHandle zh, const char *db)
    \brief creates a database
    \param zh session handle
    \param db database to be created
 */
-YAZ_EXPORT int zebra_create_database(ZebraHandle zh, const char *db);
+YAZ_EXPORT ZEBRA_RES zebra_create_database(ZebraHandle zh, const char *db);
 
 /**
    \fn int zebra_drop_database(ZebraHandle zh, const char *db)
@@ -302,35 +305,55 @@ YAZ_EXPORT int zebra_create_database(ZebraHandle zh, const char *db);
    \param zh session handle
    \param db database to be deleted
 */
-YAZ_EXPORT int zebra_drop_database(ZebraHandle zh, const char *db);
+YAZ_EXPORT
+ZEBRA_RES zebra_drop_database(ZebraHandle zh, const char *db);
 
-YAZ_EXPORT int zebra_admin_shutdown(ZebraHandle zh);
-YAZ_EXPORT int zebra_admin_start(ZebraHandle zh);
+YAZ_EXPORT
+ZEBRA_RES zebra_admin_shutdown(ZebraHandle zh);
 
-YAZ_EXPORT int zebra_shutdown(ZebraService zs);
+YAZ_EXPORT
+ZEBRA_RES zebra_admin_start(ZebraHandle zh);
 
-YAZ_EXPORT int zebra_admin_import_begin(ZebraHandle zh, const char *database,
-                                          const char *record_type);
+YAZ_EXPORT
+ZEBRA_RES zebra_shutdown(ZebraService zs);
 
-YAZ_EXPORT int zebra_admin_import_segment(ZebraHandle zh,
-                                           Z_Segment *segment);
+YAZ_EXPORT
+ZEBRA_RES zebra_admin_import_begin(ZebraHandle zh, const char *database,
+                                  const char *record_type);
 
-YAZ_EXPORT int zebra_admin_import_end(ZebraHandle zh);
+YAZ_EXPORT 
+ZEBRA_RES zebra_admin_import_segment(ZebraHandle zh,
+                                    Z_Segment *segment);
+
+YAZ_EXPORT 
+ZEBRA_RES zebra_admin_import_end(ZebraHandle zh);
+
+YAZ_EXPORT 
+ZEBRA_RES zebra_admin_exchange_record(ZebraHandle zh,
+                                     const char *rec_buf,
+                                     size_t rec_len,
+                                     const char *recid_buf, size_t recid_len,
+                                     int action);
 
-YAZ_EXPORT int zebra_admin_exchange_record(ZebraHandle zh,
-                                 const char *rec_buf,
-                                 size_t rec_len,
-                                 const char *recid_buf, size_t recid_len,
-                                 int action);
+YAZ_EXPORT 
+ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw);
 
-YAZ_EXPORT int zebra_begin_trans(ZebraHandle zh, int rw);
-YAZ_EXPORT int zebra_end_trans(ZebraHandle zh);
-YAZ_EXPORT int zebra_end_transaction(ZebraHandle zh, ZebraTransactionStatus *stat);
+YAZ_EXPORT
+ZEBRA_RES zebra_end_trans(ZebraHandle zh);
 
-YAZ_EXPORT int zebra_commit(ZebraHandle zh);
-YAZ_EXPORT int zebra_clean(ZebraHandle zh);
+YAZ_EXPORT
+ZEBRA_RES zebra_end_transaction(ZebraHandle zh,
+                               ZebraTransactionStatus *stat);
+
+YAZ_EXPORT
+ZEBRA_RES zebra_commit(ZebraHandle zh);
+
+YAZ_EXPORT
+ZEBRA_RES zebra_clean(ZebraHandle zh);
+
+YAZ_EXPORT
+ZEBRA_RES zebra_init(ZebraHandle zh);
 
-YAZ_EXPORT int zebra_init(ZebraHandle zh);
 YAZ_EXPORT int zebra_compact(ZebraHandle zh);
 YAZ_EXPORT int zebra_repository_update(ZebraHandle zh, const char *path);
 YAZ_EXPORT int zebra_repository_delete(ZebraHandle zh, const char *path);
@@ -338,64 +361,69 @@ YAZ_EXPORT int zebra_repository_show(ZebraHandle zh, const char *path);
 
 YAZ_EXPORT int zebra_add_record(ZebraHandle zh, const char *buf, int buf_size);
                               
-YAZ_EXPORT int zebra_insert_record(ZebraHandle zh, 
-                        const char *recordType,
-                        SYSNO *sysno, const char *match, const char *fname,
-                        const char *buf, int buf_size,
-                        int force_update);
-YAZ_EXPORT int zebra_update_record(ZebraHandle zh, 
-                        const char *recordType,
-                        SYSNO *sysno, const char *match, const char *fname,
-                        const char *buf, int buf_size,
-                        int force_update);
-YAZ_EXPORT int zebra_delete_record(ZebraHandle zh, 
-                        const char *recordType,
-                        SYSNO *sysno, const char *match, const char *fname,
-                        const char *buf, int buf_size,
-                        int force_update);
-
-YAZ_EXPORT int zebra_resultSetTerms(ZebraHandle zh, const char *setname, 
-                                     int no, zint *count, 
-                                     int *type, char *out, size_t *len);
-
-YAZ_EXPORT int zebra_sort(ZebraHandle zh, ODR stream,
-                          int num_input_setnames,
-                          const char **input_setnames,
-                          const char *output_setname,
-                          Z_SortKeySpecList *sort_sequence,
-                          int *sort_status);
-
+YAZ_EXPORT 
+ZEBRA_RES zebra_insert_record(ZebraHandle zh, 
+                             const char *recordType,
+                             SYSNO *sysno, const char *match,
+                             const char *fname,
+                             const char *buf, int buf_size,
+                             int force_update);
 YAZ_EXPORT
-int zebra_select_databases(ZebraHandle zh, int num_bases, 
-                          const char **basenames);
+ZEBRA_RES zebra_update_record(ZebraHandle zh, 
+                             const char *recordType,
+                             SYSNO *sysno, const char *match,
+                             const char *fname,
+                             const char *buf, int buf_size,
+                             int force_update);
+YAZ_EXPORT 
+ZEBRA_RES zebra_delete_record(ZebraHandle zh, 
+                             const char *recordType,
+                             SYSNO *sysno, const char *match, const char *fname,
+                             const char *buf, int buf_size,
+                             int force_update);
+
+YAZ_EXPORT 
+int zebra_resultSetTerms(ZebraHandle zh, const char *setname, 
+                        int no, zint *count, 
+                        int *type, char *out, size_t *len);
+
+YAZ_EXPORT 
+ZEBRA_RES zebra_sort(ZebraHandle zh, ODR stream,
+                    int num_input_setnames,
+                    const char **input_setnames,
+                    const char *output_setname,
+                    Z_SortKeySpecList *sort_sequence,
+                    int *sort_status);
 
 YAZ_EXPORT
-int zebra_select_database(ZebraHandle zh, const char *basename);
+ZEBRA_RES zebra_select_databases(ZebraHandle zh, int num_bases, 
+                                const char **basenames);
 
 YAZ_EXPORT
-int zebra_shadow_enable(ZebraHandle zh, int value);
+ZEBRA_RES zebra_select_database(ZebraHandle zh, const char *basename);
 
 YAZ_EXPORT
-int zebra_register_statistics(ZebraHandle zh, int dumpdict);
+void zebra_shadow_enable(ZebraHandle zh, int value);
 
 YAZ_EXPORT
-int zebra_record_encoding(ZebraHandle zh, const char *encoding);
+int zebra_register_statistics(ZebraHandle zh, int dumpdict);
 
 YAZ_EXPORT
-int zebra_record_encoding(ZebraHandle zh, const char *encoding);
+ZEBRA_RES zebra_record_encoding(ZebraHandle zh, const char *encoding);
 
 YAZ_EXPORT
-int zebra_octet_term_encoding(ZebraHandle zh, const char *encoding);
+ZEBRA_RES zebra_octet_term_encoding(ZebraHandle zh, const char *encoding);
 
 /* Resources */
 YAZ_EXPORT
-int zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
+void zebra_set_resource(ZebraHandle zh, const char *name, const char *value);
 YAZ_EXPORT
 const char *zebra_get_resource(ZebraHandle zh, 
-               const char *name, const char *defaultvalue);
+                              const char *name, const char *defaultvalue);
 
 
-YAZ_EXPORT void zebra_pidfname(ZebraService zs, char *path);
+YAZ_EXPORT
+void zebra_pidfname(ZebraService zs, char *path);
 
 typedef struct {
     char *term;
index ccb5644..7b7aeba 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: isamc.h,v 1.3 2005-04-13 13:03:47 adam Exp $
+/* $Id: isamc.h,v 1.4 2005-04-15 10:47:48 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -57,20 +57,37 @@ typedef struct ISAMC_I_s {
     void *clientData;
 } ISAMC_I;
 
+YAZ_EXPORT
 void isamc_getmethod (ISAMC_M *m);
 
+YAZ_EXPORT
 ISAMC isamc_open (BFiles bfs, const char *name, int writeflag,
                  ISAMC_M *method);
+YAZ_EXPORT
 int isamc_close (ISAMC is);
+
+YAZ_EXPORT
 void isamc_merge (ISAMC is, ISAM_P *pos, ISAMC_I *data);
 
+YAZ_EXPORT
 ISAMC_PP isamc_pp_open (ISAMC is, ISAM_P pos);
+
+YAZ_EXPORT
 void isamc_pp_close (ISAMC_PP pp);
+
+YAZ_EXPORT
 int isamc_read_item (ISAMC_PP pp, char **dst);
+
+YAZ_EXPORT
 int isamc_pp_read (ISAMC_PP pp, void *buf);
+
+YAZ_EXPORT
 zint isamc_pp_num (ISAMC_PP pp);
 
+YAZ_EXPORT
 zint isamc_block_used (ISAMC is, int type);
+
+YAZ_EXPORT
 int isamc_block_size (ISAMC is, int type);
 
 #define isamc_type(x) ((x) & 7)
index 41f356e..dab4490 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: util.h,v 1.1 2005-03-30 09:25:23 adam Exp $
+/* $Id: util.h,v 1.2 2005-04-15 10:47:48 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -23,7 +23,8 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #ifndef ZEBRA_UTIL_H
 #define ZEBRA_UTIL_H
 
-#include <yaz/yaz-util.h>
+#include <yaz/yconfig.h>
+#include <yaz/log.h>
 
 #include <idzebra/version.h>
 
@@ -50,6 +51,10 @@ typedef long zint;
 #endif
 #endif
 
+typedef short ZEBRA_RES;
+#define ZEBRA_FAIL -1
+#define ZEBRA_OK   0
+
 typedef zint SYSNO;
 
 YAZ_EXPORT
index 8892855..5e8df1a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: rset.h,v 1.48 2005-04-13 13:03:47 adam Exp $
+/* $Id: rset.h,v 1.49 2005-04-15 10:47:48 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -23,6 +23,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #ifndef RSET_H
 #define RSET_H
 
+#include <yaz/yaz-util.h>
 /* unfortunately we need the isam includes here, for the arguments for */
 /* rsisamX_create */
 #include <idzebra/isamb.h> 
index 2f8e0fe..8f0cf0b 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: extract.c,v 1.177 2005-03-17 09:48:46 adam Exp $
+/* $Id: extract.c,v 1.178 2005-04-15 10:47:48 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -812,16 +812,16 @@ int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname,
   If not, and a record is provided, then sysno is got from there
   
  */
-int buffer_extract_record (ZebraHandle zh, 
-                          const char *buf, size_t buf_size,
-                          int delete_flag,
-                          int test_mode, 
-                          const char *recordType,
-                          SYSNO *sysno,
-                          const char *match_criteria,
-                          const char *fname,
-                          int force_update,
-                          int allow_update)
+ZEBRA_RES buffer_extract_record (ZebraHandle zh, 
+                                const char *buf, size_t buf_size,
+                                int delete_flag,
+                                int test_mode, 
+                                const char *recordType,
+                                SYSNO *sysno,
+                                const char *match_criteria,
+                                const char *fname,
+                                int force_update,
+                                int allow_update)
 {
     RecordAttr *recordAttr;
     struct recExtractCtrl extractCtrl;
@@ -860,17 +860,21 @@ int buffer_extract_record (ZebraHandle zh,
     {
         if (zebraExplain_newDatabase (zh->reg->zei, zh->basenames[0], 
                                      zh->m_explain_database))
-            return 0;
+            return ZEBRA_FAIL;
     }
     
-    if (recordType && *recordType) {
+    if (recordType && *recordType)
+    {
         yaz_log (YLOG_DEBUG, "Record type explicitly specified: %s", recordType);
         recType = recType_byName (zh->reg->recTypes, zh->res, recordType,
                                   &clientData);
-    } else {
-        if (!(zh->m_record_type)) {
+    } 
+    else
+    {
+        if (!(zh->m_record_type))
+       {
             yaz_log (YLOG_WARN, "No such record type defined");
-            return 0;
+            return ZEBRA_FAIL;
         }
         yaz_log (YLOG_DEBUG, "Get record type from rgroup: %s",zh->m_record_type);
         recType = recType_byName (zh->reg->recTypes, zh->res,
@@ -878,9 +882,10 @@ int buffer_extract_record (ZebraHandle zh,
         recordType = zh->m_record_type;
     }
     
-    if (!recType) {
+    if (!recType)
+    {
         yaz_log (YLOG_WARN, "No such record type: %s", zh->m_record_type);
-        return 0;
+        return ZEBRA_FAIL;
     }
     
     extractCtrl.init = extract_init;
@@ -902,18 +907,18 @@ int buffer_extract_record (ZebraHandle zh,
     r = (*recType->extract)(clientData, &extractCtrl);
 
     if (r == RECCTRL_EXTRACT_EOF)
-       return 0;
+       return ZEBRA_FAIL;
     else if (r == RECCTRL_EXTRACT_ERROR_GENERIC)
     {
        /* error occured during extraction ... */
        yaz_log (YLOG_WARN, "extract error: generic");
-       return 0;
+       return ZEBRA_FAIL;
     }
     else if (r == RECCTRL_EXTRACT_ERROR_NO_SUCH_FILTER)
     {
        /* error occured during extraction ... */
        yaz_log (YLOG_WARN, "extract error: no such filter");
-       return 0;
+       return ZEBRA_FAIL;
     }
     /* match criteria */
     matchStr = NULL;
@@ -932,7 +937,7 @@ int buffer_extract_record (ZebraHandle zh,
                if (!matchStr)
                 {
                     yaz_log (YLOG_WARN, "Bad match criteria (recordID)");
-                   return 1;
+                   return ZEBRA_FAIL;
                 }
             }
         }
@@ -950,7 +955,7 @@ int buffer_extract_record (ZebraHandle zh,
        /* the extraction process returned no information - the record
           is probably empty - unless flagShowRecords is in use */
        if (test_mode)
-           return 1;
+           return ZEBRA_OK;
     }
 
     if (! *sysno)
@@ -962,7 +967,7 @@ int buffer_extract_record (ZebraHandle zh,
                yaz_log (YLOG_LOG, "delete %s %s %ld", recordType,
                         pr_fname, (long) recordOffset);
             yaz_log (YLOG_WARN, "cannot delete record above (seems new)");
-            return 1;
+            return ZEBRA_FAIL;
         }
        if (show_progress)
            yaz_log (YLOG_LOG, "add %s %s %ld", recordType, pr_fname,
@@ -995,7 +1000,7 @@ int buffer_extract_record (ZebraHandle zh,
                yaz_log (YLOG_LOG, "skipped %s %s %ld", 
                         recordType, pr_fname, (long) recordOffset);
            logRecord(zh);
-           return -1;
+           return ZEBRA_FAIL;
        }
 
         rec = rec_get (zh->reg->records, *sysno);
@@ -1013,7 +1018,7 @@ int buffer_extract_record (ZebraHandle zh,
                extract_flushSortKeys (zh, *sysno, -1, &zh->reg->sortKeys);
                rec_rm (&rec);
                logRecord(zh);
-               return -1;
+               return ZEBRA_FAIL;
            }
        }
 
@@ -1050,7 +1055,7 @@ int buffer_extract_record (ZebraHandle zh,
             }
            rec_rm (&rec);
             logRecord(zh);
-            return 0;
+            return ZEBRA_OK;
         }
         else
         {
@@ -1150,7 +1155,7 @@ int buffer_extract_record (ZebraHandle zh,
     /* commit this record */
     rec_put (zh->reg->records, &rec);
     logRecord(zh);
-    return 0;
+    return ZEBRA_OK;
 }
 
 int explain_extract (void *handle, Record rec, data1_node *n)
index 8e7b995..92edee0 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: index.h,v 1.132 2005-04-13 13:03:47 adam Exp $
+/* $Id: index.h,v 1.133 2005-04-15 10:47:48 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -335,16 +335,17 @@ struct term_set_list {
     struct term_set_entry *last;
 };
 
-RSET rpn_search (ZebraHandle zh, NMEM mem, NMEM rset_nmem,
-                Z_RPNQuery *rpn, int num_bases, char **basenames, 
-                const char *setname, ZebraSet sset);
+RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs,
+                          oid_value attributeSet, 
+                          NMEM stream, NMEM rset_nmem,
+                          Z_SortKeySpecList *sort_sequence,
+                          int num_bases, char **basenames);
 
-
-void rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
-              oid_value attributeset,
-              int num_bases, char **basenames,
-              int *position, int *num_entries, ZebraScanEntry **list,
-              int *is_partial, RSET limit_set, int return_zero);
+ZEBRA_RES rpn_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
+                   oid_value attributeset,
+                   int num_bases, char **basenames,
+                   int *position, int *num_entries, ZebraScanEntry **list,
+                   int *is_partial, RSET limit_set, int return_zero);
 
 RSET rset_trunc (ZebraHandle zh, ISAM_P *isam_p, int no,
                 const char *term, int length_term, const char *flags,
@@ -356,9 +357,9 @@ void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
                       int use, const char *term);
 ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov);
 ZebraSet resultSetGet (ZebraHandle zh, const char *name);
-ZebraSet resultSetAddRPN (ZebraHandle zh, NMEM m, Z_RPNQuery *rpn,
-                          int num_bases, char **basenames,
-                          const char *setname);
+ZEBRA_RES resultSetAddRPN (ZebraHandle zh, NMEM m, Z_RPNQuery *rpn,
+                    int num_bases, char **basenames,
+                    const char *setname);
 RSET resultSetRef (ZebraHandle zh, const char *resultSetId);
 void resultSetDestroy (ZebraHandle zh, int num_names, char **names,
                       int *statuses);
@@ -405,16 +406,16 @@ void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no);
 
 void zebra_index_merge (ZebraHandle zh);
 
-int buffer_extract_record (ZebraHandle zh, 
-                          const char *buf, size_t buf_size,
-                          int delete_flag,
-                          int test_mode, 
-                          const char *recordType,
-                          SYSNO *sysno,
-                          const char *match_criteria,
-                          const char *fname,
-                          int force_update,
-                          int allow_update);
+ZEBRA_RES buffer_extract_record (ZebraHandle zh, 
+                                const char *buf, size_t buf_size,
+                                int delete_flag,
+                                int test_mode, 
+                                const char *recordType,
+                                SYSNO *sysno,
+                                const char *match_criteria,
+                                const char *fname,
+                                int force_update,
+                                int allow_update);
 
 #if 0
 int extract_rec_in_mem (ZebraHandle zh, const char *recordType,
@@ -454,8 +455,8 @@ int explain_extract (void *handle, Record rec, data1_node *n);
 int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname,
                 int deleteFlag);
 
-int zebra_begin_read (ZebraHandle zh);
-int zebra_end_read (ZebraHandle zh);
+ZEBRA_RES zebra_begin_read (ZebraHandle zh);
+ZEBRA_RES zebra_end_read (ZebraHandle zh);
 
 int zebra_file_stat (const char *file_name, struct stat *buf,
                      int follow_links);
index 69ed2d1..8449381 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: recindex.c,v 1.42 2005-01-16 23:14:57 adam Exp $
+/* $Id: recindex.c,v 1.43 2005-04-15 10:47:48 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -42,6 +42,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <assert.h>
 #include <string.h>
 
+#include <yaz/yaz-util.h>
 #include "recindxp.h"
 
 #if HAVE_BZLIB_H
index 76ffe45..02680d4 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zebraapi.c,v 1.160 2005-04-14 12:02:08 adam Exp $
+/* $Id: zebraapi.c,v 1.161 2005-04-15 10:47:48 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -398,7 +398,7 @@ struct zebra_register *zebra_register_open (ZebraService zs, const char *name,
     return reg;
 }
 
-int zebra_admin_shutdown (ZebraHandle zh)
+ZEBRA_RES zebra_admin_shutdown (ZebraHandle zh)
 {
     ASSERTZH;
     yaz_log(log_level, "zebra_admin_shutdown");
@@ -407,10 +407,10 @@ int zebra_admin_shutdown (ZebraHandle zh)
     zebra_mutex_cond_lock (&zh->service->session_lock);
     zh->service->stop_flag = 1;
     zebra_mutex_cond_unlock (&zh->service->session_lock);
-    return 0;
+    return ZEBRA_OK;
 }
 
-int zebra_admin_start (ZebraHandle zh)
+ZEBRA_RES zebra_admin_start (ZebraHandle zh)
 {
     ZebraService zs;
     ASSERTZH;
@@ -419,7 +419,7 @@ int zebra_admin_start (ZebraHandle zh)
     zs = zh->service;
     zebra_mutex_cond_lock (&zs->session_lock);
     zebra_mutex_cond_unlock (&zs->session_lock);
-    return 0;
+    return ZEBRA_OK;
 }
 
 static void zebra_register_close (ZebraService zs, struct zebra_register *reg)
@@ -460,10 +460,10 @@ static void zebra_register_close (ZebraService zs, struct zebra_register *reg)
     xfree(reg);
 }
 
-int zebra_stop(ZebraService zs)
+ZEBRA_RES zebra_stop(ZebraService zs)
 {
     if (!zs)
-        return 0;
+        return ZEBRA_OK;
     yaz_log (log_level, "zebra_stop");
 
     while (zs->sessions)
@@ -481,10 +481,10 @@ int zebra_stop(ZebraService zs)
     res_close (zs->global_res);
     xfree(zs->configName);
     xfree(zs);
-    return 0;
+    return ZEBRA_OK;
 }
 
-int zebra_close (ZebraHandle zh)
+ZEBRA_RES zebra_close (ZebraHandle zh)
 {
     ZebraService zs;
     struct zebra_session **sp;
@@ -492,7 +492,7 @@ int zebra_close (ZebraHandle zh)
 
     yaz_log(log_level, "zebra_close");
     if (!zh)
-        return 0;
+        return ZEBRA_OK;
     ASSERTZH;
     zh->errCode = 0;
     
@@ -535,7 +535,7 @@ int zebra_close (ZebraHandle zh)
     zh->service = 0; /* more likely to trigger an assert */
     xfree(zh->path_reg);
     xfree(zh);
-    return 0;
+    return ZEBRA_OK;
 }
 
 struct map_baseinfo {
@@ -583,12 +583,12 @@ static void zebra_close_res (ZebraHandle zh)
     zh->res = 0;
 }
 
-static int zebra_select_register (ZebraHandle zh, const char *new_reg)
+static void zebra_select_register (ZebraHandle zh, const char *new_reg)
 {
     ASSERTZH;
     zh->errCode = 0;
     if (zh->res && strcmp (zh->reg_name, new_reg) == 0)
-        return 0;
+        return;
     if (!zh->res)
     {
         assert (zh->reg == 0);
@@ -646,7 +646,6 @@ static int zebra_select_register (ZebraHandle zh, const char *new_reg)
             zebra_lock_create (res_get(zh->res, "lockDir"), fname, 0);
 
     }
-    return 1;
 }
 
 void map_basenames_func (void *vp, const char *name, const char *value)
@@ -732,7 +731,7 @@ void map_basenames (ZebraHandle zh, ODR stream,
        yaz_log (YLOG_DEBUG, "base %s", (*basenames)[i]);
 }
 
-int zebra_select_database (ZebraHandle zh, const char *basename)
+ZEBRA_RES zebra_select_database (ZebraHandle zh, const char *basename)
 {
     ASSERTZH;
     yaz_log(log_level, "zebra_select_database %s",basename);
@@ -741,8 +740,8 @@ int zebra_select_database (ZebraHandle zh, const char *basename)
     return zebra_select_databases (zh, 1, &basename);
 }
 
-int zebra_select_databases (ZebraHandle zh, int num_bases,
-                            const char **basenames)
+ZEBRA_RES zebra_select_databases (ZebraHandle zh, int num_bases,
+                                 const char **basenames)
 {
     int i;
     const char *cp;
@@ -758,7 +757,7 @@ int zebra_select_databases (ZebraHandle zh, int num_bases,
     if (num_bases < 1)
     {
         zh->errCode = 23;
-        return -1;
+        return ZEBRA_FAIL;
     }
     for (i = 0; i < zh->num_basenames; i++)
         xfree(zh->basenames[i]);
@@ -803,7 +802,7 @@ int zebra_select_databases (ZebraHandle zh, int num_bases,
             if (cp1)
             {
                 zh->errCode = 23;
-                return -1;
+                return ZEBRA_FAIL;
             }
         }
     }
@@ -812,21 +811,20 @@ int zebra_select_databases (ZebraHandle zh, int num_bases,
     if (!zh->res)
     {
         zh->errCode = 109;
-        return -1;
+        return ZEBRA_FAIL;
     }
     if (!zh->lock_normal || !zh->lock_shadow)
     {
         zh->errCode = 2;
-       return -1;
+       return ZEBRA_FAIL;
     }
-    return 0;
+    return ZEBRA_OK;
 }
 
-int zebra_search_RPN (ZebraHandle zh, ODR o,
-                      Z_RPNQuery *query, const char *setname, zint *hits)
+ZEBRA_RES zebra_search_RPN (ZebraHandle zh, ODR o, Z_RPNQuery *query,
+                           const char *setname, zint *hits)
 {
-    const char *max;
-    zint maxhits;
+    ZEBRA_RES r;
     ASSERTZH;
     assert(o);
     assert(query);
@@ -837,38 +835,25 @@ int zebra_search_RPN (ZebraHandle zh, ODR o,
     zh->hits = 0;
     *hits = 0;
 
-    if (zebra_begin_read (zh))
-       return 1;
+    if (zebra_begin_read(zh) == ZEBRA_FAIL)
+       return ZEBRA_FAIL;
 
-    resultSetAddRPN (zh, odr_extract_mem(o), query, 
-                     zh->num_basenames, zh->basenames, setname);
-
-    zebra_end_read (zh);
-    max = res_get (zh->res, "maxhits");
-    if (max)
-       maxhits = atoi(max);
-    else {
-        int i = 0; 
-       maxhits = INT_MAX;  /* properly rounded, to make it look like a limit*/
-       while (maxhits>100) { maxhits/=10; i++;}
-       while (i--) maxhits *= 10;
-    }
-    if (zh->hits > maxhits) { /* too large for yaz to handle */
-        yaz_log(YLOG_DEBUG, "limiting hits to "ZINT_FORMAT, maxhits);
-       *hits = maxhits;  
-    }
-    else
-        *hits = zh->hits;
-    return 0;
+    r = resultSetAddRPN(zh, odr_extract_mem(o), query, 
+                       zh->num_basenames, zh->basenames, setname);
+    zebra_end_read(zh);
+    *hits = zh->hits;
+    return r;
 }
 
-int zebra_records_retrieve (ZebraHandle zh, ODR stream,
-                           const char *setname, Z_RecordComposition *comp,
-                           oid_value input_format, int num_recs,
-                           ZebraRetrievalRecord *recs)
+ZEBRA_RES zebra_records_retrieve (ZebraHandle zh, ODR stream,
+                                 const char *setname,
+                                 Z_RecordComposition *comp,
+                                 oid_value input_format, int num_recs,
+                                 ZebraRetrievalRecord *recs)
 {
     ZebraMetaRecord *poset;
-    int i, ret = 0;
+    int i;
+    ZEBRA_RES ret = ZEBRA_OK;
     zint *pos_array;
     ASSERTZH;
     assert(stream);
@@ -883,13 +868,13 @@ int zebra_records_retrieve (ZebraHandle zh, ODR stream,
     {
         zh->errCode = 30;
         zh->errString = odr_strdup(stream, setname);
-        return -1;
+        return ZEBRA_FAIL;
     }
     
     zh->errCode = 0;
 
-    if (zebra_begin_read (zh))
-       return -1;
+    if (zebra_begin_read (zh) == ZEBRA_FAIL)
+       return ZEBRA_FAIL;
 
     pos_array = (zint *) xmalloc(num_recs * sizeof(*pos_array));
     for (i = 0; i<num_recs; i++)
@@ -900,7 +885,7 @@ int zebra_records_retrieve (ZebraHandle zh, ODR stream,
         yaz_log (YLOG_DEBUG, "zebraPosSetCreate error");
         zh->errCode = 30;
         zh->errString = nmem_strdup (stream->mem, setname);
-       ret = -1;
+       ret = ZEBRA_FAIL;
     }
     else
     {
@@ -941,7 +926,7 @@ int zebra_records_retrieve (ZebraHandle zh, ODR stream,
                sprintf (num_str, ZINT_FORMAT, pos_array[i]);   
                zh->errCode = 13;
                 zh->errString = odr_strdup (stream, num_str);
-               ret = -1;
+               ret = ZEBRA_FAIL;
                 break;
            }
        }
@@ -952,9 +937,10 @@ int zebra_records_retrieve (ZebraHandle zh, ODR stream,
     return ret;
 }
 
-int zebra_scan_PQF(ZebraHandle zh, ODR stream, const char *query,
-                  int *position, int *num_entries, ZebraScanEntry **entries,
-                  int *is_partial)
+ZEBRA_RES zebra_scan_PQF(ZebraHandle zh, ODR stream, const char *query,
+                        int *position,
+                        int *num_entries, ZebraScanEntry **entries,
+                        int *is_partial)
 {
     YAZ_PQF_Parser pqf_parser = yaz_pqf_create ();
     Z_AttributesPlusTerm *zapt;
@@ -963,18 +949,20 @@ int zebra_scan_PQF(ZebraHandle zh, ODR stream, const char *query,
     if (!(zapt = yaz_pqf_scan(pqf_parser, stream, &attributeSet, query)))
     {
        yaz_pqf_destroy (pqf_parser);
-       return -1;
+       return ZEBRA_FAIL;
     }
     yaz_pqf_destroy (pqf_parser);
     return zebra_scan(zh, stream, zapt, VAL_BIB1,
                      position, num_entries, entries, is_partial);
 }
 
-int zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
-               oid_value attributeset,
-               int *position, int *num_entries, ZebraScanEntry **entries,
-               int *is_partial)
+ZEBRA_RES zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
+                     oid_value attributeset,
+                     int *position,
+                     int *num_entries, ZebraScanEntry **entries,
+                     int *is_partial)
 {
+    ZEBRA_RES res;
     ASSERTZH;
     assert(stream);
     assert(zapt);
@@ -984,23 +972,24 @@ int zebra_scan (ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
     assert(entries);
     yaz_log(log_level, "zebra_scan");
     zh->errCode = 0;
-    if (zebra_begin_read (zh))
+    if (zebra_begin_read (zh) == ZEBRA_FAIL)
     {
        *entries = 0;
        *num_entries = 0;
-       return 1;
+       return ZEBRA_FAIL;
     }
-    rpn_scan (zh, stream, zapt, attributeset,
-             zh->num_basenames, zh->basenames, position,
-             num_entries, entries, is_partial, 0, 0);
+    res = rpn_scan (zh, stream, zapt, attributeset,
+                   zh->num_basenames, zh->basenames, position,
+                   num_entries, entries, is_partial, 0, 0);
     zebra_end_read (zh);
-    return 0;
+    return res;
 }
 
-int zebra_sort (ZebraHandle zh, ODR stream,
-                int num_input_setnames, const char **input_setnames,
-                const char *output_setname, Z_SortKeySpecList *sort_sequence,
-                int *sort_status)
+ZEBRA_RES zebra_sort (ZebraHandle zh, ODR stream,
+                     int num_input_setnames, const char **input_setnames,
+                     const char *output_setname,
+                     Z_SortKeySpecList *sort_sequence,
+                     int *sort_status)
 {
     ASSERTZH;
     assert(stream);
@@ -1010,12 +999,11 @@ int zebra_sort (ZebraHandle zh, ODR stream,
     assert(sort_status);
     yaz_log(log_level, "zebra_sort");
     zh->errCode = 0;
-    if (zebra_begin_read (zh))
-       return 1;
+    if (zebra_begin_read (zh) == ZEBRA_FAIL)
+       return ZEBRA_FAIL;
     resultSetSort (zh, stream->mem, num_input_setnames, input_setnames,
                   output_setname, sort_sequence, sort_status);
-    zebra_end_read(zh);
-    return 0;
+    return zebra_end_read(zh);
 }
 
 int zebra_deleteResultSet(ZebraHandle zh, int function,
@@ -1082,11 +1070,11 @@ void zebra_clearError(ZebraHandle zh)
     if (zh)
     {
         zh->errCode = 0;
-        zh->errString="";
+        zh->errString = 0;
     }
 }
 
-int zebra_auth (ZebraHandle zh, const char *user, const char *pass)
+ZEBRA_RES zebra_auth (ZebraHandle zh, const char *user, const char *pass)
 {
     const char *p;
     char u[40];
@@ -1103,38 +1091,36 @@ int zebra_auth (ZebraHandle zh, const char *user, const char *pass)
 
     /* users that don't require a password .. */
     if (zh->user_perm && strchr(zh->user_perm, 'a'))
-       return 0;
+       return ZEBRA_OK;
     
     if (!zs->passwd_db || !passwd_db_auth (zs->passwd_db, user, pass))
-       return 0;
-    return 1;
+       return ZEBRA_OK;
+    return ZEBRA_FAIL;
 }
 
-int zebra_admin_import_begin (ZebraHandle zh, const char *database,
+ZEBRA_RES zebra_admin_import_begin (ZebraHandle zh, const char *database,
                                const char *record_type)
 {
     ASSERTZH;
     yaz_log(log_level, "zebra_admin_import_begin db=%s rt=%s", 
                     database, record_type);
     zh->errCode = 0;
-    if (zebra_select_database(zh, database))
-        return 1;
-    if (zebra_begin_trans (zh, 1))
-       return 1;
-    return 0;
+    if (zebra_select_database(zh, database) == ZEBRA_FAIL)
+        return ZEBRA_FAIL;
+    return zebra_begin_trans(zh, 1);
 }
 
-int zebra_admin_import_end (ZebraHandle zh)
+ZEBRA_RES zebra_admin_import_end (ZebraHandle zh)
 {
     ASSERTZH;
     yaz_log(log_level, "zebra_admin_import_end");
     zh->errCode = 0;
-    zebra_end_trans (zh);
-    return 0;
+    return zebra_end_trans(zh);
 }
 
-int zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment)
+ZEBRA_RES zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment)
 {
+    ZEBRA_RES res = ZEBRA_OK;
     SYSNO sysno;
     int i;
     ASSERTZH;
@@ -1144,42 +1130,39 @@ int zebra_admin_import_segment (ZebraHandle zh, Z_Segment *segment)
     {
        Z_NamePlusRecord *npr = segment->segmentRecords[i];
 
-       printf ("--------------%d--------------------\n", i);
-        /* FIXME - What! printing on stdout ??? */
        if (npr->which == Z_NamePlusRecord_intermediateFragment)
        {
            Z_FragmentSyntax *fragment = npr->u.intermediateFragment;
            if (fragment->which == Z_FragmentSyntax_notExternallyTagged)
            {
                Odr_oct *oct = fragment->u.notExternallyTagged;
-               printf ("%.*s", (oct->len > 100 ? 100 : oct->len) ,
-                       oct->buf);
-               
                sysno = 0;
                
-               zebra_update_record(zh, 
-                                   0, /* record Type */
-                                   &sysno,
-                                   0, /* match */
-                                   0, /* fname */
-                                   oct->buf, oct->len,
-                                   0);
+               if ( zebra_update_record(zh, 
+                                        0, /* record Type */
+                                        &sysno,
+                                        0, /* match */
+                                        0, /* fname */
+                                        oct->buf, oct->len,
+                                        0) == ZEBRA_FAIL)
+                   res = ZEBRA_FAIL;
            }
        }
     }
-    return 0;
+    return res;
 }
 
-int zebra_admin_exchange_record (ZebraHandle zh,
-                                 const char *rec_buf,
-                                 size_t rec_len,
-                                 const char *recid_buf, size_t recid_len,
-                                 int action)
+ZEBRA_RES zebra_admin_exchange_record (ZebraHandle zh,
+                                      const char *rec_buf,
+                                      size_t rec_len,
+                                      const char *recid_buf, size_t recid_len,
+                                      int action)
     /* 1 = insert. Fail it already exists */
     /* 2 = replace. Fail it does not exist */
     /* 3 = delete. Fail if does not exist */
     /* 4 = update. Insert/replace */
 {
+    ZEBRA_RES res;
     SYSNO sysno = 0;
     char *rinfo = 0;
     char recid_z[256];
@@ -1191,12 +1174,13 @@ int zebra_admin_exchange_record (ZebraHandle zh,
     zh->errCode = 0;
 
     if (!recid_buf || recid_len <= 0 || recid_len >= sizeof(recid_z))
-        return -1;
+        return ZEBRA_FAIL;
+
     memcpy (recid_z, recid_buf, recid_len);
     recid_z[recid_len] = 0;
 
-    if (zebra_begin_trans(zh, 1))
-       return -1;
+    if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL)
+       return ZEBRA_FAIL;
 
     rinfo = dict_lookup (zh->reg->matchDict, recid_z);
     if (rinfo)
@@ -1204,7 +1188,7 @@ int zebra_admin_exchange_record (ZebraHandle zh,
         if (action == 1)  /* fail if insert */
         {
             zebra_end_trans(zh);
-            return -1;
+            return ZEBRA_FAIL;
        }
 
         memcpy (&sysno, rinfo+1, sizeof(sysno));
@@ -1214,19 +1198,19 @@ int zebra_admin_exchange_record (ZebraHandle zh,
         if (action == 2 || action == 3) /* fail if delete or update */
         {
            zebra_end_trans(zh);
-            return -1;
+            return ZEBRA_FAIL;
        }
        action = 1;  /* make it an insert (if it's an update).. */
     }
-    buffer_extract_record (zh, rec_buf, rec_len,
-                          action == 3 ? 1 : 0 /* delete flag */,
-                          0, /* test mode */
-                          0, /* recordType */
-                          &sysno, 
-                          0, /* match */
-                          0, /* fname */
+    res = buffer_extract_record (zh, rec_buf, rec_len,
+                                action == 3 ? 1 : 0 /* delete flag */,
+                                0, /* test mode */
+                                0, /* recordType */
+                                &sysno, 
+                                0, /* match */
+                                0, /* fname */
                           0, /* force update */
-                          1  /* allow update */
+                                1  /* allow update */
        );
     if (action == 1)
     {
@@ -1237,7 +1221,7 @@ int zebra_admin_exchange_record (ZebraHandle zh,
         dict_delete (zh->reg->matchDict, recid_z);
     }
     zebra_end_trans(zh);
-    return 0;
+    return res;
 }
 
 int delete_w_handle(const char *info, void *handle)
@@ -1269,17 +1253,17 @@ static int delete_SU_handle(void *handle, int ord)
     return 0;
 }
 
-int zebra_drop_database  (ZebraHandle zh, const char *database)
+ZEBRA_RES zebra_drop_database  (ZebraHandle zh, const char *database)
 {
-    int ret = 0;
+    ZEBRA_RES ret = ZEBRA_OK;
     ASSERTZH;
     yaz_log(log_level, "zebra_drop_database");
     zh->errCode = 0;
 
-    if (zebra_select_database (zh, database))
-        return -1;
-    if (zebra_begin_trans (zh, 1))
-        return -1;
+    if (zebra_select_database (zh, database) == ZEBRA_FAIL)
+        return ZEBRA_FAIL;
+    if (zebra_begin_trans (zh, 1) == ZEBRA_FAIL)
+        return ZEBRA_FAIL;
     if (zh->reg->isamb)
     {
        zebraExplain_curDatabase (zh->reg->zei, database);
@@ -1290,23 +1274,23 @@ int zebra_drop_database  (ZebraHandle zh, const char *database)
     else
     {
        yaz_log(YLOG_WARN, "drop database only supported for isam:b");
-       ret = -1;
+       ret = ZEBRA_FAIL;
     }
     zebra_end_trans (zh);
     return ret;
 }
 
-int zebra_create_database (ZebraHandle zh, const char *database)
+ZEBRA_RES zebra_create_database (ZebraHandle zh, const char *database)
 {
     ASSERTZH;
-    yaz_log(log_level, "zebra_create_database %s",database);
+    yaz_log(log_level, "zebra_create_database %s", database);
     assert(database);
     zh->errCode = 0;
 
-    if (zebra_select_database (zh, database))
-        return -1;
+    if (zebra_select_database (zh, database) == ZEBRA_FAIL)
+        return ZEBRA_FAIL;
     if (zebra_begin_trans (zh, 1))
-        return -1;
+        return ZEBRA_FAIL;
 
     /* announce database */
     if (zebraExplain_newDatabase (zh->reg->zei, database, 0 
@@ -1315,10 +1299,9 @@ int zebra_create_database (ZebraHandle zh, const char *database)
         zebra_end_trans (zh);
        zh->errCode = 224;
        zh->errString = "database already exist";
-       return -1;
+       return ZEBRA_FAIL;
     }
-    zebra_end_trans (zh);
-    return 0;
+    return zebra_end_trans (zh);
 }
 
 int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
@@ -1345,9 +1328,7 @@ int zebra_string_norm (ZebraHandle zh, unsigned reg_id,
     return wrbuf_len(wrbuf);
 }
 
-
-int zebra_set_state (ZebraHandle zh, int val, int seqno)
-    /* FIXME - zint seqno ?? */
+static void zebra_set_state (ZebraHandle zh, int val, int seqno)
 {
     char state_fname[256];
     char *fname;
@@ -1365,10 +1346,9 @@ int zebra_set_state (ZebraHandle zh, int val, int seqno)
     fprintf (f, "%c %d %ld\n", val, seqno, p);
     fclose (f);
     xfree(fname);
-    return 0;
 }
 
-int zebra_get_state (ZebraHandle zh, char *val, int *seqno)
+static void zebra_get_state (ZebraHandle zh, char *val, int *seqno)
 {
     char state_fname[256];
     char *fname;
@@ -1389,15 +1369,14 @@ int zebra_get_state (ZebraHandle zh, char *val, int *seqno)
         fclose (f);
     }
     xfree(fname);
-    return 0;
 }
 
-int zebra_begin_read (ZebraHandle zh)
+ZEBRA_RES zebra_begin_read (ZebraHandle zh)
 {
     return zebra_begin_trans(zh, 0);
 }
 
-int zebra_end_read (ZebraHandle zh)
+ZEBRA_RES zebra_end_read (ZebraHandle zh)
 {
     return zebra_end_trans(zh);
 }
@@ -1431,7 +1410,7 @@ static void read_res_for_transaction(ZebraHandle zh)
     zh->m_file_verbose_limit = atoi(v);
 }
 
-int zebra_begin_trans (ZebraHandle zh, int rw)
+ZEBRA_RES zebra_begin_trans(ZebraHandle zh, int rw)
 {
     ASSERTZH;
     zebra_select_default_database(zh);
@@ -1439,7 +1418,7 @@ int zebra_begin_trans (ZebraHandle zh, int rw)
     {
         zh->errCode = 2;
         zh->errString = "zebra_begin_trans: no database selected";
-        return -1;
+        return ZEBRA_FAIL;
     }
     ASSERTZHRES;
     yaz_log(log_level, "zebra_begin_trans rw=%d",rw);
@@ -1450,7 +1429,7 @@ int zebra_begin_trans (ZebraHandle zh, int rw)
        {
            zh->errCode = 223;
            zh->errString = 0;
-           return -1;
+           return ZEBRA_FAIL;
        }
     }
 
@@ -1472,7 +1451,7 @@ int zebra_begin_trans (ZebraHandle zh, int rw)
         {
             zh->errCode = 2;
             zh->errString = "zebra_begin_trans: write trans not allowed within read trans";
-            return -1;
+            return ZEBRA_FAIL;
         }
         if (zh->reg)
        {
@@ -1538,7 +1517,7 @@ int zebra_begin_trans (ZebraHandle zh, int rw)
         {
             yaz_log (YLOG_FATAL, "zebra_begin_trans couldn't finish commit");
             abort();
-            return -1;
+            return ZEBRA_FAIL;
         }
         zebra_set_state (zh, 'd', seqno);
         
@@ -1560,7 +1539,7 @@ int zebra_begin_trans (ZebraHandle zh, int rw)
             zh->errCode = 2;
             zh->errString = "zebra_begin_trans: cannot open register";
             yaz_log(YLOG_FATAL, zh->errString);
-            return -1;
+            return ZEBRA_FAIL;
         }
     }
     else
@@ -1574,7 +1553,7 @@ int zebra_begin_trans (ZebraHandle zh, int rw)
         if (zh->trans_no != 1)
         {
             zebra_flush_reg (zh);
-            return 0;
+            return ZEBRA_OK;
         }
         zh->errCode = 0;
 #if HAVE_SYS_TIMES_H
@@ -1584,13 +1563,13 @@ int zebra_begin_trans (ZebraHandle zh, int rw)
         {
             (zh->trans_no)--;
             zh->errCode = 109;
-            return -1;
+            return ZEBRA_FAIL;
         }
         if (!zh->lock_normal || !zh->lock_shadow)
         {
             (zh->trans_no)--;
             zh->errCode = 2;
-            return -1;
+            return ZEBRA_FAIL;
         }
         zebra_get_state (zh, &val, &seqno);
         if (val == 'd')
@@ -1611,7 +1590,7 @@ int zebra_begin_trans (ZebraHandle zh, int rw)
             dirty = 1;
         }
         if (!dirty)
-            return 0;
+            return ZEBRA_OK;
         
         if (val == 'c')
             zebra_lock_r (zh->lock_shadow);
@@ -1632,16 +1611,16 @@ int zebra_begin_trans (ZebraHandle zh, int rw)
             zebra_unlock (zh->lock_shadow);
             zh->trans_no--;
             zh->errCode = 109;
-            return -1;
+            return ZEBRA_FAIL;
         }
         zh->reg->last_val = val;
         zh->reg->seqno = seqno;
     }
     read_res_for_transaction(zh);
-    return 0;
+    return ZEBRA_OK;
 }
 
-int zebra_end_trans (ZebraHandle zh)
+ZEBRA_RES zebra_end_trans (ZebraHandle zh)
 {
     ZebraTransactionStatus dummy;
     ASSERTZH;
@@ -1649,7 +1628,7 @@ int zebra_end_trans (ZebraHandle zh)
     return zebra_end_transaction(zh, &dummy);
 }
 
-int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status)
+ZEBRA_RES zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status)
 {
     char val;
     int seqno;
@@ -1670,13 +1649,13 @@ int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status)
     {
         zh->errCode = 2;
         zh->errString = "zebra_end_trans: no open transaction";
-        return -1;
+        return ZEBRA_FAIL;
     }
     if (zh->trans_no != zh->trans_w_no)
     {
         zh->trans_no--;
         if (zh->trans_no != 0)
-            return 0;
+            return ZEBRA_OK;
 
         /* release read lock */
 
@@ -1735,7 +1714,7 @@ int zebra_end_transaction (ZebraHandle zh, ZebraTransactionStatus *status)
     status->utime = (long) (zh->tms2.tms_utime - zh->tms1.tms_utime);
     status->stime = (long) (zh->tms2.tms_stime - zh->tms1.tms_stime);
 #endif
-    return 0;
+    return ZEBRA_OK;
 }
 
 int zebra_repository_update (ZebraHandle zh, const char *path)
@@ -1829,21 +1808,21 @@ static int zebra_commit_ex (ZebraHandle zh, int clean_only)
     return 0;
 }
 
-int zebra_clean (ZebraHandle zh)
+ZEBRA_RES zebra_clean (ZebraHandle zh)
 {
     ASSERTZH;
     yaz_log(log_level, "zebra_clean");
     return zebra_commit_ex(zh, 1);
 }
 
-int zebra_commit (ZebraHandle zh)
+ZEBRA_RES zebra_commit (ZebraHandle zh)
 {
     ASSERTZH;
     yaz_log(log_level, "zebra_commit");
     return zebra_commit_ex(zh, 0);
 }
 
-int zebra_init (ZebraHandle zh)
+ZEBRA_RES zebra_init (ZebraHandle zh)
 {
     const char *rval;
     BFiles bfs = 0;
@@ -1855,20 +1834,20 @@ int zebra_init (ZebraHandle zh)
     if (!zh->res)
     {
         zh->errCode = 109;
-        return -1;
+       return ZEBRA_FAIL;
     }
     rval = res_get (zh->res, "shadow");
 
     bfs = bfs_create (res_get (zh->res, "register"), zh->path_reg);
     if (!bfs)
-       return -1;
+       return ZEBRA_FAIL;
     if (rval && *rval)
         bf_cache (bfs, rval);
     
     bf_reset (bfs);
     bfs_destroy (bfs);
     zebra_set_state (zh, 'o', 0);
-    return 0;
+    return ZEBRA_OK;
 }
 
 int zebra_compact (ZebraHandle zh)
@@ -1897,16 +1876,15 @@ int zebra_result (ZebraHandle zh, int *code, char **addinfo)
     return 0;
 }
 
-int zebra_shadow_enable (ZebraHandle zh, int value)
+void zebra_shadow_enable (ZebraHandle zh, int value)
 {
     ASSERTZH;
     yaz_log(log_level, "zebra_shadow_enable");
     zh->errCode = 0;
     zh->shadow_enable = value;
-    return 0;
 }
 
-int zebra_octet_term_encoding(ZebraHandle zh, const char *encoding)
+ZEBRA_RES zebra_octet_term_encoding(ZebraHandle zh, const char *encoding)
 {
     ASSERTZH;
     assert(encoding);
@@ -1927,10 +1905,10 @@ int zebra_octet_term_encoding(ZebraHandle zh, const char *encoding)
     if (zh->iconv_to_utf8 == 0)
         yaz_log (YLOG_WARN, "iconv: UTF-8 to %s unsupported", encoding);
 
-    return 0;
+    return ZEBRA_OK;
 }
 
-int zebra_record_encoding (ZebraHandle zh, const char *encoding)
+ZEBRA_RES zebra_record_encoding (ZebraHandle zh, const char *encoding)
 {
     ASSERTZH;
     yaz_log(log_level, "zebra_record_encoding");
@@ -1939,10 +1917,10 @@ int zebra_record_encoding (ZebraHandle zh, const char *encoding)
     zh->record_encoding = 0;
     if (encoding)
        zh->record_encoding = xstrdup (encoding);
-    return 0;
+    return ZEBRA_OK;
 }
 
-int zebra_set_resource(ZebraHandle zh, const char *name, const char *value)
+void zebra_set_resource(ZebraHandle zh, const char *name, const char *value)
 {
     ASSERTZH;
     assert(name);
@@ -1950,7 +1928,6 @@ int zebra_set_resource(ZebraHandle zh, const char *name, const char *value)
     yaz_log(log_level, "zebra_set_resource %s:%s",name,value);
     zh->errCode = 0;
     res_set(zh->res, name, value);
-    return 0;
 }
 
 const char *zebra_get_resource(ZebraHandle zh,
@@ -1983,12 +1960,11 @@ int zebra_get_shadow_enable (ZebraHandle zh)
     return (zh->shadow_enable);
 }
 
-int zebra_set_shadow_enable (ZebraHandle zh, int value)
+void zebra_set_shadow_enable (ZebraHandle zh, int value)
 {
     ASSERTZH;
     yaz_log(log_level, "zebra_set_shadow_enable %d",value);
     zh->shadow_enable = value;
-    return 0;
 }
 
 /* Used by Perl API.. Added the record buffer dup to zebra_records_retrieve
@@ -2019,12 +1995,13 @@ int zebra_add_record(ZebraHandle zh,
     return zebra_update_record(zh, 0, &sysno, 0, 0, buf, buf_size, 0);
 }
 
-int zebra_insert_record (ZebraHandle zh, 
-                        const char *recordType,
-                        SYSNO *sysno, const char *match, const char *fname,
-                        const char *buf, int buf_size, int force_update)
+ZEBRA_RES zebra_insert_record (ZebraHandle zh, 
+                              const char *recordType,
+                              SYSNO *sysno, const char *match,
+                              const char *fname,
+                              const char *buf, int buf_size, int force_update)
 {
-    int res;
+    ZEBRA_RES res;
     ASSERTZH;
     assert(sysno);
     assert(buf);
@@ -2033,8 +2010,8 @@ int zebra_insert_record (ZebraHandle zh,
     if (buf_size < 1)
        buf_size = strlen(buf);
 
-    if (zebra_begin_trans(zh, 1))
-       return 1;
+    if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL)
+       return ZEBRA_FAIL;
     res = buffer_extract_record (zh, buf, buf_size, 
                                 0, /* delete_flag  */
                                 0, /* test_mode */
@@ -2047,13 +2024,14 @@ int zebra_insert_record (ZebraHandle zh,
     return res; 
 }
 
-int zebra_update_record (ZebraHandle zh, 
-                        const char *recordType,
-                        SYSNO* sysno, const char *match, const char *fname,
-                        const char *buf, int buf_size,
-                        int force_update)
+ZEBRA_RES zebra_update_record (ZebraHandle zh, 
+                              const char *recordType,
+                              SYSNO* sysno, const char *match,
+                              const char *fname,
+                              const char *buf, int buf_size,
+                              int force_update)
 {
-    int res;
+    ZEBRA_RES res;
     ASSERTZH;
     assert(sysno);
     assert(buf);
@@ -2062,8 +2040,8 @@ int zebra_update_record (ZebraHandle zh,
 
     if (buf_size < 1) buf_size = strlen(buf);
 
-    if (zebra_begin_trans(zh, 1))
-       return 1;
+    if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL)
+       return ZEBRA_FAIL;
     res = buffer_extract_record (zh, buf, buf_size, 
                                 0, /* delete_flag */
                                 0, /* test_mode */
@@ -2076,13 +2054,14 @@ int zebra_update_record (ZebraHandle zh,
     return res; 
 }
 
-int zebra_delete_record (ZebraHandle zh, 
-                        const char *recordType,
-                        SYSNO *sysno, const char *match, const char *fname,
-                        const char *buf, int buf_size,
-                        int force_update) 
+ZEBRA_RES zebra_delete_record (ZebraHandle zh, 
+                              const char *recordType,
+                              SYSNO *sysno, const char *match,
+                              const char *fname,
+                              const char *buf, int buf_size,
+                              int force_update) 
 {
-    int res;
+    ZEBRA_RES res;
     ASSERTZH;
     assert(sysno);
     assert(buf);
@@ -2090,8 +2069,8 @@ int zebra_delete_record (ZebraHandle zh,
 
     if (buf_size < 1) buf_size = strlen(buf);
 
-    if (zebra_begin_trans(zh, 1))
-       return 1;
+    if (zebra_begin_trans(zh, 1) == ZEBRA_FAIL)
+       return ZEBRA_FAIL;
     res = buffer_extract_record (zh, buf, buf_size,
                                 1, /* delete_flag */
                                 0, /* test_mode */
@@ -2101,18 +2080,18 @@ int zebra_delete_record (ZebraHandle zh,
                                 force_update,
                                 1); /* allow_update */
     zebra_end_trans(zh);
-    return res;   
+    return res;
 }
 
 /* ---------------------------------------------------------------------------
   Searching 
 */
 
-int zebra_search_PQF (ZebraHandle zh, const char *pqf_query,
-                     const char *setname, zint *numhits)
+ZEBRA_RES zebra_search_PQF (ZebraHandle zh, const char *pqf_query,
+                           const char *setname, zint *numhits)
 {
     zint hits = 0;
-    int res = -1;
+    ZEBRA_RES res = ZEBRA_OK;
     Z_RPNQuery *query;
     ODR odr = odr_createmem(ODR_ENCODE);
     ASSERTZH;
@@ -2124,7 +2103,10 @@ int zebra_search_PQF (ZebraHandle zh, const char *pqf_query,
     query = p_query_rpn (odr, PROTO_Z3950, pqf_query);
     
     if (!query)
+    {
         yaz_log (YLOG_WARN, "bad query %s\n", pqf_query);
+       res = ZEBRA_FAIL;
+    }
     else
         res = zebra_search_RPN (zh, odr, query, setname, &hits);
     
index 472e7bd..0f1ef43 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zrpn.c,v 1.174 2005-04-14 09:03:24 adam Exp $
+/* $Id: zrpn.c,v 1.175 2005-04-15 10:47:48 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -788,9 +788,10 @@ void string_rel_add_char(char **term_p, const char *src, int *indx)
  *              ([^a-].*|a[^b-].*|ab[^c-].*|abc)
  */
 static int string_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
-                            const char **term_sub, char *term_dict,
-                            oid_value attributeSet,
-                            int reg_type, int space_split, char *term_dst)
+                          const char **term_sub, char *term_dict,
+                          oid_value attributeSet,
+                          int reg_type, int space_split, char *term_dst,
+                          int *error_code)
 {
     AttrType relation;
     int relation_value;
@@ -801,6 +802,7 @@ static int string_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
     attr_init(&relation, zapt, 2);
     relation_value = attr_find(&relation, NULL);
 
+    *error_code = 0;
     yaz_log(YLOG_DEBUG, "string relation value=%d", relation_value);
     switch (relation_value)
     {
@@ -945,7 +947,8 @@ static int string_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
         *term_tmp = '\0';
         break;
     case 3:
-    default:
+    case 102:
+    case -1:
         yaz_log(log_level_rpn, "Relation =");
         if (!term_100 (zh->reg->zebra_maps, reg_type, term_sub,
                        term_component, space_split, term_dst))
@@ -953,41 +956,47 @@ static int string_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
         strcat(term_tmp, "(");
         strcat(term_tmp, term_component);
         strcat(term_tmp, ")");
+       break;
+    default:
+       *error_code = 117;
+       return 0;
     }
     return 1;
 }
 
-static int string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
-                        const char **term_sub, 
-                        oid_value attributeSet, NMEM stream,
-                        struct grep_info *grep_info,
-                        int reg_type, int complete_flag,
-                        int num_bases, char **basenames,
-                        char *term_dst, int xpath_use);
+static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
+                            const char **term_sub, 
+                            oid_value attributeSet, NMEM stream,
+                            struct grep_info *grep_info,
+                            int reg_type, int complete_flag,
+                            int num_bases, char **basenames,
+                            char *term_dst, int xpath_use);
 
 static RSET term_trunc(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
-                        const char **term_sub, 
-                        oid_value attributeSet, NMEM stream,
-                        struct grep_info *grep_info,
-                        int reg_type, int complete_flag,
-                        int num_bases, char **basenames,
-                        char *term_dst,
-                        const char *rank_type, int xpath_use,
-                        NMEM rset_nmem)
+                      const char **term_sub, 
+                      oid_value attributeSet, NMEM stream,
+                      struct grep_info *grep_info,
+                      int reg_type, int complete_flag,
+                      int num_bases, char **basenames,
+                      char *term_dst,
+                      const char *rank_type, int xpath_use,
+                      NMEM rset_nmem)
 {
-    int r;
+    ZEBRA_RES res;
     grep_info->isam_p_indx = 0;
-    r = string_term(zh, zapt, term_sub, attributeSet, stream, grep_info,
-                     reg_type, complete_flag, num_bases, basenames,
-                     term_dst, xpath_use);
-    if (r < 1)
+    res = string_term(zh, zapt, term_sub, attributeSet, stream, grep_info,
+                     reg_type, complete_flag, num_bases, basenames,
+                     term_dst, xpath_use);
+    if (res != ZEBRA_OK)
         return 0;
+    if (!*term_sub)  /* no more terms ? */
+       return 0;
     yaz_log(log_level_rpn, "term: %s", term_dst);
     return rset_trunc(zh, grep_info->isam_p_buf,
-                       grep_info->isam_p_indx, term_dst,
-                       strlen(term_dst), rank_type, 1 /* preserve pos */,
-                       zapt->term->which, rset_nmem,
-                       key_it_ctrl,key_it_ctrl->scope);
+                     grep_info->isam_p_indx, term_dst,
+                     strlen(term_dst), rank_type, 1 /* preserve pos */,
+                     zapt->term->which, rset_nmem,
+                     key_it_ctrl, key_it_ctrl->scope);
 }
 static char *nmem_strdup_i(NMEM nmem, int v)
 {
@@ -996,13 +1005,13 @@ static char *nmem_strdup_i(NMEM nmem, int v)
     return nmem_strdup(nmem, val_str);
 }
 
-static int string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
-                      const char **term_sub, 
-                      oid_value attributeSet, NMEM stream,
-                      struct grep_info *grep_info,
-                      int reg_type, int complete_flag,
-                      int num_bases, char **basenames,
-                      char *term_dst, int xpath_use)
+static ZEBRA_RES string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
+                            const char **term_sub, 
+                            oid_value attributeSet, NMEM stream,
+                            struct grep_info *grep_info,
+                            int reg_type, int complete_flag,
+                            int num_bases, char **basenames,
+                            char *term_dst, int xpath_use)
 {
     char term_dict[2*IT_MAX_WORD+4000];
     int j, r, base_no;
@@ -1040,6 +1049,7 @@ static int string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
         data1_local_attribute id_xpath_attr;
         data1_local_attribute *local_attr;
         int max_pos, prefix_len = 0;
+       int relation_error;
 
         termp = *term_sub;
 
@@ -1047,7 +1057,7 @@ static int string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
         {
             zh->errCode = 109; /* Database unavailable */
             zh->errString = basenames[base_no];
-            return -1;
+            return ZEBRA_FAIL;
         }
         if (xpath_use > 0 && use_value == -2) 
         {
@@ -1144,21 +1154,9 @@ static int string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
                term_dict[prefix_len++] = ord_buf[i];
            }
        }
-        if (!prefix_len)
-        {
-#if 1
-            bases_ok++;
-#else
-            errCode = 114;
-            errString = nmem_strdup_i(stream, use_value);
-            continue;
-#endif
-        }
-       else
-       {
-           bases_ok++; /* this has OK attributes */
+       bases_ok++;
+        if (prefix_len)
            attr_ok = 1;
-       }
 
         term_dict[prefix_len++] = ')';
         term_dict[prefix_len++] = 1;
@@ -1172,42 +1170,66 @@ static int string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
         case 100:        /* do not truncate */
             if (!string_relation (zh, zapt, &termp, term_dict,
                                   attributeSet,
-                                  reg_type, space_split, term_dst))
-                return 0;
+                                  reg_type, space_split, term_dst,
+                                 &relation_error))
+           {
+               if (relation_error)
+               {
+                   zh->errCode = relation_error;
+                   return ZEBRA_FAIL;
+               }
+               *term_sub = 0;
+               return ZEBRA_OK;
+           }
            break;
         case 1:          /* right truncation */
             term_dict[j++] = '(';
             if (!term_100(zh->reg->zebra_maps, reg_type,
                          &termp, term_dict + j, space_split, term_dst))
-                return 0;
+           {
+               *term_sub = 0;
+               return ZEBRA_OK;
+           }
             strcat(term_dict, ".*)");
             break;
         case 2:          /* keft truncation */
             term_dict[j++] = '('; term_dict[j++] = '.'; term_dict[j++] = '*';
             if (!term_100(zh->reg->zebra_maps, reg_type,
                          &termp, term_dict + j, space_split, term_dst))
-                return 0;
+           {
+               *term_sub = 0;
+               return ZEBRA_OK;
+           }
             strcat(term_dict, ")");
             break;
         case 3:          /* left&right truncation */
             term_dict[j++] = '('; term_dict[j++] = '.'; term_dict[j++] = '*';
             if (!term_100(zh->reg->zebra_maps, reg_type,
                          &termp, term_dict + j, space_split, term_dst))
-                return 0;
+           {
+               *term_sub = 0;
+               return ZEBRA_OK;
+           }
             strcat(term_dict, ".*)");
             break;
         case 101:        /* process # in term */
             term_dict[j++] = '(';
             if (!term_101(zh->reg->zebra_maps, reg_type,
                          &termp, term_dict + j, space_split, term_dst))
-                return 0;
+           {
+               *term_sub = 0;
+                return ZEBRA_OK;
+           }
             strcat(term_dict, ")");
             break;
         case 102:        /* Regexp-1 */
             term_dict[j++] = '(';
             if (!term_102(zh->reg->zebra_maps, reg_type,
                          &termp, term_dict + j, space_split, term_dst))
-                return 0;
+           {
+               *term_sub = 0;
+                return ZEBRA_OK;
+           }
             strcat(term_dict, ")");
             break;
         case 103:       /* Regexp-2 */
@@ -1217,33 +1239,45 @@ static int string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
             if (!term_103 (zh->reg->zebra_maps, reg_type,
                            &termp, term_dict + j, &regex_range,
                           space_split, term_dst))
-                return 0;
+           {
+               *term_sub = 0;
+                return ZEBRA_OK;
+           }
             strcat(term_dict, ")");
         case 104:        /* process # and ! in term */
             term_dict[j++] = '(';
             if (!term_104 (zh->reg->zebra_maps, reg_type,
                            &termp, term_dict + j, space_split, term_dst))
-                return 0;
+           {
+               *term_sub = 0;
+                return ZEBRA_OK;
+           }
             strcat(term_dict, ")");
             break;
         case 105:        /* process * and ! in term */
             term_dict[j++] = '(';
             if (!term_105 (zh->reg->zebra_maps, reg_type,
                            &termp, term_dict + j, space_split, term_dst, 1))
-                return 0;
+           {
+               *term_sub = 0;
+                return ZEBRA_OK;
+           }
             strcat(term_dict, ")");
             break;
         case 106:        /* process * and ! in term */
             term_dict[j++] = '(';
             if (!term_105 (zh->reg->zebra_maps, reg_type,
                            &termp, term_dict + j, space_split, term_dst, 0))
-                return 0;
+           {
+               *term_sub = 0;
+                return ZEBRA_OK;
+           }
             strcat(term_dict, ")");
             break;
        default:
            zh->errCode = 120;
            zh->errString = nmem_strdup_i(stream, truncation_value);
-           return -1;
+           return ZEBRA_FAIL;
         }
        if (attr_ok)
        {
@@ -1265,11 +1299,11 @@ static int string_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
     {
         zh->errCode = errCode;
         zh->errString = errString;
-        return -1;
+        return ZEBRA_FAIL;
     }
     *term_sub = termp;
     yaz_log(YLOG_DEBUG, "%d positions", grep_info->isam_p_indx);
-    return 1;
+    return ZEBRA_OK;
 }
 
 
@@ -1463,15 +1497,15 @@ static int grep_info_prepare (ZebraHandle zh,
 }
                                
 
-static RSET rpn_search_APT_phrase (ZebraHandle zh,
-                                   Z_AttributesPlusTerm *zapt,
-                                   const char *termz_org,
-                                   oid_value attributeSet,
-                                   NMEM stream,
-                                   int reg_type, int complete_flag,
-                                   const char *rank_type, int xpath_use,
-                                   int num_bases, char **basenames, 
-                                   NMEM rset_nmem)
+static RSET rpn_search_APT_phrase(ZebraHandle zh,
+                                 Z_AttributesPlusTerm *zapt,
+                                 const char *termz_org,
+                                 oid_value attributeSet,
+                                 NMEM stream,
+                                 int reg_type, int complete_flag,
+                                 const char *rank_type, int xpath_use,
+                                 int num_bases, char **basenames, 
+                                 NMEM rset_nmem)
 {
     char term_dst[IT_MAX_WORD+1];
     RSET rset[TERM_LIST_LENGTH_MAX], result;
@@ -1487,15 +1521,22 @@ static RSET rpn_search_APT_phrase (ZebraHandle zh,
     { 
         yaz_log(log_level_rpn, "APT_phrase termp=%s", termp);
         rset[rset_no] = term_trunc(zh, zapt, &termp, attributeSet,
-                                    stream, &grep_info,
-                                    reg_type, complete_flag,
-                                    num_bases, basenames,
-                                    term_dst, rank_type,
-                                    xpath_use,rset_nmem);
-        if (!rset[rset_no])
-            break;
+                                  stream, &grep_info,
+                                  reg_type, complete_flag,
+                                  num_bases, basenames,
+                                  term_dst, rank_type,
+                                  xpath_use, rset_nmem);
+        if (!rset[rset_no])  /* error or no more terms */
+           break;
     }
     grep_info_delete (&grep_info);
+    if (termp)
+    {
+       int i;
+       for (i = 0; i<rset_no; i++)
+           rset_delete(rset[i]);
+       return 0;
+    }
     if (rset_no == 0)
         return rsnull_create (rset_nmem,key_it_ctrl); 
     else if (rset_no == 1)
@@ -1508,16 +1549,16 @@ static RSET rpn_search_APT_phrase (ZebraHandle zh,
     return result;
 }
 
-static RSET rpn_search_APT_or_list (ZebraHandle zh,
-                                    Z_AttributesPlusTerm *zapt,
-                                    const char *termz_org,
-                                    oid_value attributeSet,
-                                    NMEM stream,
-                                    int reg_type, int complete_flag,
-                                    const char *rank_type,
-                                    int xpath_use,
-                                    int num_bases, char **basenames,
-                                    NMEM rset_nmem)
+static RSET rpn_search_APT_or_list(ZebraHandle zh,
+                                  Z_AttributesPlusTerm *zapt,
+                                  const char *termz_org,
+                                  oid_value attributeSet,
+                                  NMEM stream,
+                                  int reg_type, int complete_flag,
+                                  const char *rank_type,
+                                  int xpath_use,
+                                  int num_bases, char **basenames,
+                                  NMEM rset_nmem)
 {
     char term_dst[IT_MAX_WORD+1];
     RSET rset[TERM_LIST_LENGTH_MAX];
@@ -1526,37 +1567,44 @@ static RSET rpn_search_APT_or_list (ZebraHandle zh,
     char *termz = normalize_term(zh, zapt, termz_org, stream, reg_type);
     const char *termp = termz;
 
-    if (grep_info_prepare (zh, zapt, &grep_info, reg_type, stream))
+    if (grep_info_prepare(zh, zapt, &grep_info, reg_type, stream))
         return 0;
     for (; rset_no < sizeof(rset)/sizeof(*rset); rset_no++)
     { 
         yaz_log(log_level_rpn, "APT_or_list termp=%s", termp);
         rset[rset_no] = term_trunc(zh, zapt, &termp, attributeSet,
-                                    stream, &grep_info,
-                                    reg_type, complete_flag,
-                                    num_bases, basenames,
-                                    term_dst, rank_type,
-                                    xpath_use,rset_nmem);
-        if (!rset[rset_no])
-            break;
+                                  stream, &grep_info,
+                                  reg_type, complete_flag,
+                                  num_bases, basenames,
+                                  term_dst, rank_type,
+                                  xpath_use, rset_nmem);
+        if (!rset[rset_no])  /* error or no more terms */
+           break;
     }
     grep_info_delete (&grep_info);
+    if (termp)
+    {
+       int i;
+       for (i = 0; i<rset_no; i++)
+           rset_delete(rset[i]);
+       return 0;
+    }
     if (rset_no == 0)
         return rsnull_create (rset_nmem,key_it_ctrl);  
-    return rsmulti_or_create(rset_nmem, key_it_ctrl,key_it_ctrl->scope,
+    return rsmulti_or_create(rset_nmem, key_it_ctrl, key_it_ctrl->scope,
                             rset_no, rset);
 }
 
-static RSET rpn_search_APT_and_list (ZebraHandle zh,
-                                     Z_AttributesPlusTerm *zapt,
-                                     const char *termz_org,
-                                     oid_value attributeSet,
-                                     NMEM stream,
-                                     int reg_type, int complete_flag,
-                                     const char *rank_type, 
-                                     int xpath_use,
-                                     int num_bases, char **basenames,
-                                     NMEM rset_nmem)
+static RSET rpn_search_APT_and_list(ZebraHandle zh,
+                                   Z_AttributesPlusTerm *zapt,
+                                   const char *termz_org,
+                                   oid_value attributeSet,
+                                   NMEM stream,
+                                   int reg_type, int complete_flag,
+                                   const char *rank_type, 
+                                   int xpath_use,
+                                   int num_bases, char **basenames,
+                                   NMEM rset_nmem)
 {
     char term_dst[IT_MAX_WORD+1];
     RSET rset[TERM_LIST_LENGTH_MAX];
@@ -1565,36 +1613,44 @@ static RSET rpn_search_APT_and_list (ZebraHandle zh,
     char *termz = normalize_term(zh, zapt, termz_org, stream, reg_type);
     const char *termp = termz;
 
-    if (grep_info_prepare (zh, zapt, &grep_info, reg_type, stream))
+    if (grep_info_prepare(zh, zapt, &grep_info, reg_type, stream))
         return 0;
     for (; rset_no < sizeof(rset)/sizeof(*rset); rset_no++)
     { 
         yaz_log(log_level_rpn, "APT_and_list termp=%s", termp);
         rset[rset_no] = term_trunc(zh, zapt, &termp, attributeSet,
-                                    stream, &grep_info,
-                                    reg_type, complete_flag,
-                                    num_bases, basenames,
-                                    term_dst, rank_type,
-                                    xpath_use, rset_nmem);
-        if (!rset[rset_no])
-            break;
+                                  stream, &grep_info,
+                                  reg_type, complete_flag,
+                                  num_bases, basenames,
+                                  term_dst, rank_type,
+                                  xpath_use, rset_nmem);
+        if (!rset[rset_no])  /* error or no more terms */
+           break;
     }
     grep_info_delete (&grep_info);
+    if (termp)
+    {
+       int i;
+       for (i = 0; i<rset_no; i++)
+           rset_delete(rset[i]);
+       return 0;
+    }
     if (rset_no == 0)
-        return rsnull_create(rset_nmem,key_it_ctrl); 
+        return rsnull_create(rset_nmem, key_it_ctrl); 
     
     return rsmulti_and_create(rset_nmem, key_it_ctrl, key_it_ctrl->scope,
                              rset_no, rset);
 }
 
-static int numeric_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
-                             const char **term_sub,
-                             char *term_dict,
-                             oid_value attributeSet,
-                             struct grep_info *grep_info,
-                             int *max_pos,
-                             int reg_type,
-                             char *term_dst)
+static int numeric_relation(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
+                           const char **term_sub,
+                           char *term_dict,
+                           oid_value attributeSet,
+                           struct grep_info *grep_info,
+                           int *max_pos,
+                           int reg_type,
+                           char *term_dst,
+                           int *error_code)
 {
     AttrType relation;
     int relation_value;
@@ -1602,37 +1658,42 @@ static int numeric_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
     int r;
     char *term_tmp = term_dict + strlen(term_dict);
 
+    *error_code = 0;
     attr_init (&relation, zapt, 2);
     relation_value = attr_find (&relation, NULL);
 
     yaz_log(log_level_rpn, "numeric relation value=%d", relation_value);
 
-    if (!term_100 (zh->reg->zebra_maps, reg_type, term_sub, term_tmp, 1,
-                   term_dst))
+    if (!term_100(zh->reg->zebra_maps, reg_type, term_sub, term_tmp, 1,
+                 term_dst))
         return 0;
     term_value = atoi (term_tmp);
     switch (relation_value)
     {
     case 1:
         yaz_log(log_level_rpn, "Relation <");
-        gen_regular_rel (term_tmp, term_value-1, 1);
+        gen_regular_rel(term_tmp, term_value-1, 1);
         break;
     case 2:
         yaz_log(log_level_rpn, "Relation <=");
-        gen_regular_rel (term_tmp, term_value, 1);
+        gen_regular_rel(term_tmp, term_value, 1);
         break;
     case 4:
         yaz_log(log_level_rpn, "Relation >=");
-        gen_regular_rel (term_tmp, term_value, 0);
+        gen_regular_rel(term_tmp, term_value, 0);
         break;
     case 5:
         yaz_log(log_level_rpn, "Relation >");
-        gen_regular_rel (term_tmp, term_value+1, 0);
+        gen_regular_rel(term_tmp, term_value+1, 0);
         break;
+    case -1:
     case 3:
-    default:
         yaz_log(log_level_rpn, "Relation =");
-        sprintf (term_tmp, "(0*%d)", term_value);
+        sprintf(term_tmp, "(0*%d)", term_value);
+       break;
+    default:
+       *error_code = 117;
+       return 0;
     }
     yaz_log(log_level_rpn, "dict_lookup_grep: %s", term_tmp);
     r = dict_lookup_grep(zh->reg->dict, term_dict, 0, grep_info, max_pos,
@@ -1643,12 +1704,13 @@ static int numeric_relation (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
     return 1;
 }
 
-static int numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
-                         const char **term_sub, 
-                         oid_value attributeSet, struct grep_info *grep_info,
-                         int reg_type, int complete_flag,
-                         int num_bases, char **basenames,
-                         char *term_dst, int xpath_use, NMEM stream)
+static ZEBRA_RES numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
+                             const char **term_sub, 
+                             oid_value attributeSet,
+                             struct grep_info *grep_info,
+                             int reg_type, int complete_flag,
+                             int num_bases, char **basenames,
+                             char *term_dst, int xpath_use, NMEM stream)
 {
     char term_dict[2*IT_MAX_WORD+2];
     int r, base_no;
@@ -1676,6 +1738,7 @@ static int numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
         data1_local_attribute id_xpath_attr;
         data1_local_attribute *local_attr;
         int max_pos, prefix_len = 0;
+       int relation_error = 0;
 
         termp = *term_sub;
         if (use_value == -2)  /* string attribute (assume IDXPATH/any) */
@@ -1755,36 +1818,45 @@ static int numeric_term(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
         term_dict[prefix_len++] = reg_type;
         yaz_log(YLOG_DEBUG, "reg_type = %d", term_dict[prefix_len-1]);
         term_dict[prefix_len] = '\0';
-        if (!numeric_relation (zh, zapt, &termp, term_dict,
-                               attributeSet, grep_info, &max_pos, reg_type,
-                               term_dst))
-            return 0;
+        if (!numeric_relation(zh, zapt, &termp, term_dict,
+                             attributeSet, grep_info, &max_pos, reg_type,
+                             term_dst, &relation_error))
+       {
+           if (relation_error)
+           {
+               zh->errCode = relation_error;
+               zh->errString = 0;
+               return ZEBRA_FAIL;
+           }
+           *term_sub = 0;
+            return ZEBRA_OK;
+       }
     }
     if (!bases_ok)
     {
         zh->errCode = errCode;
         zh->errString = errString;
-        return -1;
+        return ZEBRA_FAIL;
     }
     *term_sub = termp;
     yaz_log(YLOG_DEBUG, "%d positions", grep_info->isam_p_indx);
-    return 1;
+    return ZEBRA_OK;
 }
 
-static RSET rpn_search_APT_numeric (ZebraHandle zh,
-                                    Z_AttributesPlusTerm *zapt,
-                                    const char *termz,
-                                    oid_value attributeSet,
-                                    NMEM stream,
-                                    int reg_type, int complete_flag,
-                                    const char *rank_type, int xpath_use,
-                                    int num_bases, char **basenames,
-                                    NMEM rset_nmem)
+static RSET rpn_search_APT_numeric(ZebraHandle zh,
+                                  Z_AttributesPlusTerm *zapt,
+                                  const char *termz,
+                                  oid_value attributeSet,
+                                  NMEM stream,
+                                  int reg_type, int complete_flag,
+                                  const char *rank_type, int xpath_use,
+                                  int num_bases, char **basenames,
+                                  NMEM rset_nmem)
 {
     char term_dst[IT_MAX_WORD+1];
     const char *termp = termz;
     RSET rset[TERM_LIST_LENGTH_MAX];
-    int  r;
+    ZEBRA_RES  r;
     size_t rset_no = 0;
     struct grep_info grep_info;
 
@@ -1796,11 +1868,11 @@ static RSET rpn_search_APT_numeric (ZebraHandle zh,
         yaz_log(YLOG_DEBUG, "APT_numeric termp=%s", termp);
         grep_info.isam_p_indx = 0;
         r = numeric_term(zh, zapt, &termp, attributeSet, &grep_info,
-                          reg_type, complete_flag, num_bases, basenames,
-                          term_dst, xpath_use,
-                          stream);
-        if (r < 1)
-            break;
+                        reg_type, complete_flag, num_bases, basenames,
+                        term_dst, xpath_use,
+                        stream);
+       if (r == ZEBRA_FAIL || termp == 0)
+           break;
         yaz_log(YLOG_DEBUG, "term: %s", term_dst);
         rset[rset_no] = rset_trunc(zh, grep_info.isam_p_buf,
                                     grep_info.isam_p_indx, term_dst,
@@ -1812,6 +1884,13 @@ static RSET rpn_search_APT_numeric (ZebraHandle zh,
            break;
     }
     grep_info_delete (&grep_info);
+    if (termp)
+    {
+       int i;
+       for (i = 0; i<rset_no; i++)
+           rset_delete(rset[i]);
+       return 0;
+    }
     if (rset_no == 0)
         return rsnull_create(rset_nmem,key_it_ctrl);
     if (rset_no == 1)
@@ -2154,11 +2233,11 @@ static RSET rpn_search_xpath (ZebraHandle zh,
 
 
 
-static RSET rpn_search_APT (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
-                            oid_value attributeSet, NMEM stream,
-                            Z_SortKeySpecList *sort_sequence,
-                            int num_bases, char **basenames, 
-                            NMEM rset_nmem)
+static RSET rpn_search_APT(ZebraHandle zh, Z_AttributesPlusTerm *zapt,
+                          oid_value attributeSet, NMEM stream,
+                          Z_SortKeySpecList *sort_sequence,
+                          int num_bases, char **basenames, 
+                          NMEM rset_nmem)
 {
     unsigned reg_id;
     char *search_type = NULL;
@@ -2176,8 +2255,8 @@ static RSET rpn_search_APT (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
         log_level_rpn = yaz_log_module_level("rpn");
         log_level_set = 1;
     }
-    zebra_maps_attr (zh->reg->zebra_maps, zapt, &reg_id, &search_type,
-                     rank_type, &complete_flag, &sort_flag);
+    zebra_maps_attr(zh->reg->zebra_maps, zapt, &reg_id, &search_type,
+                   rank_type, &complete_flag, &sort_flag);
     
     yaz_log(YLOG_DEBUG, "reg_id=%c", reg_id);
     yaz_log(YLOG_DEBUG, "complete_flag=%d", complete_flag);
@@ -2188,8 +2267,8 @@ static RSET rpn_search_APT (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
         return 0;
 
     if (sort_flag)
-        return rpn_sort_spec (zh, zapt, attributeSet, stream, sort_sequence,
-                              rank_type);
+        return rpn_sort_spec(zh, zapt, attributeSet, stream, sort_sequence,
+                            rank_type);
     xpath_len = parse_xpath(zh, zapt, attributeSet, xpath, 10, stream);
     if (xpath_len >= 0)
     {
@@ -2200,53 +2279,56 @@ static RSET rpn_search_APT (ZebraHandle zh, Z_AttributesPlusTerm *zapt,
 
     if (!strcmp (search_type, "phrase"))
     {
-        rset = rpn_search_APT_phrase (zh, zapt, termz, attributeSet, stream,
-                                      reg_id, complete_flag, rank_type,
-                                      xpath_use,
-                                      num_bases, basenames, rset_nmem);
+        rset = rpn_search_APT_phrase(zh, zapt, termz, attributeSet, stream,
+                                    reg_id, complete_flag, rank_type,
+                                    xpath_use,
+                                    num_bases, basenames, rset_nmem);
     }
     else if (!strcmp (search_type, "and-list"))
     {
-        rset = rpn_search_APT_and_list (zh, zapt, termz, attributeSet, stream,
-                                        reg_id, complete_flag, rank_type,
-                                        xpath_use,
-                                        num_bases, basenames, rset_nmem);
+        rset = rpn_search_APT_and_list(zh, zapt, termz, attributeSet, stream,
+                                      reg_id, complete_flag, rank_type,
+                                      xpath_use,
+                                      num_bases, basenames, rset_nmem);
     }
     else if (!strcmp (search_type, "or-list"))
     {
-        rset = rpn_search_APT_or_list (zh, zapt, termz, attributeSet, stream,
-                                       reg_id, complete_flag, rank_type,
-                                       xpath_use,
-                                       num_bases, basenames, rset_nmem);
+        rset = rpn_search_APT_or_list(zh, zapt, termz, attributeSet, stream,
+                                     reg_id, complete_flag, rank_type,
+                                     xpath_use,
+                                     num_bases, basenames, rset_nmem);
     }
     else if (!strcmp (search_type, "local"))
     {
-        rset = rpn_search_APT_local (zh, zapt, termz, attributeSet, stream,
-                                     rank_type, rset_nmem);
+        rset = rpn_search_APT_local(zh, zapt, termz, attributeSet, stream,
+                                   rank_type, rset_nmem);
     }
     else if (!strcmp (search_type, "numeric"))
     {
-        rset = rpn_search_APT_numeric (zh, zapt, termz, attributeSet, stream,
-                                       reg_id, complete_flag, rank_type,
-                                       xpath_use,
-                                       num_bases, basenames, rset_nmem);
+        rset = rpn_search_APT_numeric(zh, zapt, termz, attributeSet, stream,
+                                     reg_id, complete_flag, rank_type,
+                                     xpath_use,
+                                     num_bases, basenames, rset_nmem);
     }
     else if (!strcmp (search_type, "always"))
     {
         rset = 0;
     }
     else
+    {
         zh->errCode = 118;
+       return 0;
+    }
     return rpn_search_xpath (zh, attributeSet, num_bases, basenames,
                              stream, rank_type, rset, 
                              xpath_len, xpath, rset_nmem);
 }
 
-static RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs,
-                                  oid_value attributeSet, 
-                                  NMEM stream, NMEM rset_nmem,
-                                  Z_SortKeySpecList *sort_sequence,
-                                  int num_bases, char **basenames)
+RSET rpn_search_structure(ZebraHandle zh, Z_RPNStructure *zs,
+                         oid_value attributeSet, 
+                         NMEM stream, NMEM rset_nmem,
+                         Z_SortKeySpecList *sort_sequence,
+                         int num_bases, char **basenames)
 {
     RSET r = NULL;
     if (zs->which == Z_RPNStructure_complex)
@@ -2254,19 +2336,19 @@ static RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs,
         Z_Operator *zop = zs->u.complex->roperator;
         RSET rsets[2]; /* l and r argument */
 
-        rsets[0]=rpn_search_structure (zh, zs->u.complex->s1,
-                                       attributeSet, stream, rset_nmem,
-                                       sort_sequence,
-                                       num_bases, basenames);
+        rsets[0] = rpn_search_structure(zh, zs->u.complex->s1,
+                                       attributeSet, stream, rset_nmem,
+                                       sort_sequence,
+                                       num_bases, basenames);
         if (rsets[0] == NULL)
             return NULL;
-        rsets[1]=rpn_search_structure (zh, zs->u.complex->s2,
-                                       attributeSet, stream, rset_nmem,
-                                       sort_sequence,
-                                       num_bases, basenames);
+        rsets[1] = rpn_search_structure(zh, zs->u.complex->s2,
+                                       attributeSet, stream, rset_nmem,
+                                       sort_sequence,
+                                       num_bases, basenames);
         if (rsets[1] == NULL)
         {
-            rset_delete (rsets[0]);
+            rset_delete(rsets[0]);
             return NULL;
         }
 
@@ -2282,7 +2364,7 @@ static RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs,
             break;
         case Z_Operator_and_not:
             r = rsbool_create_not(rset_nmem,key_it_ctrl, key_it_ctrl->scope,
-                    rsets[0],rsets[1]);
+                    rsets[0], rsets[1]);
             break;
         case Z_Operator_prox:
             if (zop->u.prox->which != Z_ProximityOperator_known)
@@ -2320,9 +2402,9 @@ static RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs,
         if (zs->u.simple->which == Z_Operand_APT)
         {
             yaz_log(YLOG_DEBUG, "rpn_search_APT");
-            r = rpn_search_APT (zh, zs->u.simple->u.attributesPlusTerm,
-                                attributeSet, stream, sort_sequence,
-                                num_bases, basenames,rset_nmem);
+            r = rpn_search_APT(zh, zs->u.simple->u.attributesPlusTerm,
+                              attributeSet, stream, sort_sequence,
+                              num_bases, basenames,rset_nmem);
         }
         else if (zs->u.simple->which == Z_Operand_resultSetId)
         {
@@ -2330,14 +2412,12 @@ static RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs,
             r = resultSetRef (zh, zs->u.simple->u.resultSetId);
             if (!r)
             {
-                r = rsnull_create (rset_nmem,key_it_ctrl);
                 zh->errCode = 30;
                 zh->errString =
                     nmem_strdup (stream, zs->u.simple->u.resultSetId);
                 return 0;
             }
-            else
-                rset_dup(r);
+           rset_dup(r);
         }
         else
         {
@@ -2353,60 +2433,6 @@ static RSET rpn_search_structure (ZebraHandle zh, Z_RPNStructure *zs,
     return r;
 }
 
-
-RSET rpn_search(ZebraHandle zh, NMEM nmem, NMEM rset_nmem,
-               Z_RPNQuery *rpn, int num_bases, char **basenames, 
-               const char *setname,
-               ZebraSet sset)
-{
-    RSET rset;
-    oident *attrset;
-    oid_value attributeSet;
-    Z_SortKeySpecList *sort_sequence;
-    int sort_status, i;
-
-    zh->errCode = 0;
-    zh->errString = NULL;
-    zh->hits = 0;
-
-    sort_sequence = (Z_SortKeySpecList *)
-        nmem_malloc(nmem, sizeof(*sort_sequence));
-    sort_sequence->num_specs = 10; /* FIXME - Hard-coded number */
-    sort_sequence->specs = (Z_SortKeySpec **)
-        nmem_malloc(nmem, sort_sequence->num_specs *
-                     sizeof(*sort_sequence->specs));
-    for (i = 0; i<sort_sequence->num_specs; i++)
-        sort_sequence->specs[i] = 0;
-    
-    attrset = oid_getentbyoid (rpn->attributeSetId);
-    attributeSet = attrset->value;
-    rset = rpn_search_structure (zh, rpn->RPNStructure, attributeSet,
-                                 nmem, rset_nmem,
-                                 sort_sequence, num_bases, basenames);
-    if (!rset)
-        return 0;
-
-    if (zh->errCode)
-        yaz_log(YLOG_DEBUG, "search error: %d", zh->errCode);
-    
-    for (i = 0; sort_sequence->specs[i]; i++)
-        ;
-    sort_sequence->num_specs = i;
-    if (!i)
-        resultSetRank (zh, sset, rset, rset_nmem);
-    else
-    {
-        yaz_log(YLOG_DEBUG, "resultSetSortSingle in rpn_search");
-        resultSetSortSingle (zh, nmem, sset, rset,
-                             sort_sequence, &sort_status);
-        if (zh->errCode)
-        {
-            yaz_log(YLOG_DEBUG, "resultSetSortSingle status = %d", zh->errCode);
-        }
-    }
-    return rset;
-}
-
 struct scan_info_entry {
     char *term;
     ISAM_P isam_p;
@@ -2494,11 +2520,11 @@ static void count_set (RSET r, int *count)
     yaz_log(YLOG_DEBUG, "%d keys, %d records", kno, *count);
 }
 
-void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
-               oid_value attributeset,
-               int num_bases, char **basenames,
-               int *position, int *num_entries, ZebraScanEntry **list,
-               int *is_partial, RSET limit_set, int return_zero)
+ZEBRA_RES rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
+                  oid_value attributeset,
+                  int num_bases, char **basenames,
+                  int *position, int *num_entries, ZebraScanEntry **list,
+                  int *is_partial, RSET limit_set, int return_zero)
 {
     int i;
     int pos = *position;
@@ -2569,7 +2595,7 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
     {
         *num_entries = 0;
         zh->errCode = 113;
-        return ;
+        return ZEBRA_FAIL;
     }
     yaz_log (YLOG_DEBUG, "use_value = %d", use_value);
 
@@ -2586,7 +2612,7 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
            zh->errString = basenames[base_no];
            zh->errCode = 109; /* Database unavailable */
            *num_entries = 0;
-           return;
+           return ZEBRA_FAIL;
        }
 
        if (use_string &&
@@ -2640,12 +2666,12 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
         zh->errCode = errCode;
         zh->errString = errString;
         *num_entries = 0;
-       return;
+       return ZEBRA_FAIL;
     }
     if (ord_no == 0)
     {
         *num_entries = 0;
-        return;
+        return ZEBRA_OK;
     }
     /* prepare dictionary scanning */
     before = pos-1;
@@ -2676,7 +2702,7 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
         strcpy(scan_info->prefix, termz);
 
         if (trans_scan_term(zh, zapt, termz+prefix_len, reg_id))
-            return ;
+            return ZEBRA_FAIL;
        
         dict_scan(zh->reg->dict, termz, &before_tmp, &after_tmp,
                  scan_info, scan_handle);
@@ -2837,7 +2863,6 @@ void rpn_scan(ZebraHandle zh, ODR stream, Z_AttributesPlusTerm *zapt,
     
     yaz_log(YLOG_DEBUG, "position = %d, num_entries = %d",
            *position, *num_entries);
-    if (zh->errCode)
-        yaz_log(YLOG_DEBUG, "scan error: %d", zh->errCode);
+    return ZEBRA_OK;
 }
 
index 09b11fe..87dab70 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zserver.c,v 1.130 2005-03-08 14:02:12 adam Exp $
+/* $Id: zserver.c,v 1.131 2005-04-15 10:47:49 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -263,6 +263,7 @@ int bend_search (void *handle, bend_search_rr *r)
 {
     ZebraHandle zh = (ZebraHandle) handle;
     zint zhits = 0;
+    ZEBRA_RES res;
 
     r->hits = 0;
     r->errcode = 0;
@@ -278,15 +279,18 @@ int bend_search (void *handle, bend_search_rr *r)
     switch (r->query->which)
     {
     case Z_Query_type_1: case Z_Query_type_101:
-       zebra_search_RPN (zh, r->stream, r->query->u.type_1,
-                         r->setname, &zhits);
-       if (zhits >   2147483646)
-           r->hits = 2147483647;
-       else
+       res = zebra_search_RPN (zh, r->stream, r->query->u.type_1,
+                               r->setname, &zhits);
+       if (zebra_errCode(zh) == 0)
+       {
+           if (zhits >   2147483646)
+               r->hits = 2147483647;
+           else
            r->hits = (int) zhits;
-        zebra_result (zh, &r->errcode, &r->errstring);
-        if (!r->errcode)
             search_terms (zh, r);
+       }
+       else
+           zebra_result (zh, &r->errcode, &r->errstring);
         break;
     case Z_Query_type_2:
        r->errcode = 107;
@@ -643,7 +647,7 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr)
                        }
                        else
                        {
-                           int r = -1;
+                           ZEBRA_RES r = ZEBRA_FAIL;
                            switch(action) {
                            case 1:
                                r = zebra_insert_record(
@@ -655,7 +659,7 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr)
                                    rec->u.octet_aligned->buf,
                                    rec->u.octet_aligned->len,
                                    0);
-                               if (r)
+                               if (r == ZEBRA_FAIL)
                                {
                                    rr->errcode = 224;
                                    rr->errstring = "insert_record failed";
@@ -672,7 +676,7 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr)
                                    rec->u.octet_aligned->buf,
                                    rec->u.octet_aligned->len,
                                    1);
-                               if (r)
+                               if (r == ZEBRA_FAIL)
                                {
                                    rr->errcode = 224;
                                    rr->errstring = "update_record failed";
@@ -688,7 +692,7 @@ int bend_esrequest (void *handle, bend_esrequest_rr *rr)
                                    rec->u.octet_aligned->buf,
                                    rec->u.octet_aligned->len,
                                    0);
-                               if (r)
+                               if (r == ZEBRA_FAIL)
                                {
                                    rr->errcode = 224;
                                    rr->errstring = "delete_record failed";
index 4bec43b..37dc5a7 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: zsets.c,v 1.79 2005-04-14 12:01:22 adam Exp $
+/* $Id: zsets.c,v 1.80 2005-04-15 10:47:49 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -89,16 +89,71 @@ static void loglevels()
     log_level_searchhits = yaz_log_module_level("searchhits");
     log_level_searchterms = yaz_log_module_level("searchterms");
     log_level_resultsets = yaz_log_module_level("resultsets");
-    log_level_set=1;
+    log_level_set = 1;
 }
 
-ZebraSet resultSetAddRPN (ZebraHandle zh, NMEM m,
-                          Z_RPNQuery *rpn, int num_bases,
-                          char **basenames, 
-                          const char *setname)
+ZEBRA_RES resultSetSearch(ZebraHandle zh, NMEM nmem, NMEM rset_nmem,
+                         Z_RPNQuery *rpn, ZebraSet sset)
+{
+    RSET rset;
+    oident *attrset;
+    Z_SortKeySpecList *sort_sequence;
+    int sort_status, i;
+
+    zh->errCode = 0;
+    zh->errString = NULL;
+    zh->hits = 0;
+
+    sort_sequence = (Z_SortKeySpecList *)
+        nmem_malloc(nmem, sizeof(*sort_sequence));
+    sort_sequence->num_specs = 10; /* FIXME - Hard-coded number */
+    sort_sequence->specs = (Z_SortKeySpec **)
+        nmem_malloc(nmem, sort_sequence->num_specs *
+                     sizeof(*sort_sequence->specs));
+    for (i = 0; i<sort_sequence->num_specs; i++)
+        sort_sequence->specs[i] = 0;
+    
+    attrset = oid_getentbyoid (rpn->attributeSetId);
+    rset = rpn_search_structure (zh, rpn->RPNStructure, attrset->value,
+                                 nmem, rset_nmem,
+                                 sort_sequence,
+                                sset->num_bases, sset->basenames);
+    if (!rset)
+    {
+       sset->rset = 0;
+        return ZEBRA_FAIL;
+    }
+
+    if (zh->errCode)
+        yaz_log(YLOG_DEBUG, "search error: %d", zh->errCode);
+    
+    for (i = 0; sort_sequence->specs[i]; i++)
+        ;
+    sort_sequence->num_specs = i;
+    if (!i)
+        resultSetRank (zh, sset, rset, rset_nmem);
+    else
+    {
+        yaz_log(YLOG_DEBUG, "resultSetSortSingle in rpn_search");
+        resultSetSortSingle (zh, nmem, sset, rset,
+                             sort_sequence, &sort_status);
+        if (zh->errCode)
+        {
+            yaz_log(YLOG_DEBUG, "resultSetSortSingle status = %d", zh->errCode);
+        }
+    }
+    sset->rset = rset;
+    return ZEBRA_OK;
+}
+
+
+ZEBRA_RES resultSetAddRPN (ZebraHandle zh, NMEM m, Z_RPNQuery *rpn,
+                          int num_bases, char **basenames,
+                          const char *setname)
 {
     ZebraSet zebraSet;
     int i;
+    ZEBRA_RES res;
 
     zh->errCode = 0;
     zh->errString = NULL;
@@ -106,11 +161,11 @@ ZebraSet resultSetAddRPN (ZebraHandle zh, NMEM m,
 
     zebraSet = resultSetAdd (zh, setname, 1);
     if (!zebraSet)
-        return 0;
+        return ZEBRA_FAIL;
     zebraSet->locked = 1;
     zebraSet->rpn = 0;
     zebraSet->nmem = m;
-    zebraSet->rset_nmem=nmem_create(); 
+    zebraSet->rset_nmem = nmem_create(); 
 
     zebraSet->num_bases = num_bases;
     zebraSet->basenames = 
@@ -118,16 +173,15 @@ ZebraSet resultSetAddRPN (ZebraHandle zh, NMEM m,
     for (i = 0; i<num_bases; i++)
         zebraSet->basenames[i] = nmem_strdup (zebraSet->nmem, basenames[i]);
 
-
-    zebraSet->rset = rpn_search (zh, zebraSet->nmem, zebraSet->rset_nmem,
-                                 rpn, zebraSet->num_bases,
-                                 zebraSet->basenames, zebraSet->name,
-                                 zebraSet);
+    res = resultSetSearch(zh, zebraSet->nmem, zebraSet->rset_nmem,
+                         rpn, zebraSet);
     zh->hits = zebraSet->hits;
     if (zebraSet->rset)
         zebraSet->rpn = rpn;
     zebraSet->locked = 0;
-    return zebraSet;
+    if (!zebraSet->rset)
+       return ZEBRA_FAIL;
+    return res;
 }
 
 void resultSetAddTerm (ZebraHandle zh, ZebraSet s, int reg_type,
@@ -215,7 +269,7 @@ ZebraSet resultSetAdd (ZebraHandle zh, const char *name, int ov)
     s->term_entries = 0;
     s->hits = 0;
     s->rset = 0;
-    s->rset_nmem=0;
+    s->rset_nmem = 0;
     s->nmem = 0;
     s->rpn = 0;
     s->cache_position = 0;
@@ -236,9 +290,7 @@ ZebraSet resultSetGet (ZebraHandle zh, const char *name)
                 yaz_log(log_level_resultsets, "research %s", name);
                 if (!s->rset_nmem)
                     s->rset_nmem=nmem_create();
-                s->rset =
-                    rpn_search (zh, nmem, s->rset_nmem, s->rpn, s->num_bases,
-                                s->basenames, s->name, s);
+               resultSetSearch(zh, nmem, s->rset_nmem, s->rpn, s);
                 nmem_destroy (nmem);
             }
             return s;
index 294683d..1f57c73 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: isamb.c,v 1.76 2005-04-13 13:03:47 adam Exp $
+/* $Id: isamb.c,v 1.77 2005-04-15 10:47:49 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -196,7 +196,7 @@ ISAMB isamb_open(BFiles bfs, const char *name, int writeflag, ISAMC_M *method,
     isamb->skipped_numbers = 0;
     isamb->returned_numbers = 0;
     for (i = 0; i<ISAMB_MAX_LEVEL; i++)
-      isamb->skipped_nodes[i] = isamb->accessed_nodes[i] = 0;
+       isamb->skipped_nodes[i] = isamb->accessed_nodes[i] = 0;
 
     assert(cache == 0);
     isamb->file = xmalloc(sizeof(*isamb->file) * isamb->no_cat);
index 57376a2..8164a0d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: t3.c,v 1.16 2005-03-09 12:14:42 adam Exp $
+/* $Id: t3.c,v 1.17 2005-04-15 10:47:49 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -41,9 +41,6 @@ int main(int argc, char **argv)
 
     for (i = 0; i<4; i++)
     {
-#if 0
-        ZebraRetrievalRecord retrievalRecord;
-#endif
         char setname[20];
         char *setnamep = setname;
         int status;
@@ -62,15 +59,8 @@ int main(int argc, char **argv)
         zebra_end_trans (zh);
         zebra_end_trans (zh);
         yaz_pqf_destroy(parser);
-#if 0
-        /*FIXME Why is this disabled ??? */
-        zebra_records_retrieve(zh, odr_output, setname, 0,
-                              VAL_TEXT_XML, 1, &retrievalRecord);
-#endif
-#if 1
         zebra_deleteResultSet(zh, Z_DeleteRequest_list,
                               1, &setnamep, &status);
-#endif
         odr_destroy(odr_input);
         odr_destroy(odr_output);
     }
index 30ccd1f..fb515e6 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: t5.c,v 1.11 2005-01-15 19:38:35 adam Exp $
+/* $Id: t5.c,v 1.12 2005-04-15 10:47:49 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -37,28 +37,64 @@ int main(int argc, char **argv)
 
     init_data(zh, myrec);
 
-    do_query(__LINE__,zh, "@attr 1=4 my", 3);
-    do_query(__LINE__,zh, "@attr 1=4 {my x}", 1);
-    do_query(__LINE__,zh, "@attr 1=4 {my x}", 1);
-    do_query(__LINE__,zh, "@attr 1=4 {x my}", 0);
-    do_query(__LINE__,zh, "@attr 1=4 {my x title}", 1);
-    do_query(__LINE__,zh, "@attr 1=4 {my title}", 2);
-    do_query(__LINE__,zh, "@attr 1=4 @and x title", 2);
+    /* phrase searches */
+    do_query(__LINE__, zh, "@attr 1=4 my", 3);
+    do_query(__LINE__, zh, "@attr 1=4 {my x}", 1);
+    do_query(__LINE__, zh, "@attr 1=4 @attr 4=1 {my x}", 1);
+    do_query(__LINE__, zh, "@attr 1=4 {my x}", 1);
+    do_query(__LINE__, zh, "@attr 1=4 {x my}", 0);
+    do_query(__LINE__, zh, "@attr 1=4 {my x title}", 1);
+    do_query(__LINE__, zh, "@attr 1=4 {my title}", 2);
+
+    /* and-list searches */
+    do_query(__LINE__, zh, "@attr 1=4 @attr 4=6 {x my}", 2);
+    do_query(__LINE__, zh, "@attr 1=4 @attr 4=6 {my x}", 2);
+    do_query(__LINE__, zh, "@attr 1=4 @attr 4=6 {my my}", 3);
+    do_query(__LINE__, zh, "@attr 1=4 @attr 4=6 {e x}", 0);
+
+    /* or-list searches */
+    do_query(__LINE__, zh, "@attr 1=4 @attr 4=105 {x my}", 3);
+    do_query(__LINE__, zh, "@attr 1=4 @attr 4=105 {my x}", 3);
+    do_query(__LINE__, zh, "@attr 1=4 @attr 4=105 {my my}", 3);
+    do_query(__LINE__, zh, "@attr 1=4 @attr 4=105 {e x}", 2);
+    do_query(__LINE__, zh, "@attr 1=4 @attr 4=106 {e x}", 2);
+
+    do_query(__LINE__, zh, "@attr 1=4 @and x title", 2);
 
     /* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */
-    do_query(__LINE__,zh, "@prox 0 2 1 2 k 2 my x", 2);
+    do_query(__LINE__, zh, "@prox 0 2 1 2 k 2 my x", 2);
 
     /* exl=0 distance=2 order=1 relation=2 (<=), known, unit=word */
-    do_query(__LINE__,zh, "@prox 0 2 1 2 k 2 x my", 0);
+    do_query(__LINE__, zh, "@prox 0 2 1 2 k 2 x my", 0);
 
     /* exl=0 distance=2 order=0 relation=2 (<=), known, unit=word */
-    do_query(__LINE__,zh, "@prox 0 2 0 2 k 2 x my", 2);
+    do_query(__LINE__, zh, "@prox 0 2 0 2 k 2 x my", 2);
 
     /* exl=0 distance=2 order=0 relation=3 (=), known, unit=word */
-    do_query(__LINE__,zh, "@prox 0 2 1 3 k 2 my x", 1);
+    do_query(__LINE__, zh, "@prox 0 2 1 3 k 2 my x", 1);
 
     /* exl=1 distance=2 order=0 relation=3 (=), known, unit=word */
-    do_query(__LINE__,zh, "@prox 1 2 1 3 k 2 my x", 1);
+    do_query(__LINE__, zh, "@prox 1 2 1 3 k 2 my x", 1);
+
+    /* provoke unsupported use attribute */
+    do_query_x(__LINE__, zh, "@attr 1=999 @attr 4=1 x", 0, 114);
+    do_query_x(__LINE__, zh, "@attr 1=999 @attr 4=6 x", 0, 114);
+    do_query_x(__LINE__, zh, "@attr 1=999 @attr 4=105 x", 0, 114);
+    do_query_x(__LINE__, zh, "@attr 1=999 @attr 4=109 123", 0, 114);
+    do_query_x(__LINE__, zh, "@attrset 1.2.840.10003.3.1 @attr 1=999 x",
+              0, 114);
+    /* provoke unsupported attribute set */
+    do_query_x(__LINE__, zh, "@attrset 1.2.8 @attr 1=999 @attr 4=1 x", 0, 121);
+    do_query_x(__LINE__, zh, "@attrset 1.2.8 @attr 1=999 @attr 4=6 x", 0,
+              121);
+    do_query_x(__LINE__, zh, "@attrset 1.2.8 @attr 1=999 @attr 4=105 x", 0,
+              121);
+    do_query_x(__LINE__, zh, "@attrset 1.2.8 @attr 1=999 @attr 4=109 123",
+              0, 121);
 
+    /* provoke unsupported relation */
+    do_query_x(__LINE__, zh, "@attr 1=1016 @attr 2=6 x", 0, 117);
+    do_query_x(__LINE__, zh, "@attr 1=1016 @attr 2=6 @attr 4=109 x", 0, 117);
     return close_down(zh, zs, 0);
 }
index d54c7c1..94554a2 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: testlib.c,v 1.12 2005-03-09 12:14:42 adam Exp $
+/* $Id: testlib.c,v 1.13 2005-04-15 10:47:49 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -120,38 +120,38 @@ void init_data(ZebraHandle zh, const char **recs)
     zebra_select_database(zh, "Default");
     yaz_log(log_level, "going to call init");
     i = zebra_init(zh);
-    yaz_log(log_level, "init returned %d",i);
+    yaz_log(log_level, "init returned %d", i);
     if (i) 
     {
         printf("init failed with %d\n",i);
         zebra_result(zh, &i, &addinfo);
-        printf("  Error %d   %s\n",i,addinfo);
+        printf("  Error %d   %s\n", i, addinfo);
         exit(1);
     }
     if (recs)
     {
         zebra_begin_trans (zh, 1);
         for (i = 0; recs[i]; i++)
-            zebra_add_record (zh, recs[i], strlen(recs[i]));
-        zebra_end_trans (zh);
-        zebra_commit (zh);
+            zebra_add_record(zh, recs[i], strlen(recs[i]));
+        zebra_end_trans(zh);
+        zebra_commit(zh);
     }
 
 }
 
-int do_query(int lineno, ZebraHandle zh, char *query, int exphits)
+int do_query_x(int lineno, ZebraHandle zh, char *query, int exphits,
+             int experror)
 {
     ODR odr;
     YAZ_PQF_Parser parser;
     Z_RPNQuery *rpn;
     const char *setname="rsetname";
     zint hits;
-    int rc;
-        
+    ZEBRA_RES rc;
 
-    yaz_log(log_level,"======================================");
-    yaz_log(log_level,"qry[%d]: %s", lineno, query);
-    odr=odr_createmem (ODR_DECODE);    
+    yaz_log(log_level, "======================================");
+    yaz_log(log_level, "qry[%d]: %s", lineno, query);
+    odr = odr_createmem (ODR_DECODE);    
 
     parser = yaz_pqf_create();
     rpn = yaz_pqf_parse(parser, odr, query);
@@ -159,16 +159,36 @@ int do_query(int lineno, ZebraHandle zh, char *query, int exphits)
         printf("Error: Parse failed \n%s\n",query);
         exit(1);
     }
-    rc = zebra_search_RPN (zh, odr, rpn, setname, &hits);
-    if (rc) {
-        printf("Error: search returned %d \n%s\n",rc,query);
-        exit (1);
+    rc = zebra_search_RPN(zh, odr, rpn, setname, &hits);
+    if (experror)
+    {
+       if (rc != ZEBRA_FAIL)
+       {
+           printf("Error: search returned %d (OK), but error was expected\n"
+                  "%s\n",  rc, query);
+           exit(1);
+       }
+       int code = zebra_errCode(zh);
+       if (code != experror)
+       {
+           printf("Error: search returned error code %d, but error %d was "
+                  "expected\n%s\n",
+                  code, experror, query);
+           exit(1);
+       }
     }
-
-    if (hits != exphits) {
-        printf("Error: search returned " ZINT_FORMAT " hits instead of %d\n",
-                hits, exphits);
-        exit (1);
+    else
+    {
+       if (rc == ZEBRA_FAIL) {
+           printf("Error: search returned %d\n%s\n", rc, query);
+           exit (1);
+       }
+       if (hits != exphits) {
+           printf("Error: search returned " ZINT_FORMAT 
+                  " hits instead of %d\n%s\n",
+                  hits, exphits, query);
+           exit (1);
+       }
     }
     yaz_pqf_destroy(parser);
     odr_destroy (odr);
@@ -176,12 +196,18 @@ int do_query(int lineno, ZebraHandle zh, char *query, int exphits)
 }
 
 
+int do_query(int lineno, ZebraHandle zh, char *query, int exphits)
+{
+    return do_query_x(lineno, zh, query, exphits, 0);
+}
+
+
 /** 
  * makes a query, checks number of hits, and for the first hit, that 
  * it contains the given string, and that it gets the right score
  */
 void ranking_query(int lineno, ZebraHandle zh, char *query, 
-          int exphits, char *firstrec, int firstscore )
+                  int exphits, char *firstrec, int firstscore)
 {
     ZebraRetrievalRecord retrievalRecord[10];
     ODR odr_output = odr_createmem (ODR_ENCODE);    
@@ -207,8 +233,8 @@ void ranking_query(int lineno, ZebraHandle zh, char *query,
     if (!strstr(retrievalRecord[0].buf, firstrec))
     {
         printf("Error: Got the wrong record first\n");
-        printf("Expected '%s' but got \n",firstrec);
-        printf("%.*s\n",retrievalRecord[0].len,retrievalRecord[0].buf);
+        printf("Expected '%s' but got \n", firstrec);
+        printf("%.*s\n", retrievalRecord[0].len, retrievalRecord[0].buf);
         exit(1);
     }
     
index b1f7726..23de293 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: testlib.h,v 1.10 2005-01-15 19:38:35 adam Exp $
+/* $Id: testlib.h,v 1.11 2005-04-15 10:47:49 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -82,6 +82,12 @@ void init_data( ZebraHandle zh, const char **recs);
 int do_query(int lineno, ZebraHandle zh, char *query, int exphits);
 
 
+/**
+ * do_query does a simple query, and checks that error is what is expected
+ */
+int do_query_x(int lineno, ZebraHandle zh, char *query, int exphits,
+              int experror);
+
 /** 
  * ranking_query makes a query, checks number of hits, and for 
  * the first hit, that it contains the given string, and that it 
index 952b900..af41a8b 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: res.c,v 1.40 2005-03-30 09:25:25 adam Exp $
+/* $Id: res.c,v 1.41 2005-04-15 10:47:49 adam Exp $
    Copyright (C) 1995-2005
    Index Data ApS
 
@@ -30,6 +30,7 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <unistd.h>
 #endif
 
+#include <yaz/yaz-util.h>
 #include <idzebra/res.h>
 
 struct res_entry {