1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data
3 * See the file LICENSE for details.
7 * \brief ISO 5426 decoding
10 * http://www.loc.gov/marc/specifications/specchariso8.html
12 * ISO 5426 reference (in German)
13 * Zeichenkonkordanz MAB2-Zeichensatz - ISO/IEC 10646 / Unicode
14 * http://www.d-nb.de/standardisierung/pdf/mab_unic.pdf
25 #include <yaz/xmalloc.h>
34 unsigned long comb_x[8];
35 size_t comb_no_read[8];
38 yaz_conv_func_t yaz_iso5426_42_conv;
39 yaz_conv_func_t yaz_iso5426_45_conv;
40 yaz_conv_func_t yaz_iso5426_67_conv;
41 yaz_conv_func_t yaz_iso5426_62_conv;
42 yaz_conv_func_t yaz_iso5426_70_conv;
43 yaz_conv_func_t yaz_iso5426_32_conv;
44 yaz_conv_func_t yaz_iso5426_4E_conv;
45 yaz_conv_func_t yaz_iso5426_51_conv;
46 yaz_conv_func_t yaz_iso5426_33_conv;
47 yaz_conv_func_t yaz_iso5426_34_conv;
48 yaz_conv_func_t yaz_iso5426_53_conv;
49 yaz_conv_func_t yaz_iso5426_31_conv;
52 static unsigned long yaz_read_iso5426_comb(yaz_iconv_t cd,
53 struct decoder_data *data,
55 size_t inbytesleft, size_t *no_read,
58 static unsigned long read_iso5426(yaz_iconv_t cd, yaz_iconv_decoder_t d,
60 size_t inbytesleft, size_t *no_read)
62 struct decoder_data *data = (struct decoder_data *) d->data;
64 if (data->comb_offset < data->comb_size)
66 *no_read = data->comb_no_read[data->comb_offset];
67 x = data->comb_x[data->comb_offset];
69 /* special case for double-diacritic combining characters,
70 INVERTED BREVE and DOUBLE TILDE.
71 We'll increment the no_read counter by 1, since we want to skip over
72 the processing of the closing ligature character
74 /* this code is no longer necessary.. our handlers code in
75 yaz_iso5426_?_conv (generated by charconv.tcl) now returns
76 0 and no_read=1 when a sequence does not match the input.
77 The SECOND HALFs in codetables.xml produces a non-existant
78 entry in the conversion trie.. Hence when met, the input byte is
79 skipped as it should (in yaz_iconv)
82 if (x == 0x0361 || x == 0x0360)
89 data->comb_offset = 0;
90 for (data->comb_size = 0; data->comb_size < 8; data->comb_size++)
94 if (inbytesleft == 0 && data->comb_size)
96 yaz_iconv_set_errno(cd, YAZ_ICONV_EINVAL);
101 x = yaz_read_iso5426_comb(cd, data, inp, inbytesleft, no_read, &comb);
104 data->comb_x[data->comb_size] = x;
105 data->comb_no_read[data->comb_size] = *no_read;
107 inbytesleft = inbytesleft - *no_read;
112 static unsigned long yaz_read_iso5426_comb(yaz_iconv_t cd,
113 struct decoder_data *data,
115 size_t inbytesleft, size_t *no_read,
119 while (inbytesleft > 0 && *inp == 27)
121 int *modep = &data->g0_mode;
122 size_t inbytesleft0 = inbytesleft;
126 if (inbytesleft == 0)
128 if (*inp == '$') /* set with multiple bytes */
133 if (inbytesleft == 0)
135 if (*inp == '(' || *inp == ',') /* G0 */
140 else if (*inp == ')' || *inp == '-') /* G1 */
144 modep = &data->g1_mode;
146 if (inbytesleft == 0)
148 if (*inp == '!') /* ANSEL is a special case */
153 if (inbytesleft == 0)
155 *modep = *inp++; /* Final character */
158 (*no_read) += inbytesleft0 - inbytesleft;
160 if (inbytesleft == 0)
162 else if (*inp == ' ')
170 size_t no_read_sub = 0;
171 int mode = *inp < 128 ? data->g0_mode : data->g1_mode;
176 case 'B': /* Basic ASCII */
177 case 's': /* ASCII */
178 x = yaz_iso5426_42_conv(inp, inbytesleft, &no_read_sub, comb,
181 case 'E': /* ANSEL */
182 x = yaz_iso5426_45_conv(inp, inbytesleft, &no_read_sub, comb,
187 yaz_iconv_set_errno(cd, YAZ_ICONV_EILSEQ);
190 *no_read += no_read_sub;
195 yaz_iconv_set_errno(cd, YAZ_ICONV_EINVAL);
200 static size_t init_iso5426(yaz_iconv_t cd, yaz_iconv_decoder_t d,
202 size_t inbytesleft, size_t *no_read)
204 struct decoder_data *data = (struct decoder_data *) d->data;
207 data->comb_offset = data->comb_size = 0;
211 void destroy_iso5426(yaz_iconv_decoder_t d)
213 struct decoder_data *data = (struct decoder_data *) d->data;
217 yaz_iconv_decoder_t yaz_iso5426_decoder(const char *fromcode,
218 yaz_iconv_decoder_t d)
220 if (!yaz_matchstr(fromcode, "ISO5426"))
221 d->read_handle = read_iso5426;
225 struct decoder_data *data = (struct decoder_data *)
226 xmalloc(sizeof(*data));
228 d->init_handle = init_iso5426;
229 d->destroy_handle = destroy_iso5426;
238 * c-file-style: "Stroustrup"
239 * indent-tabs-mode: nil
241 * vim: shiftwidth=4 tabstop=8 expandtab