1 /* This file is part of the Zebra server.
2 Copyright (C) 1994-2010 Index Data
4 Zebra is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <yaz/proto.h>
27 #include <yaz/yaz-util.h>
29 #include <idzebra/util.h>
31 #define d1_isspace(c) strchr(" \r\n\t\f", c)
32 #define d1_isdigit(c) ((c) <= '9' && (c) >= '0')
36 #define data1_matchstr(s1, s2) yaz_matchstr(s1, s2)
38 #define DATA1_MAX_SYMBOL 31
41 * This structure describes a attset, perhaps made up by inclusion
42 * (supersetting) of other attribute sets. When indexing and searching,
43 * we perform a normalisation, where we associate a given tag with
44 * the set that originally defined it, rather than the superset. This
45 * allows the most flexible access. Eg, the tags common to GILS and BIB-1
46 * should be searchable by both names.
51 typedef struct data1_attset data1_attset;
52 typedef struct data1_att data1_att;
53 typedef struct data1_attset_child data1_attset_child;
57 data1_attset *parent; /* attribute set */
58 char *name; /* symbolic name of this attribute */
59 int value; /* attribute value */
63 struct data1_attset_child {
65 data1_attset_child *next;
70 char *name; /* symbolic name */
71 Odr_oid *oid; /* attribute set OID */
72 data1_att *atts; /* attributes */
73 data1_attset_child *children; /* included attset */
74 data1_attset *next; /* next in cache */
77 typedef struct data1_handle_info *data1_handle;
79 YAZ_EXPORT data1_att *data1_getattbyname(data1_handle dh, data1_attset *s,
81 YAZ_EXPORT data1_attset *data1_read_attset(data1_handle dh, const char *file);
83 YAZ_EXPORT data1_attset *data1_empty_attset(data1_handle dh);
85 typedef struct data1_maptag
89 #define D1_MAPTAG_numeric 1
90 #define D1_MAPTAG_string 2
97 struct data1_maptag *next;
100 typedef struct data1_mapunit data1_mapunit;
102 typedef struct data1_maptab
105 Odr_oid *oid; /* target abstract syntax */
106 char *target_absyn_name;
108 struct data1_maptab *next;
112 typedef struct data1_name
115 struct data1_name *next;
118 typedef struct data1_absyn_cache_info *data1_absyn_cache;
119 typedef struct data1_attset_cache_info *data1_attset_cache;
120 typedef struct data1_absyn data1_absyn;
122 typedef enum data1_datatype
130 DATA1K_generalizedtime,
137 typedef struct data1_marctab
140 Odr_oid *oid; /* MARC OID */
142 char record_status[2];
143 char implementation_codes[5];
144 int indicator_length;
145 int identifier_length;
146 char user_systems[4];
148 int length_data_entry;
150 int length_implementation;
153 int force_indicator_length;
154 int force_identifier_length;
155 char leader[24]; /* Fixme! Need linear access to LEADER of MARC record */
156 struct data1_marctab *next;
159 typedef struct data1_esetname
163 struct data1_esetname *next;
167 * Variant set definitions.
170 typedef struct data1_vartype
173 struct data1_varclass *zclass;
175 data1_datatype datatype;
176 struct data1_vartype *next;
179 typedef struct data1_varclass
182 struct data1_varset *set;
184 data1_vartype *types;
185 struct data1_varclass *next;
188 typedef struct data1_varset
191 Odr_oid *oid; /* variant OID */
192 data1_varclass *classes;
201 typedef struct data1_tag
204 #define DATA1T_numeric 1
205 #define DATA1T_string 2
214 struct data1_tagset *tagset;
215 struct data1_tag *next;
218 typedef struct data1_tagset data1_tagset;
222 int type; /* type of tagset in current context */
223 char *name; /* symbolic name */
224 Odr_oid *oid; /* variant OID */
225 data1_tag *tags; /* tags defined by this set */
226 data1_tagset *children; /* children */
227 data1_tagset *next; /* sibling */
230 typedef struct data1_termlist
235 struct data1_termlist *next;
239 * abstract syntax specification
242 typedef struct data1_element
246 data1_termlist *termlists;
248 struct data1_element *children;
249 struct data1_element *next;
250 struct data1_hash_table *hash;
253 typedef struct data1_sub_elements {
255 struct data1_sub_elements *next;
256 data1_element *elements;
257 } data1_sub_elements;
259 typedef struct data1_xattr {
262 struct data1_xattr *next;
263 unsigned short what; /* DATA1I_text, .. see data1_node.u.data */
268 * record data node (tag/data/variant)
271 typedef struct data1_node
273 /* the root of a record (containing global data) */
274 #define DATA1N_root 1
277 /* some data under a leaf tag or variant */
278 #define DATA1N_data 3
279 /* variant specification (a triple, actually) */
280 #define DATA1N_variant 4
281 /* comment (same as data) */
282 #define DATA1N_comment 5
283 /* preprocessing instruction */
284 #define DATA1N_preprocess 6
291 struct data1_absyn *absyn; /* abstract syntax for this type */
297 data1_element *element;
298 int no_data_requested;
300 unsigned node_selected : 1;
301 unsigned make_variantlist : 1;
302 data1_xattr *attributes;
307 char *data; /* filename or data */
310 #define DATA1I_inctxt 1
311 /* binary data inclusion */
312 #define DATA1I_incbin 2
314 #define DATA1I_text 3
317 /* object identifier */
320 #define DATA1I_xmltext 6
322 unsigned formatted_text : 1; /* newlines are significant */
334 data1_xattr *attributes;
338 #define DATA1_LOCALDATA 12
339 char lbuf[DATA1_LOCALDATA]; /* small buffer for local data */
340 struct data1_node *next;
341 struct data1_node *child;
342 struct data1_node *last_child;
343 struct data1_node *parent;
344 struct data1_node *root;
347 enum DATA1_XPATH_INDEXING {
348 DATA1_XPATH_INDEXING_DISABLE,
349 DATA1_XPATH_INDEXING_ENABLE
352 YAZ_EXPORT data1_handle data1_create (void);
355 YAZ_EXPORT void data1_destroy(data1_handle dh);
356 YAZ_EXPORT data1_node *get_parent_tag(data1_handle dh, data1_node *n);
357 YAZ_EXPORT data1_node *data1_read_node(data1_handle dh, const char **buf,
359 YAZ_EXPORT data1_node *data1_read_nodex (data1_handle dh, NMEM m,
360 int (*get_byte)(void *fh), void *fh,
362 YAZ_EXPORT data1_node *data1_read_record(data1_handle dh,
363 int (*rf)(void *, char *, size_t),
366 YAZ_EXPORT void data1_remove_node (data1_handle dh, data1_node *n);
367 YAZ_EXPORT void data1_remove_idzebra_subtree (data1_handle dh, data1_node *n);
368 YAZ_EXPORT data1_tag *data1_gettagbynum(data1_handle dh,
370 int type, int value);
371 YAZ_EXPORT data1_tagset *data1_empty_tagset (data1_handle dh);
372 YAZ_EXPORT data1_tagset *data1_read_tagset(data1_handle dh,
375 YAZ_EXPORT data1_element *data1_getelementbytagname(data1_handle dh,
377 data1_element *parent,
378 const char *tagname);
379 YAZ_EXPORT Z_GenericRecord *data1_nodetogr(data1_handle dh, data1_node *n,
382 YAZ_EXPORT data1_tag *data1_gettagbyname(data1_handle dh, data1_tagset *s,
384 YAZ_EXPORT char *data1_nodetobuf(data1_handle dh, data1_node *n,
385 int select, int *len);
386 YAZ_EXPORT data1_node *data1_mk_tag_data_wd(data1_handle dh,
388 const char *tagname, NMEM m);
389 YAZ_EXPORT data1_node *data1_mk_tag_data(data1_handle dh, data1_node *at,
390 const char *tagname, NMEM m);
391 YAZ_EXPORT data1_datatype data1_maptype(data1_handle dh, char *t);
392 YAZ_EXPORT data1_varset *data1_read_varset(data1_handle dh, const char *file);
393 YAZ_EXPORT data1_vartype *data1_getvartypebyct(data1_handle dh,
397 YAZ_EXPORT data1_vartype *data1_getvartypeby_absyn(data1_handle dh,
399 char *zclass, char *type);
400 YAZ_EXPORT Z_Espec1 *data1_read_espec1(data1_handle dh, const char *file);
401 YAZ_EXPORT int data1_doespec1(data1_handle dh, data1_node *n, Z_Espec1 *e);
402 YAZ_EXPORT data1_esetname *data1_getesetbyname(data1_handle dh,
405 YAZ_EXPORT data1_element *data1_getelementbyname(data1_handle dh,
408 YAZ_EXPORT data1_node *data1_mk_node2(data1_handle dh, NMEM m,
409 int type, data1_node *parent);
411 YAZ_EXPORT data1_node *data1_mk_tag (data1_handle dh, NMEM nmem,
412 const char *tag, const char **attr,
414 YAZ_EXPORT data1_node *data1_mk_tag_n (data1_handle dh, NMEM nmem,
415 const char *tag, size_t len,
418 YAZ_EXPORT void data1_tag_add_attr (data1_handle dh, NMEM nmem,
419 data1_node *res, const char **attr);
421 YAZ_EXPORT data1_node *data1_mk_text_n (data1_handle dh, NMEM mem,
422 const char *buf, size_t len,
424 YAZ_EXPORT data1_node *data1_mk_text_nf (data1_handle dh, NMEM mem,
425 const char *buf, size_t len,
427 YAZ_EXPORT data1_node *data1_mk_text (data1_handle dh, NMEM mem,
428 const char *buf, data1_node *parent);
430 YAZ_EXPORT data1_node *data1_mk_comment_n (data1_handle dh, NMEM mem,
431 const char *buf, size_t len,
434 YAZ_EXPORT data1_node *data1_mk_comment (data1_handle dh, NMEM mem,
435 const char *buf, data1_node *parent);
437 YAZ_EXPORT data1_node *data1_mk_preprocess_n (data1_handle dh, NMEM nmem,
438 const char *target, size_t len,
442 YAZ_EXPORT data1_node *data1_mk_preprocess (data1_handle dh, NMEM nmem,
447 YAZ_EXPORT data1_node *data1_insert_preprocess_n (data1_handle dh, NMEM nmem,
453 YAZ_EXPORT data1_node *data1_insert_preprocess (data1_handle dh, NMEM nmem,
458 YAZ_EXPORT data1_node *data1_mk_root (data1_handle dh, NMEM nmem,
460 YAZ_EXPORT void data1_set_root(data1_handle dh, data1_node *res,
461 NMEM nmem, const char *name);
463 YAZ_EXPORT data1_node *data1_mk_tag_data_zint (data1_handle dh, data1_node *at,
464 const char *tag, zint num,
466 YAZ_EXPORT data1_node *data1_mk_tag_data_int (data1_handle dh, data1_node *at,
467 const char *tag, int num,
469 YAZ_EXPORT data1_node *data1_mk_tag_data_oid (data1_handle dh, data1_node *at,
470 const char *tag, Odr_oid *oid,
472 YAZ_EXPORT data1_node *data1_mk_tag_data_text (data1_handle dh, data1_node *at,
476 YAZ_EXPORT data1_node *data1_mk_tag_data_text_uni (data1_handle dh,
482 YAZ_EXPORT data1_absyn *data1_get_absyn (data1_handle dh, const char *name,
483 enum DATA1_XPATH_INDEXING en);
485 YAZ_EXPORT data1_node *data1_search_tag (data1_handle dh, data1_node *n,
487 YAZ_EXPORT data1_node *data1_mk_tag_uni (data1_handle dh, NMEM nmem,
488 const char *tag, data1_node *at);
489 YAZ_EXPORT data1_attset *data1_get_attset (data1_handle dh, const char *name);
490 YAZ_EXPORT data1_maptab *data1_read_maptab(data1_handle dh, const char *file);
491 YAZ_EXPORT data1_node *data1_map_record(data1_handle dh, data1_node *n,
492 data1_maptab *map, NMEM m);
493 YAZ_EXPORT data1_marctab *data1_read_marctab (data1_handle dh,
495 YAZ_EXPORT data1_marctab *data1_absyn_getmarctab(data1_handle dh,
497 YAZ_EXPORT data1_element *data1_absyn_getelements(data1_handle dh,
499 YAZ_EXPORT char *data1_nodetomarc(data1_handle dh, data1_marctab *p,
500 data1_node *n, int selected, int *len);
501 YAZ_EXPORT char *data1_nodetoidsgml(data1_handle dh, data1_node *n,
502 int select, int *len);
503 YAZ_EXPORT Z_ExplainRecord *data1_nodetoexplain(data1_handle dh,
504 data1_node *n, int select,
506 YAZ_EXPORT Z_BriefBib *data1_nodetosummary(data1_handle dh,
507 data1_node *n, int select,
509 YAZ_EXPORT char *data1_nodetosoif(data1_handle dh, data1_node *n, int select,
511 YAZ_EXPORT void data1_set_tabpath(data1_handle dh, const char *path);
512 YAZ_EXPORT void data1_set_tabroot (data1_handle dp, const char *p);
513 YAZ_EXPORT const char *data1_get_tabpath(data1_handle dh);
514 YAZ_EXPORT const char *data1_get_tabroot(data1_handle dh);
516 YAZ_EXPORT WRBUF data1_get_wrbuf (data1_handle dp);
517 YAZ_EXPORT char **data1_get_read_buf (data1_handle dp, int **lenp);
518 YAZ_EXPORT char **data1_get_map_buf (data1_handle dp, int **lenp);
519 YAZ_EXPORT data1_absyn_cache *data1_absyn_cache_get (data1_handle dh);
520 YAZ_EXPORT data1_attset_cache *data1_attset_cache_get (data1_handle dh);
521 YAZ_EXPORT NMEM data1_nmem_get (data1_handle dh);
522 YAZ_EXPORT void data1_pr_tree (data1_handle dh, data1_node *n, FILE *out);
523 YAZ_EXPORT char *data1_insert_string (data1_handle dh, data1_node *res,
524 NMEM m, const char *str);
525 YAZ_EXPORT char *data1_insert_string_n (data1_handle dh, data1_node *res,
526 NMEM m, const char *str, size_t len);
527 YAZ_EXPORT data1_node *data1_read_sgml (data1_handle dh, NMEM m,
529 YAZ_EXPORT data1_node *data1_read_xml (data1_handle dh,
530 int (*rf)(void *, char *, size_t),
532 YAZ_EXPORT void data1_absyn_trav (data1_handle dh, void *handle,
533 void (*fh)(data1_handle dh,
534 void *h, data1_absyn *a));
536 YAZ_EXPORT data1_attset *data1_attset_search_id (data1_handle dh,
539 YAZ_EXPORT char *data1_getNodeValue(data1_node* node, char* pTagPath);
540 YAZ_EXPORT data1_node *data1_LookupNode(data1_node* node, char* pTagPath);
541 YAZ_EXPORT int data1_CountOccurences(data1_node* node, char* pTagPath);
543 YAZ_EXPORT FILE *data1_path_fopen (data1_handle dh, const char *file,
546 /* obsolete functions ... */
548 YAZ_EXPORT data1_node *data1_mk_node (data1_handle dh, NMEM m);
549 YAZ_EXPORT data1_node *data1_insert_taggeddata (data1_handle dh,
552 const char *tagname, NMEM m);
553 YAZ_EXPORT data1_node *data1_mk_node_type (data1_handle dh, NMEM m, int type);
554 YAZ_EXPORT data1_node *data1_add_taggeddata (data1_handle dh, data1_node *root,
559 YAZ_EXPORT data1_node *data1_get_root_tag (data1_handle dh, data1_node *n);
561 YAZ_EXPORT int data1_iconv (data1_handle dh, NMEM m, data1_node *n,
563 const char *fromcode);
565 YAZ_EXPORT const char *data1_get_encoding (data1_handle dh, data1_node *n);
567 YAZ_EXPORT int data1_is_xmlmode(data1_handle dh);
569 YAZ_EXPORT const char *data1_systag_lookup(data1_absyn *absyn, const char *tag,
570 const char *default_value);
572 YAZ_EXPORT void data1_concat_text(data1_handle dh, NMEM m, data1_node *n);
573 YAZ_EXPORT void data1_chop_text(data1_handle dh, NMEM m, data1_node *n);
575 YAZ_EXPORT void data1_absyn_destroy(data1_handle dh);
577 YAZ_EXPORT const char *data1_absyn_get_staticrank(data1_absyn *absyn);
585 * c-file-style: "Stroustrup"
586 * indent-tabs-mode: nil
588 * vim: shiftwidth=4 tabstop=8 expandtab