[uim-commit] r2072 - branches/r5rs/sigscheme
kzk at freedesktop.org
kzk at freedesktop.org
Mon Nov 7 08:09:28 PST 2005
Author: kzk
Date: 2005-11-07 08:09:22 -0800 (Mon, 07 Nov 2005)
New Revision: 2072
Modified:
branches/r5rs/sigscheme/debug.c
branches/r5rs/sigscheme/read.c
Log:
* sigscheme/read.c
- (read_char): simplify with Scm_special_char_table
- (read_string): Ditto
* sigscheme/debug.c
- (print_char): Ditto
- (print_string): Ditto
Modified: branches/r5rs/sigscheme/debug.c
===================================================================
--- branches/r5rs/sigscheme/debug.c 2005-11-07 15:54:29 UTC (rev 2071)
+++ branches/r5rs/sigscheme/debug.c 2005-11-07 16:09:22 UTC (rev 2072)
@@ -291,20 +291,25 @@
static void print_char(ScmObj port, ScmObj obj, enum OutputType otype)
{
+ const ScmSpecialCharInfo *info = NULL;
+ const char *lex_rep = NULL;
+
+ /* sanity check */
+ if (SCM_CHAR_VALUE(obj) == NULL)
+ return;
+
switch (otype) {
case AS_WRITE:
- /* FIXME: Simplify with Scm_special_char_table */
- /*
- * in write, character objects are written using the #\ notation.
- */
- if (strcmp(SCM_CHAR_VALUE(obj), " ") == 0) {
- SCM_PORT_PRINT(port, "#\\space");
- } else if(strcmp(SCM_CHAR_VALUE(obj), "\n") == 0) {
- SCM_PORT_PRINT(port, "#\\newline");
- } else {
- SigScm_PortPrintf(port, "#\\%s", SCM_CHAR_VALUE(obj));
+ lex_rep = SCM_CHAR_VALUE(obj);
+ for (info = Scm_special_char_table; info->esc_seq; info++) {
+ if (SCM_CHAR_VALUE(obj)[0] == info->code) {
+ lex_rep = info->lex_rep;
+ break;
+ }
}
+ SigScm_PortPrintf(port, "#\\%s", lex_rep);
break;
+
case AS_DISPLAY:
/*
* in display, character objects appear in the reqpresentation as
@@ -312,6 +317,7 @@
*/
SCM_PORT_PRINT(port, SCM_CHAR_VALUE(obj));
break;
+
default:
ERR("print_char : unknown output type");
break;
@@ -321,9 +327,11 @@
static void print_string(ScmObj port, ScmObj obj, enum OutputType otype)
{
const char *str = SCM_STRING_STR(obj);
- int size = strlen(str);
- int i = 0;
- char c = 0;
+ const ScmSpecialCharInfo *info = NULL;
+ int size = strlen(str);
+ int i = 0;
+ int found = 0;
+ unsigned int c = 0;
switch (otype) {
case AS_WRITE:
@@ -334,19 +342,18 @@
*/
SCM_PORT_PRINT(port, "\""); /* first doublequote */
for (i = 0; i < size; i++) {
- /* FIXME: Simplify with Scm_special_char_table */
+ /* iterate Scm_special_char_table */
c = str[i];
- switch (c) {
- case '\"': SCM_PORT_PRINT(port, "\\\""); break;
- case '\n': SCM_PORT_PRINT(port, "\\n"); break;
- case '\r': SCM_PORT_PRINT(port, "\\r"); break;
- case '\f': SCM_PORT_PRINT(port, "\\f"); break;
- case '\t': SCM_PORT_PRINT(port, "\\t"); break;
- case '\\': SCM_PORT_PRINT(port, "\\\\"); break;
- default:
+ found = 0;
+ for (info = Scm_special_char_table; info->esc_seq; info++) {
+ if (c == info->code) {
+ SigScm_PortPrintf(port, "%s", info->lex_rep);
+ found = 1;
+ break;
+ }
+ }
+ if (!found)
SigScm_PortPrintf(port, "%c", str[i]);
- break;
- }
}
SCM_PORT_PRINT(port, "\""); /* last doublequote */
break;
Modified: branches/r5rs/sigscheme/read.c
===================================================================
--- branches/r5rs/sigscheme/read.c 2005-11-07 15:54:29 UTC (rev 2071)
+++ branches/r5rs/sigscheme/read.c 2005-11-07 16:09:22 UTC (rev 2072)
@@ -331,24 +331,17 @@
static ScmObj read_char(ScmObj port)
{
char *ch = read_char_sequence(port);
+ const ScmSpecialCharInfo *info = Scm_special_char_table;
CDBG((SCM_DBG_PARSER, "read_char : ch = %s", ch));
- /* FIXME: Simplify with Scm_special_char_table */
- /* check special sequence "space" and "newline" */
- if (strcmp(ch, "space") == 0) {
- ch[0] = ' ';
- ch[1] = '\0';
-#if 0
- /* to avoid portability problem, we should not support #\Space and so on */
- } else if (strcmp(ch, "Space") == 0) {
- ch[0] = ' ';
- ch[1] = '\0';
-#endif
- } else if (strcmp(ch, "newline") == 0) {
- /* TODO: Support platform-dependent newline character sequence */
- ch[0] = '\n';
- ch[1] = '\0';
+ /* check special sequence */
+ for (; info->esc_seq; info++) {
+ if (strcmp(ch, info->lex_rep) == 0) {
+ ch[0] = info->code;
+ ch[1] = '\0';
+ break;
+ }
}
return Scm_NewChar(ch);
@@ -359,6 +352,8 @@
char stringbuf[1024]; /* FIXME! */
int stringlen = 0;
int c = 0;
+ const ScmSpecialCharInfo *info = NULL;
+ int found = 0;
CDBG((SCM_DBG_PARSER, "read_string"));
@@ -378,24 +373,23 @@
return Scm_NewStringCopying(stringbuf);
case '\\':
- /* FIXME: Simplify with Scm_special_char_table */
/*
* (R5RS) 6.3.5 String
* A double quote can be written inside a string only by
* escaping it with a backslash (\).
*/
SCM_PORT_GETC(port, c);
- switch (c) {
- case '\"': stringbuf[stringlen] = c; break;
- case 'n': stringbuf[stringlen] = '\n'; break;
- case 'r': stringbuf[stringlen] = '\r'; break;
- case 'f': stringbuf[stringlen] = '\f'; break;
- case 't': stringbuf[stringlen] = '\t'; break;
- case '\\': stringbuf[stringlen] = '\\'; break;
- default:
+ found = 0;
+ for (info = Scm_special_char_table; info->esc_seq; info++) {
+ if (strlen(info->esc_seq) > 1 && c == info->esc_seq[1]) {
+ stringbuf[stringlen] = info->code;
+ found = 1;
+ break;
+ }
+ }
+ if (!found) {
stringbuf[stringlen] = '\\';
stringbuf[++stringlen] = c;
- break;
}
stringlen++;
break;
More information about the uim-commit
mailing list