2 * Copyright (c) 1995-2000, 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.7 2002-04-04 20:49:46 adam
28 * New functions yaz_is_abspath, yaz_path_fopen_base
30 * Revision 1.6 2000/12/05 12:21:45 adam
31 * Added termlist source for data1 system.
33 * Revision 1.5 2000/11/29 14:22:47 adam
34 * Implemented XML/SGML attributes for data1 so that d1_read reads them
35 * and d1_write generates proper attributes for XML/SGML records. Added
36 * register locking for threaded version.
38 * Revision 1.4 2000/02/28 11:20:06 adam
39 * Using autoconf. New definitions: YAZ_BEGIN_CDECL/YAZ_END_CDECL.
41 * Revision 1.3 2000/01/04 17:46:17 ian
42 * Added function to count occurences of a tag spec in a data1 tree.
44 * Revision 1.2 1999/12/21 14:16:19 ian
45 * Changed retrieval module to allow data1 trees with no associated absyn.
46 * Also added a simple interface for extracting values from data1 trees using
47 * a string based tagpath.
49 * Revision 1.1 1999/11/30 13:47:11 adam
50 * Improved installation. Moved header files to include/yaz.
52 * Revision 1.42 1999/10/21 12:06:28 adam
53 * Retrieval module no longer uses ctype.h - functions.
55 * Revision 1.41 1999/07/13 13:23:47 adam
56 * Non-recursive version of data1_read_node. data1_read_nodex reads
57 * stream of bytes (instead of buffer in memory).
59 * Revision 1.40 1998/11/03 10:14:12 adam
60 * Changed definition of data1 node so that it uses less space.
62 * Revision 1.39 1998/10/28 15:10:06 adam
63 * Added --with-yc option to configure. For the data1_node in data1.h:
64 * decreased size of localdata and removed member "line" which wasn't useful.
66 * Revision 1.38 1998/10/15 08:29:15 adam
67 * Tag set type may be specified in reference to it using "tagset"
68 * directive in .abs-files and "include" directive in .tag-files.
70 * Revision 1.37 1998/10/13 16:09:46 adam
71 * Added support for arbitrary OID's for tagsets, schemas and attribute sets.
72 * Added support for multiple attribute set references and tagset references
73 * from an abstract syntax file.
74 * Fixed many bad logs-calls in routines that read the various
75 * specifications regarding data1 (*.abs,*.att,...) and made the messages
76 * consistent whenever possible.
77 * Added extra 'lineno' argument to function readconf_line.
79 * Revision 1.36 1998/05/18 13:06:57 adam
80 * Changed the way attribute sets are handled by the retriaval module.
81 * Extended Explain conversion / schema.
82 * Modified server and client to work with ASN.1 compiled protocol handlers.
84 * Revision 1.35 1998/03/05 08:15:32 adam
85 * Implemented data1_add_insert_taggeddata utility which is more flexible
86 * than data1_insert_taggeddata.
88 * Revision 1.34 1998/02/27 14:08:04 adam
89 * Added const to some char pointer arguments.
90 * Reworked data1_read_node so that it doesn't create a tree with
91 * pointers to original "SGML"-buffer.
93 * Revision 1.33 1997/12/18 10:51:30 adam
94 * Implemented sub-trees feature for schemas - including forward
97 * Revision 1.32 1997/12/09 16:18:16 adam
98 * Work on EXPLAIN schema. First implementation of sub-schema facility
101 * Revision 1.31 1997/11/18 09:51:08 adam
102 * Removed element num_children from data1_node. Minor changes in
105 * Revision 1.30 1997/10/31 12:20:07 adam
106 * Improved memory debugging for xmalloc/nmem.c. References to NMEM
107 * instead of ODR in n ESPEC-1 handling in source d1_espec.c.
108 * Bug fix: missing fclose in data1_read_espec1.
110 * Revision 1.29 1997/10/27 13:54:18 adam
111 * Changed structure field in data1 node to be simple string which
112 * is "unknown" to the retrieval system itself.
114 * Revision 1.28 1997/10/06 09:37:53 adam
115 * Added prototype for data1_get_map_buf.
117 * Revision 1.27 1997/09/24 13:35:44 adam
118 * Added two members to data1_marctab to ease reading of weird MARC records.
120 * Revision 1.26 1997/09/17 12:10:32 adam
123 * Revision 1.25 1997/09/05 09:50:55 adam
124 * Removed global data1_tabpath - uses data1_get_tabpath() instead.
126 * Revision 1.24 1997/09/01 09:30:39 adam
127 * Added include of yaz-util.h.
129 * Revision 1.23 1997/09/01 08:58:04 adam
130 * Removed declaration of data1_matchstr since it's a macro.
132 * Revision 1.22 1997/09/01 08:49:48 adam
133 * New windows NT/95 port using MSV5.0. To export DLL functions the
134 * YAZ_EXPORT modifier was added. Defined in yconfig.h.
136 * Revision 1.21 1997/05/14 06:53:38 adam
139 * Revision 1.20 1996/10/29 13:34:39 adam
140 * New functions to get/set data1_tabpath.
142 * Revision 1.19 1996/10/11 11:57:16 quinn
145 * Revision 1.18 1996/10/07 15:29:16 quinn
148 * Revision 1.17 1996/07/06 19:58:32 quinn
149 * System headerfiles gathered in yconfig
151 * Revision 1.16 1996/06/10 08:55:34 quinn
152 * Added Summary. Unfinished work
154 * Revision 1.15 1996/06/03 09:46:03 quinn
157 * Revision 1.14 1996/05/09 07:27:11 quinn
158 * Multiple local values supported.
160 * Revision 1.13 1996/02/20 16:32:48 quinn
163 * Revision 1.12 1996/01/18 09:46:34 adam
164 * Changed prototype for reader function parsed to data1_read_record.
166 * Revision 1.11 1995/12/15 16:19:45 quinn
167 * Added formatted_text.
169 * Revision 1.10 1995/12/14 11:09:43 quinn
172 * Revision 1.9 1995/12/13 15:32:47 quinn
175 * Revision 1.8 1995/12/13 13:44:23 quinn
176 * Modified Data1-system to use nmem
178 * Revision 1.7 1995/12/12 16:37:05 quinn
179 * Added destroy element to data1_node.
181 * Revision 1.6 1995/12/11 15:22:12 quinn
182 * Added last_child field to the node.
184 * Revision 1.5 1995/12/05 14:26:40 quinn
185 * Added global lbuf to data1_node.
187 * Revision 1.4 1995/11/13 09:27:29 quinn
188 * Fiddling with the variant stuff.
190 * Revision 1.3 1995/11/01 16:34:52 quinn
191 * Making data1 look for tables in data1_tabpath
193 * Revision 1.2 1995/11/01 13:54:35 quinn
196 * Revision 1.1 1995/11/01 13:07:18 quinn
197 * Data1 module now lives in YAZ.
199 * Revision 1.13 1995/10/25 16:00:49 quinn
200 * USMARC support is now almost operational
202 * Revision 1.12 1995/10/16 14:02:59 quinn
203 * Changes to support element set names and espec1
205 * Revision 1.11 1995/10/13 16:05:10 quinn
206 * Adding Espec1-processing
208 * Revision 1.10 1995/10/11 14:53:46 quinn
211 * Revision 1.9 1995/10/10 16:27:59 quinn
212 * *** empty log message ***
214 * Revision 1.8 1995/10/06 16:44:14 quinn
215 * Work on attribute set mapping, etc.
217 * Revision 1.7 1995/10/06 12:58:36 quinn
220 * Revision 1.6 1995/10/04 09:29:51 quinn
221 * Adjustments to support USGS test data
223 * Revision 1.5 1995/10/03 17:56:44 quinn
226 * Revision 1.4 1995/10/02 14:55:43 quinn
227 * *** empty log message ***
229 * Revision 1.3 1995/09/15 14:41:43 quinn
232 * Revision 1.2 1995/09/14 15:18:14 quinn
235 * Revision 1.1 1995/09/12 11:24:33 quinn
236 * Beginning to add code for structured records.
246 #include <yaz/nmem.h>
248 #include <yaz/proto.h>
250 #include <yaz/d1_attset.h>
251 #include <yaz/d1_map.h>
252 #include <yaz/yaz-util.h>
253 #include <yaz/wrbuf.h>
255 #define d1_isspace(c) strchr(" \r\n\t\f", c)
256 #define d1_isdigit(c) ((c) <= '9' && (c) >= '0')
258 #define DATA1_USING_XATTR 1
262 #define data1_matchstr(s1, s2) yaz_matchstr(s1, s2)
264 #define DATA1_MAX_SYMBOL 31
266 typedef struct data1_name
269 struct data1_name *next;
272 typedef struct data1_absyn_cache_info *data1_absyn_cache;
273 typedef struct data1_attset_cache_info *data1_attset_cache;
275 typedef enum data1_datatype
283 DATA1K_generalizedtime,
290 typedef struct data1_marctab
295 char record_status[2];
296 char implementation_codes[5];
297 int indicator_length;
298 int identifier_length;
299 char user_systems[4];
301 int length_data_entry;
303 int length_implementation;
306 int force_indicator_length;
307 int force_identifier_length;
308 struct data1_marctab *next;
311 typedef struct data1_esetname
315 struct data1_esetname *next;
319 * Variant set definitions.
322 typedef struct data1_vartype
325 struct data1_varclass *zclass;
327 data1_datatype datatype;
328 struct data1_vartype *next;
331 typedef struct data1_varclass
334 struct data1_varset *set;
336 data1_vartype *types;
337 struct data1_varclass *next;
340 typedef struct data1_varset
344 data1_varclass *classes;
353 typedef struct data1_tag
356 #define DATA1T_numeric 1
357 #define DATA1T_string 2
366 struct data1_tagset *tagset;
367 struct data1_tag *next;
370 typedef struct data1_tagset data1_tagset;
374 int type; /* type of tagset in current context */
375 char *name; /* symbolic name */
377 data1_tag *tags; /* tags defined by this set */
378 data1_tagset *children; /* children */
379 data1_tagset *next; /* sibling */
382 typedef struct data1_termlist
387 struct data1_termlist *next;
391 * abstract syntax specification
394 typedef struct data1_element
398 data1_termlist *termlists;
400 struct data1_element *children;
401 struct data1_element *next;
404 typedef struct data1_sub_elements {
406 struct data1_sub_elements *next;
407 data1_element *elements;
408 } data1_sub_elements;
410 #if DATA1_USING_XATTR
411 typedef struct data1_xattr {
414 struct data1_xattr *next;
418 typedef struct data1_absyn
422 data1_tagset *tagset;
423 data1_attset *attset;
424 data1_varset *varset;
425 data1_esetname *esetnames;
426 data1_maptab *maptabs;
428 data1_sub_elements *sub_elements;
429 data1_element *main_elements;
433 * record data node (tag/data/variant)
436 typedef struct data1_node
438 /* the root of a record (containing global data) */
439 #define DATA1N_root 1
442 /* some data under a leaf tag or variant */
443 #define DATA1N_data 3
444 /* variant specification (a triple, actually) */
445 #define DATA1N_variant 4
453 data1_absyn *absyn; /* abstract syntax for this type */
459 data1_element *element;
460 int no_data_requested;
462 unsigned node_selected : 1;
463 unsigned make_variantlist : 1;
464 #if DATA1_USING_XATTR
465 data1_xattr *attributes;
471 char *data; /* filename or data */
474 #define DATA1I_inctxt 1
475 /* binary data inclusion */
476 #define DATA1I_incbin 2
478 #define DATA1I_text 3
481 /* object identifier */
484 unsigned formatted_text : 1; /* newlines are significant */
494 void (*destroy)(struct data1_node *n);
495 #define DATA1_LOCALDATA 12
496 char lbuf[DATA1_LOCALDATA]; /* small buffer for local data */
497 struct data1_node *next;
498 struct data1_node *child;
499 struct data1_node *last_child;
500 struct data1_node *parent;
501 struct data1_node *root;
504 YAZ_EXPORT data1_handle data1_create (void);
505 YAZ_EXPORT void data1_destroy(data1_handle dh);
506 YAZ_EXPORT data1_node *get_parent_tag(data1_handle dh, data1_node *n);
507 YAZ_EXPORT data1_node *data1_read_node(data1_handle dh, const char **buf,
509 YAZ_EXPORT data1_node *data1_read_nodex (data1_handle dh, NMEM m,
510 int (*get_byte)(void *fh), void *fh,
512 YAZ_EXPORT data1_node *data1_read_record(data1_handle dh,
513 int (*rf)(void *, char *, size_t),
515 YAZ_EXPORT data1_absyn *data1_read_absyn(data1_handle dh, const char *file);
516 YAZ_EXPORT data1_tag *data1_gettagbynum(data1_handle dh,
518 int type, int value);
519 YAZ_EXPORT data1_tagset *data1_empty_tagset (data1_handle dh);
520 YAZ_EXPORT data1_tagset *data1_read_tagset(data1_handle dh,
523 YAZ_EXPORT data1_element *data1_getelementbytagname(data1_handle dh,
525 data1_element *parent,
526 const char *tagname);
527 YAZ_EXPORT Z_GenericRecord *data1_nodetogr(data1_handle dh, data1_node *n,
530 YAZ_EXPORT data1_tag *data1_gettagbyname(data1_handle dh, data1_tagset *s,
532 YAZ_EXPORT void data1_free_tree(data1_handle dh, data1_node *t);
533 YAZ_EXPORT char *data1_nodetobuf(data1_handle dh, data1_node *n,
534 int select, int *len);
535 YAZ_EXPORT data1_node *data1_insert_taggeddata(data1_handle dh,
538 const char *tagname, NMEM m);
539 YAZ_EXPORT data1_node *data1_add_taggeddata(data1_handle dh, data1_node *root,
541 const char *tagname, NMEM m);
542 YAZ_EXPORT data1_datatype data1_maptype(data1_handle dh, char *t);
543 YAZ_EXPORT data1_varset *data1_read_varset(data1_handle dh, const char *file);
544 YAZ_EXPORT data1_vartype *data1_getvartypebyct(data1_handle dh,
546 char *zclass, char *type);
547 YAZ_EXPORT Z_Espec1 *data1_read_espec1(data1_handle dh, const char *file);
548 YAZ_EXPORT int data1_doespec1(data1_handle dh, data1_node *n, Z_Espec1 *e);
549 YAZ_EXPORT data1_esetname *data1_getesetbyname(data1_handle dh,
552 YAZ_EXPORT data1_element *data1_getelementbyname(data1_handle dh,
555 YAZ_EXPORT data1_node *data1_mk_node(data1_handle dh, NMEM m);
556 YAZ_EXPORT data1_node *data1_mk_node_type (data1_handle dh, NMEM m, int type);
557 YAZ_EXPORT data1_absyn *data1_get_absyn(data1_handle dh, const char *name);
558 YAZ_EXPORT data1_attset *data1_get_attset (data1_handle dh, const char *name);
559 YAZ_EXPORT data1_maptab *data1_read_maptab(data1_handle dh, const char *file);
560 YAZ_EXPORT data1_node *data1_map_record(data1_handle dh, data1_node *n,
561 data1_maptab *map, NMEM m);
562 YAZ_EXPORT data1_marctab *data1_read_marctab (data1_handle dh,
564 YAZ_EXPORT char *data1_nodetomarc(data1_handle dh, data1_marctab *p,
565 data1_node *n, int selected, int *len);
566 YAZ_EXPORT char *data1_nodetoidsgml(data1_handle dh, data1_node *n,
567 int select, int *len);
568 YAZ_EXPORT Z_ExplainRecord *data1_nodetoexplain(data1_handle dh,
569 data1_node *n, int select,
571 YAZ_EXPORT Z_BriefBib *data1_nodetosummary(data1_handle dh,
572 data1_node *n, int select,
574 YAZ_EXPORT char *data1_nodetosoif(data1_handle dh, data1_node *n, int select,
576 YAZ_EXPORT void data1_set_tabpath(data1_handle dh, const char *path);
577 YAZ_EXPORT void data1_set_tabroot (data1_handle dp, const char *p);
578 YAZ_EXPORT const char *data1_get_tabpath(data1_handle dh);
579 YAZ_EXPORT const char *data1_get_tabroot(data1_handle dh);
581 YAZ_EXPORT WRBUF data1_get_wrbuf (data1_handle dp);
582 YAZ_EXPORT char **data1_get_read_buf (data1_handle dp, int **lenp);
583 YAZ_EXPORT char **data1_get_map_buf (data1_handle dp, int **lenp);
584 YAZ_EXPORT data1_absyn_cache *data1_absyn_cache_get (data1_handle dh);
585 YAZ_EXPORT data1_attset_cache *data1_attset_cache_get (data1_handle dh);
586 YAZ_EXPORT NMEM data1_nmem_get (data1_handle dh);
587 YAZ_EXPORT void data1_pr_tree (data1_handle dh, data1_node *n, FILE *out);
588 YAZ_EXPORT char *data1_insert_string (data1_handle dh, data1_node *res,
589 NMEM m, const char *str);
590 YAZ_EXPORT data1_node *data1_read_sgml (data1_handle dh, NMEM m,
592 YAZ_EXPORT void data1_absyn_trav (data1_handle dh, void *handle,
593 void (*fh)(data1_handle dh,
594 void *h, data1_absyn *a));
596 YAZ_EXPORT data1_attset *data1_attset_search_id (data1_handle dh, int id);
598 YAZ_EXPORT data1_node
599 *data1_add_insert_taggeddata(data1_handle dh, data1_node *root,
600 data1_node *at, const char *tagname, NMEM m,
601 int first_flag, int local_allowed);
603 YAZ_EXPORT char *data1_getNodeValue(data1_node* node, char* pTagPath);
604 YAZ_EXPORT data1_node *data1_LookupNode(data1_node* node, char* pTagPath);
605 YAZ_EXPORT int data1_CountOccurences(data1_node* node, char* pTagPath);
607 YAZ_EXPORT FILE *data1_path_fopen (data1_handle dh, const char *file,