[uim-commit] r2787 - branches/r5rs/sigscheme

yamaken at freedesktop.org yamaken at freedesktop.org
Wed Jan 4 14:36:34 PST 2006


Author: yamaken
Date: 2006-01-04 14:36:29 -0800 (Wed, 04 Jan 2006)
New Revision: 2787

Modified:
   branches/r5rs/sigscheme/TODO
   branches/r5rs/sigscheme/encoding.c
   branches/r5rs/sigscheme/encoding.h
   branches/r5rs/sigscheme/sigscheme.h
Log:
* sigscheme/encoding.h
  - (SCM_MBS_GET_STATE, SCM_MBS_SET_STATE, SCM_MBS_CLEAR_STATE,
    SCM_MBCINFO_INIT, SCM_MBS_INIT, SCM_MBS_SKIP_CHAR): Make state
    macros warning-free when !SCM_USE_STATEFUL_ENCODING
  - (SCM_MBCINFO_SET_SIZE, SCM_MBCINFO_GET_SIZE,
    SCM_MBCINFO_CLEAR_STATE, SCM_MBCINFO_SET_STATE,
    SCM_MBCINFO_GET_STATE):
    * Ditto
    * Replace shared MBS macros with dedicated ones to avoid confusions
  - (scm_bool): New type
  - (scm_false, scm_true): New macro
  - (ScmCharCodecMethod_statefulp): Change return type to scm_bool
* sigscheme/encoding.c
  - (SCM_USE_UTF8, SCM_USE_EUCJP, SCM_USE_EUCCN, SCM_USE_EUCKR,
    SCM_USE_SJIS, SCM_USE_UTF8_AS_DEFAULT, CDBG): New macro for
    !SCM_ENCODING_USE_WITH_SIGSCHEME
  - (pred_always_true, pred_always_false): Change return type to
    scm_bool
  - (scm_mb_strlen): Logical simplification
  - (scm_mb_bare_c_strlen, scm_mb_substring, RETURN, RETURN_ERROR,
    RETURN_INCOMPLETE, SAVE_STATE, utf8_scan_char, sjis_scan_char,
    unibyte_scan_char): Cosmetic change
  - (IN_GR96): Suppless the warning
  - (eucjp_char_len, euc_char_len, utf8_char_len, sjis_char_len):
    Change buffer type to uchar
* sigscheme/sigscheme.h
  - (scm_bool, scm_false, scm_true): Enclose into duplicate definition
    guard
* sigscheme/TODO
  - Update


Modified: branches/r5rs/sigscheme/TODO
===================================================================
--- branches/r5rs/sigscheme/TODO	2006-01-04 20:15:08 UTC (rev 2786)
+++ branches/r5rs/sigscheme/TODO	2006-01-04 22:36:29 UTC (rev 2787)
@@ -12,7 +12,7 @@
 * Fix all destructive expression on macros
 
 * Review and refactor all functions in syntax.c(listran, vectran,
-  qquote_internal, scm_s_quasiquote, scm_s_do), encoding.[hc] and *port.[hc]
+  qquote_internal, scm_s_quasiquote, scm_s_do) and *port.[hc]
   sigschemeinternal.h, storage-fatty.h (other files had already been done
   except for the destructive exp on macros)
 

Modified: branches/r5rs/sigscheme/encoding.c
===================================================================
--- branches/r5rs/sigscheme/encoding.c	2006-01-04 20:15:08 UTC (rev 2786)
+++ branches/r5rs/sigscheme/encoding.c	2006-01-04 22:36:29 UTC (rev 2787)
@@ -53,6 +53,14 @@
 #if SCM_ENCODING_USE_WITH_SIGSCHEME
 #include "sigscheme.h"
 #include "sigschemeinternal.h"
+#else
+#define SCM_USE_UTF8  1
+#define SCM_USE_EUCJP 1
+#define SCM_USE_EUCCN 1
+#define SCM_USE_EUCKR 1
+#define SCM_USE_SJIS  1
+#define SCM_USE_UTF8_AS_DEFAULT 1
+#define CDBG(args)
 #endif
 
 /*=======================================
@@ -64,8 +72,8 @@
 /*=======================================
   File Local Functions
 =======================================*/
