changeset 34816:f998b856d92b

(CCL_WRITE_CHAR): Don't handle EOL conversion here. (CCL_READ_CHAR): Handle EOL conversion here. (ccl_driver) <CCL_ReadMultibyteChar2>: Likewise.
author Kenichi Handa <handa@m17n.org>
date Fri, 22 Dec 2000 00:06:52 +0000
parents 504dbe8c4d45
children 41f50ad22d7a
files src/ccl.c
diffstat 1 files changed, 57 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/src/ccl.c	Thu Dec 21 23:26:09 2000 +0000
+++ b/src/ccl.c	Fri Dec 22 00:06:52 2000 +0000
@@ -701,22 +701,11 @@
 #define CCL_WRITE_CHAR(ch)					\
   do {								\
     int bytes = SINGLE_BYTE_CHAR_P (ch) ? 1: CHAR_BYTES (ch);	\
-    if (ch == '\n' && ccl->eol_type == CODING_EOL_CRLF)		\
-      bytes++;							\
     if (!dst)							\
       CCL_INVALID_CMD;						\
     else if (dst + bytes <= (dst_bytes ? dst_end : src))	\
       {								\
-	if (ch == '\n')						\
-	  {							\
-	    if (ccl->eol_type == CODING_EOL_CRLF)		\
-	      *dst++ = '\r', *dst++ = '\n';			\
-	    else if (ccl->eol_type == CODING_EOL_CR)		\
-	      *dst++ = '\r';					\
-	    else						\
-	      *dst++ = '\n';					\
-	  }							\
-	else if (bytes == 1)					\
+	if (bytes == 1)						\
 	  {							\
 	    *dst++ = (ch);					\
 	    if ((ch) >= 0x80 && (ch) < 0xA0)			\
@@ -746,24 +735,42 @@
   } while (0)
 
 /* Read one byte from the current input buffer into Rth register.  */
-#define CCL_READ_CHAR(r)			\
-  do {						\
-    if (!src)					\
-      CCL_INVALID_CMD;				\
-    else if (src < src_end)			\
-      {						\
-	r = *src++;				\
-	if (r == LEADING_CODE_8_BIT_CONTROL	\
-	    && ccl->multibyte)			\
-	  r = *src++ - 0x20;			\
-      }						\
-    else if (ccl->last_block)			\
-      {						\
-        ic = ccl->eof_ic;			\
-        goto ccl_repeat;			\
-      }						\
-    else					\
-      CCL_SUSPEND (CCL_STAT_SUSPEND_BY_SRC);	\
+#define CCL_READ_CHAR(r)				\
+  do {							\
+    if (!src)						\
+      CCL_INVALID_CMD;					\
+    else if (src < src_end)				\
+      {							\
+	r = *src++;					\
+	if (r == '\n'					\
+	    && ccl->eol_type != CODING_EOL_LF)		\
+	  {						\
+	    /* We are encoding.  */			\
+	    if (ccl->eol_type == CODING_EOL_CRLF)	\
+	      {						\
+		if (ccl->cr_consumed)			\
+		  ccl->cr_consumed = 0;			\
+		else					\
+		  {					\
+		    ccl->cr_consumed = 1;		\
+		    r = '\r';				\
+		    src--;				\
+		  }					\
+	      }						\
+	    else					\
+	      r = '\r';					\
+	  }						\
+	if (r == LEADING_CODE_8_BIT_CONTROL		\
+	    && ccl->multibyte)				\
+	  r = *src++ - 0x20;				\
+      }							\
+    else if (ccl->last_block)				\
+      {							\
+        ic = ccl->eof_ic;				\
+        goto ccl_repeat;				\
+      }							\
+    else						\
+      CCL_SUSPEND (CCL_STAT_SUSPEND_BY_SRC);		\
   } while (0)
 
 
@@ -1209,7 +1216,26 @@
 		  }
 	      
 		i = *src++;
-		if (i < 0x80)
+		if (i == '\n' && ccl->eol_type != CODING_EOL_LF)
+		  {
+		    /* We are encoding.  */ 
+		    if (ccl->eol_type == CODING_EOL_CRLF)
+		      {
+			if (ccl->cr_consumed)
+			  ccl->cr_consumed = 0;
+			else
+			  {
+			    ccl->cr_consumed = 1;
+			    i = '\r';
+			    src--;
+			  }
+		      }
+		    else
+		      i = '\r';
+		    reg[rrr] = i;
+		    reg[RRR] = CHARSET_ASCII;
+		  }
+		else if (i < 0x80)
 		  {
 		    /* ASCII */
 		    reg[rrr] = i;