[uim-commit] r2839 - branches/r5rs/sigscheme
yamaken at freedesktop.org
yamaken at freedesktop.org
Sun Jan 8 01:18:47 PST 2006
Author: yamaken
Date: 2006-01-08 01:18:44 -0800 (Sun, 08 Jan 2006)
New Revision: 2839
Modified:
branches/r5rs/sigscheme/encoding.c
branches/r5rs/sigscheme/encoding.h
branches/r5rs/sigscheme/print.c
Log:
* sigscheme/encoding.h
- (SCM_MBS_INIT2, SCM_CHARCODEC_READ_CHAR): New macro
- (scm_charcodec_read_char): New function decl
* sigscheme/encoding.c
- (scm_charcodec_read_char): New function
* sigscheme/print.c
- (print_string): Support multibyte string properly
Modified: branches/r5rs/sigscheme/encoding.c
===================================================================
--- branches/r5rs/sigscheme/encoding.c 2006-01-08 09:17:00 UTC (rev 2838)
+++ branches/r5rs/sigscheme/encoding.c 2006-01-08 09:18:44 UTC (rev 2839)
@@ -334,6 +334,35 @@
return NULL;
}
+int
+scm_charcodec_read_char(ScmCharCodec *codec, ScmMultibyteString *mbs,
+ const char *caller)
+{
+ ScmMultibyteCharInfo mbc;
+ ScmMultibyteState state;
+ int ch;
+ DECLARE_INTERNAL_FUNCTION("scm_charcodec_read_char");
+
+ SCM_ASSERT(SCM_MBS_GET_SIZE(*mbs));
+
+ SCM_MANGLE(name) = caller;
+
+ state = SCM_MBS_GET_STATE(*mbs);
+ mbc = SCM_CHARCODEC_SCAN_CHAR(codec, *mbs);
+ if (SCM_MBCINFO_ERRORP(mbc) || SCM_MBCINFO_INCOMPLETEP(mbc))
+ ERR("invalid char sequence");
+ ch = SCM_CHARCODEC_STR2INT(codec,
+ SCM_MBS_GET_STR(*mbs),
+ SCM_MBCINFO_GET_SIZE(mbc),
+ state);
+ if (ch == EOF)
+ ERR("invalid char sequence");
+
+ SCM_MBS_SKIP_CHAR(*mbs, mbc);
+
+ return ch;
+}
+
/*=======================================
Encoding-specific functions
=======================================*/
Modified: branches/r5rs/sigscheme/encoding.h
===================================================================
--- branches/r5rs/sigscheme/encoding.h 2006-01-08 09:17:00 UTC (rev 2838)
+++ branches/r5rs/sigscheme/encoding.h 2006-01-08 09:18:44 UTC (rev 2839)
@@ -97,6 +97,12 @@
SCM_MBS_SET_SIZE((mbs), 0); \
SCM_MBS_CLEAR_STATE(mbs); \
} while (/* CONSTCOND */ 0)
+#define SCM_MBS_INIT2(mbs, s, siz) \
+ do { \
+ SCM_MBS_SET_STR((mbs), (s)); \
+ SCM_MBS_SET_SIZE((mbs), (siz)); \
+ SCM_MBS_CLEAR_STATE(mbs); \
+ } while (/* CONSTCOND */ 0)
#define SCM_MBS_SKIP_CHAR(mbs, inf) \
do { \
SCM_MBS_SET_STR((mbs), \
@@ -115,6 +121,8 @@
((*(codec)->str2int)((src), (len), (state)))
#define SCM_CHARCODEC_INT2STR(codec, dst, ch, state) \
((*(codec)->int2str)((dst), (ch), (state)))
+#define SCM_CHARCODEC_READ_CHAR(codec, mbs) \
+ (scm_charcodec_read_char((codec), &(mbs), SCM_MANGLE(name)))
/*=======================================
Type Definitions
@@ -198,6 +206,7 @@
ScmMultibyteString scm_mb_substring(ScmMultibyteString str, int i, int len);
#define scm_mb_strref(str, i) (scm_mb_substring((str), (i), 1))
ScmCharCodec *scm_mb_find_codec(const char *encoding);
+int scm_charcodec_read_char(ScmCharCodec *codec, ScmMultibyteString *mbs,
+ const char *caller);
-
#endif /* __SCM_ENCODING_H */
Modified: branches/r5rs/sigscheme/print.c
===================================================================
--- branches/r5rs/sigscheme/print.c 2006-01-08 09:17:00 UTC (rev 2838)
+++ branches/r5rs/sigscheme/print.c 2006-01-08 09:18:44 UTC (rev 2839)
@@ -286,32 +286,45 @@
}
}
-/* FIXME: support multibyte char properly */
static void
print_string(ScmObj port, ScmObj obj, enum OutputType otype)
{
+ ScmCharCodec *codec;
+ ScmMultibyteString mbs;
const ScmSpecialCharInfo *info;
const char *str;
- int len, c, i;
+ int len, c;
+ DECLARE_INTERNAL_FUNCTION("print_string");
str = SCM_STRING_STR(obj);
len = strlen(str);
switch (otype) {
case AS_WRITE:
- scm_port_put_char(port, '\"'); /* first doublequote */
- for (i = 0; i < len; i++) {
- c = str[i];
- for (info = scm_special_char_table; info->esc_seq; info++) {
- if (c == info->code) {
- scm_port_puts(port, info->esc_seq);
- break;
+ scm_port_put_char(port, '\"'); /* opening doublequote */
+ if (scm_current_char_codec != scm_port_codec(port)) {
+ /* Since the str does not have its encoding information, here
+ * assumes that scm_current_char_codec is that. And then SigScheme
+ * does not have an encoding conversion mechanism, puts it
+ * as-is. */
+ scm_port_puts(port, str);
+ } else {
+ codec = scm_port_codec(port);
+ SCM_MBS_INIT2(mbs, str, len);
+ while (SCM_MBS_GET_SIZE(mbs)) {
+ c = SCM_CHARCODEC_READ_CHAR(codec, mbs);
+ for (info = scm_special_char_table; info->esc_seq; info++) {
+ if (c == info->code) {
+ scm_port_puts(port, info->esc_seq);
+ goto continue2;
+ }
}
+ scm_port_put_char(port, c);
+ continue2:
+ ;
}
- if (!info->esc_seq)
- scm_port_put_char(port, str[i]);
}
- scm_port_put_char(port, '\"'); /* last doublequote */
+ scm_port_put_char(port, '\"'); /* closing doublequote */
break;
case AS_DISPLAY:
More information about the uim-commit
mailing list