YAZ  5.34.0
marcdisp.h
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data.
3  * All rights reserved.
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of Index Data nor the names of its contributors
13  * may be used to endorse or promote products derived from this
14  * software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
33 #ifndef MARCDISP_H
34 #define MARCDISP_H
35 
36 #include <yaz/yconfig.h>
37 #include <stdio.h>
38 #include <yaz/wrbuf.h>
39 
40 #include <yaz/nmem.h>
41 #include <yaz/xmltypes.h>
42 #include <yaz/z-opac.h>
43 
45 
47 typedef struct yaz_marc_t_ *yaz_marc_t;
48 
50 YAZ_EXPORT yaz_marc_t yaz_marc_create(void);
51 
53 YAZ_EXPORT void yaz_marc_destroy(yaz_marc_t mt);
54 
61 YAZ_EXPORT void yaz_marc_xml(yaz_marc_t mt, int xmlmode);
62 
64 #define YAZ_MARC_LINE 0
66 #define YAZ_MARC_SIMPLEXML 1
68 #define YAZ_MARC_OAIMARC 2
70 #define YAZ_MARC_MARCXML 3
72 #define YAZ_MARC_ISO2709 4
74 #define YAZ_MARC_XCHANGE 5
76 #define YAZ_MARC_CHECK 6
78 #define YAZ_MARC_TURBOMARC 7
80 #define YAZ_MARC_JSON 8
81 
83 YAZ_EXPORT void yaz_marc_iconv(yaz_marc_t mt, yaz_iconv_t cd);
84 
87 
92 YAZ_EXPORT void yaz_marc_debug(yaz_marc_t mt, int level);
93 
105 YAZ_EXPORT int yaz_marc_decode_buf(yaz_marc_t mt, const char *buf, int bsize,
106  const char **result, size_t *rsize);
107 
118 YAZ_EXPORT int yaz_marc_decode_wrbuf(yaz_marc_t mt, const char *buf,
119  int bsize, WRBUF wrbuf);
120 
121 YAZ_EXPORT void yaz_marc_subfield_str(yaz_marc_t mt, const char *s);
122 YAZ_EXPORT void yaz_marc_endline_str(yaz_marc_t mt, const char *s);
123 
125 YAZ_EXPORT void yaz_marc_modify_leader(yaz_marc_t mt, size_t off,
126  const char *str);
127 
133 YAZ_EXPORT int atoi_n(const char *buf, int len);
134 
142 YAZ_EXPORT
143 int atoi_n_check(const char *buf, int size, int *val);
144 
146 #define ISO2709_RS 035
148 #define ISO2709_FS 036
150 #define ISO2709_IDFS 037
151 
161 YAZ_EXPORT int yaz_marc_read_iso2709(yaz_marc_t mt,
162  const char *buf, int bsize);
163 
175 YAZ_EXPORT
177  int (*getbyte)(void *client_data),
178  void (*ungetbyte)(int b, void *client_data),
179  void *client_data);
180 
181 #if YAZ_HAVE_XML2
188 YAZ_EXPORT int yaz_marc_read_xml(yaz_marc_t mt, const xmlNode *ptr);
189 #endif
190 
197 YAZ_EXPORT int yaz_marc_write_line(yaz_marc_t mt, WRBUF wrbuf);
198 
207 YAZ_EXPORT int yaz_marc_write_marcxml(yaz_marc_t mt, WRBUF wrbuf);
208 
215 YAZ_EXPORT int yaz_marc_write_turbomarc(yaz_marc_t mt, WRBUF wrbuf);
216 
226  const char *format,
227  const char *type);
228 
235 YAZ_EXPORT int yaz_marc_write_iso2709(yaz_marc_t mt, WRBUF wrbuf);
236 
246 YAZ_EXPORT int yaz_marc_write_mode(yaz_marc_t mt, WRBUF wrbuf);
247 
248 #if YAZ_HAVE_XML2
258 YAZ_EXPORT
259 int yaz_marc_write_xml(yaz_marc_t mt, xmlNode **root_ptr,
260  const char *ns,
261  const char *format,
262  const char *type);
263 #endif
264 
271 YAZ_EXPORT
273 
285 YAZ_EXPORT int yaz_marc_leader_spec(yaz_marc_t mt, const char *leader_spec);
286 
287 
298 YAZ_EXPORT
299 void yaz_marc_set_leader(yaz_marc_t mt, const char *leader,
300  int *indicator_length,
301  int *identifier_length,
302  int *base_address,
303  int *length_data_entry,
304  int *length_starting,
305  int *length_implementation);
306 
307 
312 YAZ_EXPORT
313 void yaz_marc_add_comment(yaz_marc_t mt, char *comment);
314 
319 YAZ_EXPORT
320 void yaz_marc_cprintf(yaz_marc_t mt, const char *fmt, ...);
321 
327 YAZ_EXPORT
329  const char *code_data, size_t code_data_len);
330 
331 
338 YAZ_EXPORT
339 void yaz_marc_add_controlfield(yaz_marc_t mt, const char *tag,
340  const char *data, size_t data_len);
341 
342 
343 #if YAZ_HAVE_XML2
349 YAZ_EXPORT
350 void yaz_marc_add_controlfield_xml(yaz_marc_t mt, const xmlNode *ptr_tag,
351  const xmlNode *ptr_data);
352 
358 YAZ_EXPORT
359 void yaz_marc_add_controlfield_xml2(yaz_marc_t mt, char *tag,
360  const xmlNode *ptr_data);
361 #endif
362 
369 YAZ_EXPORT
370 void yaz_marc_add_datafield(yaz_marc_t mt, const char *tag,
371  const char *indicator, size_t indicator_len);
372 
373 #if YAZ_HAVE_XML2
380 YAZ_EXPORT
381 void yaz_marc_add_datafield_xml(yaz_marc_t mt, const xmlNode *ptr_tag,
382  const char *indicator, size_t indicator_len);
383 
389 YAZ_EXPORT
390 void yaz_marc_add_datafield_xml2(yaz_marc_t mt, char *tag_value,
391  char *indicators);
392 
393 #endif
394 
399 YAZ_EXPORT
401 
405 YAZ_EXPORT
406 void yaz_marc_reset(yaz_marc_t mt);
407 
411 YAZ_EXPORT
413 
419 YAZ_EXPORT
420 int yaz_marc_decode_formatstr(const char *arg);
421 
426 YAZ_EXPORT
427 void yaz_marc_write_using_libxml2(yaz_marc_t mt, int enable);
428 
437 YAZ_EXPORT void yaz_opac_decode_wrbuf(yaz_marc_t mt, Z_OPACRecord *r,
438  WRBUF wrbuf);
439 
449 YAZ_EXPORT void yaz_opac_decode_wrbuf2(yaz_marc_t mt, Z_OPACRecord *r,
450  WRBUF wrbuf, yaz_iconv_t cd);
451 
452 #if YAZ_HAVE_XML2
464 YAZ_EXPORT int yaz_xml_to_opac(yaz_marc_t mt,
465  const char *buf_in, size_t size_in,
466  Z_OPACRecord **dst, yaz_iconv_t cd,
467  NMEM nmem, const Odr_oid *syntax);
468 #endif
469 
476 YAZ_EXPORT int yaz_marc_write_trailer(yaz_marc_t mt, WRBUF wr);
477 
481 YAZ_EXPORT void yaz_marc_enable_collection(yaz_marc_t mt);
482 
483 struct json_node;
484 
485 YAZ_EXPORT int yaz_marc_read_json_node(yaz_marc_t mt, struct json_node *n);
486 
494 YAZ_EXPORT
495 int yaz_marc_check_marc21_coding(const char *charset,
496  const char *marc_buf, int sz);
497 
498 YAZ_EXPORT
499 int yaz_opac_check_marc21_coding(const char *charset, Z_OPACRecord *r);
500 
501 
502 size_t yaz_marc_sizeof_char(yaz_marc_t mt, const char *buf);
503 
505 
506 #endif
507 /*
508  * Local variables:
509  * c-basic-offset: 4
510  * c-file-style: "Stroustrup"
511  * indent-tabs-mode: nil
512  * End:
513  * vim: shiftwidth=4 tabstop=8 expandtab
514  */
515 
enum l_file_type type
Definition: log.c:47
int yaz_marc_leader_spec(yaz_marc_t mt, const char *leader_spec)
sets leader spec (for modifying bytes in 24 byte leader)
Definition: marcdisp.c:1410
void yaz_marc_add_controlfield_xml(yaz_marc_t mt, const xmlNode *ptr_tag, const xmlNode *ptr_data)
adds controlfield to MARC structure using xml Nodes
Definition: marcdisp.c:160
int yaz_marc_read_iso2709(yaz_marc_t mt, const char *buf, int bsize)
read ISO2709/MARC record from buffer
int yaz_marc_write_mode(yaz_marc_t mt, WRBUF wrbuf)
writes record in mode - given by yaz_marc_xml mode
Definition: marcdisp.c:623
int atoi_n_check(const char *buf, int size, int *val)
like atoi_n but checks for proper formatting
Definition: atoin.c:32
void yaz_marc_cprintf(yaz_marc_t mt, const char *fmt,...)
adds MARC annotation - printf interface
Definition: marcdisp.c:188
int yaz_marc_check_marc21_coding(const char *charset, const char *marc_buf, int sz)
check if MARC21 is UTF-8 encoded
Definition: marcdisp.c:1490
yaz_marc_t yaz_marc_create(void)
construct yaz_marc_t handle
Definition: marcdisp.c:102
int yaz_marc_read_xml(yaz_marc_t mt, const xmlNode *ptr)
parses MARCXML/MarcXchange/TurboMARC record from xmlNode pointer
size_t yaz_marc_sizeof_char(yaz_marc_t mt, const char *buf)
Definition: marcdisp.c:478
void yaz_marc_iconv(yaz_marc_t mt, yaz_iconv_t cd)
set iconv handle for character set conversion
Definition: marcdisp.c:1387
void yaz_opac_decode_wrbuf2(yaz_marc_t mt, Z_OPACRecord *r, WRBUF wrbuf, yaz_iconv_t cd)
Performs "pretty" display of OPAC record to WRBUF using marc_t.
Definition: opac_to_xml.c:62
int yaz_marc_read_line(yaz_marc_t mt, int(*getbyte)(void *client_data), void(*ungetbyte)(int b, void *client_data), void *client_data)
read MARC lineformat from stream
void yaz_marc_xml(yaz_marc_t mt, int xmlmode)
set XML mode YAZ_MARC_LINE, YAZ_MARCXML, YAZ_MARC_ISO2709 ..
Definition: marcdisp.c:1376
void yaz_marc_add_subfield(yaz_marc_t mt, const char *code_data, size_t code_data_len)
adds subfield to MARC structure
Definition: marcdisp.c:316
int yaz_marc_write_iso2709(yaz_marc_t mt, WRBUF wrbuf)
writes record in ISO2709 format
Definition: marcdisp.c:1119
void yaz_marc_add_datafield_xml(yaz_marc_t mt, const xmlNode *ptr_tag, const char *indicator, size_t indicator_len)
adds datafield to MARC structure using xml Nodes
Definition: marcdisp.c:284
void yaz_marc_write_using_libxml2(yaz_marc_t mt, int enable)
Enables or disables writing of MARC XML records using Libxml2.
Definition: marcdisp.c:1485
NMEM yaz_marc_get_nmem(yaz_marc_t mt)
returns memory for MARC handle
Definition: marcdisp.c:130
void yaz_marc_endline_str(yaz_marc_t mt, const char *s)
Definition: marcdisp.c:438
int yaz_marc_get_debug(yaz_marc_t mt)
gets debug level for MARC system
Definition: marcdisp.c:199
void yaz_marc_set_leader(yaz_marc_t mt, const char *leader, int *indicator_length, int *identifier_length, int *base_address, int *length_data_entry, int *length_starting, int *length_implementation)
sets leader, validates it, and returns important values
Definition: marcdisp.c:356
void yaz_marc_add_datafield(yaz_marc_t mt, const char *tag, const char *indicator, size_t indicator_len)
adds datafield to MARC structure using strings
Definition: marcdisp.c:233
void yaz_marc_add_datafield_xml2(yaz_marc_t mt, char *tag_value, char *indicators)
adds datafield to MARC structure using xml Nodes
Definition: marcdisp.c:297
void yaz_marc_modify_leader(yaz_marc_t mt, size_t off, const char *str)
modifies part of the MARC leader
Definition: marcdisp.c:1397
int yaz_marc_write_xml(yaz_marc_t mt, xmlNode **root_ptr, const char *ns, const char *format, const char *type)
writes MARC record as libxml2 tree
Definition: marcdisp.c:1025
int yaz_marc_decode_formatstr(const char *arg)
Converts MARC format type to format type(YAZ_MARC_..)
Definition: marcdisp.c:1467
void yaz_marc_subfield_str(yaz_marc_t mt, const char *s)
Definition: marcdisp.c:432
yaz_iconv_t yaz_marc_get_iconv(yaz_marc_t mt)
supply iconv handle for character set conversion
Definition: marcdisp.c:1392
void yaz_marc_destroy(yaz_marc_t mt)
destroy yaz_marc_t handle
Definition: marcdisp.c:120
int yaz_marc_read_json_node(yaz_marc_t mt, struct json_node *n)
int yaz_marc_decode_wrbuf(yaz_marc_t mt, const char *buf, int bsize, WRBUF wrbuf)
decodes ISO2709/MARC buffer and stores result in WRBUF
Definition: marcdisp.c:1351
int yaz_marc_write_marcxml(yaz_marc_t mt, WRBUF wrbuf)
writes record in MARCXML format
Definition: marcdisp.c:850
void yaz_marc_add_controlfield_xml2(yaz_marc_t mt, char *tag, const xmlNode *ptr_data)
adds controlfield to MARC structure using xml Nodes for data
Definition: marcdisp.c:169
int yaz_marc_write_turbomarc(yaz_marc_t mt, WRBUF wrbuf)
writes record in TurboMARC format
Definition: marcdisp.c:861
int yaz_opac_check_marc21_coding(const char *charset, Z_OPACRecord *r)
Definition: opac_to_xml.c:194
void yaz_marc_add_controlfield(yaz_marc_t mt, const char *tag, const char *data, size_t data_len)
adds controlfield to MARC structure
Definition: marcdisp.c:212
void yaz_marc_add_comment(yaz_marc_t mt, char *comment)
adds MARC comment string
Definition: marcdisp.c:181
int yaz_marc_write_line(yaz_marc_t mt, WRBUF wrbuf)
writes record in line format
Definition: marcdisp.c:537
void yaz_marc_reset(yaz_marc_t mt)
clears memory and MARC record
Definition: marcdisp.c:483
void yaz_opac_decode_wrbuf(yaz_marc_t mt, Z_OPACRecord *r, WRBUF wrbuf)
Performs "pretty" display of OPAC record to WRBUF using marc_t.
Definition: opac_to_xml.c:189
int yaz_marc_write_json(yaz_marc_t mt, WRBUF w)
writes MARC record in JSON represenation
Definition: marcdisp.c:1257
void yaz_marc_enable_collection(yaz_marc_t mt)
enables record collection output
Definition: marcdisp.c:618
int atoi_n(const char *buf, int len)
like atoi(3) except that it reads exactly len characters
Definition: atoin.c:19
int yaz_marc_write_trailer(yaz_marc_t mt, WRBUF wr)
flushes records
Definition: marcdisp.c:600
int yaz_xml_to_opac(yaz_marc_t mt, const char *buf_in, size_t size_in, Z_OPACRecord **dst, yaz_iconv_t cd, NMEM nmem, const Odr_oid *syntax)
Converts XML to OPAC.
Definition: xml_to_opac.c:299
int yaz_marc_decode_buf(yaz_marc_t mt, const char *buf, int bsize, const char **result, size_t *rsize)
decodes ISO2709 buffer using straight buffers
Definition: marcdisp.c:1362
struct yaz_marc_t_ * yaz_marc_t
a yaz_marc_t handle (private content)
Definition: marcdisp.h:47
void yaz_marc_debug(yaz_marc_t mt, int level)
set debug level
Definition: marcdisp.c:1381
int yaz_marc_write_marcxchange(yaz_marc_t mt, WRBUF wrbuf, const char *format, const char *type)
writes record in MarcXchange XML (ISO25577)
Definition: marcdisp.c:871
Header for Nibble Memory functions.
short Odr_oid
Definition: oid_util.h:42
JSON node.
Definition: json.h:53
string buffer
Definition: wrbuf.h:43
the internals of a yaz_marc_t handle
Definition: marcdisp.c:86
NMEM nmem
Definition: marcdisp.c:88
char * leader_spec
Definition: marcdisp.c:96
Header for WRBUF (growing buffer)
Define xmlNode and xmlDocPtr if Libxml2 is present.
Header with fundamental macros.
#define YAZ_BEGIN_CDECL
Definition: yconfig.h:56
#define YAZ_END_CDECL
Definition: yconfig.h:57
ASN.1 Module RecordSyntax-opac.