+ *no_read = 0;
+ while(inbytesleft >= 1 && inp[0] == 27)
+ {
+ size_t inbytesleft0 = inbytesleft;
+ inp++;
+ inbytesleft--;
+ if (inbytesleft <= 1)
+ {
+ *no_read = 0;
+ cd->my_errno = YAZ_ICONV_EINVAL;
+ return 0;
+ }
+ if (*inp == '(' || *inp == ',') /* GO, one bytes */
+ {
+ inbytesleft--;
+ inp++;
+ }
+ else if (*inp == '$') /* G0, multi byte */
+ {
+ inbytesleft--;
+ inp++;
+ if (inp[0] == ',')
+ {
+ inbytesleft--;
+ inp++;
+ }
+ }
+ if (inbytesleft <= 0)
+ {
+ *no_read = 0;
+ cd->my_errno = YAZ_ICONV_EINVAL;
+ return 0;
+ }
+ if (*inp == '!')
+ {
+ if (inbytesleft <= 1)
+ {
+ *no_read = 0;
+ cd->my_errno = YAZ_ICONV_EINVAL;
+ return 0;
+ }
+ inbytesleft--;
+ inp++;
+ }
+ cd->marc8_esc_mode = *inp++;
+ inbytesleft--;
+ (*no_read) += inbytesleft0 - inbytesleft;
+ }
+ if (inbytesleft <= 0)
+ return 0;
+ else
+ {
+ unsigned long x;
+ size_t no_read_sub = 0;
+
+ switch(cd->marc8_esc_mode)
+ {
+ case 'B':
+ case 'E':
+ x = yaz_marc8_conv(inp, inbytesleft, &no_read_sub);
+ *no_read += no_read_sub;
+ return x;
+ case '1':
+ x = yaz_marc8_cjk_conv(inp, inbytesleft, &no_read_sub);
+ *no_read += no_read_sub;
+ return x;
+ default:
+ *no_read = 0;
+ cd->my_errno = YAZ_ICONV_EILSEQ;
+ return 0;
+ }
+ }