2 * Copyright (c) 1995-1998, Index Data.
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation, in whole or in part, for any purpose, is hereby granted,
8 * 1. This copyright and permission notice appear in all copies of the
9 * software and its documentation. Notices of copyright or attribution
10 * which appear at the beginning of any file must remain unchanged.
12 * 2. The names of Index Data or the individual authors may not be used to
13 * endorse or promote products derived from this software without specific
14 * prior written permission.
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19 * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
20 * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
21 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR
22 * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
27 * Revision 1.40 1998-11-03 10:14:12 adam
28 * Changed definition of data1 node so that it uses less space.
30 * Revision 1.39 1998/10/28 15:10:06 adam
31 * Added --with-yc option to configure. For the data1_node in data1.h:
32 * decreased size of localdata and removed member "line" which wasn't useful.
34 * Revision 1.38 1998/10/15 08:29:15 adam
35 * Tag set type may be specified in reference to it using "tagset"
36 * directive in .abs-files and "include" directive in .tag-files.
38 * Revision 1.37 1998/10/13 16:09:46 adam
39 * Added support for arbitrary OID's for tagsets, schemas and attribute sets.
40 * Added support for multiple attribute set references and tagset references
41 * from an abstract syntax file.
42 * Fixed many bad logs-calls in routines that read the various
43 * specifications regarding data1 (*.abs,*.att,...) and made the messages
44 * consistent whenever possible.
45 * Added extra 'lineno' argument to function readconf_line.
47 * Revision 1.36 1998/05/18 13:06:57 adam
48 * Changed the way attribute sets are handled by the retriaval module.
49 * Extended Explain conversion / schema.
50 * Modified server and client to work with ASN.1 compiled protocol handlers.
52 * Revision 1.35 1998/03/05 08:15:32 adam
53 * Implemented data1_add_insert_taggeddata utility which is more flexible
54 * than data1_insert_taggeddata.
56 * Revision 1.34 1998/02/27 14:08:04 adam
57 * Added const to some char pointer arguments.
58 * Reworked data1_read_node so that it doesn't create a tree with
59 * pointers to original "SGML"-buffer.
61 * Revision 1.33 1997/12/18 10:51:30 adam
62 * Implemented sub-trees feature for schemas - including forward
65 * Revision 1.32 1997/12/09 16:18:16 adam
66 * Work on EXPLAIN schema. First implementation of sub-schema facility
69 * Revision 1.31 1997/11/18 09:51:08 adam
70 * Removed element num_children from data1_node. Minor changes in
73 * Revision 1.30 1997/10/31 12:20:07 adam
74 * Improved memory debugging for xmalloc/nmem.c. References to NMEM
75 * instead of ODR in n ESPEC-1 handling in source d1_espec.c.
76 * Bug fix: missing fclose in data1_read_espec1.
78 * Revision 1.29 1997/10/27 13:54:18 adam
79 * Changed structure field in data1 node to be simple string which
80 * is "unknown" to the retrieval system itself.
82 * Revision 1.28 1997/10/06 09:37:53 adam
83 * Added prototype for data1_get_map_buf.
85 * Revision 1.27 1997/09/24 13:35:44 adam
86 * Added two members to data1_marctab to ease reading of weird MARC records.
88 * Revision 1.26 1997/09/17 12:10:32 adam
91 * Revision 1.25 1997/09/05 09:50:55 adam
92 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
94 * Revision 1.24 1997/09/01 09:30:39 adam
95 * Added include of yaz-util.h.
97 * Revision 1.23 1997/09/01 08:58:04 adam
98 * Removed declaration of data1_matchstr since it's a macro.
100 * Revision 1.22 1997/09/01 08:49:48 adam
101 * New windows NT/95 port using MSV5.0. To export DLL functions the
102 * YAZ_EXPORT modifier was added. Defined in yconfig.h.
104 * Revision 1.21 1997/05/14 06:53:38 adam
107 * Revision 1.20 1996/10/29 13:34:39 adam
108 * New functions to get/set data1_tabpath.
110 * Revision 1.19 1996/10/11 11:57:16 quinn
113 * Revision 1.18 1996/10/07 15:29:16 quinn
116 * Revision 1.17 1996/07/06 19:58:32 quinn
117 * System headerfiles gathered in yconfig
119 * Revision 1.16 1996/06/10 08:55:34 quinn
120 * Added Summary. Unfinished work
122 * Revision 1.15 1996/06/03 09:46:03 quinn
125 * Revision 1.14 1996/05/09 07:27:11 quinn
126 * Multiple local values supported.
128 * Revision 1.13 1996/02/20 16:32:48 quinn
131 * Revision 1.12 1996/01/18 09:46:34 adam
132 * Changed prototype for reader function parsed to data1_read_record.
134 * Revision 1.11 1995/12/15 16:19:45 quinn
135 * Added formatted_text.
137 * Revision 1.10 1995/12/14 11:09:43 quinn
140 * Revision 1.9 1995/12/13 15:32:47 quinn
143 * Revision 1.8 1995/12/13 13:44:23 quinn
144 * Modified Data1-system to use nmem
146 * Revision 1.7 1995/12/12 16:37:05 quinn
147 * Added destroy element to data1_node.
149 * Revision 1.6 1995/12/11 15:22:12 quinn
150 * Added last_child field to the node.
152 * Revision 1.5 1995/12/05 14:26:40 quinn
153 * Added global lbuf to data1_node.
155 * Revision 1.4 1995/11/13 09:27:29 quinn
156 * Fiddling with the variant stuff.
158 * Revision 1.3 1995/11/01 16:34:52 quinn
159 * Making data1 look for tables in data1_tabpath
161 * Revision 1.2 1995/11/01 13:54:35 quinn
164 * Revision 1.1 1995/11/01 13:07:18 quinn
165 * Data1 module now lives in YAZ.
167 * Revision 1.13 1995/10/25 16:00:49 quinn
168 * USMARC support is now almost operational
170 * Revision 1.12 1995/10/16 14:02:59 quinn
171 * Changes to support element set names and espec1
173 * Revision 1.11 1995/10/13 16:05:10 quinn
174 * Adding Espec1-processing
176 * Revision 1.10 1995/10/11 14:53:46 quinn
179 * Revision 1.9 1995/10/10 16:27:59 quinn
180 * *** empty log message ***
182 * Revision 1.8 1995/10/06 16:44:14 quinn
183 * Work on attribute set mapping, etc.
185 * Revision 1.7 1995/10/06 12:58:36 quinn
188 * Revision 1.6 1995/10/04 09:29:51 quinn
189 * Adjustments to support USGS test data
191 * Revision 1.5 1995/10/03 17:56:44 quinn
194 * Revision 1.4 1995/10/02 14:55:43 quinn
195 * *** empty log message ***
197 * Revision 1.3 1995/09/15 14:41:43 quinn
200 * Revision 1.2 1995/09/14 15:18:14 quinn
203 * Revision 1.1 1995/09/12 11:24:33 quinn
204 * Beginning to add code for structured records.
218 #include <d1_attset.h>
220 #include <yaz-util.h>
227 #define data1_matchstr(s1, s2) yaz_matchstr(s1, s2)
229 #define DATA1_MAX_SYMBOL 31
231 typedef struct data1_name
234 struct data1_name *next;
237 typedef struct data1_absyn_cache_info *data1_absyn_cache;
238 typedef struct data1_attset_cache_info *data1_attset_cache;
240 typedef enum data1_datatype
248 DATA1K_generalizedtime,
255 typedef struct data1_marctab
260 char record_status[2];
261 char implementation_codes[5];
262 int indicator_length;
263 int identifier_length;
264 char user_systems[4];
266 int length_data_entry;
268 int length_implementation;
271 int force_indicator_length;
272 int force_identifier_length;
273 struct data1_marctab *next;
276 typedef struct data1_esetname
280 struct data1_esetname *next;
284 * Variant set definitions.
287 typedef struct data1_vartype
290 struct data1_varclass *zclass;
292 data1_datatype datatype;
293 struct data1_vartype *next;
296 typedef struct data1_varclass
299 struct data1_varset *set;
301 data1_vartype *types;
302 struct data1_varclass *next;
305 typedef struct data1_varset
309 data1_varclass *classes;
318 typedef struct data1_tag
321 #define DATA1T_numeric 1
322 #define DATA1T_string 2
331 struct data1_tagset *tagset;
332 struct data1_tag *next;
335 typedef struct data1_tagset data1_tagset;
339 int type; /* type of tagset in current context */
340 char *name; /* symbolic name */
342 data1_tag *tags; /* tags defined by this set */
343 data1_tagset *children; /* children */
344 data1_tagset *next; /* sibling */
347 typedef struct data1_termlist
351 struct data1_termlist *next;
355 * abstract syntax specification
358 typedef struct data1_element
362 data1_termlist *termlists;
364 struct data1_element *children;
365 struct data1_element *next;
368 typedef struct data1_sub_elements {
370 struct data1_sub_elements *next;
371 data1_element *elements;
372 } data1_sub_elements;
374 typedef struct data1_absyn
378 data1_tagset *tagset;
379 data1_attset *attset;
380 data1_varset *varset;
381 data1_esetname *esetnames;
382 data1_maptab *maptabs;
384 data1_sub_elements *sub_elements;
385 data1_element *main_elements;
389 * record data node (tag/data/variant)
392 typedef struct data1_node
394 /* the root of a record (containing global data) */
395 #define DATA1N_root 1
398 /* some data under a leaf tag or variant */
399 #define DATA1N_data 3
400 /* variant specification (a triple, actually) */
401 #define DATA1N_variant 4
409 data1_absyn *absyn; /* abstract syntax for this type */
415 data1_element *element;
416 int no_data_requested;
418 unsigned node_selected : 1;
419 unsigned make_variantlist : 1;
424 char *data; /* filename or data */
427 #define DATA1I_inctxt 1
428 /* binary data inclusion */
429 #define DATA1I_incbin 2
431 #define DATA1I_text 3
434 /* object identifier */
437 unsigned formatted_text : 1; /* newlines are significant */
447 void (*destroy)(struct data1_node *n);
448 #define DATA1_LOCALDATA 12
449 char lbuf[DATA1_LOCALDATA]; /* small buffer for local data */
450 struct data1_node *next;
451 struct data1_node *child;
452 struct data1_node *last_child;
453 struct data1_node *parent;
454 struct data1_node *root;
457 YAZ_EXPORT data1_handle data1_create (void);
458 YAZ_EXPORT void data1_destroy(data1_handle dh);
459 YAZ_EXPORT data1_node *get_parent_tag(data1_handle dh, data1_node *n);
460 YAZ_EXPORT data1_node *data1_read_node(data1_handle dh, const char **buf,
462 int *line, data1_absyn *absyn, NMEM m);
463 YAZ_EXPORT data1_node *data1_read_record(data1_handle dh,
464 int (*rf)(void *, char *, size_t),
466 YAZ_EXPORT data1_absyn *data1_read_absyn(data1_handle dh, const char *file);
467 YAZ_EXPORT data1_tag *data1_gettagbynum(data1_handle dh,
469 int type, int value);
470 YAZ_EXPORT data1_tagset *data1_empty_tagset (data1_handle dh);
471 YAZ_EXPORT data1_tagset *data1_read_tagset(data1_handle dh,
474 YAZ_EXPORT data1_element *data1_getelementbytagname(data1_handle dh,
476 data1_element *parent,
477 const char *tagname);
478 YAZ_EXPORT Z_GenericRecord *data1_nodetogr(data1_handle dh, data1_node *n,
481 YAZ_EXPORT data1_tag *data1_gettagbyname(data1_handle dh, data1_tagset *s,
483 YAZ_EXPORT void data1_free_tree(data1_handle dh, data1_node *t);
484 YAZ_EXPORT char *data1_nodetobuf(data1_handle dh, data1_node *n,
485 int select, int *len);
486 YAZ_EXPORT data1_node *data1_insert_taggeddata(data1_handle dh,
489 const char *tagname, NMEM m);
490 YAZ_EXPORT data1_node *data1_add_taggeddata(data1_handle dh, data1_node *root,
492 const char *tagname, NMEM m);
493 YAZ_EXPORT data1_datatype data1_maptype(data1_handle dh, char *t);
494 YAZ_EXPORT data1_varset *data1_read_varset(data1_handle dh, const char *file);
495 YAZ_EXPORT data1_vartype *data1_getvartypebyct(data1_handle dh,
497 char *zclass, char *type);
498 YAZ_EXPORT Z_Espec1 *data1_read_espec1(data1_handle dh, const char *file);
499 YAZ_EXPORT int data1_doespec1(data1_handle dh, data1_node *n, Z_Espec1 *e);
500 YAZ_EXPORT data1_esetname *data1_getesetbyname(data1_handle dh,
503 YAZ_EXPORT data1_element *data1_getelementbyname(data1_handle dh,
506 YAZ_EXPORT data1_node *data1_mk_node(data1_handle dh, NMEM m);
507 YAZ_EXPORT data1_absyn *data1_get_absyn(data1_handle dh, const char *name);
508 YAZ_EXPORT data1_attset *data1_get_attset (data1_handle dh, const char *name);
509 YAZ_EXPORT data1_maptab *data1_read_maptab(data1_handle dh, const char *file);
510 YAZ_EXPORT data1_node *data1_map_record(data1_handle dh, data1_node *n,
511 data1_maptab *map, NMEM m);
512 YAZ_EXPORT data1_marctab *data1_read_marctab (data1_handle dh,
514 YAZ_EXPORT char *data1_nodetomarc(data1_handle dh, data1_marctab *p,
515 data1_node *n, int selected, int *len);
516 YAZ_EXPORT char *data1_nodetoidsgml(data1_handle dh, data1_node *n,
517 int select, int *len);
518 YAZ_EXPORT Z_ExplainRecord *data1_nodetoexplain(data1_handle dh,
519 data1_node *n, int select,
521 YAZ_EXPORT Z_BriefBib *data1_nodetosummary(data1_handle dh,
522 data1_node *n, int select,
524 YAZ_EXPORT char *data1_nodetosoif(data1_handle dh, data1_node *n, int select,
526 YAZ_EXPORT void data1_set_tabpath(data1_handle dh, const char *path);
527 YAZ_EXPORT const char *data1_get_tabpath(data1_handle dh);
529 YAZ_EXPORT WRBUF data1_get_wrbuf (data1_handle dp);
530 YAZ_EXPORT char **data1_get_read_buf (data1_handle dp, int **lenp);
531 YAZ_EXPORT char **data1_get_map_buf (data1_handle dp, int **lenp);
532 YAZ_EXPORT data1_absyn_cache *data1_absyn_cache_get (data1_handle dh);
533 YAZ_EXPORT data1_attset_cache *data1_attset_cache_get (data1_handle dh);
534 YAZ_EXPORT NMEM data1_nmem_get (data1_handle dh);
535 YAZ_EXPORT void data1_pr_tree (data1_handle dh, data1_node *n, FILE *out);
536 YAZ_EXPORT char *data1_insert_string (data1_handle dh, data1_node *res,
537 NMEM m, const char *str);
538 YAZ_EXPORT data1_node *data1_read_sgml (data1_handle dh, NMEM m,
540 YAZ_EXPORT void data1_absyn_trav (data1_handle dh, void *handle,
541 void (*fh)(data1_handle dh,
542 void *h, data1_absyn *a));
544 YAZ_EXPORT data1_attset *data1_attset_search_id (data1_handle dh, int id);
546 YAZ_EXPORT data1_node
547 *data1_add_insert_taggeddata(data1_handle dh, data1_node *root,
548 data1_node *at, const char *tagname, NMEM m,
549 int first_flag, int local_allowed);