*** empty log message ***
[m17n/m17n-lib.git] / src / internal.h
index 8bb2318..37bff5c 100644 (file)
@@ -66,6 +66,8 @@ extern int mdebug_hook ();
     exit (err);                \
   } while (0)
 
+#define MFAILP(cond) ((cond) ? 0 : mdebug_hook ())
+
 #define M_CHECK_CHAR(c, ret)           \
   if ((c) < 0 || (c) > MCHAR_MAX)      \
     MERROR (MERROR_CHAR, (ret));       \
@@ -91,11 +93,10 @@ extern int mdebug_hook ();
     be one of enum MErrorCode.  If the allocation fails, the macro
     MEMORY_FULL () is called with argument ERR.  */
 
-#define MTABLE_MALLOC(p, size, err)            \
-  do {                                         \
-    int bytes = sizeof (*(p)) * (size);                \
-    if (! ((p) = (void *) malloc (bytes)))     \
-      MEMORY_FULL (err);                       \
+#define MTABLE_MALLOC(p, size, err)                            \
+  do {                                                         \
+    if (! ((p) = (void *) malloc (sizeof (*(p)) * (size))))    \
+      MEMORY_FULL (err);                                       \
   } while (0)
 
 
@@ -131,10 +132,10 @@ extern int mdebug_hook ();
 
 #define MTABLE_ALLOCA(p, size, err)            \
   do {                                         \
-    int bytes = sizeof (*(p)) * (size);                \
-    if (! ((p) = (void *) alloca (bytes)))     \
+    int allocasize = sizeof (*(p)) * (size);   \
+    if (! ((p) = (void *) alloca (allocasize)))        \
       MEMORY_FULL (err);                       \
-    memset ((p), 0, bytes);                    \
+    memset ((p), 0, allocasize);               \
   } while (0)
 
 
@@ -424,11 +425,19 @@ extern void mdebug__unregister_object (M17NObjectArray *array, void *object);
 
 struct MTextPlist;
 
+enum MTextCoverage
+  {
+    MTEXT_COVERAGE_ASCII,
+    MTEXT_COVERAGE_UNICODE,
+    MTEXT_COVERAGE_FULL
+  };
+
 struct MText
 {
   M17NObject control;
 
-  enum MTextFormat format;
+  enum MTextFormat format : 16;
+  enum MTextCoverage coverage : 16;
 
   /**en Number of characters in the M-text */
   /**ja M-text Ãæ¤Îʸ»ú¿ô */
@@ -530,50 +539,53 @@ enum MDebugMaskBit
     MDEBUG_FONT_FLT =  0x0200,
     MDEBUG_FONT_OTF =  0x0400,
     MDEBUG_INPUT =     0x0800,
+    MDEBUG_ALL =       0xFFFF,
     MDEBUG_MAX
   };
 
 extern int mdebug__flag;
+extern FILE *mdebug__output;
 extern void mdebug__push_time ();
 extern void mdebug__pop_time ();
 extern void mdebug__print_time ();
 
-#define MDEBUG_PRINT(msg)              \
+#define MDEBUG_PRINT0(FPRINTF)         \
   do {                                 \
     if (mdebug__flag & mdebug_mask)    \
-      fprintf (stderr, (msg));         \
+      {                                        \
+       FPRINTF;                        \
+       fflush (mdebug__output);        \
+      }                                        \
   } while (0)
 
-#define MDEBUG_PRINT1(fmt, arg)                \
-  do {                                 \
-    if (mdebug__flag & mdebug_mask)    \
-      fprintf (stderr, (fmt), (arg));  \
-  } while (0)
+#define MDEBUG_PRINT(msg) \
+  MDEBUG_PRINT0 (fprintf (mdebug__output, "%s", (msg)))
 
-#define MDEBUG_PRINT2(fmt, arg1, arg2)         \
-  do {                                         \
-    if (mdebug__flag & mdebug_mask)            \
-      fprintf (stderr, (fmt), (arg1), (arg2)); \
-  } while (0)
+#define MDEBUG_PRINT1(fmt, arg) \
+  MDEBUG_PRINT0 (fprintf (mdebug__output, (fmt), (arg)))
 
-#define MDEBUG_PRINT3(fmt, arg1, arg2, arg3)           \
-  do {                                                 \
-    if (mdebug__flag & mdebug_mask)                    \
-      fprintf (stderr, (fmt), (arg1), (arg2), (arg3)); \
-  } while (0)
+#define MDEBUG_PRINT2(fmt, arg1, arg2) \
+  MDEBUG_PRINT0 (fprintf (mdebug__output, (fmt), (arg1), (arg2)))
 
-#define MDEBUG_PRINT4(fmt, arg1, arg2, arg3, arg4)             \
-  do {                                                         \
-    if (mdebug__flag & mdebug_mask)                            \
-      fprintf (stderr, (fmt), (arg1), (arg2), (arg3), (arg4)); \
-  } while (0)
+#define MDEBUG_PRINT3(fmt, arg1, arg2, arg3) \
+  MDEBUG_PRINT0 (fprintf (mdebug__output, (fmt), (arg1), (arg2), (arg3)))
 
-#define MDEBUG_PRINT5(fmt, arg1, arg2, arg3, arg4, arg5)               \
-  do {                                                                 \
-    if (mdebug__flag & mdebug_mask)                                    \
-      fprintf (stderr, (fmt), (arg1), (arg2), (arg3), (arg4), (arg5)); \
-  } while (0)
+#define MDEBUG_PRINT4(fmt, arg1, arg2, arg3, arg4)     \
+  MDEBUG_PRINT0 (fprintf (mdebug__output, (fmt), (arg1), (arg2), (arg3), (arg4)))
+
+#define MDEBUG_PRINT5(fmt, arg1, arg2, arg3, arg4, arg5)       \
+  MDEBUG_PRINT0 (fprintf (mdebug__output, (fmt), (arg1), (arg2), (arg3), (arg4), (arg5)))
 
+#define MDEBUG_DUMP(prefix, postfix, call)             \
+  do {                                                 \
+    if (mdebug__flag & mdebug_mask)                    \
+      {                                                        \
+       fprintf (mdebug__output, "%s", prefix);         \
+       call;                                           \
+       fprintf (mdebug__output, "%s", postfix);        \
+       fflush (mdebug__output);                        \
+      }                                                        \
+  } while (0)
 
 #define MDEBUG_PUSH_TIME()             \
   do {                                 \
@@ -589,15 +601,15 @@ extern void mdebug__print_time ();
   } while (0)
 
 
-#define MDEBUG_PRINT_TIME(tag, ARG_LIST)       \
-  do {                                         \
-    if (mdebug__flag & mdebug_mask)            \
-      {                                                \
-       fprintf (stderr, " [%s] ", tag);        \
-       mdebug__print_time ();                  \
-       fprintf ARG_LIST;                       \
-       fprintf (stderr, "\n");                 \
-      }                                                \
+#define MDEBUG_PRINT_TIME(tag, ARG_LIST)               \
+  do {                                                 \
+    if (mdebug__flag & mdebug_mask)                    \
+      {                                                        \
+       fprintf (mdebug__output, " [%s] ", tag);        \
+       mdebug__print_time ();                          \
+       fprintf ARG_LIST;                               \
+       fprintf (mdebug__output, "\n");                 \
+      }                                                        \
   } while (0)