9c599610fe4d87151d085f1611940f5a16eb705d
[yaz-moved-to-github.git] / include / yaz / marcdisp.h
1 /*
2  * Copyright (c) 1995-2006, 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 /* $Id: marcdisp.h,v 1.20 2006-12-07 11:08:04 adam Exp $ */
28
29 /**
30  * \file marcdisp.h
31  * \brief MARC conversion
32  */
33
34 #ifndef MARCDISP_H
35 #define MARCDISP_H
36
37 #include <yaz/yconfig.h>
38 #include <stdio.h>
39 #include <yaz/wrbuf.h>
40
41 YAZ_BEGIN_CDECL
42
43 /** \brief a yaz_marc_t handle (private content) */
44 typedef struct yaz_marc_t_ *yaz_marc_t;
45
46 /** \brief construct yaz_marc_t handle */
47 YAZ_EXPORT yaz_marc_t yaz_marc_create(void);
48
49 /** \brief destroy yaz_marc_t handle */
50 YAZ_EXPORT void yaz_marc_destroy(yaz_marc_t mt);
51
52 /** \brief set XML mode YAZ_MARC_LINE, YAZ_MARC_SIMPLEXML, ... */
53 YAZ_EXPORT void yaz_marc_xml(yaz_marc_t mt, int xmlmode);
54
55 /** \brief Output format: Line-format */
56 #define YAZ_MARC_LINE      0
57 /** \brief Output format: simplexml (no longer supported) */
58 #define YAZ_MARC_SIMPLEXML 1
59 /** \brief Output format: OAI-MARC (no longer supported) */
60 #define YAZ_MARC_OAIMARC   2
61 /** \brief Output format: MARCXML */
62 #define YAZ_MARC_MARCXML   3
63 /** \brief Output format: ISO2709 */
64 #define YAZ_MARC_ISO2709   4
65 /** \brief Output format: MarcXchange */
66 #define YAZ_MARC_XCHANGE   5
67 /** \brief Output format: check only (no marc output) */
68 #define YAZ_MARC_CHECK  6
69
70 /** \brief supply iconv handle for character set conversion .. */
71 YAZ_EXPORT void yaz_marc_iconv(yaz_marc_t mt, yaz_iconv_t cd);
72
73 /** \brief set debug level 
74     \param mt handle
75     \param level level, where 0=lowest, 1 more debug, 2 even more 
76 */
77 YAZ_EXPORT void yaz_marc_debug(yaz_marc_t mt, int level);
78
79 /** \brief decodes ISO2709 buffer using straight buffers
80     \param mt marc handle
81     \param buf input buffer
82     \param bsize size of buffer or (-1 if "any size")
83     \param result result to be stored here (allocate before use!)
84     \param rsize size of result (set before calling)
85
86     Decodes MARC in buf of size bsize.
87     On success, result in *result with size *rsize. 
88     Returns -1 on error, or size of input record (>0) if OK
89 */
90 YAZ_EXPORT int yaz_marc_decode_buf(yaz_marc_t mt, const char *buf, int bsize,
91                                    char **result, int *rsize);
92
93 /** \brief decodes ISO2709/MARC buffer and stores result in WRBUF
94     \param mt handle
95     \param buf input buffer
96     \param bsize size of buffer (-1 if "any size")
97     \param wrbuf WRBUF for output
98
99     Decodes MARC in buf of size bsize.
100     On success, result in wrbuf
101     Returns -1 on error, or size of input record (>0) if OK
102 */
103 YAZ_EXPORT int yaz_marc_decode_wrbuf(yaz_marc_t mt, const char *buf,
104                                      int bsize, WRBUF wrbuf);
105
106 /** \brief depricated */
107 YAZ_EXPORT int marc_display(const char *buf, FILE *outf);
108 /** \brief depricated */
109 YAZ_EXPORT int marc_display_ex(const char *buf, FILE *outf, int debug);
110 /** \brief depricated */
111 YAZ_EXPORT int marc_display_exl(const char *buf, FILE *outf, int debug,
112                                 int length);
113 /** \brief depricated */
114 YAZ_EXPORT int marc_display_wrbuf(const char *buf, WRBUF wr, int debug,
115                                   int bsize);
116 /** \brief depricated */
117 YAZ_EXPORT int yaz_marc_decode(const char *buf, WRBUF wr,
118                                int debug, int bsize, int xml);
119
120 YAZ_EXPORT void yaz_marc_subfield_str(yaz_marc_t mt, const char *s);
121 YAZ_EXPORT void yaz_marc_endline_str(yaz_marc_t mt, const char *s);
122
123 /** \brief modifies part of the MARC leader */
124 YAZ_EXPORT void yaz_marc_modify_leader(yaz_marc_t mt, size_t off,
125                                        const char *str);
126
127 /** \brief like atoi(3) except that it reads exactly len characters */
128 YAZ_EXPORT int atoi_n(const char *buf, int len);
129
130 /** \brief MARC control char: record separator (29 Dec, 1D Hex) */
131 #define ISO2709_RS 035
132 /** \brief MARC control char: field separator (30 Dec, 1E Hex) */
133 #define ISO2709_FS 036
134 /** \brief MARC control char: identifier-field separator (31 Dec, 1F Hex) */
135 #define ISO2709_IDFS 037
136
137 /** \brief read ISO2709/MARC record from buffer
138     \param mt handle
139     \param buf ISO2709 buffer of size bsize
140     \param bsize size of buffer (-1 for unlimited size)
141
142     Parses ISO2709 record from supplied buffer
143     Returns > 0 for OK (same as length), -1=ERROR
144 */
145 YAZ_EXPORT int yaz_marc_read_iso2709(yaz_marc_t mt,
146                                      const char *buf, int bsize);
147
148 /** \brief parses MARCXML/MarcXchange record from xmlNode pointer 
149     \param mt handle
150     \param xmlnode is a pointer to root xmlNode pointer 
151
152     Returns 0=OK, -1=ERROR
153 */
154 YAZ_EXPORT int yaz_marc_read_xml(yaz_marc_t mt, const void *xmlnode);
155
156 /** \brief writes record in line format
157     \param mt handle
158     \param wrbuf WRBUF for output
159
160     Returns 0=OK, -1=ERROR
161 */
162 YAZ_EXPORT int yaz_marc_write_line(yaz_marc_t mt, WRBUF wrbuf);
163
164 /** \brief writes record in MARCXML format
165     \param mt handle
166     \param wrbuf WRBUF for output
167
168     Sets leader[9]='a' . Returns 0=OK, -1=ERROR . 
169 */
170
171 YAZ_EXPORT int yaz_marc_write_marcxml(yaz_marc_t mt, WRBUF wrbuf);
172
173 /** \brief writes record in MarcXchange XML
174     \param mt handle
175     \param wrbuf WRBUF for output
176     \param format record format (e.g. "MARC21")
177     \param type record type (e.g. Bibliographic)
178
179     Returns 0=OK, -1=ERROR
180 */
181 YAZ_EXPORT int yaz_marc_write_marcxchange(yaz_marc_t mt, WRBUF wrbuf,
182                                           const char *format,
183                                           const char *type);
184
185 /** \brief writes record in ISO2709 format
186     \param mt handle
187     \param wrbuf WRBUF for output
188     Returns 0=OK, -1=ERROR
189 */
190 YAZ_EXPORT int yaz_marc_write_iso2709(yaz_marc_t mt, WRBUF wrbuf);
191
192 /** \brief writes record in mode - given by yaz_marc_xml mode
193     \param mt handle
194     \param wrbuf WRBUF for output
195     This function calls yaz_marc_write_iso2709, yaz_marc_write_marcxml,
196     etc.. depending on mode given by yaz_marc_xml. 
197     Returns 0=OK, -1=ERROR 
198 */  
199 YAZ_EXPORT int yaz_marc_write_mode(yaz_marc_t mt, WRBUF wrbuf);
200
201 /** \brief sets leader spec (for modifying bytes in 24 byte leader)
202     \param mt handle
203     \param leader_spec
204     \retval 0 OK
205     \retval -1 ERROR
206     
207     Spec takes form pos=val,pos=val,...
208     where value is either a number (decimal char value) or a
209     string in 'a', e.g. 9='a'
210     
211 */  
212 YAZ_EXPORT int yaz_marc_leader_spec(yaz_marc_t mt, const char *leader_spec);
213 YAZ_END_CDECL
214
215 #endif
216 /*
217  * Local variables:
218  * c-basic-offset: 4
219  * indent-tabs-mode: nil
220  * End:
221  * vim: shiftwidth=4 tabstop=8 expandtab
222  */
223