7a78de2ff8f53f7309b71f5f559e23ea4f898c4c
[idzebra-moved-to-github.git] / index / index.h
1 /*
2  * Copyright (C) 1995-2002, Index Data
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
5  * $Id: index.h,v 1.74 2002-03-21 10:25:42 adam Exp $
6  */
7
8 #ifndef INDEX_H
9 #define INDEX_H
10
11 #include <time.h>
12 #include <zebraver.h>
13 #include <zebrautl.h>
14 #include <zebramap.h>
15
16 #include <dict.h>
17 #include <isams.h>
18 #if ZMBOL
19 #include <isam.h>
20 #include <isamc.h>
21 #include <isamd.h>
22 #define ISAM_DEFAULT "c"
23 #else
24 #define ISAM_DEFAULT "s"
25 #endif
26 #include <yaz/data1.h>
27 #include <recctrl.h>
28 #include "zebraapi.h"
29
30 YAZ_BEGIN_CDECL
31
32 #define SU_SCHEME 1
33
34 #define IT_MAX_WORD 256
35 #define IT_KEY_HAVE_SEQNO 1
36 #define IT_KEY_HAVE_FIELD 0
37
38 typedef int SYSNO;
39
40 struct it_key {
41     int  sysno;
42     int  seqno;
43 };
44
45 enum dirsKind { dirs_dir, dirs_file };
46
47 struct dir_entry {
48     enum dirsKind kind;
49     char *name;
50     time_t mtime;
51 };
52
53 struct dirs_entry {
54     enum dirsKind kind;
55     char path[256];
56     SYSNO sysno;
57     time_t mtime;
58 };
59
60 struct recordGroup {
61     char         *groupName;
62     char         *databaseName;
63     char         *path;
64     char         *recordId;
65     char         *recordType;
66     int          flagStoreData;
67     int          flagStoreKeys;
68     int          flagRw;
69     int          fileVerboseLimit;
70     int          databaseNamePath;
71     int          explainDatabase;
72 };
73
74 void getFnameTmp (Res res, char *fname, int no);
75         
76 struct dirs_info *dirs_open (Dict dict, const char *rep, int rw);
77 struct dirs_info *dirs_fopen (Dict dict, const char *path);
78 struct dirs_entry *dirs_read (struct dirs_info *p);
79 struct dirs_entry *dirs_last (struct dirs_info *p);
80 void dirs_mkdir (struct dirs_info *p, const char *src, time_t mtime);
81 void dirs_rmdir (struct dirs_info *p, const char *src);
82 void dirs_add (struct dirs_info *p, const char *src, int sysno, time_t mtime);
83 void dirs_del (struct dirs_info *p, const char *src);
84 void dirs_free (struct dirs_info **pp);
85
86 struct dir_entry *dir_open (const char *rep);
87 void dir_sort (struct dir_entry *e);
88 void dir_free (struct dir_entry **e_p);
89
90 void repositoryUpdate (ZebraHandle zh);
91 void repositoryAdd (ZebraHandle zh);
92 void repositoryDelete (ZebraHandle zh);
93 void repositoryShow (ZebraHandle zh);
94
95 int key_open (ZebraHandle zh, int mem);
96 int key_close (ZebraHandle zh);
97 int key_compare (const void *p1, const void *p2);
98 int key_get_pos (const void *p);
99 int key_compare_it (const void *p1, const void *p2);
100 int key_qsort_compare (const void *p1, const void *p2);
101 void key_logdump (int mask, const void *p);
102 void inv_prstat (ZebraHandle zh);
103 void inv_compact (BFiles bfs);
104 void key_input (ZebraHandle zh, int nkeys, int cache, Res res);
105 ISAMS_M key_isams_m (Res res, ISAMS_M me);
106 #if ZMBOL
107 ISAMC_M key_isamc_m (Res res, ISAMC_M me);
108 ISAMD_M key_isamd_m (Res res, ISAMD_M me);
109 #endif
110 int merge_sort (char **buf, int from, int to);
111 int key_SU_code (int ch, char *out);
112
113 #define FNAME_DICT "dict"
114 #define FNAME_ISAM "isam"
115 #define FNAME_ISAMC "isamc"
116 #define FNAME_ISAMS "isams"
117 #define FNAME_ISAMH "isamh"
118 #define FNAME_ISAMD "isamd"
119 #define FNAME_CONFIG "zebra.cfg"
120
121 #define GMATCH_DICT "gmatch"
122 #define FMATCH_DICT "fmatch"
123
124 struct strtab *strtab_mk (void);
125 int strtab_src (struct strtab *t, const char *name, void ***infop);
126 void strtab_del (struct strtab *t,
127                  void (*func)(const char *name, void *info, void *data),
128                  void *data);
129 int index_char_cvt (int c);
130 int index_word_prefix (char *string, int attset_ordinal,
131                        int local_attribute, const char *databaseName);
132
133 int fileExtract (ZebraHandle zh, SYSNO *sysno, const char *fname,
134                  const struct recordGroup *rGroup, int deleteFlag);
135
136 void zebraIndexLockMsg (ZebraHandle zh, const char *str);
137 void zebraIndexUnlock (ZebraHandle zh);
138 int zebraIndexLock (BFiles bfs, ZebraHandle zh, int commitNow, const char *rval);
139 int zebraIndexWait (ZebraHandle zh, int commitPhase);
140
141 #define FNAME_MAIN_LOCK   "zebraidx.LCK"
142 #define FNAME_COMMIT_LOCK "zebracmt.LCK"
143 #define FNAME_ORG_LOCK    "zebraorg.LCK"
144 #define FNAME_TOUCH_TIME  "zebraidx.time"
145
146 typedef struct zebra_lock_info *ZebraLockHandle;
147 ZebraLockHandle zebra_lock_create(const char *dir,
148                                   const char *file, int excl_flag);
149 void zebra_lock_destroy (ZebraLockHandle h);
150 int zebra_lock (ZebraLockHandle h);
151 int zebra_lock_nb (ZebraLockHandle h);
152 int zebra_unlock (ZebraLockHandle h);
153 int zebra_lock_fd (ZebraLockHandle h);
154 void zebra_lock_prefix (Res res, char *dst);
155 char *zebra_mk_fname (const char *dir, const char *name);
156
157 int zebra_lock_w (ZebraLockHandle h);
158 int zebra_lock_r (ZebraLockHandle h);
159
160 void zebra_load_atts (data1_handle dh, Res res);
161
162 int key_SU_decode (int *ch, const unsigned char *out);
163 int key_SU_encode (int ch, char *out);
164
165 // extern Res common_resource;
166
167 struct encode_info {
168     int  sysno;
169     int  seqno;
170     int  cmd;
171     char buf[768];
172 };
173
174 void encode_key_init (struct encode_info *i);
175 char *encode_key_int (int d, char *bp);
176 void encode_key_write (char *k, struct encode_info *i, FILE *outf);
177
178
179 YAZ_END_CDECL
180
181 #endif