2 * Copyright (c) 1995-2006, Index Data
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
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.
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.
27 /* $Id: marcdisp.h,v 1.21 2006-12-13 11:25:17 adam Exp $ */
31 * \brief MARC conversion
37 #include <yaz/yconfig.h>
39 #include <yaz/wrbuf.h>
41 #include <yaz/xmltypes.h>
45 /** \brief a yaz_marc_t handle (private content) */
46 typedef struct yaz_marc_t_ *yaz_marc_t;
48 /** \brief construct yaz_marc_t handle */
49 YAZ_EXPORT yaz_marc_t yaz_marc_create(void);
51 /** \brief destroy yaz_marc_t handle */
52 YAZ_EXPORT void yaz_marc_destroy(yaz_marc_t mt);
54 /** \brief set XML mode YAZ_MARC_LINE, YAZ_MARC_SIMPLEXML, ... */
55 YAZ_EXPORT void yaz_marc_xml(yaz_marc_t mt, int xmlmode);
57 /** \brief Output format: Line-format */
58 #define YAZ_MARC_LINE 0
59 /** \brief Output format: simplexml (no longer supported) */
60 #define YAZ_MARC_SIMPLEXML 1
61 /** \brief Output format: OAI-MARC (no longer supported) */
62 #define YAZ_MARC_OAIMARC 2
63 /** \brief Output format: MARCXML */
64 #define YAZ_MARC_MARCXML 3
65 /** \brief Output format: ISO2709 */
66 #define YAZ_MARC_ISO2709 4
67 /** \brief Output format: MarcXchange */
68 #define YAZ_MARC_XCHANGE 5
69 /** \brief Output format: check only (no marc output) */
70 #define YAZ_MARC_CHECK 6
72 /** \brief supply iconv handle for character set conversion .. */
73 YAZ_EXPORT void yaz_marc_iconv(yaz_marc_t mt, yaz_iconv_t cd);
75 /** \brief set debug level
77 \param level level, where 0=lowest, 1 more debug, 2 even more
79 YAZ_EXPORT void yaz_marc_debug(yaz_marc_t mt, int level);
81 /** \brief decodes ISO2709 buffer using straight buffers
83 \param buf input buffer
84 \param bsize size of buffer or (-1 if "any size")
85 \param result result to be stored here (allocate before use!)
86 \param rsize size of result (set before calling)
88 Decodes MARC in buf of size bsize.
89 On success, result in *result with size *rsize.
90 Returns -1 on error, or size of input record (>0) if OK
92 YAZ_EXPORT int yaz_marc_decode_buf(yaz_marc_t mt, const char *buf, int bsize,
93 char **result, int *rsize);
95 /** \brief decodes ISO2709/MARC buffer and stores result in WRBUF
97 \param buf input buffer
98 \param bsize size of buffer (-1 if "any size")
99 \param wrbuf WRBUF for output
101 Decodes MARC in buf of size bsize.
102 On success, result in wrbuf
103 Returns -1 on error, or size of input record (>0) if OK
105 YAZ_EXPORT int yaz_marc_decode_wrbuf(yaz_marc_t mt, const char *buf,
106 int bsize, WRBUF wrbuf);
108 /** \brief depricated */
109 YAZ_EXPORT int marc_display(const char *buf, FILE *outf);
110 /** \brief depricated */
111 YAZ_EXPORT int marc_display_ex(const char *buf, FILE *outf, int debug);
112 /** \brief depricated */
113 YAZ_EXPORT int marc_display_exl(const char *buf, FILE *outf, int debug,
115 /** \brief depricated */
116 YAZ_EXPORT int marc_display_wrbuf(const char *buf, WRBUF wr, int debug,
118 /** \brief depricated */
119 YAZ_EXPORT int yaz_marc_decode(const char *buf, WRBUF wr,
120 int debug, int bsize, int xml);
122 YAZ_EXPORT void yaz_marc_subfield_str(yaz_marc_t mt, const char *s);
123 YAZ_EXPORT void yaz_marc_endline_str(yaz_marc_t mt, const char *s);
125 /** \brief modifies part of the MARC leader */
126 YAZ_EXPORT void yaz_marc_modify_leader(yaz_marc_t mt, size_t off,
129 /** \brief like atoi(3) except that it reads exactly len characters */
130 YAZ_EXPORT int atoi_n(const char *buf, int len);
132 /** \brief MARC control char: record separator (29 Dec, 1D Hex) */
133 #define ISO2709_RS 035
134 /** \brief MARC control char: field separator (30 Dec, 1E Hex) */
135 #define ISO2709_FS 036
136 /** \brief MARC control char: identifier-field separator (31 Dec, 1F Hex) */
137 #define ISO2709_IDFS 037
139 /** \brief read ISO2709/MARC record from buffer
141 \param buf ISO2709 buffer of size bsize
142 \param bsize size of buffer (-1 for unlimited size)
144 Parses ISO2709 record from supplied buffer
145 Returns > 0 for OK (same as length), -1=ERROR
147 YAZ_EXPORT int yaz_marc_read_iso2709(yaz_marc_t mt,
148 const char *buf, int bsize);
150 /** \brief parses MARCXML/MarcXchange record from xmlNode pointer
152 \param ptr is a pointer to root xml node
154 Returns 0=OK, -1=ERROR
156 YAZ_EXPORT int yaz_marc_read_xml(yaz_marc_t mt, const xmlNode *ptr);
158 /** \brief writes record in line format
160 \param wrbuf WRBUF for output
162 Returns 0=OK, -1=ERROR
164 YAZ_EXPORT int yaz_marc_write_line(yaz_marc_t mt, WRBUF wrbuf);
166 /** \brief writes record in MARCXML format
168 \param wrbuf WRBUF for output
170 Sets leader[9]='a' . Returns 0=OK, -1=ERROR .
172 YAZ_EXPORT int yaz_marc_write_marcxml(yaz_marc_t mt, WRBUF wrbuf);
174 /** \brief writes record in MarcXchange XML
176 \param wrbuf WRBUF for output
177 \param format record format (e.g. "MARC21")
178 \param type record type (e.g. Bibliographic)
180 Returns 0=OK, -1=ERROR
182 YAZ_EXPORT int yaz_marc_write_marcxchange(yaz_marc_t mt, WRBUF wrbuf,
186 /** \brief writes record in ISO2709 format
188 \param wrbuf WRBUF for output
189 Returns 0=OK, -1=ERROR
191 YAZ_EXPORT int yaz_marc_write_iso2709(yaz_marc_t mt, WRBUF wrbuf);
193 /** \brief writes record in mode - given by yaz_marc_xml mode
195 \param wrbuf WRBUF for output
196 This function calls yaz_marc_write_iso2709, yaz_marc_write_marcxml,
197 etc.. depending on mode given by yaz_marc_xml.
198 Returns 0=OK, -1=ERROR
200 YAZ_EXPORT int yaz_marc_write_mode(yaz_marc_t mt, WRBUF wrbuf);
202 /** \brief sets leader spec (for modifying bytes in 24 byte leader)
208 Spec takes form pos=val,pos=val,...
209 where value is either a number (decimal char value) or a
210 string in 'a', e.g. 9='a'
213 YAZ_EXPORT int yaz_marc_leader_spec(yaz_marc_t mt, const char *leader_spec);
220 * indent-tabs-mode: nil
222 * vim: shiftwidth=4 tabstop=8 expandtab