+Moved towards generic character mapping. Type w, p uses
+string.chr, u uses urx.chr and n uses numeric.chr.
+
Added support for C++, headers uses extern "C" for public definitions.
New filter grs.marc.<syntax> that reads MARC records in the ISO2709
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: lookgrep.c,v $
- * Revision 1.19 1997-09-18 08:59:18 adam
+ * Revision 1.20 1997-10-27 14:33:03 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ * Revision 1.19 1997/09/18 08:59:18 adam
* Extra generic handle for the character mapping routines.
*
* Revision 1.18 1997/09/05 15:29:58 adam
struct DFA *dfa = dfa_init();
int i, d;
- logf (LOG_DEBUG, "dict_lookup_grep '%s' range=%d", pattern, range);
+ logf (LOG_DEBUG, "dict_lookup_grep range=%d", range);
+ for (i = 0; pattern[i]; i++)
+ {
+ logf (LOG_DEBUG, " %3d %c", pattern[i],
+ (pattern[i] > ' ' && pattern[i] < 127) ? pattern[i] : '?');
+ }
dfa_set_cmap (dfa, dict->grep_cmap_data, dict->grep_cmap);
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: scan.c,v $
- * Revision 1.8 1996-02-02 13:43:52 adam
+ * Revision 1.9 1997-10-27 14:33:04 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ * Revision 1.8 1996/02/02 13:43:52 adam
* The public functions simply use char instead of Dict_char to represent
* search strings. Dict_char is used internally only.
*
int dict_scan (Dict dict, char *str, int *before, int *after, void *client,
int (*f)(char *name, const char *info, int pos, void *client))
{
+ int i;
+
+ logf (LOG_DEBUG, "dict_scan");
+ for (i = 0; str[i]; i++)
+ {
+ logf (LOG_DEBUG, " %3d %c", str[i],
+ (str[i] > ' ' && str[i] < 127) ? str[i] : '?');
+ }
if (dict->head.last <= 1)
return 0;
return dict_scan_r (dict, 1, 0, (Dict_char *) str, before, after, client,
* OF THIS SOFTWARE.
*
* $Log: charmap.h,v $
- * Revision 1.3 1997-09-05 15:29:59 adam
+ * Revision 1.4 1997-10-27 14:33:04 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ * Revision 1.3 1997/09/05 15:29:59 adam
* Changed prototype for chr_map_input - added const.
* Added support for C++, headers uses extern "C" for public definitions.
*
struct chr_t_entry;
typedef struct chr_t_entry chr_t_entry;
-typedef struct chrmaptab
-{
- chr_t_entry *input; /* mapping table for input data */
- chr_t_entry *query_equiv; /* mapping table for queries */
- unsigned char *output[256]; /* return mapping - for display of registers */
- int base_uppercase; /* Start of upper-case ordinals */
-} chrmaptab, *CHRMAPTAB;
+typedef struct chrmaptab_info *chrmaptab;
+
+chrmaptab chrmaptab_create(const char *tabpath, const char *name,
+ int map_only);
+void chrmaptab_destroy (chrmaptab tab);
+
+const char **chr_map_input(chrmaptab t, const char **from, int len);
-chrmaptab *chr_read_maptab(const char *tabpath, const char *name);
-int chr_map_chrs(chr_t_entry *t, char **from, int len, int *read, char **to,
- int max);
-const char **chr_map_input(chr_t_entry *t, const char **from, int len);
+const char *chr_map_output(chrmaptab t, const char **from, int len);
#ifdef __cplusplus
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: recctrl.h,v $
- * Revision 1.21 1997-09-18 08:59:19 adam
+ * Revision 1.22 1997-10-27 14:33:04 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ * Revision 1.21 1997/09/18 08:59:19 adam
* Extra generic handle for the character mapping routines.
*
* Revision 1.20 1997/09/17 12:19:10 adam
#include <oid.h>
#include <odr.h>
#include <data1.h>
+#include <zebramap.h>
#ifdef __cplusplus
extern "C" {
#endif
-typedef enum {
- Word_String,
- Word_Phrase,
- Word_Numeric
-} RecWordType;
/* single word entity */
typedef struct {
int attrSet;
int attrUse;
- RecWordType which;
-#if 0
- enum {
- Word_String,
- Word_Phrase,
- Word_Numeric
- } which;
-#endif
- union {
- char *string;
- int numeric;
- } u;
+ unsigned reg_type;
+ char *string;
int seqno;
} RecWord;
char *subType;
void (*init)(RecWord *p);
void (*add)(const RecWord *p);
- const char **(*map_chrs_input)(void *vp, const char **from, int len);
+ ZebraMaps zebra_maps;
int flagShowRecords;
data1_handle dh;
};
--- /dev/null
+/*
+ * Copyright (C) 1994-1997, Index Data I/S
+ * All rights reserved.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: zebramap.h,v $
+ * Revision 1.1 1997-10-27 14:33:04 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ */
+
+#ifndef ZEBRAMAP_H
+#define ZEBRAMAP_H
+
+#include <proto.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct zebra_maps *ZebraMaps;
+ZebraMaps zebra_maps_open (const char *tabpath);
+
+void zebra_maps_close (ZebraMaps zm);
+
+const char **zebra_maps_input (ZebraMaps zms, int reg_type,
+ const char **from, int len);
+const char *zebra_maps_output(ZebraMaps, int reg_type, const char **from);
+
+int zebra_maps_attr (ZebraMaps zms, Z_AttributesPlusTerm *zapt,
+ int *reg_type, char **search_type, int *complete_flag);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zebrautl.h,v $
- * Revision 1.3 1997-09-17 12:19:11 adam
+ * Revision 1.4 1997-10-27 14:33:04 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ * Revision 1.3 1997/09/17 12:19:11 adam
* Zebra version corresponds to YAZ version 1.4.
* Changed Zebra server so that it doesn't depend on global common_resource.
*
#ifndef ZEBRA_UTIL_H
#define ZEBRA_UTIL_H
-#include <log.h>
-#include <options.h>
-#include <xmalloc.h>
+#include <yaz-util.h>
#include <res.h>
-#include <readconf.h>
#endif
# Copyright (C) 1995-1996, Index Data I/S
# All rights reserved.
# Sebastian Hammer, Adam Dickmeiss
-# $Id: Makefile,v 1.43 1997-09-04 13:59:28 adam Exp $
+# $Id: Makefile,v 1.44 1997-10-27 14:33:04 adam Exp $
SHELL=/bin/sh
RANLIB=ranlib
DEFS=$(INCLUDE)
O1 = main.o dir.o dirs.o trav.o extract.o kinput.o kcompare.o \
symtab.o recindex.o recstat.o lockutil.o lockidx.o \
- zinfo.o invstat.o keychars.o
+ zinfo.o invstat.o
O2 = kdump.o
O3 = zserver.o kcompare.o zrpn.o zsets.o attribute.o recindex.o \
- zlogs.o lockutil.o locksrv.o zinfo.o keychars.o trunc.o
+ zlogs.o lockutil.o locksrv.o zinfo.o trunc.o
CPP=$(CC) -E
all: $(TPROG1) $(TPROG2) $(TPROG3)
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: extract.c,v $
- * Revision 1.75 1997-09-17 12:19:12 adam
+ * Revision 1.76 1997-10-27 14:33:04 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ * Revision 1.75 1997/09/17 12:19:12 adam
* Zebra version corresponds to YAZ version 1.4.
* Changed Zebra server so that it doesn't depend on global common_resource.
*
{
p->attrSet = 1;
p->attrUse = 1016;
- p->which = Word_String;
+ p->reg_type = 'w';
}
struct recKeys {
memcpy (dst, &attrUse, sizeof(attrUse));
dst += sizeof(attrUse);
}
- switch (p->which)
- {
- case Word_String:
- *dst++ = 'w';
- break;
- case Word_Phrase:
- *dst++ = 'p';
- break;
- case Word_Numeric:
- *dst++ = 'n';
- }
- for (i = 0; p->u.string[i] && i < IT_MAX_WORD-3; i++)
- *dst++ = p->u.string[i];
+ *dst++ = p->reg_type;
+ for (i = 0; p->string[i] && i < IT_MAX_WORD-3; i++)
+ *dst++ = p->string[i];
*dst++ = '\0';
if (!diff)
extractCtrl.seekf = file_seek;
extractCtrl.tellf = file_tell;
extractCtrl.endf = file_end;
- extractCtrl.map_chrs_input = map_chrs_input;
+ extractCtrl.zebra_maps = rGroup->zebra_maps;
extractCtrl.flagShowRecords = rGroup->flagShowRecords;
if (rGroup->flagShowRecords)
printf ("File: %s %ld\n", fname, (long) recordOffset);
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: index.h,v $
- * Revision 1.54 1997-09-29 09:08:36 adam
+ * Revision 1.55 1997-10-27 14:33:04 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ * Revision 1.54 1997/09/29 09:08:36 adam
* Revised locking system to be thread safe for the server.
*
* Revision 1.53 1997/09/25 14:54:43 adam
#include <time.h>
#include <zebraver.h>
#include <zebrautl.h>
+#include <zebramap.h>
#include <dict.h>
#include <isam.h>
time_t mtime;
};
+
struct recordGroup {
char *groupName;
char *databaseName;
int fileVerboseLimit;
data1_handle dh;
BFiles bfs;
+ ZebraMaps zebra_maps;
};
void getFnameTmp (char *fname, int no);
int zebra_lock_fd (ZebraLockHandle h);
void zebra_lock_prefix (Res res, char *dst);
-void init_charmap(Res res);
-const char **map_chrs_input(void *vp, const char **from, int len);
-const char *map_chrs_output(const char **from);
extern Res common_resource;
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: kdump.c,v $
- * Revision 1.13 1997-09-09 13:38:07 adam
+ * Revision 1.14 1997-10-27 14:33:04 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ * Revision 1.13 1997/09/09 13:38:07 adam
* Partial port to WIN95/NT.
*
* Revision 1.12 1997/09/05 09:52:32 adam
char key_info[256];
FILE *inf;
struct it_key prevk;
- chrmaptab *map = 0;
+ chrmaptab map = 0;
prevk.sysno = 0;
prevk.seqno = 0;
}
else if (ret == 'm')
{
- if (!(map = chr_read_maptab (NULL, arg)))
+ if (!(map = chrmaptab_create (NULL, arg, 0)))
{
logf(LOG_FATAL, "Failed to open maptab");
exit(1);
while (*from)
{
- char *res = (char*)map->output[(unsigned char) *(from++)];
+ char *res = chr_map_output(map, from, 1);
while (*res)
*(to++) = *(res++);
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: main.c,v $
- * Revision 1.50 1997-09-25 14:55:52 adam
+ * Revision 1.51 1997-10-27 14:33:05 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ * Revision 1.50 1997/09/25 14:55:52 adam
* Minor changes.
*
* Revision 1.49 1997/09/17 12:19:15 adam
rGroupDef.flagStoreKeys = -1;
rGroupDef.flagShowRecords = 0;
rGroupDef.fileVerboseLimit = 100000;
+ rGroupDef.zebra_maps = NULL;
rGroupDef.dh = data1_create ();
prog = *argv;
bf_lockDir (rGroupDef.bfs,
res_get (common_resource, "lockDir"));
- init_charmap(common_resource);
+ rGroupDef.zebra_maps = zebra_maps_open (res_get(
+ common_resource, "profilePath"));
}
if (!strcmp (arg, "update"))
cmd = 'u';
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zinfo.c,v $
- * Revision 1.4 1997-09-25 14:57:08 adam
+ * Revision 1.5 1997-10-27 14:33:05 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ * Revision 1.4 1997/09/25 14:57:08 adam
* Added string.h.
*
* Revision 1.3 1996/05/22 08:21:59 adam
zti->curDatabaseInfo->dirty = 1;
memcpy (&zti->curDatabaseInfo->info, zdi, sizeof(*zdi));
}
+
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zrpn.c,v $
- * Revision 1.67 1997-09-29 09:06:10 adam
+ * Revision 1.68 1997-10-27 14:33:06 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ * Revision 1.67 1997/09/29 09:06:10 adam
* Removed one static var in order to make this module thread safe.
*
* Revision 1.66 1997/09/25 14:58:03 adam
#include <rsbool.h>
#include <rsrel.h>
+struct rpn_char_map_info {
+ ZebraMaps zm;
+ int reg_type;
+};
+
+static const char **rpn_char_map_handler (void *vp, const char **from, int len)
+{
+ struct rpn_char_map_info *p = vp;
+ return zebra_maps_input (p->zm, p->reg_type, from, len);
+}
+
+static void rpn_char_map_prepare (ZServerInfo *zi, int reg_type,
+ struct rpn_char_map_info *map_info)
+{
+ map_info->zm = zi->zebra_maps;
+ map_info->reg_type = reg_type;
+ dict_grep_cmap (zi->dict, map_info, rpn_char_map_handler);
+}
+
typedef struct {
int type;
int major;
return 0;
}
-static int term_pre (const char **src, const char *ct1, const char *ct2)
+static int term_pre (ZebraMaps zebra_maps, int reg_type, const char **src,
+ const char *ct1, const char *ct2)
{
const char *s1, *s0 = *src;
const char **map;
if (ct2 && strchr (ct2, *s0))
break;
s1 = s0;
- map = map_chrs_input (0, &s1, strlen(s1));
+ map = zebra_maps_input (zebra_maps, reg_type, &s1, strlen(s1));
if (**map != *CHR_SPACE)
break;
s0 = s1;
return *s0;
}
-static int term_100 (const char **src, char *dst, int space_split)
+static int term_100 (ZebraMaps zebra_maps, int reg_type,
+ const char **src, char *dst, int space_split)
{
const char *s0, *s1;
const char **map;
int i = 0;
- if (!term_pre (src, NULL, NULL))
+ if (!term_pre (zebra_maps, reg_type, src, NULL, NULL))
return 0;
s0 = *src;
while (*s0)
{
s1 = s0;
- map = map_chrs_input (0, &s0, strlen(s0));
+ map = zebra_maps_input (zebra_maps, reg_type, &s0, strlen(s0));
if (space_split && **map == *CHR_SPACE)
break;
while (s1 < s0)
{
- if (!isalnum (*s1))
+ if (!isalnum (*s1) && *s1 != '-')
dst[i++] = '\\';
dst[i++] = *s1++;
}
return i;
}
-static int term_101 (const char **src, char *dst, int space_split)
+static int term_101 (ZebraMaps zebra_maps, int reg_type,
+ const char **src, char *dst, int space_split)
{
const char *s0, *s1;
const char **map;
int i = 0;
- if (!term_pre (src, "#", "#"))
+ if (!term_pre (zebra_maps, reg_type, src, "#", "#"))
return 0;
s0 = *src;
while (*s0)
else
{
s1 = s0;
- map = map_chrs_input (0, &s0, strlen(s0));
+ map = zebra_maps_input (zebra_maps, reg_type, &s0, strlen(s0));
if (space_split && **map == *CHR_SPACE)
break;
while (s1 < s0)
}
-static int term_103 (const char **src, char *dst, int *errors, int space_split)
+static int term_103 (ZebraMaps zebra_maps, int reg_type, const char **src,
+ char *dst, int *errors, int space_split)
{
int i = 0;
const char *s0, *s1;
const char **map;
- if (!term_pre (src, "^\\()[].*+?|", "("))
+ if (!term_pre (zebra_maps, reg_type, src, "^\\()[].*+?|", "("))
return 0;
s0 = *src;
if (errors && *s0 == '+' && s0[1] && s0[2] == '+' && s0[3] &&
else
{
s1 = s0;
- map = map_chrs_input (0, &s0, strlen(s0));
+ map = zebra_maps_input (zebra_maps, reg_type, &s0, strlen(s0));
if (**map == *CHR_SPACE)
break;
while (s1 < s0)
return i;
}
-static int term_102 (const char **src, char *dst, int space_split)
+static int term_102 (ZebraMaps zebra_maps, int reg_type, const char **src,
+ char *dst, int space_split)
{
- return term_103 (src, dst, NULL, space_split);
+ return term_103 (zebra_maps, reg_type, src, dst, NULL, space_split);
}
/* gen_regular_rel - generate regular expression from relation
if (val >= 0)
{
if (islt)
- strcpy (dst, "(-[0-9]+|");
+ strcpy (dst, "(-[0-9]+|(");
else
- strcpy (dst, "(");
+ strcpy (dst, "((");
}
else
{
if (!islt)
{
- strcpy (dst, "([0-9]+|-");
+ strcpy (dst, "([0-9]+|-(");
dst_p = strlen (dst);
islt = 1;
}
else
{
- strcpy (dst, "(-");
+ strcpy (dst, "((-");
islt = 0;
}
val = -val;
strcat (dst, "[0-9]");
strcat (dst, "[0-9]*");
}
- strcat (dst, ")");
+ strcat (dst, "))");
}
static int relational_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
char *term_dict,
oid_value attributeSet,
struct grep_info *grep_info,
- int *max_pos)
+ int *max_pos,
+ int reg_type)
{
AttrType relation;
int relation_value;
int term_value;
int r;
+ char *term_tmp = term_dict + strlen(term_dict);
attr_init (&relation, zapt, 2);
relation_value = attr_find (&relation, NULL);
+ logf (LOG_DEBUG, "relation value=%d", relation_value);
switch (relation_value)
{
case 1:
- if (!term_100 (term_sub, term_dict, 1))
+ if (!term_100 (zi->zebra_maps, reg_type, term_sub, term_tmp, 1))
return 0;
- term_value = atoi (term_dict);
- if (term_value <= 0)
- return 1;
+ term_value = atoi (term_tmp);
logf (LOG_DEBUG, "Relation <");
- gen_regular_rel (term_dict + strlen(term_dict), term_value-1, 1);
+ gen_regular_rel (term_tmp, term_value-1, 1);
break;
case 2:
- if (!term_100 (term_sub, term_dict, 1))
+ if (!term_100 (zi->zebra_maps, reg_type, term_sub, term_tmp, 1))
return 0;
- term_value = atoi (term_dict);
- if (term_value < 0)
- return 1;
+ term_value = atoi (term_tmp);
logf (LOG_DEBUG, "Relation <=");
- gen_regular_rel (term_dict + strlen(term_dict), term_value, 1);
+ gen_regular_rel (term_tmp, term_value, 1);
break;
case 4:
- if (!term_100 (term_sub, term_dict, 1))
+ if (!term_100 (zi->zebra_maps, reg_type, term_sub, term_tmp, 1))
return 0;
- term_value = atoi (term_dict);
- if (term_value < 0)
- term_value = 0;
+ term_value = atoi (term_tmp);
logf (LOG_DEBUG, "Relation >=");
- gen_regular_rel (term_dict + strlen(term_dict), term_value, 0);
+ gen_regular_rel (term_tmp, term_value, 0);
break;
case 5:
- if (!term_100 (term_sub, term_dict, 1))
+ if (!term_100 (zi->zebra_maps, reg_type, term_sub, term_tmp, 1))
return 0;
- term_value = atoi (term_dict);
- if (term_value < 0)
- term_value = 0;
+ term_value = atoi (term_tmp);
logf (LOG_DEBUG, "Relation >");
- gen_regular_rel (term_dict + strlen(term_dict), term_value+1, 0);
+ gen_regular_rel (term_tmp, term_value+1, 0);
break;
default:
return 0;
}
- logf (LOG_DEBUG, "dict_lookup_grep: %s", term_dict);
+ logf (LOG_DEBUG, "dict_lookup_grep: %s", term_tmp);
r = dict_lookup_grep (zi->dict, term_dict, 0, grep_info, max_pos,
0, grep_handle);
if (r)
}
static int field_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
- const char **term_sub, int regType,
+ const char **term_sub,
oid_value attributeSet, struct grep_info *grep_info,
- int num_bases, char **basenames, int space_split)
+ int reg_type, int complete_flag,
+ int num_bases, char **basenames)
{
char term_dict[2*IT_MAX_WORD+2];
int j, r, base_no;
int use_value;
oid_value curAttributeSet = attributeSet;
const char *termp;
+ struct rpn_char_map_info rcmi;
+ int space_split = complete_flag ? 0 : 1;
+ rpn_char_map_prepare (zi, reg_type, &rcmi);
attr_init (&use, zapt, 1);
use_value = attr_find (&use, &curAttributeSet);
logf (LOG_DEBUG, "field_term, use value %d", use_value);
}
term_dict[prefix_len++] = ')';
term_dict[prefix_len++] = 1;
- term_dict[prefix_len++] = regType;
+ term_dict[prefix_len++] = reg_type;
+ logf (LOG_LOG, "reg_type = %d", term_dict[prefix_len-1]);
term_dict[prefix_len] = '\0';
if (!relational_term (zi, zapt, &termp, term_dict,
- attributeSet, grep_info, &max_pos))
+ attributeSet, grep_info, &max_pos, reg_type))
{
j = prefix_len;
switch (truncation_value)
case -1: /* not specified */
case 100: /* do not truncate */
term_dict[j++] = '(';
- if (!term_100 (&termp, term_dict + j, space_split))
+ if (!term_100 (zi->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split))
return 0;
strcat (term_dict, ")");
r = dict_lookup_grep (zi->dict, term_dict, 0, grep_info,
break;
case 1: /* right truncation */
term_dict[j++] = '(';
- if (!term_100 (&termp, term_dict + j, space_split))
+ if (!term_100 (zi->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split))
return 0;
strcat (term_dict, ".*)");
dict_lookup_grep (zi->dict, term_dict, 0, grep_info,
return -1;
case 101: /* process # in term */
term_dict[j++] = '(';
- if (!term_101 (&termp, term_dict + j, space_split))
+ if (!term_101 (zi->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split))
return 0;
strcat (term_dict, ")");
r = dict_lookup_grep (zi->dict, term_dict, 0, grep_info,
break;
case 102: /* Regexp-1 */
term_dict[j++] = '(';
- if (!term_102 (&termp, term_dict + j, space_split))
+ if (!term_102 (zi->zebra_maps, reg_type,
+ &termp, term_dict + j, space_split))
return 0;
strcat (term_dict, ")");
logf (LOG_DEBUG, "Regexp-1 tolerance=%d", r);
logf (LOG_WARN, "dict_lookup_grep err, trunc=regular: %d",
r);
break;
- case 103: /* Regexp-1 */
+ case 103: /* Regexp-2 */
r = 1;
term_dict[j++] = '(';
- if (!term_103 (&termp, term_dict + j, &r, space_split))
+ if (!term_103 (zi->zebra_maps, reg_type,
+ &termp, term_dict + j, &r, space_split))
return 0;
strcat (term_dict, ")");
logf (LOG_DEBUG, "Regexp-2 tolerance=%d", r);
}
static void trans_scan_term (ZServerInfo *zi, Z_AttributesPlusTerm *zapt,
- char *termz)
+ char *termz, int reg_type)
{
Z_Term *term = zapt->term;
const char **map;
while ((len = (cp_end - cp)) > 0)
{
- map = map_chrs_input (0, &cp, len);
+ map = zebra_maps_input (zi->zebra_maps, reg_type, &cp, len);
if (**map == *CHR_SPACE)
space_map = *map;
else
static RSET rpn_search_APT_relevance (ZServerInfo *zi,
Z_AttributesPlusTerm *zapt,
oid_value attributeSet,
+ int reg_type, int complete_flag,
int num_bases, char **basenames)
{
rset_relevance_parms parms;
grep_info.isam_p_buf = NULL;
while (1)
{
- r = field_term (zi, zapt, &termp, 'w', attributeSet, &grep_info,
- num_bases, basenames, 1);
+ r = field_term (zi, zapt, &termp, attributeSet, &grep_info,
+ reg_type, complete_flag, num_bases, basenames);
if (r <= 0)
break;
#ifdef TERM_COUNT
return result;
}
-static RSET rpn_search_APT_cphrase (ZServerInfo *zi,
- Z_AttributesPlusTerm *zapt,
- oid_value attributeSet,
- int num_bases, char **basenames)
-{
- char termz[IT_MAX_WORD+1];
- struct grep_info grep_info;
- RSET result;
- const char *termp = termz;
- int r;
-
- if (zapt->term->which != Z_Term_general)
- {
- zi->errCode = 124;
- return NULL;
- }
- trans_term (zi, zapt, termz);
-
-#ifdef TERM_COUNT
- grep_info.term_no = 0;
-#endif
- grep_info.isam_p_indx = 0;
- grep_info.isam_p_size = 0;
- grep_info.isam_p_buf = NULL;
-
- r = field_term (zi, zapt, &termp, 'p', attributeSet, &grep_info,
- num_bases, basenames, 0);
- result = rset_trunc (zi, grep_info.isam_p_buf, grep_info.isam_p_indx);
-#ifdef TERM_COUNT
- xfree(grep_info.term_no);
-#endif
- xfree (grep_info.isam_p_buf);
- return result;
-}
-
static RSET rpn_proximity (ZServerInfo *zi, RSET rset1, RSET rset2,
int ordered,
int exclusion, int relation, int distance)
static RSET rpn_search_APT_phrase (ZServerInfo *zi,
Z_AttributesPlusTerm *zapt,
oid_value attributeSet,
+ int reg_type, int complete_flag,
int num_bases, char **basenames)
{
char termz[IT_MAX_WORD+1];
grep_info.isam_p_buf = NULL;
while (1)
- {
- grep_info.isam_p_indx = 0;
- r = field_term (zi, zapt, &termp, 'w', attributeSet, &grep_info,
- num_bases, basenames, 1);
+ {
+ logf (LOG_LOG, "APT_phrase termp=%s", termp);
+ grep_info.isam_p_indx = 0;
+ r = field_term (zi, zapt, &termp, attributeSet, &grep_info,
+ reg_type, complete_flag, num_bases, basenames);
if (r < 1)
break;
rset[rset_no] = rset_trunc (zi, grep_info.isam_p_buf,
oid_value attributeSet,
int num_bases, char **basenames)
{
- AttrType relation;
- AttrType structure;
- AttrType completeness;
- int relation_value, structure_value, completeness_value;
+ int reg_type;
+ char *search_type = NULL;
+ int complete_flag;
- attr_init (&relation, zapt, 2);
- attr_init (&structure, zapt, 4);
- attr_init (&completeness, zapt, 6);
+ zebra_maps_attr (zi->zebra_maps, zapt, ®_type, &search_type,
+ &complete_flag);
- relation_value = attr_find (&relation, NULL);
- structure_value = attr_find (&structure, NULL);
- completeness_value = attr_find (&completeness, NULL);
- switch (structure_value)
+ logf (LOG_DEBUG, "reg_type=%c", reg_type);
+ logf (LOG_DEBUG, "complete_flag=%d", complete_flag);
+ logf (LOG_DEBUG, "search_type=%s", search_type);
+ if (!strcmp (search_type, "phrase"))
+ {
+ return rpn_search_APT_phrase (zi, zapt, attributeSet,
+ reg_type, complete_flag,
+ num_bases, basenames);
+ }
+ else if (!strcmp (search_type, "ranked"))
{
- case -1:
- if (relation_value == 102) /* relevance relation */
- return rpn_search_APT_relevance (zi, zapt, attributeSet,
- num_bases, basenames);
- if (completeness_value == 2 || completeness_value == 3)
- return rpn_search_APT_cphrase (zi, zapt, attributeSet,
- num_bases, basenames);
- return rpn_search_APT_phrase (zi, zapt, attributeSet,
- num_bases, basenames);
- case 1: /* phrase */
- if (relation_value == 102) /* relevance relation */
- return rpn_search_APT_relevance (zi, zapt, attributeSet,
- num_bases, basenames);
- if (completeness_value == 2 || completeness_value == 3)
- return rpn_search_APT_cphrase (zi, zapt, attributeSet,
- num_bases, basenames);
- return rpn_search_APT_phrase (zi, zapt, attributeSet,
- num_bases, basenames);
- break;
- case 2: /* word */
- if (relation_value == 102) /* relevance relation */
- return rpn_search_APT_relevance (zi, zapt, attributeSet,
- num_bases, basenames);
- if (completeness_value == 2 || completeness_value == 3)
- return rpn_search_APT_cphrase (zi, zapt, attributeSet,
- num_bases, basenames);
- return rpn_search_APT_phrase (zi, zapt, attributeSet,
- num_bases, basenames);
- case 3: /* key */
- break;
- case 4: /* year */
- break;
- case 5: /* date - normalized */
- break;
- case 6: /* word list */
- return rpn_search_APT_relevance (zi, zapt, attributeSet,
- num_bases, basenames);
- case 100: /* date - un-normalized */
- break;
- case 101: /* name - normalized */
- break;
- case 102: /* date - un-normalized */
- break;
- case 103: /* structure */
- break;
- case 104: /* urx */
- break;
- case 105: /* free-form-text */
- return rpn_search_APT_relevance (zi, zapt, attributeSet,
- num_bases, basenames);
- case 106: /* document-text */
return rpn_search_APT_relevance (zi, zapt, attributeSet,
+ reg_type, complete_flag,
num_bases, basenames);
- case 107: /* local-number */
+ }
+ else if (!strcmp (search_type, "local"))
+ {
return rpn_search_APT_local (zi, zapt, attributeSet);
- case 108: /* string */
- return rpn_search_APT_phrase (zi, zapt, attributeSet,
- num_bases, basenames);
- case 109: /* numeric string */
- break;
}
zi->errCode = 118;
return NULL;
oident *attrset;
oid_value attributeSet;
- dict_grep_cmap (zi->dict, 0, map_chrs_input);
zlog_rpn (rpn);
zi->errCode = 0;
}
-static void scan_term_untrans (ODR odr, char **dstp, const char *src)
+static void scan_term_untrans (ZServerInfo *zi, int reg_type,
+ char **dstp, const char *src)
{
- char *dst = odr_malloc (odr, strlen(src)*2+1);
+ char *dst = odr_malloc (zi->odr, strlen(src)*2+1);
*dstp = dst;
while (*src)
{
- const char *cp = map_chrs_output (&src);
+ const char *cp = zebra_maps_output (zi->zebra_maps, reg_type, &src);
while (*cp)
*dst++ = *cp++;
}
char termz[IT_MAX_WORD+20];
AttrType use;
int use_value;
- AttrType completeness;
- int completeness_value;
struct scan_info *scan_info_array;
struct scan_entry *glist;
int ords[32], ord_no = 0;
int ptr[32];
+ int reg_type;
+ char *search_type = NULL;
+ int complete_flag;
+
logf (LOG_DEBUG, "scan, position = %d, num = %d", pos, num);
if (attributeset == VAL_NONE)
use_value = attr_find (&use, &attributeset);
logf (LOG_DEBUG, "use value %d", use_value);
- attr_init (&completeness, zapt, 6);
- completeness_value = attr_find (&completeness, NULL);
- logf (LOG_DEBUG, "completeness value %d", completeness_value);
+ if (zebra_maps_attr (zi->zebra_maps, zapt, ®_type, &search_type,
+ &complete_flag))
+ {
+ zi->errCode = 113;
+ return zi->errCode;
+ }
if (use_value == -1)
use_value = 1016;
int j, prefix_len = 0;
int before_tmp = before, after_tmp = after;
struct scan_info *scan_info = scan_info_array + i;
+ struct rpn_char_map_info rcmi;
+
+ rpn_char_map_prepare (zi, reg_type, &rcmi);
scan_info->before = before;
scan_info->after = after;
for (j = 0; j<before+after; j++)
scan_info->list[j].term = NULL;
termz[prefix_len++] = ords[i];
- termz[prefix_len++] =
- (completeness_value==2 || completeness_value==3) ? 'p': 'w';
+ termz[prefix_len++] = reg_type;
termz[prefix_len] = 0;
strcpy (scan_info->prefix, termz);
- trans_scan_term (zi, zapt, termz+prefix_len);
+ trans_scan_term (zi, zapt, termz+prefix_len, reg_type);
dict_scan (zi->dict, termz, &before_tmp, &after_tmp, scan_info,
scan_handle);
}
if (j0 == -1)
break;
- scan_term_untrans (zi->odr, &glist[i+before].term, mterm);
+ scan_term_untrans (zi, reg_type, &glist[i+before].term, mterm);
rset = rset_trunc (zi, &scan_info_array[j0].list[ptr[j0]].isam_p, 1);
ptr[j0]++;
if (j0 == -1)
break;
- scan_term_untrans (zi->odr, &glist[before-1-i].term, mterm);
+ scan_term_untrans (zi, reg_type, &glist[before-1-i].term, mterm);
rset = rset_trunc
(zi, &scan_info_array[j0].list[before-1-ptr[j0]].isam_p, 1);
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zserver.c,v $
- * Revision 1.50 1997-09-29 09:08:36 adam
+ * Revision 1.51 1997-10-27 14:33:06 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ * Revision 1.50 1997/09/29 09:08:36 adam
* Revised locking system to be thread safe for the server.
*
* Revision 1.49 1997/09/25 14:57:23 adam
return -1;
}
zi->zti = zebTargetInfo_open (zi->records, 0);
- init_charmap (zi->res);
+
return 0;
}
zi->records = NULL;
zi->odr = odr_createmem (ODR_ENCODE);
zi->registered_sets = NULL;
+ zi->zebra_maps = zebra_maps_open (res_get(zi->res, "profilePath"));
return r;
}
void bend_close (void *handle)
{
ZServerInfo *zi = handle;
+
if (zi->records)
{
resultSetDestroy (zi);
+ zebTargetInfo_close (zi->zti, 0);
dict_close (zi->dict);
if (zi->isam)
is_close (zi->isam);
rec_close (&zi->records);
register_unlock (zi);
}
+ odr_destroy (zi->odr);
+ zebra_maps_close (zi->zebra_maps);
bfs_destroy (zi->bfs);
data1_destroy (zi->dh);
zebra_server_lock_destroy (zi);
- return;
+
+ res_close (zi->res);
+ xfree (zi);
}
+#ifndef WINDOWS
+static void pre_init (struct statserv_options_block *sob)
+{
+ char *pidfile = "zebrasrv.pid";
+ int fd = creat (pidfile, 0666);
+
+ if (fd == -1)
+ logf (LOG_WARN|LOG_ERRNO, "creat %s", pidfile);
+ else
+ {
+ char pidstr[30];
+
+ sprintf (pidstr, "%ld", (long) getpid ());
+ write (fd, pidstr, strlen(pidstr));
+ close (fd);
+ }
+}
+#endif
+
int main (int argc, char **argv)
{
struct statserv_options_block *sob;
sob = statserv_getcontrol ();
strcpy (sob->configname, FNAME_CONFIG);
+#ifndef WINDOWS
+ sob->pre_init = pre_init;
+#endif
statserv_setcontrol (sob);
return statserv_main (argc, argv);
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zserver.h,v $
- * Revision 1.26 1997-09-29 12:41:35 adam
+ * Revision 1.27 1997-10-27 14:33:06 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ * Revision 1.26 1997/09/29 12:41:35 adam
* Fixed bug regarding USE_TIMES var.
*
* Revision 1.25 1997/09/29 09:08:36 adam
struct tms tms1;
struct tms tms2;
#endif
+ ZebraMaps zebra_maps;
} ZServerInfo;
int rpn_search (ZServerInfo *zi,
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: rectext.c,v $
- * Revision 1.4 1996-11-04 14:09:16 adam
+ * Revision 1.5 1997-10-27 14:33:06 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ * Revision 1.4 1996/11/04 14:09:16 adam
* Minor changes.
*
* Revision 1.3 1996/11/01 09:00:33 adam
struct buf_info *fi = buf_open (p);
(*p->init)(&recWord);
- recWord.which = Word_String;
+ recWord.reg_type = 'w';
do
{
int i = 0;
w[j] = tolower(w[j]);
w[i] = 0;
recWord.seqno = seqno++;
- recWord.u.string = w;
+ recWord.string = w;
(*p->add)(&recWord);
}
} while (r > 0);
# Copyright (C) 1994-1996, Index Data I/S
# All rights reserved.
# Sebastian Hammer, Adam Dickmeiss
-# $Id: Makefile,v 1.26 1997-09-17 12:19:23 adam Exp $
+# $Id: Makefile,v 1.27 1997-10-27 14:33:06 adam Exp $
SHELL=/bin/sh
RANLIB=ranlib
DEFS=$(INCLUDE)
CPP=$(CC) -E
LIB=../lib/zebrautl.a
-PO = res.o charmap.o
+PO = res.o charmap.o zebramap.o
all: $(LIB)
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: charmap.c,v $
- * Revision 1.12 1997-09-05 15:30:11 adam
+ * Revision 1.13 1997-10-27 14:33:06 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ * Revision 1.12 1997/09/05 15:30:11 adam
* Changed prototype for chr_map_input - added const.
* Added support for C++, headers uses extern "C" for public definitions.
*
#include <string.h>
#include <assert.h>
-#include <zebrautl.h>
#include <yaz-util.h>
#include <charmap.h>
-#include <tpath.h>
#define CHR_MAXSTR 1024
#define CHR_MAXEQUIV 32
+int chr_map_chrs(chr_t_entry *t, char **from, int len,
+ int *read, char **to, int max);
+
const char *CHR_UNKNOWN = "\001";
const char *CHR_SPACE = "\002";
const char *CHR_BASE = "\003";
+struct chrmaptab_info
+{
+ chr_t_entry *input; /* mapping table for input data */
+ chr_t_entry *query_equiv; /* mapping table for queries */
+ unsigned char *output[256]; /* return mapping - for display of registers */
+ int base_uppercase; /* Start of upper-case ordinals */
+ char **tmp_buf;
+ NMEM nmem;
+};
+
/*
* Character map trie node.
*/
*/
typedef struct chrwork
{
- chrmaptab *map;
+ chrmaptab map;
char string[CHR_MAXSTR+1];
} chrwork;
/*
* Add an entry to the character map.
*/
-static chr_t_entry *set_map_string(chr_t_entry *root, const char *from,
- int len, char *to)
+static chr_t_entry *set_map_string(chr_t_entry *root, NMEM nmem,
+ const char *from, int len, char *to)
{
if (!root)
{
- root = xmalloc(sizeof(*root));
+ root = nmem_malloc(nmem, sizeof(*root));
root->children = 0;
root->target = 0;
}
{
if (!root->target || (char*) root->target == CHR_SPACE ||
(char*) root->target == CHR_UNKNOWN)
- root->target = (unsigned char *) xstrdup(to);
+ root->target = (unsigned char *) nmem_strdup(nmem, to);
else if ((char*) to != CHR_SPACE)
logf(LOG_DEBUG, "Character map overlap");
}
{
int i;
- root->children = xmalloc(sizeof(chr_t_entry*) * 256);
+ root->children = nmem_malloc(nmem, sizeof(chr_t_entry*) * 256);
for (i = 0; i < 256; i++)
root->children[i] = 0;
}
if (!(root->children[(unsigned char) *from] =
- set_map_string(root->children[(unsigned char) *from], from + 1,
- len - 1, to)))
+ set_map_string(root->children[(unsigned char) *from], nmem,
+ from + 1, len - 1, to)))
return 0;
}
return root;
return t->target ? t : 0;
}
-const char **chr_map_input(chr_t_entry *t, const char **from, int len)
+const char **chr_map_input(chrmaptab maptab, const char **from, int len)
{
- static const char *buf[2] = {0, 0};
+ chr_t_entry *t = maptab->input;
chr_t_entry *res;
if (!(res = find_entry(t, from, len)))
abort();
- buf[0] = (char *) res->target;
- return buf;
+ maptab->tmp_buf[0] = (char*) res->target;
+ maptab->tmp_buf[1] = NULL;
+ return (const char **) maptab->tmp_buf;
}
+const char *chr_map_output(chrmaptab maptab, const char **from, int len)
+{
+ unsigned char c = ** (unsigned char **) from;
+ (*from)++;
+ return (const char*) maptab->output[c];
+}
static unsigned char prim(char **s)
{
*/
static void fun_addentry(const char *s, void *data, int num)
{
- chrmaptab *tab = data;
+ chrmaptab tab = data;
char tmp[2];
tmp[0] = num; tmp[1] = '\0';
- tab->input = set_map_string(tab->input, s, strlen(s), tmp);
- tab->output[num + tab->base_uppercase] = (unsigned char *) xstrdup(s);
+ tab->input = set_map_string(tab->input, tab->nmem, s, strlen(s), tmp);
+ tab->output[num + tab->base_uppercase] =
+ (unsigned char *) nmem_strdup(tab->nmem, s);
}
/*
*/
static void fun_addspace(const char *s, void *data, int num)
{
- chrmaptab *tab = data;
- tab->input = set_map_string(tab->input, s, strlen(s), (char*) CHR_SPACE);
+ chrmaptab tab = data;
+ tab->input = set_map_string(tab->input, tab->nmem, s, strlen(s),
+ (char*) CHR_SPACE);
}
/*
chrwork *arg = data;
const char **res, *p = s;
- res = chr_map_input(arg->map->input, &s, strlen(s));
+ res = chr_map_input(arg->map, &s, strlen(s));
if (*res == (char*) CHR_UNKNOWN)
logf(LOG_WARN, "Map: '%s' has no mapping", p);
strncat(arg->string, *res, CHR_MAXSTR - strlen(arg->string));
chrwork *arg = data;
assert(arg->map->input);
- set_map_string(arg->map->input, s, strlen(s), arg->string);
+ set_map_string(arg->map->input, arg->map->nmem, s, strlen(s), arg->string);
}
static int scan_string(char *s, void (*fun)(const char *c, void *data, int num),
return 0;
}
-chrmaptab *chr_read_maptab(const char *tabpath, const char *name)
+chrmaptab chrmaptab_create(const char *tabpath, const char *name, int map_only)
{
FILE *f;
char line[512], *argv[50];
- chrmaptab *res = xmalloc(sizeof(*res));
+ chrmaptab res;
int argc, num = (int) *CHR_BASE, i;
if (!(f = yaz_path_fopen(tabpath, name, "r")))
return 0;
}
res = xmalloc(sizeof(*res));
- res->input = xmalloc(sizeof(*res->input));
+ res->nmem = nmem_create ();
+ res->tmp_buf = nmem_malloc (res->nmem, sizeof(*res->tmp_buf) * 100);
+ res->input = nmem_malloc(res->nmem, sizeof(*res->input));
res->input->target = (unsigned char*) CHR_UNKNOWN;
res->input->equiv = 0;
-#if 1
- res->input->children = xmalloc(sizeof(res->input) * 256);
+ res->input->children = nmem_malloc(res->nmem, sizeof(res->input) * 256);
for (i = 0; i < 256; i++)
{
- res->input->children[i] = xmalloc(sizeof(*res->input));
+ res->input->children[i] = nmem_malloc(res->nmem, sizeof(*res->input));
res->input->children[i]->children = 0;
- res->input->children[i]->target = (unsigned char*) CHR_UNKNOWN;
+ if (map_only)
+ {
+ res->input->children[i]->target = nmem_malloc (res->nmem,
+ 2 * sizeof(char));
+ res->input->children[i]->target[0] = i;
+ res->input->children[i]->target[1] = 0;
+ }
+ else
+ res->input->children[i]->target = (unsigned char*) CHR_UNKNOWN;
res->input->children[i]->equiv = 0;
}
-#else
- res->input->children = 0;
-#endif
res->query_equiv = 0;
for (i = *CHR_BASE; i < 256; i++)
res->output[i] = 0;
res->base_uppercase = 0;
while ((argc = readconf_line(f, line, 512, argv, 50)))
- if (!yaz_matchstr(argv[0], "lowercase"))
+ if (!map_only && !yaz_matchstr(argv[0], "lowercase"))
{
if (argc != 2)
{
res->output[(int) *CHR_UNKNOWN + num] = (unsigned char*) "@";
num = (int) *CHR_BASE;
}
- else if (!yaz_matchstr(argv[0], "uppercase"))
+ else if (!map_only && !yaz_matchstr(argv[0], "uppercase"))
{
if (!res->base_uppercase)
{
return 0;
}
}
- else if (!yaz_matchstr(argv[0], "space"))
+ else if (!map_only && !yaz_matchstr(argv[0], "space"))
{
if (argc != 2)
{
}
else
{
-#if 0
- logf(LOG_WARN, "Syntax error at '%s' in %s", line, file);
- fclose(f);
- return 0;
-#endif
+ logf(LOG_WARN, "Syntax error at '%s' in %s", line, name);
}
fclose(f);
return res;
}
+
+void chrmaptab_destroy(chrmaptab tab)
+{
+ nmem_destroy (tab->nmem);
+ xfree (tab);
+}
+
+
--- /dev/null
+/*
+ * Copyright (C) 1994-1997, Index Data I/S
+ * All rights reserved.
+ * Sebastian Hammer, Adam Dickmeiss
+ *
+ * $Log: zebramap.c,v $
+ * Revision 1.1 1997-10-27 14:33:06 adam
+ * Moved towards generic character mapping depending on "structure"
+ * field in abstract syntax file. Fixed a few memory leaks. Fixed
+ * bug with negative integers when doing searches with relational
+ * operators.
+ *
+ */
+
+#include <assert.h>
+#include <ctype.h>
+
+#include <yaz-util.h>
+#include <charmap.h>
+#include <zebramap.h>
+
+struct zebra_map {
+ int reg_type;
+ chrmaptab maptab;
+ struct zebra_map *next;
+};
+
+struct zebra_maps {
+ char *tabpath;
+ NMEM nmem;
+ struct zebra_map *map_list;
+};
+
+void zebra_maps_close (ZebraMaps zms)
+{
+ struct zebra_map *zm = zms->map_list;
+ while (zm)
+ {
+ struct zebra_map *zm_next = zm->next;
+
+ chrmaptab_destroy (zm->maptab);
+ xfree (zm);
+ zm = zm_next;
+ }
+ nmem_destroy (zms->nmem);
+ xfree (zms);
+}
+
+ZebraMaps zebra_maps_open (const char *tabpath)
+{
+ ZebraMaps zms = xmalloc (sizeof(*zms));
+
+ zms->nmem = nmem_create ();
+ zms->tabpath = nmem_strdup (zms->nmem, tabpath);
+ zms->map_list = NULL;
+ return zms;
+}
+
+chrmaptab zebra_map_get (ZebraMaps zms, int reg_type)
+{
+ char name[512];
+ struct zebra_map *zm;
+
+ for (zm = zms->map_list; zm; zm = zm->next)
+ {
+ if (reg_type == zm->reg_type)
+ return zm->maptab;
+ }
+ *name = '\0';
+ switch (reg_type)
+ {
+ case 'w':
+ case 'p':
+ strcat (name, "string");
+ break;
+ case 'n':
+ strcat (name, "numeric");
+ break;
+ case 'u':
+ strcat (name, "urx");
+ break;
+ default:
+ strcat (name, "null");
+ }
+ strcat (name, ".chr");
+
+ zm = xmalloc (sizeof(*zm));
+ zm->reg_type = reg_type;
+ zm->next = zms->map_list;
+ zms->map_list = zm;
+ if (!(zm->maptab = chrmaptab_create (zms->tabpath, name, 0)))
+ logf(LOG_WARN, "Failed to read character table %s", name);
+ else
+ logf(LOG_LOG, "Read table %s", name);
+ return zm->maptab;
+}
+
+const char **zebra_maps_input (ZebraMaps zms, int reg_type,
+ const char **from, int len)
+{
+ static char str[2] = {0,0};
+ static const char *buf[2] = {0,0};
+ chrmaptab maptab;
+
+ maptab = zebra_map_get (zms, reg_type);
+ if (maptab)
+ return chr_map_input(maptab, from, len);
+
+ if (isalnum(**from))
+ {
+ str[0] = isupper(**from) ? tolower(**from) : **from;
+ buf[0] = str;
+ }
+ else
+ buf[0] = (char*) CHR_SPACE;
+ (*from)++;
+ return buf;
+}
+
+const char *zebra_maps_output(ZebraMaps zms, int reg_type, const char **from)
+{
+ chrmaptab maptab;
+ unsigned char i = (unsigned char) **from;
+ static char buf[2] = {0,0};
+
+ maptab = zebra_map_get (zms, reg_type);
+ if (maptab)
+ return chr_map_output (maptab, from, 1);
+ (*from)++;
+ buf[0] = i;
+ return buf;
+}
+
+
+/* ------------------------------------ */
+
+typedef struct {
+ int type;
+ int major;
+ int minor;
+ Z_AttributesPlusTerm *zapt;
+} AttrType;
+
+static int attr_find (AttrType *src, oid_value *attributeSetP)
+{
+ while (src->major < src->zapt->num_attributes)
+ {
+ Z_AttributeElement *element;
+
+ element = src->zapt->attributeList[src->major];
+ if (src->type == *element->attributeType)
+ {
+ switch (element->which)
+ {
+ case Z_AttributeValue_numeric:
+ ++(src->major);
+ if (element->attributeSet && attributeSetP)
+ {
+ oident *attrset;
+
+ attrset = oid_getentbyoid (element->attributeSet);
+ *attributeSetP = attrset->value;
+ }
+ return *element->value.numeric;
+ break;
+ case Z_AttributeValue_complex:
+ if (src->minor >= element->value.complex->num_list ||
+ element->value.complex->list[src->minor]->which !=
+ Z_StringOrNumeric_numeric)
+ break;
+ ++(src->minor);
+ if (element->attributeSet && attributeSetP)
+ {
+ oident *attrset;
+
+ attrset = oid_getentbyoid (element->attributeSet);
+ *attributeSetP = attrset->value;
+ }
+ return *element->value.complex->list[src->minor-1]->u.numeric;
+ default:
+ assert (0);
+ }
+ }
+ ++(src->major);
+ }
+ return -1;
+}
+
+static void attr_init (AttrType *src, Z_AttributesPlusTerm *zapt,
+ int type)
+{
+ src->zapt = zapt;
+ src->type = type;
+ src->major = 0;
+ src->minor = 0;
+}
+
+/* ------------------------------------ */
+
+int zebra_maps_is_complete (ZebraMaps zms, int reg_type)
+{
+ if (reg_type == 'p')
+ return 1;
+ return 0;
+}
+
+int zebra_maps_attr (ZebraMaps zms, Z_AttributesPlusTerm *zapt,
+ int *reg_type, char **search_type, int *complete_flag)
+{
+ AttrType completeness;
+ AttrType structure;
+ AttrType relation;
+ int completeness_value;
+ int structure_value;
+ int relation_value;
+
+ attr_init (&structure, zapt, 4);
+ attr_init (&completeness, zapt, 6);
+ attr_init (&relation, zapt, 2);
+
+ completeness_value = attr_find (&completeness, NULL);
+ structure_value = attr_find (&structure, NULL);
+
+ if (completeness_value == 2 || completeness_value == 3)
+ *complete_flag = 1;
+ else
+ *complete_flag = 0;
+ *reg_type = 0;
+
+ *search_type = "phrase";
+ if (relation_value == 102)
+ *search_type = "ranked";
+
+ switch (structure_value)
+ {
+ case -1:
+ case 1: /* phrase */
+ case 2: /* word */
+ case 3: /* key */
+ case 6: /* word list */
+ case 105: /* free-form-text */
+ case 106: /* document-text */
+ case 108: /* string */
+ if (*complete_flag)
+ *reg_type = 'p';
+ else
+ *reg_type = 'w';
+ break;
+ case 107: /* local-number */
+ *search_type = "local";
+ *reg_type = 0;
+ case 109: /* numeric string */
+ *reg_type = 'n';
+ break;
+ case 104: /* urx */
+ *reg_type = 'u';
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}