1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>5. MARC</title><meta name="generator" content="DocBook XSL Stylesheets V1.70.1"><link rel="start" href="index.html" title="YAZ User's Guide and Reference"><link rel="up" href="tools.html" title="Chapter 8. Supporting Tools"><link rel="prev" href="tools.log.html" title="4. Log"><link rel="next" href="odr.html" title="Chapter 9. The ODR Module"></head><body><link rel="stylesheet" type="text/css" href="common/style1.css"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5. MARC</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="tools.log.html">Prev</a> </td><th width="60%" align="center">Chapter 8. Supporting Tools</th><td width="20%" align="right"> <a accesskey="n" href="odr.html">Next</a></td></tr></table><hr></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="tools.marc"></a>5. MARC</h2></div></div></div><p>
2 YAZ provides a fast utility that decodes MARC records and
3 encodes to a varity of output formats. The MARC records must
5 </p><pre class="synopsis">
6 #include <yaz/marcdisp.h>
9 yaz_marc_t yaz_marc_create(void);
11 void yaz_marc_destroy(yaz_marc_t mt);
13 /* set XML mode YAZ_MARC_LINE, YAZ_MARC_SIMPLEXML, ... */
14 void yaz_marc_xml(yaz_marc_t mt, int xmlmode);
15 #define YAZ_MARC_LINE 0
16 #define YAZ_MARC_SIMPLEXML 1
17 #define YAZ_MARC_OAIMARC 2
18 #define YAZ_MARC_MARCXML 3
19 #define YAZ_MARC_ISO2709 4
20 #define YAZ_MARC_XCHANGE 5
22 /* supply iconv handle for character set conversion .. */
23 void yaz_marc_iconv(yaz_marc_t mt, yaz_iconv_t cd);
25 /* set debug level, 0=none, 1=more, 2=even more, .. */
26 void yaz_marc_debug(yaz_marc_t mt, int level);
28 /* decode MARC in buf of size bsize. Returns >0 on success; <=0 on failure.
29 On success, result in *result with size *rsize. */
30 int yaz_marc_decode_buf (yaz_marc_t mt, const char *buf, int bsize,
31 char **result, int *rsize);
33 /* decode MARC in buf of size bsize. Returns >0 on success; <=0 on failure.
34 On success, result in WRBUF */
35 int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf,
36 int bsize, WRBUF wrbuf);
39 A MARC conversion handle must be created by using
40 <code class="function">yaz_marc_create</code> and destroyed
41 by calling <code class="function">yaz_marc_destroy</code>.
43 All other function operate on a <code class="literal">yaz_marc_t</code> handle.
44 The output is specified by a call to <code class="function">yaz_marc_xml</code>.
45 The <code class="literal">xmlmode</code> must be one of
46 </p><div class="variablelist"><dl><dt><span class="term">YAZ_MARC_LINE</span></dt><dd><p>
47 A simple line-by-line format suitable for display but not
48 recommend for further (machine) processing.
49 </p></dd><dt><span class="term">YAZ_MARC_MARXML</span></dt><dd><p>
50 The resulting record is converted to MARCXML.
51 </p></dd><dt><span class="term">YAZ_MARC_ISO2709</span></dt><dd><p>
52 The resulting record is converted to ISO2709 (MARC).
53 </p></dd></dl></div><p>
55 The actual conversion functions are
56 <code class="function">yaz_marc_decode_buf</code> and
57 <code class="function">yaz_marc_decode_wrbuf</code> which decodes and encodes
58 a MARC record. The former function operates on simple buffers, the
59 stores the resulting record in a WRBUF handle (WRBUF is a simple string
61 </p><div class="example"><a name="id2596589"></a><p class="title"><b>Example 8.11. Display of MARC record</b></p><div class="example-contents"><p>
62 The followint program snippet illustrates how the MARC API may
63 be used to convert a MARC record to the line-by-line format:
64 </p><pre class="programlisting">
65 void print_marc(const char *marc_buf, int marc_buf_size)
67 char *result; /* for result buf */
68 int result_len; /* for size of result */
69 yaz_marc_t mt = yaz_marc_create();
70 yaz_marc_xml(mt, YAZ_MARC_LINE);
71 yaz_marc_decode_buf(mt, marc_buf, marc_buf_size,
72 &result, &result_len);
73 fwrite(result, result_len, 1, stdout);
74 yaz_marc_destroy(mt); /* note that result is now freed... */
78 </p></div></div><br class="example-break"></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="tools.log.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="tools.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="odr.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">4. Log </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 9. The ODR Module</td></tr></table></div></body></html>