Added utility yaz_marc_modify_leader which modifies a one or
[yaz-moved-to-github.git] / include / yaz / marcdisp.h
1 /*
2  * Copyright (C) 1995-2006, Index Data ApS
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation, in whole or in part, for any purpose, is hereby granted,
6  * provided that:
7  *
8  * 1. This copyright and permission notice appear in all copies of the
9  * software and its documentation. Notices of copyright or attribution
10  * which appear at the beginning of any file must remain unchanged.
11  *
12  * 2. The name of Index Data or the individual authors may not be used to
13  * endorse or promote products derived from this software without specific
14  * prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS, IMPLIED, OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
18  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19  * IN NO EVENT SHALL INDEX DATA BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
20  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
21  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR
22  * NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24  * OF THIS SOFTWARE.
25  *
26  * $Id: marcdisp.h,v 1.16 2006-04-20 19:47:01 adam Exp $
27  */
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
68 /** \brief supply iconv handle for character set conversion .. */
69 YAZ_EXPORT void yaz_marc_iconv(yaz_marc_t mt, yaz_iconv_t cd);
70
71 /** \brief set debug level 
72     \param mt handle
73     \param level level, where 0=lowest, 1 more debug, 2 even more 
74 */
75 YAZ_EXPORT void yaz_marc_debug(yaz_marc_t mt, int level);
76
77 /** \brief decodes ISO2709 buffer using straight buffers
78     \param mt marc handle
79     \param buf input buffer
80     \param bsize size of buffer or (-1 if "any size")
81     \param result result to be stored here (allocate before use!)
82     \param rsize size of result (set before calling)
83     
84     decode MARC in buf of size bsize. Returns >0 on success; <=0 on failure.
85     On success, result in *result with size *rsize. 
86     Returns -1 on error, size of input record (>0) if OK
87 */
88 YAZ_EXPORT int yaz_marc_decode_buf(yaz_marc_t mt, const char *buf, int bsize,
89                                    char **result, int *rsize);
90
91 /** \brief decodes ISO2709/MAC buffer and stores result in WRBUF */
92 YAZ_EXPORT int yaz_marc_decode_wrbuf(yaz_marc_t mt, const char *buf,
93                                      int bsize, WRBUF wrbuf);
94
95 /** \brief depricated */
96 YAZ_EXPORT int marc_display(const char *buf, FILE *outf);
97 /** \brief depricated */
98 YAZ_EXPORT int marc_display_ex(const char *buf, FILE *outf, int debug);
99 /** \brief depricated */
100 YAZ_EXPORT int marc_display_exl(const char *buf, FILE *outf, int debug,
101                                 int length);
102 /** \brief depricated */
103 YAZ_EXPORT int marc_display_wrbuf(const char *buf, WRBUF wr, int debug,
104                                   int bsize);
105 /** \brief depricated */
106 YAZ_EXPORT int yaz_marc_decode(const char *buf, WRBUF wr,
107                                int debug, int bsize, int xml);
108
109 YAZ_EXPORT void yaz_marc_subfield_str(yaz_marc_t mt, const char *s);
110 YAZ_EXPORT void yaz_marc_endline_str(yaz_marc_t mt, const char *s);
111
112 /** \brief modifies part of the MARC leader */
113 YAZ_EXPORT void yaz_marc_modify_leader(yaz_marc_t mt, size_t off,
114                                        const char *str);
115
116 /** \brief like atoi except that it reads exactly len characters */
117 YAZ_EXPORT int atoi_n(const char *buf, int len);
118
119 /** \brief MARC control char: record separator (29 Dec, 1D Hex) */
120 #define ISO2709_RS 035
121 /** \brief MARC control char: field separator (30 Dec, 1E Hex) */
122 #define ISO2709_FS 036
123 /** \brief MARC control char: identifier-field separator (31 Dec, 1F Hex) */
124 #define ISO2709_IDFS 037
125
126 /** \brief read ISO2709/MARC record from buffer */
127 YAZ_EXPORT int yaz_marc_read_iso2709(yaz_marc_t mt,
128                                      const char *buf, int bsize);
129 /** \brief read MARCXML record from buffer */
130 YAZ_EXPORT int yaz_marc_read_xml(yaz_marc_t mt, const void *xmlnode);
131
132 /** \brief writes record in line format */
133 YAZ_EXPORT int yaz_marc_write_line(yaz_marc_t mt, WRBUF wrbuf);
134 /** \brief writes record in MARCXML format */
135 YAZ_EXPORT int yaz_marc_write_marcxml(yaz_marc_t mt, WRBUF wrbuf);
136 /** \brief writes record in MarcXchange format */
137 YAZ_EXPORT int yaz_marc_write_marcxchange(yaz_marc_t mt, WRBUF wrbuf);
138 /** \brief writes record in ISO2709 format */
139 YAZ_EXPORT int yaz_marc_write_iso2709(yaz_marc_t mt, WRBUF wrbuf);
140 /** \brief writes record in mode - given by yaz_marc_xml mode */
141 YAZ_EXPORT int yaz_marc_write_mode(yaz_marc_t mt, WRBUF wr);
142
143 YAZ_END_CDECL
144
145 #endif
146 /*
147  * Local variables:
148  * c-basic-offset: 4
149  * indent-tabs-mode: nil
150  * End:
151  * vim: shiftwidth=4 tabstop=8 expandtab
152  */
153