1 /* $Id: data1.h,v 1.11 2006-03-29 10:43:24 adam Exp $
2 Copyright (C) 1995-2005
5 This file is part of the Zebra server.
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra. If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
30 #include <yaz/proto.h>
31 #include <yaz/yaz-util.h>
33 #include <idzebra/util.h>
35 #define d1_isspace(c) strchr(" \r\n\t\f", c)
36 #define d1_isdigit(c) ((c) <= '9' && (c) >= '0')
40 #define data1_matchstr(s1, s2) yaz_matchstr(s1, s2)
42 #define DATA1_MAX_SYMBOL 31
45 * This structure describes a attset, perhaps made up by inclusion
46 * (supersetting) of other attribute sets. When indexing and searching,
47 * we perform a normalisation, where we associate a given tag with
48 * the set that originally defined it, rather than the superset. This
49 * allows the most flexible access. Eg, the tags common to GILS and BIB-1
50 * should be searchable by both names.
55 typedef struct data1_local_attribute
58 struct data1_local_attribute *next;
59 } data1_local_attribute;
61 typedef struct data1_attset data1_attset;
62 typedef struct data1_att data1_att;
63 typedef struct data1_attset_child data1_attset_child;
67 data1_attset *parent; /* attribute set */
68 char *name; /* symbolic name of this attribute */
69 int value; /* attribute value */
70 data1_local_attribute *locals; /* local index values */
74 struct data1_attset_child {
76 data1_attset_child *next;
81 char *name; /* symbolic name */
82 oid_value reference; /* external ID of attset */
83 data1_att *atts; /* attributes */
84 data1_attset_child *children; /* included attset */
85 data1_attset *next; /* next in cache */
88 typedef struct data1_handle_info *data1_handle;
90 YAZ_EXPORT data1_att *data1_getattbyname(data1_handle dh, data1_attset *s,
92 YAZ_EXPORT data1_attset *data1_read_attset(data1_handle dh, const char *file);
94 YAZ_EXPORT data1_attset *data1_empty_attset(data1_handle dh);
96 typedef struct data1_maptag
100 #define D1_MAPTAG_numeric 1
101 #define D1_MAPTAG_string 2
108 struct data1_maptag *next;
111 typedef struct data1_mapunit
114 char *source_element_name;
115 data1_maptag *target_path;
116 struct data1_mapunit *next;
119 typedef struct data1_maptab
122 oid_value target_absyn_ref;
123 char *target_absyn_name;
125 struct data1_maptab *next;
128 typedef struct data1_name
131 struct data1_name *next;
134 typedef struct data1_absyn_cache_info *data1_absyn_cache;
135 typedef struct data1_attset_cache_info *data1_attset_cache;
136 typedef struct data1_absyn data1_absyn;
138 typedef enum data1_datatype
146 DATA1K_generalizedtime,
153 typedef struct data1_marctab
158 char record_status[2];
159 char implementation_codes[5];
160 int indicator_length;
161 int identifier_length;
162 char user_systems[4];
164 int length_data_entry;
166 int length_implementation;
169 int force_indicator_length;
170 int force_identifier_length;
171 char leader[24]; /* Fixme! Need linear access to LEADER of MARC record */
172 struct data1_marctab *next;
175 typedef struct data1_esetname
179 struct data1_esetname *next;
183 * Variant set definitions.
186 typedef struct data1_vartype
189 struct data1_varclass *zclass;
191 data1_datatype datatype;
192 struct data1_vartype *next;
195 typedef struct data1_varclass
198 struct data1_varset *set;
200 data1_vartype *types;
201 struct data1_varclass *next;
204 typedef struct data1_varset
208 data1_varclass *classes;
217 typedef struct data1_tag
220 #define DATA1T_numeric 1
221 #define DATA1T_string 2
230 struct data1_tagset *tagset;
231 struct data1_tag *next;
234 typedef struct data1_tagset data1_tagset;
238 int type; /* type of tagset in current context */
239 char *name; /* symbolic name */
241 data1_tag *tags; /* tags defined by this set */
242 data1_tagset *children; /* children */
243 data1_tagset *next; /* sibling */
246 typedef struct data1_termlist
255 struct data1_termlist *next;
259 * abstract syntax specification
262 typedef struct data1_element
266 data1_termlist *termlists;
268 struct data1_element *children;
269 struct data1_element *next;
270 struct data1_hash_table *hash;
273 typedef struct data1_sub_elements {
275 struct data1_sub_elements *next;
276 data1_element *elements;
277 } data1_sub_elements;
279 typedef struct data1_xattr {
282 struct data1_xattr *next;
283 unsigned short what; /* DATA1I_text, .. see data1_node.u.data */
288 * record data node (tag/data/variant)
291 typedef struct data1_node
293 /* the root of a record (containing global data) */
294 #define DATA1N_root 1
297 /* some data under a leaf tag or variant */
298 #define DATA1N_data 3
299 /* variant specification (a triple, actually) */
300 #define DATA1N_variant 4
301 /* comment (same as data) */
302 #define DATA1N_comment 5
303 /* preprocessing instruction */
304 #define DATA1N_preprocess 6
311 struct data1_absyn *absyn; /* abstract syntax for this type */
317 data1_element *element;
318 int no_data_requested;
320 unsigned node_selected : 1;
321 unsigned make_variantlist : 1;
322 data1_xattr *attributes;
327 char *data; /* filename or data */
330 #define DATA1I_inctxt 1
331 /* binary data inclusion */
332 #define DATA1I_incbin 2
334 #define DATA1I_text 3
337 /* object identifier */
340 #define DATA1I_xmltext 6
342 unsigned formatted_text : 1; /* newlines are significant */
354 data1_xattr *attributes;
358 void (*destroy)(struct data1_node *n);
359 #define DATA1_LOCALDATA 12
360 char lbuf[DATA1_LOCALDATA]; /* small buffer for local data */
361 struct data1_node *next;
362 struct data1_node *child;
363 struct data1_node *last_child;
364 struct data1_node *parent;
365 struct data1_node *root;
368 YAZ_EXPORT data1_handle data1_create (void);
371 YAZ_EXPORT void data1_destroy(data1_handle dh);
372 YAZ_EXPORT data1_node *get_parent_tag(data1_handle dh, data1_node *n);
373 YAZ_EXPORT data1_node *data1_read_node(data1_handle dh, const char **buf,
375 YAZ_EXPORT data1_node *data1_read_nodex (data1_handle dh, NMEM m,
376 int (*get_byte)(void *fh), void *fh,
378 YAZ_EXPORT data1_node *data1_read_record(data1_handle dh,
379 int (*rf)(void *, char *, size_t),
381 YAZ_EXPORT data1_absyn *data1_read_absyn(data1_handle dh, const char *file,
382 int file_must_exist);
383 YAZ_EXPORT data1_tag *data1_gettagbynum(data1_handle dh,
385 int type, int value);
386 YAZ_EXPORT data1_tagset *data1_empty_tagset (data1_handle dh);
387 YAZ_EXPORT data1_tagset *data1_read_tagset(data1_handle dh,
390 YAZ_EXPORT data1_element *data1_getelementbytagname(data1_handle dh,
392 data1_element *parent,
393 const char *tagname);
394 YAZ_EXPORT Z_GenericRecord *data1_nodetogr(data1_handle dh, data1_node *n,
397 YAZ_EXPORT data1_tag *data1_gettagbyname(data1_handle dh, data1_tagset *s,
399 YAZ_EXPORT void data1_free_tree(data1_handle dh, data1_node *t);
400 YAZ_EXPORT char *data1_nodetobuf(data1_handle dh, data1_node *n,
401 int select, int *len);
402 YAZ_EXPORT data1_node *data1_mk_tag_data_wd(data1_handle dh,
404 const char *tagname, NMEM m);
405 YAZ_EXPORT data1_node *data1_mk_tag_data(data1_handle dh, data1_node *at,
406 const char *tagname, NMEM m);
407 YAZ_EXPORT data1_datatype data1_maptype(data1_handle dh, char *t);
408 YAZ_EXPORT data1_varset *data1_read_varset(data1_handle dh, const char *file);
409 YAZ_EXPORT data1_vartype *data1_getvartypebyct(data1_handle dh,
413 YAZ_EXPORT data1_vartype *data1_getvartypeby_absyn(data1_handle dh,
415 char *zclass, char *type);
416 YAZ_EXPORT Z_Espec1 *data1_read_espec1(data1_handle dh, const char *file);
417 YAZ_EXPORT int data1_doespec1(data1_handle dh, data1_node *n, Z_Espec1 *e);
418 YAZ_EXPORT data1_esetname *data1_getesetbyname(data1_handle dh,
421 YAZ_EXPORT data1_element *data1_getelementbyname(data1_handle dh,
424 YAZ_EXPORT data1_node *data1_mk_node2(data1_handle dh, NMEM m,
425 int type, data1_node *parent);
427 YAZ_EXPORT data1_node *data1_mk_tag (data1_handle dh, NMEM nmem,
428 const char *tag, const char **attr,
430 YAZ_EXPORT data1_node *data1_mk_tag_n (data1_handle dh, NMEM nmem,
431 const char *tag, size_t len,
434 YAZ_EXPORT void data1_tag_add_attr (data1_handle dh, NMEM nmem,
435 data1_node *res, const char **attr);
437 YAZ_EXPORT data1_node *data1_mk_text_n (data1_handle dh, NMEM mem,
438 const char *buf, size_t len,
440 YAZ_EXPORT data1_node *data1_mk_text_nf (data1_handle dh, NMEM mem,
441 const char *buf, size_t len,
443 YAZ_EXPORT data1_node *data1_mk_text (data1_handle dh, NMEM mem,
444 const char *buf, data1_node *parent);
446 YAZ_EXPORT data1_node *data1_mk_comment_n (data1_handle dh, NMEM mem,
447 const char *buf, size_t len,
450 YAZ_EXPORT data1_node *data1_mk_comment (data1_handle dh, NMEM mem,
451 const char *buf, data1_node *parent);
453 YAZ_EXPORT data1_node *data1_mk_preprocess_n (data1_handle dh, NMEM nmem,
454 const char *target, size_t len,
458 YAZ_EXPORT data1_node *data1_mk_preprocess (data1_handle dh, NMEM nmem,
463 YAZ_EXPORT data1_node *data1_insert_preprocess_n (data1_handle dh, NMEM nmem,
469 YAZ_EXPORT data1_node *data1_insert_preprocess (data1_handle dh, NMEM nmem,
474 YAZ_EXPORT data1_node *data1_mk_root (data1_handle dh, NMEM nmem,
476 YAZ_EXPORT void data1_set_root(data1_handle dh, data1_node *res,
477 NMEM nmem, const char *name);
479 YAZ_EXPORT data1_node *data1_mk_tag_data_zint (data1_handle dh, data1_node *at,
480 const char *tag, zint num,
482 YAZ_EXPORT data1_node *data1_mk_tag_data_int (data1_handle dh, data1_node *at,
483 const char *tag, int num,
485 YAZ_EXPORT data1_node *data1_mk_tag_data_oid (data1_handle dh, data1_node *at,
486 const char *tag, Odr_oid *oid,
488 YAZ_EXPORT data1_node *data1_mk_tag_data_text (data1_handle dh, data1_node *at,
492 YAZ_EXPORT data1_node *data1_mk_tag_data_text_uni (data1_handle dh,
498 YAZ_EXPORT data1_absyn *data1_get_absyn (data1_handle dh, const char *name);
500 YAZ_EXPORT data1_node *data1_search_tag (data1_handle dh, data1_node *n,
502 YAZ_EXPORT data1_node *data1_mk_tag_uni (data1_handle dh, NMEM nmem,
503 const char *tag, data1_node *at);
504 YAZ_EXPORT data1_attset *data1_get_attset (data1_handle dh, const char *name);
505 YAZ_EXPORT data1_maptab *data1_read_maptab(data1_handle dh, const char *file);
506 YAZ_EXPORT data1_node *data1_map_record(data1_handle dh, data1_node *n,
507 data1_maptab *map, NMEM m);
508 YAZ_EXPORT data1_marctab *data1_read_marctab (data1_handle dh,
510 YAZ_EXPORT data1_marctab *data1_absyn_getmarctab(data1_handle dh,
512 YAZ_EXPORT data1_element *data1_absyn_getelements(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 void data1_set_tabroot (data1_handle dp, const char *p);
528 YAZ_EXPORT const char *data1_get_tabpath(data1_handle dh);
529 YAZ_EXPORT const char *data1_get_tabroot(data1_handle dh);
531 YAZ_EXPORT WRBUF data1_get_wrbuf (data1_handle dp);
532 YAZ_EXPORT char **data1_get_read_buf (data1_handle dp, int **lenp);
533 YAZ_EXPORT char **data1_get_map_buf (data1_handle dp, int **lenp);
534 YAZ_EXPORT data1_absyn_cache *data1_absyn_cache_get (data1_handle dh);
535 YAZ_EXPORT data1_attset_cache *data1_attset_cache_get (data1_handle dh);
536 YAZ_EXPORT NMEM data1_nmem_get (data1_handle dh);
537 YAZ_EXPORT void data1_pr_tree (data1_handle dh, data1_node *n, FILE *out);
538 YAZ_EXPORT char *data1_insert_string (data1_handle dh, data1_node *res,
539 NMEM m, const char *str);
540 YAZ_EXPORT char *data1_insert_string_n (data1_handle dh, data1_node *res,
541 NMEM m, const char *str, size_t len);
542 YAZ_EXPORT data1_node *data1_read_sgml (data1_handle dh, NMEM m,
544 YAZ_EXPORT data1_node *data1_read_xml (data1_handle dh,
545 int (*rf)(void *, char *, size_t),
547 YAZ_EXPORT void data1_absyn_trav (data1_handle dh, void *handle,
548 void (*fh)(data1_handle dh,
549 void *h, data1_absyn *a));
551 YAZ_EXPORT data1_attset *data1_attset_search_id (data1_handle dh, int id);
553 YAZ_EXPORT char *data1_getNodeValue(data1_node* node, char* pTagPath);
554 YAZ_EXPORT data1_node *data1_LookupNode(data1_node* node, char* pTagPath);
555 YAZ_EXPORT int data1_CountOccurences(data1_node* node, char* pTagPath);
557 YAZ_EXPORT FILE *data1_path_fopen (data1_handle dh, const char *file,
560 /* obsolete functions ... */
562 YAZ_EXPORT data1_node *data1_mk_node (data1_handle dh, NMEM m);
563 YAZ_EXPORT data1_node *data1_insert_taggeddata (data1_handle dh,
566 const char *tagname, NMEM m);
567 YAZ_EXPORT data1_node *data1_mk_node_type (data1_handle dh, NMEM m, int type);
568 YAZ_EXPORT data1_node *data1_add_taggeddata (data1_handle dh, data1_node *root,
573 YAZ_EXPORT data1_node *data1_get_root_tag (data1_handle dh, data1_node *n);
575 YAZ_EXPORT int data1_iconv (data1_handle dh, NMEM m, data1_node *n,
577 const char *fromcode);
579 YAZ_EXPORT const char *data1_get_encoding (data1_handle dh, data1_node *n);
581 YAZ_EXPORT int data1_is_xmlmode(data1_handle dh);
583 YAZ_EXPORT const char *data1_systag_lookup(data1_absyn *absyn, const char *tag,
584 const char *default_value);
586 YAZ_EXPORT void data1_concat_text(data1_handle dh, NMEM m, data1_node *n);
588 YAZ_EXPORT void data1_absyn_destroy(data1_handle dh);