version 1.11, 2014/11/01 04:08:43 |
version 1.12, 2014/11/14 04:24:04 |
Line 29 preconv_encode(struct buf *ib, size_t *ii, struct buf |
|
Line 29 preconv_encode(struct buf *ib, size_t *ii, struct buf |
|
int *filenc) |
int *filenc) |
{ |
{ |
size_t i; |
size_t i; |
const long one = 1L; |
int state; |
int state, be; |
|
unsigned int accum; |
unsigned int accum; |
unsigned char cu; |
unsigned char cu; |
|
|
Line 39 preconv_encode(struct buf *ib, size_t *ii, struct buf |
|
Line 38 preconv_encode(struct buf *ib, size_t *ii, struct buf |
|
|
|
state = 0; |
state = 0; |
accum = 0U; |
accum = 0U; |
be = 0; |
|
|
|
/* Quick test for big-endian value. */ |
|
|
|
if ( ! (*((const char *)(&one)))) |
|
be = 1; |
|
|
|
for (i = *ii; i < ib->sz; i++) { |
for (i = *ii; i < ib->sz; i++) { |
cu = ib->buf[i]; |
cu = ib->buf[i]; |
if (state) { |
if (state) { |
Line 66 preconv_encode(struct buf *ib, size_t *ii, struct buf |
|
Line 59 preconv_encode(struct buf *ib, size_t *ii, struct buf |
|
if (state) |
if (state) |
continue; |
continue; |
|
|
/* |
|
* Accum is held in little-endian order as |
|
* stipulated by the UTF-8 sequence coding. We |
|
* need to convert to a native big-endian if our |
|
* architecture requires it. |
|
*/ |
|
|
|
if (be) |
|
accum = (accum >> 24) | |
|
((accum << 8) & 0x00FF0000) | |
|
((accum >> 8) & 0x0000FF00) | |
|
(accum << 24); |
|
|
|
if (accum < 0x80) |
if (accum < 0x80) |
ob->buf[(*oi)++] = accum; |
ob->buf[(*oi)++] = accum; |
else |
else |
Line 93 preconv_encode(struct buf *ib, size_t *ii, struct buf |
|
Line 73 preconv_encode(struct buf *ib, size_t *ii, struct buf |
|
* UTF-8 bitmask, calculate the expected UTF-8 |
* UTF-8 bitmask, calculate the expected UTF-8 |
* state from it. |
* state from it. |
*/ |
*/ |
for (state = 0; state < 7; state++) |
for (state = 0; state < 7; state++) |
if ( ! (cu & (1 << (7 - state)))) |
if ( ! (cu & (1 << (7 - state)))) |
break; |
break; |
|
|
Line 158 preconv_cue(const struct buf *b, size_t offset) |
|
Line 138 preconv_cue(const struct buf *b, size_t offset) |
|
|
|
/* Check if we have the correct header/trailer. */ |
/* Check if we have the correct header/trailer. */ |
|
|
if ((sz = (size_t)(eoln - ln)) < 10 || |
if ((sz = (size_t)(eoln - ln)) < 10 || |
memcmp(ln, ".\\\" -*-", 7) || memcmp(eoln - 3, "-*-", 3)) |
memcmp(ln, ".\\\" -*-", 7) || memcmp(eoln - 3, "-*-", 3)) |
return(MPARSE_UTF8 | MPARSE_LATIN1); |
return(MPARSE_UTF8 | MPARSE_LATIN1); |
|
|
Line 189 preconv_cue(const struct buf *b, size_t offset) |
|
Line 169 preconv_cue(const struct buf *b, size_t offset) |
|
sz -= phsz; |
sz -= phsz; |
ln += phsz; |
ln += phsz; |
continue; |
continue; |
} |
} |
|
|
sz -= 7; |
sz -= 7; |
ln += 7; |
ln += 7; |