1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
/*
* Copyright (C) 2005 Laurent Sansonetti <lrz@chopine.be>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "rbzoom.h"
#ifdef MAKING_RDOC_HAPPY
mZoom = rb_define_module("ZOOM");
#endif
/*
* A record object is a retrieval record on the client side - created from
* result sets.
*/
static VALUE cZoomRecord;
VALUE
rbz_record_make (ZOOM_record record)
{
return record != NULL
? Data_Wrap_Struct (cZoomRecord,
NULL,
ZOOM_record_destroy,
record)
: Qnil;
}
static ZOOM_record
rbz_record_get (VALUE obj)
{
ZOOM_record record;
Data_Get_Struct (obj, struct ZOOM_record_p, record);
assert (record != NULL);
return record;
}
static char _type [128];
static const char *
rbz_record_type (const char *form, int argc, VALUE *argv)
{
VALUE charset_from;
VALUE charset_to;
if (argc == 0)
return form;
rb_scan_args (argc, argv, "11", &charset_from, &charset_to);
memset (_type, 0, sizeof _type);
if (NIL_P (charset_to))
snprintf (_type, sizeof _type, "%s; charset=%s", form,
RVAL2CSTR (charset_from));
else
snprintf (_type, sizeof _type, "%s; charset=%s,%s", form,
RVAL2CSTR (charset_from), RVAL2CSTR (charset_to));
return _type;
}
/*
* call-seq:
* database(charset_from=nil, charset_to=nil)
*
* charset_from: the name of the charset to convert from (optional).
*
* charset_to: the name of the charset to convert to (optional).
*
* Returns: the database name of the record.
*/
static VALUE
rbz_record_database (int argc, VALUE *argv, VALUE self)
{
return CSTR2RVAL (ZOOM_record_get (rbz_record_get (self),
rbz_record_type ("database", argc, argv),
NULL));
}
/*
* call-seq:
* syntax(charset_from=nil, charset_to=nil)
*
* charset_from: the name of the charset to convert from (optional).
*
* charset_to: the name of the charset to convert to (optional).
*
* Returns: the symbolic transfer syntax name of the record.
*/
static VALUE
rbz_record_syntax (int argc, VALUE *argv, VALUE self)
{
return CSTR2RVAL (ZOOM_record_get (rbz_record_get (self),
rbz_record_type ("syntax", argc, argv),
NULL));
}
/*
* call-seq:
* render(charset_from=nil, charset_to=nil)
*
* charset_from: the name of the charset to convert from (optional).
*
* charset_to: the name of the charset to convert to (optional).
*
* Returns: a display friendly description of the record.
*/
static VALUE
rbz_record_render (int argc, VALUE *argv, VALUE self)
{
return CSTR2RVAL (ZOOM_record_get (rbz_record_get (self),
rbz_record_type ("render", argc, argv),
NULL));
}
/*
* call-seq:
* xml(charset_from=nil, charset_to=nil)
*
* charset_from: the name of the charset to convert from (optional).
*
* charset_to: the name of the charset to convert to (optional).
*
* Returns an XML description of the record. SRW/SRU and Z39.50 records with
* transfer syntax XML are returned verbatim. MARC records are returned in
* MARCXML (converted from ISO2709 to MARCXML by YAZ). GRS-1 and OPAC records are
* not supported for this form.
*
* Returns: an XML description of the record.
*/
static VALUE
rbz_record_xml (int argc, VALUE *argv, VALUE self)
{
return CSTR2RVAL (ZOOM_record_get (rbz_record_get (self),
rbz_record_type ("xml", argc, argv),
NULL));
}
/*
* call-seq:
* raw
*
* MARC records are returned in ISO2709.
* GRS-1 and OPAC records are not supported for this form.
*
* Returns: an ISO2709 record.
*/
static VALUE
rbz_record_raw (int argc, VALUE *argv, VALUE self)
{
return CSTR2RVAL (ZOOM_record_get (rbz_record_get (self),
rbz_record_type ("raw", argc, argv),
NULL));
}
void
Init_zoom_record (VALUE mZoom)
{
VALUE c;
c = rb_define_class_under (mZoom, "Record", rb_cObject);
rb_undef_method (CLASS_OF (c), "new");
rb_define_method (c, "database", rbz_record_database, -1);
rb_define_method (c, "syntax", rbz_record_syntax, -1);
rb_define_method (c, "render", rbz_record_render, -1);
rb_define_alias (c, "to_s", "render");
rb_define_method (c, "xml", rbz_record_xml, -1);
rb_define_method (c, "raw", rbz_record_raw, -1);
cZoomRecord = c;
}
|