if INIT0 specified, use it instead of ASCII.

This commit is contained in:
tnozaki 2006-06-07 16:28:34 +00:00
parent ba08e93977
commit b29e60b31d
1 changed files with 11 additions and 13 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: citrus_iso2022.c,v 1.15 2006/03/19 01:19:32 christos Exp $ */ /* $NetBSD: citrus_iso2022.c,v 1.16 2006/06/07 16:28:34 tnozaki Exp $ */
/*- /*-
* Copyright (c)1999, 2002 Citrus Project, * Copyright (c)1999, 2002 Citrus Project,
@ -30,7 +30,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: citrus_iso2022.c,v 1.15 2006/03/19 01:19:32 christos Exp $"); __RCSID("$NetBSD: citrus_iso2022.c,v 1.16 2006/06/07 16:28:34 tnozaki Exp $");
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <assert.h> #include <assert.h>
@ -87,6 +87,9 @@ typedef struct {
u_char vers; u_char vers;
} _ISO2022Charset; } _ISO2022Charset;
static const _ISO2022Charset ascii = { CS94, 'B', '\0', '\0' };
static const _ISO2022Charset iso88591 = { CS96, 'A', '\0', '\0' };
typedef struct { typedef struct {
_ISO2022Charset g[4]; _ISO2022Charset g[4];
/* need 3 bits to hold -1, 0, ..., 3 */ /* need 3 bits to hold -1, 0, ..., 3 */
@ -1032,21 +1035,15 @@ _ISO2022_sputwchar(_ISO2022EncodingInfo * __restrict ei, wchar_t wc,
/* state appears to be unused */ /* state appears to be unused */
if (iscntl(wc & 0xff)) { if (iscntl(wc & 0xff)) {
/* go back to ASCII on control chars */ /* go back to INIT0 or ASCII on control chars */
cs.type = CS94; cs = ei->initg[0].final ? ei->initg[0] : ascii;
cs.final = 'B';
cs.interm = '\0';
} else if (!(wc & ~0xff)) { } else if (!(wc & ~0xff)) {
if (wc & 0x80) { if (wc & 0x80) {
/* special treatment for ISO-8859-1 */ /* special treatment for ISO-8859-1 */
cs.type = CS96; cs = iso88591;
cs.final = 'A';
cs.interm = '\0';
} else { } else {
/* special treatment for ASCII */ /* special treatment for ASCII */
cs.type = CS94; cs = ascii;
cs.final = 'B';
cs.interm = '\0';
} }
} else { } else {
cs.final = (wc >> 24) & 0x7f; cs.final = (wc >> 24) & 0x7f;
@ -1159,7 +1156,8 @@ sideok:
break; break;
case CS94MULTI: case CS94MULTI:
case CS96MULTI: case CS96MULTI:
i = isthree(cs.final) ? 3 : 2; i = !iscntl(wc & 0xff) ?
(isthree(cs.final) ? 3 : 2) : 1;
break; break;
} }
while (i-- > 0) while (i-- > 0)