-static int pred_always_true(void);
-static int pred_always_false(void);
+static scm_bool pred_always_true(void);
+static scm_bool pred_always_false(void);
 
 #if SCM_USE_EUCJP
 static const char *eucjp_encoding(void);
@@ -89,8 +97,8 @@
 
 #if SCM_USE_SJIS
 static const char *sjis_encoding(void);
- static enum ScmCodedCharSet sjis_ccs(void);
- static int sjis_char_len(int ch);
+static enum ScmCodedCharSet sjis_ccs(void);
+static int sjis_char_len(int ch);
 static ScmMultibyteCharInfo sjis_scan_char(ScmMultibyteString mbs);
 static uchar *sjis_int2str(uchar *dst, int ch, ScmMultibyteState state);
 #endif
@@ -260,17 +268,16 @@
 int
 scm_mb_strlen(ScmMultibyteString mbs)
 {
-    int len = 0;
+    int len;
     ScmMultibyteCharInfo c;
 
     CDBG((SCM_DBG_ENCODING, "mb_strlen: size = %d; str = %s;",
           SCM_MBS_GET_SIZE(mbs), SCM_MBS_GET_STR(mbs)));
 
-    while (SCM_MBS_GET_SIZE(mbs)) {
+    for (len = 0; SCM_MBS_GET_SIZE(mbs); len++) {
         c = SCM_CHARCODEC_SCAN_CHAR(scm_current_char_codec, mbs);
         CDBG((SCM_DBG_ENCODING, "%d, %d;", SCM_MBCINFO_GET_SIZE(c), c.flag));
         SCM_MBS_SKIP_CHAR(mbs, c);
-        len++;
     }
 
     CDBG((SCM_DBG_ENCODING, "len=%d\n", len));
@@ -282,6 +289,7 @@
 scm_mb_bare_c_strlen(const char *s)
 {
     ScmMultibyteString mbs;
+
     SCM_MBS_INIT(mbs);
     SCM_MBS_SET_STR(mbs, s);
     SCM_MBS_SET_SIZE(mbs, strlen(s));
@@ -291,8 +299,7 @@
 ScmMultibyteString
 scm_mb_substring(ScmMultibyteString mbs, int i, int len)
 {
-    ScmMultibyteString ret;
-    ScmMultibyteString end;
+    ScmMultibyteString ret, end;
     ScmMultibyteCharInfo c;
 
     ret = mbs;
@@ -331,16 +338,16 @@
   Encoding-specific functions
 =======================================*/
 
-static int
+static scm_bool
 pred_always_true(void)
 {
-    return 1;
+    return scm_true;
 }
 
-static int
+static scm_bool
 pred_always_false(void)
 {
-    return 0;
+    return scm_false;
 }
 
 /* Every encoding implements the <encoding name>_scan_char()
@@ -354,10 +361,22 @@
  * use it to return information on how many octets are missing.  It
  * also serves as documentation.  */
 #define ENTER   ScmMultibyteCharInfo _ret;  SCM_MBCINFO_INIT(_ret)
-#define RETURN(n)  do { SCM_MBCINFO_SET_SIZE(_ret, n); return _ret; } while (0)
-#define RETURN_ERROR() do { SCM_MBCINFO_SET_ERROR(_ret); RETURN(1); } while (0)
-#define RETURN_INCOMPLETE(n) do { SCM_MBCINFO_SET_INCOMPLETE(_ret); RETURN(n); } while (0)
-#define SAVE_STATE(stat) (SCM_MBCINFO_SET_STATE(_ret, (stat)))
+#define RETURN(n)                                                            \
+    do {                                                                     \
+        SCM_MBCINFO_SET_SIZE(_ret, n);                                       \
+        return _ret;                                                         \
+    } while (/* CONSTCOND */ 0)
+#define RETURN_ERROR()                                                       \
+    do {                                                                     \
+        SCM_MBCINFO_SET_ERROR(_ret);                                         \
+        RETURN(1);                                                           \
+    } while (/* CONSTCOND */ 0)
+#define RETURN_INCOMPLETE(n)                                                 \
+    do {                                                                     \
+        SCM_MBCINFO_SET_INCOMPLETE(_ret);                                    \
+        RETURN(n);                                                           \
+    } while (/* CONSTCOND */ 0)
+#define SAVE_STATE(stat) SCM_MBCINFO_SET_STATE(_ret, (stat))
 #define EXPECT_SIZE(size) /* Currently ignored. */
 
 /* Encodings based on ISO/IEC 2022. */
@@ -370,7 +389,7 @@
 #define IN_GL94(c) (0x21 <= (uchar)(c) && (uchar)(c) <= 0x7E)
 #define IN_GL96(c) (0x20 <= (uchar)(c) && (uchar)(c) <= 0x7F)
 #define IN_GR94(c) (0xA1 <= (uchar)(c) && (uchar)(c) <= 0xFE)
-#define IN_GR96(c) (0xA0 <= (uchar)(c) && (uchar)(c) <= 0xFF)
+#define IN_GR96(c) (0xA0 <= (uchar)(c) /* && (uchar)(c) <= 0xFF */)
 
 #define IS_ASCII(c) ((uint)(c) <= 0x7F)
 #define IS_GR_SPC_OR_DEL(c)  ((uchar)(c) == 0xA0 || (uchar)(c) == 0xFF)
@@ -404,9 +423,9 @@
 int
 eucjp_char_len(int ch)
 {
-    char *end, buf[SCM_MB_MAX_LEN + sizeof("")];
+    uchar *end, buf[SCM_MB_MAX_LEN + sizeof("")];
 
-    end = eucjp_int2str((uchar *)buf, ch, SCM_MB_STATELESS);
+    end = eucjp_int2str(buf, ch, SCM_MB_STATELESS);
 
     return (end) ? end - buf : 0;
 }
@@ -559,9 +578,9 @@
 int
 euc_char_len(int ch)
 {
-    char *end, buf[SCM_MB_MAX_LEN + sizeof("")];
+    uchar *end, buf[SCM_MB_MAX_LEN + sizeof("")];
 
-    end = euc_int2str((uchar *)buf, ch, SCM_MB_STATELESS);
+    end = euc_int2str(buf, ch, SCM_MB_STATELESS);
 
     return (end) ? end - buf : 0;
 }
@@ -721,9 +740,9 @@
 int
 utf8_char_len(int ch)
 {
-    char *end, buf[SCM_MB_MAX_LEN + sizeof("")];
+    uchar *end, buf[SCM_MB_MAX_LEN + sizeof("")];
 
-    end = utf8_int2str((uchar *)buf, ch, SCM_MB_STATELESS);
+    end = utf8_int2str(buf, ch, SCM_MB_STATELESS);
 
     return (end) ? end - buf : 0;
 }
@@ -749,7 +768,7 @@
 #if SCM_STRICT_ENCODING_CHECK
     {
         int i;
-        for (i=1; i < len; i++) {
+        for (i = 1; i < len; i++) {
             if (size <= i)
                 RETURN_INCOMPLETE(size);
             if (!IS_TRAILING(str[i]))
@@ -878,9 +897,9 @@
 int
 sjis_char_len(int ch)
 {
-    char *end, buf[SCM_MB_MAX_LEN + sizeof("")];
+    uchar *end, buf[SCM_MB_MAX_LEN + sizeof("")];
 
-    end = sjis_int2str((uchar *)buf, ch, SCM_MB_STATELESS);
+    end = sjis_int2str(buf, ch, SCM_MB_STATELESS);
 
     return (end) ? end - buf : 0;
 }
@@ -891,6 +910,7 @@
     const char *str = SCM_MBS_GET_STR(mbs);
     const int  size = SCM_MBS_GET_SIZE(mbs);
     ENTER;
+
     if (!size)
         RETURN(0);
     if (IS_LEAD(str[0])) {
@@ -967,6 +987,7 @@
 unibyte_scan_char(ScmMultibyteString mbs)
 {
     ENTER;
+
     if (SCM_MBS_GET_SIZE(mbs))
         RETURN(1);
     RETURN(0);

Modified: branches/r5rs/sigscheme/encoding.h
===================================================================
--- branches/r5rs/sigscheme/encoding.h	2006-01-04 20:15:08 UTC (rev 2786)
+++ branches/r5rs/sigscheme/encoding.h	2006-01-04 22:36:29 UTC (rev 2787)
@@ -40,6 +40,7 @@
 /*=======================================
   System Include
 =======================================*/
+#include <stddef.h>
 
 /*=======================================
   Local Include
@@ -57,19 +58,28 @@
 #define SCM_MBS_SET_SIZE(mbs, siz)      ((mbs).size = (siz))
 #define SCM_MBS_GET_SIZE(mbs)           ((mbs).size)
 
-#define SCM_MBCINFO_SET_SIZE SCM_MBS_SET_SIZE
-#define SCM_MBCINFO_GET_SIZE SCM_MBS_GET_SIZE
-#define SCM_MBCINFO_CLEAR_STATE SCM_MBS_CLEAR_STATE
-#define SCM_MBCINFO_SET_STATE SCM_MBS_SET_STATE
-#define SCM_MBCINFO_GET_STATE SCM_MBS_GET_STATE
+#define SCM_MBCINFO_SET_SIZE(inf, siz)   ((inf).size = (siz))
+#define SCM_MBCINFO_GET_SIZE(inf)        ((inf).size)
+#if SCM_USE_STATEFUL_ENCODING
+#define SCM_MBCINFO_CLEAR_STATE(inf)     ((inf).state = 0)
+#define SCM_MBCINFO_SET_STATE(inf, stat) ((inf).state = (stat))
+#define SCM_MBCINFO_GET_STATE(inf)       ((inf).state)
+#else /* SCM_USE_STATEFUL_ENCODING */
+#define SCM_MBCINFO_CLEAR_STATE(inf)
+#define SCM_MBCINFO_SET_STATE(inf, stat)
+#define SCM_MBCINFO_GET_STATE(inf)       SCM_MB_STATELESS
+#endif /* SCM_USE_STATEFUL_ENCODING */
 #define SCM_MBCINFO_CLEAR_FLAG(inf)     ((inf).flag = 0)
 #define SCM_MBCINFO_SET_ERROR(inf)      ((inf).flag |= 1)
 #define SCM_MBCINFO_SET_INCOMPLETE(inf) ((inf).flag |= 2)
 #define SCM_MBCINFO_ERRORP(inf)         ((inf).flag & 1)
 #define SCM_MBCINFO_INCOMPLETEP(inf)    ((inf).flag & 2)
-#define SCM_MBCINFO_INIT(inf)  (SCM_MBCINFO_SET_SIZE((inf), 0),  \
-                                SCM_MBCINFO_CLEAR_STATE(inf),    \
-                                SCM_MBCINFO_CLEAR_FLAG(inf))
+#define SCM_MBCINFO_INIT(inf)                                                \
+    do {                                                                     \
+        SCM_MBCINFO_SET_SIZE((inf), 0);                                      \
+        SCM_MBCINFO_CLEAR_STATE(inf);                                        \
+        SCM_MBCINFO_CLEAR_FLAG(inf);                                         \
+    } while (/* CONSTCOND */ 0)
 
 
 #if SCM_USE_STATEFUL_ENCODING
@@ -77,18 +87,24 @@
 #define SCM_MBS_SET_STATE(mbs, stat)  ((mbs).state = (stat))
 #define SCM_MBS_CLEAR_STATE(mbs)      ((mbs).state = 0)
 #else
-#define SCM_MBS_GET_STATE(mbs)        0
-#define SCM_MBS_SET_STATE(mbs, stat)  0
-#define SCM_MBS_CLEAR_STATE(mbs)      0
+#define SCM_MBS_GET_STATE(mbs)        SCM_MB_STATELESS
+#define SCM_MBS_SET_STATE(mbs, stat)
+#define SCM_MBS_CLEAR_STATE(mbs)
 #endif
-#define SCM_MBS_INIT(mbs)  (SCM_MBS_SET_STR((mbs), NULL), \
-                            SCM_MBS_SET_SIZE((mbs), 0),   \
-                            SCM_MBS_CLEAR_STATE(mbs))
-#define SCM_MBS_SKIP_CHAR(mbs, inf)                                           \
-    (SCM_MBS_SET_STR((mbs), SCM_MBS_GET_STR(mbs) + SCM_MBCINFO_GET_SIZE(inf)),\
-     SCM_MBS_SET_SIZE((mbs),                                                  \
-                      SCM_MBS_GET_SIZE(mbs) - SCM_MBCINFO_GET_SIZE(inf)),     \
-     SCM_MBS_SET_STATE((mbs), SCM_MBCINFO_GET_STATE(inf)))
+#define SCM_MBS_INIT(mbs)                                                    \
+    do {                                                                     \
+        SCM_MBS_SET_STR((mbs), NULL);                                        \
+        SCM_MBS_SET_SIZE((mbs), 0);                                          \
+        SCM_MBS_CLEAR_STATE(mbs);                                            \
+    } while (/* CONSTCOND */ 0)
+#define SCM_MBS_SKIP_CHAR(mbs, inf)                                          \
+    do {                                                                     \
+        SCM_MBS_SET_STR((mbs),                                               \
+                        SCM_MBS_GET_STR(mbs) + SCM_MBCINFO_GET_SIZE(inf));   \
+        SCM_MBS_SET_SIZE((mbs),                                              \
+                         SCM_MBS_GET_SIZE(mbs) - SCM_MBCINFO_GET_SIZE(inf)); \
+        SCM_MBS_SET_STATE((mbs), SCM_MBCINFO_GET_STATE(inf));                \
+    } while (/* CONSTCOND */ 0)
 
 #define SCM_CHARCODEC_STATEFULP(codec)          ((*(codec)->statefulp)())
 #define SCM_CHARCODEC_ENCODING(codec)           ((*(codec)->encoding)())
@@ -103,6 +119,12 @@
 /*=======================================
   Type Definitions
 =======================================*/
+#if (!defined(scm_true) && !defined(scm_false))
+typedef int scm_bool;
+#define scm_false 0
+#define scm_true  (!scm_false)
+#endif
+
 enum ScmCodedCharSet {
     SCM_CCS_UNKNOWN   = 0,
     SCM_CCS_UCS4      = 1,
@@ -113,7 +135,6 @@
 /* This type will actually contain some encoding-dependent enum value.
  * It might as well be defined as mbstate_t if we're using libc. */
 typedef int ScmMultibyteState;
-
 #define SCM_MB_STATELESS 0
 
 /* Metadata of a multibyte character.  These are usually allocated on
@@ -144,7 +165,7 @@
 typedef struct ScmCharCodecVTbl_ ScmCharCodecVTbl;
 typedef const ScmCharCodecVTbl ScmCharCodec;
 
-typedef int (*ScmCharCodecMethod_statefulp)(void);
+typedef scm_bool (*ScmCharCodecMethod_statefulp)(void);
 typedef const char *(*ScmCharCodecMethod_encoding)(void);
 typedef enum ScmCodedCharSet (*ScmCharCodecMethod_ccs)(void);
 typedef int (*ScmCharCodecMethod_char_len)(int ch);

Modified: branches/r5rs/sigscheme/sigscheme.h
===================================================================
--- branches/r5rs/sigscheme/sigscheme.h	2006-01-04 20:15:08 UTC (rev 2786)
+++ branches/r5rs/sigscheme/sigscheme.h	2006-01-04 22:36:29 UTC (rev 2787)
@@ -221,9 +221,11 @@
  * VALUE FOR TRUE. Use (val) or (val != scm_false) instead.
  *
  */
+#if (!defined(scm_true) && !defined(scm_false))
 typedef int scm_bool;
 #define scm_false 0
 #define scm_true  (!scm_false)
+#endif
 
 enum ScmDebugCategory {
     SCM_DBG_NONE         = 0,



More information about the uim-commit mailing list