5. MARC
Prev | Chapter 9. Supporting Tools | Next

## 5. MARC

YAZ provides a fast utility that decodes MARC records and encodes to a varity of output formats. The MARC records must be encoded in ISO2709.

        #include <yaz/marcdisp.h>

        /* create handler */
        yaz_marc_t yaz_marc_create(void);
        /* destroy */
        void yaz_marc_destroy(yaz_marc_t mt);

        /* set XML mode YAZ_MARC_LINE, YAZ_MARC_SIMPLEXML, ... */
        void yaz_marc_xml(yaz_marc_t mt, int xmlmode);
        #define YAZ_MARC_LINE      0
        #define YAZ_MARC_SIMPLEXML 1
        #define YAZ_MARC_OAIMARC   2
        #define YAZ_MARC_MARCXML   3
        #define YAZ_MARC_ISO2709   4
        #define YAZ_MARC_XCHANGE   5

        /* supply iconv handle for character set conversion .. */
        void yaz_marc_iconv(yaz_marc_t mt, yaz_iconv_t cd);

        /* set debug level, 0=none, 1=more, 2=even more, .. */
        void yaz_marc_debug(yaz_marc_t mt, int level);

        /* decode MARC in buf of size bsize. Returns >0 on success; <=0 on failure.
        On success, result in *result with size *rsize. */
        int yaz_marc_decode_buf (yaz_marc_t mt, const char *buf, int bsize,
                                 char **result, int *rsize);

        /* decode MARC in buf of size bsize. Returns >0 on success; <=0 on failure.
           On success, result in WRBUF */
        int yaz_marc_decode_wrbuf (yaz_marc_t mt, const char *buf,
                                   int bsize, WRBUF wrbuf);

A MARC conversion handle must be created by using `yaz_marc_create` and destroyed by calling `yaz_marc_destroy`.

All other function operate on a `yaz_marc_t` handle. The output is specified by a call to `yaz_marc_xml`. The `xmlmode` must be one of

YAZ_MARC_LINE

  A simple line-by-line format suitable for display but not recommend for further (machine) processing.

YAZ_MARC_MARCXML

  The resulting record is converted to MARCXML.

YAZ_MARC_ISO2709

  The resulting record is converted to ISO2709 (MARC).

The actual conversion functions are `yaz_marc_decode_buf` and `yaz_marc_decode_wrbuf` which decodes and encodes a MARC record. The former function operates on simple buffers, the stores the resulting record in a WRBUF handle (WRBUF is a simple string type).

Example 9.13. Display of MARC record

The followint program snippet illustrates how the MARC API may be used to convert a MARC record to the line-by-line format:

          void print_marc(const char *marc_buf, int marc_buf_size)
          {
             char *result;      /* for result buf */
             int result_len;    /* for size of result */
             yaz_marc_t mt = yaz_marc_create();
             yaz_marc_xml(mt, YAZ_MARC_LINE);
             yaz_marc_decode_buf(mt, marc_buf, marc_buf_size,
                                 &result, &result_len);
             fwrite(result, result_len, 1, stdout);
             yaz_marc_destroy(mt);  /* note that result is now freed... */
          }

Prev | Up | Next
4. Log | Home | 6. Retrieval Facility