Improved installation. Updated for inclusion of YAZ header files.
[idzebra-moved-to-github.git] / include / recctrl.h
1 /*
2  * Copyright (C) 1994-1998, Index Data
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: recctrl.h,v $
7  * Revision 1.32  1999-11-30 13:48:03  adam
8  * Improved installation. Updated for inclusion of YAZ header files.
9  *
10  * Revision 1.31  1999/09/07 07:19:21  adam
11  * Work on character mapping. Implemented replace rules.
12  *
13  * Revision 1.30  1999/05/21 12:00:17  adam
14  * Better diagnostics for extraction process.
15  *
16  * Revision 1.29  1999/05/20 12:57:18  adam
17  * Implemented TCL filter. Updated recctrl system.
18  *
19  * Revision 1.28  1999/03/02 16:15:42  quinn
20  * Added "tagsysno" and "tagrank" directives to zebra.cfg.
21  *
22  * Revision 1.27  1998/10/16 08:14:28  adam
23  * Updated record control system.
24  *
25  * Revision 1.26  1998/05/20 10:12:12  adam
26  * Implemented automatic EXPLAIN database maintenance.
27  * Modified Zebra to work with ASN.1 compiled version of YAZ.
28  *
29  * Revision 1.25  1998/03/11 11:19:04  adam
30  * Changed the way sequence numbers are generated.
31  *
32  * Revision 1.24  1998/03/05 08:38:46  adam
33  * New member recordSize in recRetrieveCtrl.
34  *
35  * Revision 1.23  1998/02/10 12:03:05  adam
36  * Implemented Sort.
37  *
38  * Revision 1.22  1997/10/27 14:33:04  adam
39  * Moved towards generic character mapping depending on "structure"
40  * field in abstract syntax file. Fixed a few memory leaks. Fixed
41  * bug with negative integers when doing searches with relational
42  * operators.
43  *
44  * Revision 1.21  1997/09/18 08:59:19  adam
45  * Extra generic handle for the character mapping routines.
46  *
47  * Revision 1.20  1997/09/17 12:19:10  adam
48  * Zebra version corresponds to YAZ version 1.4.
49  * Changed Zebra server so that it doesn't depend on global common_resource.
50  *
51  * Revision 1.19  1997/09/05 15:30:02  adam
52  * Changed prototype for chr_map_input - added const.
53  * Added support for C++, headers uses extern "C" for public definitions.
54  *
55  * Revision 1.18  1997/09/04 13:56:15  adam
56  * Added new filter grs.marc.<syntax> where <syntax> refers to
57  * abstract syntax. New method tellf in extract/retrieve control
58  * block.
59  *
60  * Revision 1.17  1997/04/30 08:56:04  quinn
61  * null
62  *
63  * Revision 1.16  1996/10/11  10:56:25  adam
64  * New module recctrl. Used to manage records (extract/retrieval).
65  * All record types are accessed by means of definitions in recctrl.h.
66  *
67  * Revision 1.15  1996/06/06 12:08:16  quinn
68  * Added showRecord Group entry
69  *
70  * Revision 1.14  1996/05/09  07:28:49  quinn
71  * Work towards phrases and multiple registers
72  *
73  * Revision 1.13  1996/05/01  13:44:05  adam
74  * Added seek function to the recExtractCtrl and recRetrieveCtrl control
75  * structures. Added end-of-file indicator function and start offset to
76  * recExtractCtrl.
77  *
78  * Revision 1.12  1996/01/17  15:01:25  adam
79  * Prototype changed for reader functions in extract/retrieve. File
80  *  is identified by 'void *' instead of 'int'.
81  *
82  * Revision 1.11  1995/12/04  14:20:54  adam
83  * Extra arg to recType_byName.
84  *
85  * Revision 1.10  1995/10/16  14:03:06  quinn
86  * Changes to support element set names and espec1
87  *
88  * Revision 1.9  1995/10/06  14:37:53  adam
89  * New result set method: r_score.
90  * Local no (sysno) and score is transferred to retrieveCtrl.
91  *
92  * Revision 1.8  1995/10/02  15:43:35  adam
93  * Extract uses file descriptors instead of FILE pointers.
94  *
95  * Revision 1.7  1995/10/02  15:18:09  adam
96  * Minor changes.
97  *
98  * Revision 1.6  1995/10/02  15:05:26  quinn
99  * Added a few fields.
100  *
101  * Revision 1.5  1995/10/02  14:55:52  quinn
102  * *** empty log message ***
103  *
104  * Revision 1.4  1995/09/27  16:17:29  adam
105  * More work on retrieve.
106  *
107  * Revision 1.3  1995/09/27  12:21:25  adam
108  * New function: recType_byName.
109  *
110  * Revision 1.2  1995/09/15  14:45:03  adam
111  * Retrieve control.
112  *
113  * Revision 1.1  1995/09/14  07:48:13  adam
114  * Record control management.
115  *
116  */
117
118 #ifndef RECCTRL_H
119 #define RECCTRL_H
120
121 #include <yaz/proto.h>
122 #include <yaz/oid.h>
123 #include <yaz/odr.h>
124 #include <yaz/data1.h>
125 #include <zebramap.h>
126
127 #ifdef __cplusplus
128 extern "C" {
129 #endif
130
131 /* single word entity */
132 typedef struct {
133     int  attrSet;
134     int  attrUse;
135     unsigned reg_type;
136     char *string;
137     int  length;
138     int  *seqnos;
139     ZebraMaps zebra_maps;
140     struct recExtractCtrl *extractCtrl;
141 } RecWord;
142
143 /* Extract record control */
144 struct recExtractCtrl {
145     void      *fh;                    /* File handle and read function     */
146     int       (*readf)(void *fh, char *buf, size_t count);
147     off_t     (*seekf)(void *fh, off_t offset);  /* seek function          */
148     off_t     (*tellf)(void *fh);                /* tell function          */
149     void      (*endf)(void *fh, off_t offset);   /* end of record position */
150     off_t     offset;                            /* start offset           */
151     char      *subType;
152     void      (*init)(struct recExtractCtrl *p, RecWord *w);
153     void      *clientData;
154     void      (*tokenAdd)(RecWord *w);
155     ZebraMaps zebra_maps;
156     int       flagShowRecords;
157     int       seqno[256];
158     void      (*schemaAdd)(struct recExtractCtrl *p, Odr_oid *oid);
159     data1_handle dh;
160 };
161
162 /* Retrieve record control */
163 struct recRetrieveCtrl {
164     /* Input parameters ... */
165     Res       res;                    /* Resource pool                     */
166     ODR       odr;                    /* ODR used to create response       */
167     void     *fh;                     /* File descriptor and read function */
168     int       (*readf)(void *fh, char *buf, size_t count);
169     off_t     (*seekf)(void *fh, off_t offset);
170     off_t     (*tellf)(void *fh);
171     oid_value input_format;           /* Preferred record syntax           */
172     Z_RecordComposition *comp;        /* formatting instructions           */
173     int       localno;                /* local id of record                */
174     int       score;                  /* score 0-1000 or -1 if none        */
175     int       recordSize;             /* size of record in bytes */
176     char      *subType;
177     data1_handle dh;
178     
179     /* response */
180     oid_value  output_format;
181     void       *rec_buf;
182     size_t     rec_len;
183     int        diagnostic;
184     char *message;
185 };
186
187 typedef struct recType *RecType;
188
189 struct recType
190 {
191     char *name;                           /* Name of record type */
192     void *(*init)(RecType recType);       /* Init function - called once */
193     void (*destroy)(void *clientData);    /* Destroy function */
194     int  (*extract)(void *clientData,
195                     struct recExtractCtrl *ctrl);   /* Extract proc */
196     int  (*retrieve)(void *clientData,
197                      struct recRetrieveCtrl *ctrl); /* Retrieve proc */
198 };
199
200 #define RECCTRL_EXTRACT_OK    0
201 #define RECCTRL_EXTRACT_EOF   1
202 #define RECCTRL_EXTRACT_ERROR 2
203
204 typedef struct recTypes *RecTypes;
205
206 RecTypes recTypes_init (data1_handle dh);
207 void recTypes_destroy (RecTypes recTypes);
208 void recTypes_default_handlers (RecTypes recTypes);
209
210 RecType recType_byName (RecTypes rts, const char *name, char *subType,
211                         void **clientDataP);
212
213 int grs_extract_tree(struct recExtractCtrl *p, data1_node *n);
214
215 #ifdef __cplusplus
216 }
217 #endif
218
219 #endif