summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--iconvdata/iso-2022-jp.c79
-rw-r--r--iconvdata/jis0201.h2
3 files changed, 79 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 117ac8fcf3..81a1348614 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+1999-09-06  Ulrich Drepper  <drepper@cygnus.com>
+
+	* iconvdata/iso-2022-jp.c: When translating to ISO-2022-JP* write
+	escape sequences out even if the character itself does not fit
+	into the buffer.
+
+	* iconvdata/jis0201.h (ucs4_to_jisx0201): Correct mapping for U005C.
+
 1999-08-31  H.J. Lu  <hjl@gnu.org>
 
 	* nscd/nscd_getgr_r.c (nscd_getgr_r): Cleanup the buffer count.
diff --git a/iconvdata/iso-2022-jp.c b/iconvdata/iso-2022-jp.c
index 31b1cbcd14..669b65afae 100644
--- a/iconvdata/iso-2022-jp.c
+++ b/iconvdata/iso-2022-jp.c
@@ -470,6 +470,11 @@ gconv_end (struct __gconv_step *data)
 	if (var == iso2022jp2 && ch == 0x0a)				      \
 	  set2 = UNSPECIFIED_set;					      \
       }									      \
+    /* ISO-2022-JP recommends to encode the newline character always in	      \
+       ASCII since this allows a context-free interpretation of the	      \
+       characters at the beginning of the next line.  Otherwise it would      \
+       have to be known whether the last line ended using ASCII or	      \
+       JIS X 0201.  */							      \
     else if (set == JISX0201_Roman_set)					      \
       {									      \
 	unsigned char buf[2];						      \
@@ -576,7 +581,7 @@ gconv_end (struct __gconv_step *data)
 	  {								      \
 	    /* We must encode using ASCII.  First write out the		      \
 	       escape sequence.  */					      \
-	    if (NEED_LENGTH_TEST && outptr + 4 > outend)		      \
+	    if (NEED_LENGTH_TEST && outptr + 3 > outend)		      \
 	      {								      \
 		result = __GCONV_FULL_OUTPUT;				      \
 		break;							      \
@@ -586,6 +591,12 @@ gconv_end (struct __gconv_step *data)
 	    *outptr++ = '(';						      \
 	    *outptr++ = 'B';						      \
 	    set = ASCII_set;						      \
+									      \
+	    if (NEED_LENGTH_TEST && outptr + 1 > outend)		      \
+	      {								      \
+		result = __GCONV_FULL_OUTPUT;				      \
+		break;							      \
+	      }								      \
 	    *outptr++ = ch;						      \
 									      \
 	    /* At the beginning of a line, G2 designation is cleared.  */     \
@@ -605,7 +616,7 @@ gconv_end (struct __gconv_step *data)
 	    if (written != __UNKNOWN_10646_CHAR && buf[0] < 0x80)	      \
 	      {								      \
 		/* We use JIS X 0201.  */				      \
-		if (NEED_LENGTH_TEST && outptr + 4 > outend)		      \
+		if (NEED_LENGTH_TEST && outptr + 3 > outend)		      \
 		  {							      \
 		    result = __GCONV_FULL_OUTPUT;			      \
 		    break;						      \
@@ -615,6 +626,12 @@ gconv_end (struct __gconv_step *data)
 		*outptr++ = '(';					      \
 		*outptr++ = 'J';					      \
 		set = JISX0201_Roman_set;				      \
+									      \
+		if (NEED_LENGTH_TEST && outptr + 1 > outend)		      \
+		  {							      \
+		    result = __GCONV_FULL_OUTPUT;			      \
+		    break;						      \
+		  }							      \
 		*outptr++ = buf[0];					      \
 	      }								      \
 	    else							      \
@@ -623,7 +640,7 @@ gconv_end (struct __gconv_step *data)
 		if (written != __UNKNOWN_10646_CHAR)			      \
 		  {							      \
 		    /* We use JIS X 0208.  */				      \
-		    if (NEED_LENGTH_TEST && outptr + 5 > outend)	      \
+		    if (NEED_LENGTH_TEST && outptr + 3 > outend)	      \
 		      {							      \
 			result = __GCONV_FULL_OUTPUT;			      \
 			break;						      \
@@ -633,6 +650,12 @@ gconv_end (struct __gconv_step *data)
 		    *outptr++ = '$';					      \
 		    *outptr++ = 'B';					      \
 		    set = JISX0208_1983_set;				      \
+									      \
+		    if (NEED_LENGTH_TEST && outptr + 2 > outend)	      \
+		      {							      \
+			result = __GCONV_FULL_OUTPUT;			      \
+			break;						      \
+		      }							      \
 		    *outptr++ = buf[0];					      \
 		    *outptr++ = buf[1];					      \
 		  }							      \
@@ -648,7 +671,7 @@ gconv_end (struct __gconv_step *data)
 		    if (written != __UNKNOWN_10646_CHAR)		      \
 		      {							      \
 			/* We use JIS X 0212.  */			      \
-			if (NEED_LENGTH_TEST && outptr + 6 > outend)	      \
+			if (NEED_LENGTH_TEST && outptr + 4 > outend)	      \
 			  {						      \
 			    result = __GCONV_FULL_OUTPUT;		      \
 			    break;					      \
@@ -658,6 +681,12 @@ gconv_end (struct __gconv_step *data)
 			*outptr++ = '(';				      \
 			*outptr++ = 'D';				      \
 			set = JISX0212_set;				      \
+									      \
+			if (NEED_LENGTH_TEST && outptr + 2 > outend)	      \
+			  {						      \
+			    result = __GCONV_FULL_OUTPUT;		      \
+			    break;					      \
+			  }						      \
 			*outptr++ = buf[0];				      \
 			*outptr++ = buf[1];				      \
 		      }							      \
@@ -668,7 +697,7 @@ gconv_end (struct __gconv_step *data)
 			    && buf[0] >= 0x80)				      \
 			  {						      \
 			    /* We use JIS X 0201.  */			      \
-			    if (NEED_LENGTH_TEST && outptr + 4 > outend)      \
+			    if (NEED_LENGTH_TEST && outptr + 3 > outend)      \
 			      {						      \
 			        result = __GCONV_FULL_OUTPUT;		      \
 			        break;					      \
@@ -678,12 +707,18 @@ gconv_end (struct __gconv_step *data)
 			    *outptr++ = '(';				      \
 			    *outptr++ = 'I';				      \
 			    set = JISX0201_Kana_set;			      \
+									      \
+			    if (NEED_LENGTH_TEST && outptr + 1 > outend)      \
+			      {						      \
+			        result = __GCONV_FULL_OUTPUT;		      \
+			        break;					      \
+			      }						      \
 			    *outptr++ = buf[0] - 0x80;			      \
 			  }						      \
 			else if (ch != 0xa5 && ch >= 0x80 && ch <= 0xff)      \
 			  {						      \
 			    /* ISO 8859-1 upper half.   */		      \
-			    if (NEED_LENGTH_TEST && outptr + 6 > outend)      \
+			    if (NEED_LENGTH_TEST && outptr + 3 > outend)      \
 			      {						      \
 				result = __GCONV_FULL_OUTPUT;		      \
 				break;					      \
@@ -693,6 +728,12 @@ gconv_end (struct __gconv_step *data)
 			    *outptr++ = '.';				      \
 			    *outptr++ = 'A';				      \
 			    set2 = ISO88591_set;			      \
+									      \
+			    if (NEED_LENGTH_TEST && outptr + 3 > outend)      \
+			      {						      \
+				result = __GCONV_FULL_OUTPUT;		      \
+				break;					      \
+			      }						      \
 			    *outptr++ = ESC;				      \
 			    *outptr++ = 'N';				      \
 			    *outptr++ = ch;				      \
@@ -703,7 +744,7 @@ gconv_end (struct __gconv_step *data)
 			    if (written != __UNKNOWN_10646_CHAR)	      \
 			      {						      \
 				/* We use GB 2312.  */			      \
-				if (NEED_LENGTH_TEST && outptr + 5 > outend)  \
+				if (NEED_LENGTH_TEST && outptr + 3 > outend)  \
 				  {					      \
 				    result = __GCONV_FULL_OUTPUT;	      \
 				    break;				      \
@@ -713,6 +754,12 @@ gconv_end (struct __gconv_step *data)
 				*outptr++ = '$';			      \
 				*outptr++ = 'A';			      \
 				set = GB2312_set;			      \
+									      \
+				if (NEED_LENGTH_TEST && outptr + 2 > outend)  \
+				  {					      \
+				    result = __GCONV_FULL_OUTPUT;	      \
+				    break;				      \
+				  }					      \
 				*outptr++ = buf[0];			      \
 				*outptr++ = buf[1];			      \
 			      }						      \
@@ -723,7 +770,7 @@ gconv_end (struct __gconv_step *data)
 				  {					      \
 				    /* We use KSC 5601.  */		      \
 				    if (NEED_LENGTH_TEST		      \
-					&& outptr + 6 > outend)		      \
+					&& outptr + 4 > outend)		      \
 				      {					      \
 					result = __GCONV_FULL_OUTPUT;	      \
 					break;				      \
@@ -733,6 +780,13 @@ gconv_end (struct __gconv_step *data)
 				    *outptr++ = '(';			      \
 				    *outptr++ = 'C';			      \
 				    set = KSC5601_set;			      \
+									      \
+				    if (NEED_LENGTH_TEST		      \
+					&& outptr + 2 > outend)		      \
+				      {					      \
+					result = __GCONV_FULL_OUTPUT;	      \
+					break;				      \
+				      }					      \
 				    *outptr++ = buf[0];			      \
 				    *outptr++ = buf[1];			      \
 				  }					      \
@@ -753,7 +807,7 @@ gconv_end (struct __gconv_step *data)
 				      {					      \
 					/* We use ISO 8859-7 greek.  */	      \
 					if (NEED_LENGTH_TEST		      \
-					    && outptr + 6 > outend)	      \
+					    && outptr + 3 > outend)	      \
 					  {				      \
 					    result = __GCONV_FULL_OUTPUT;     \
 					    break;			      \
@@ -762,6 +816,13 @@ gconv_end (struct __gconv_step *data)
 					*outptr++ = '.';		      \
 					*outptr++ = 'F';		      \
 					set2 = ISO88597_set;		      \
+									      \
+					if (NEED_LENGTH_TEST		      \
+					    && outptr + 3 > outend)	      \
+					  {				      \
+					    result = __GCONV_FULL_OUTPUT;     \
+					    break;			      \
+					  }				      \
 					*outptr++ = ESC;		      \
 					*outptr++ = 'N';		      \
 					*outptr++ = gch;		      \
diff --git a/iconvdata/jis0201.h b/iconvdata/jis0201.h
index 5a555372ae..005f73fc9c 100644
--- a/iconvdata/jis0201.h
+++ b/iconvdata/jis0201.h
@@ -46,7 +46,7 @@ ucs4_to_jisx0201 (uint32_t wch, char *s)
     ch = '\x5c';
   else if (wch == 0x203e)
     ch = '\x7e';
-  else if (wch < 0x7e)
+  else if (wch < 0x7e && wch != 0x5c)
     ch = wch;
   else if (wch >= 0xff61 && wch <= 0xff9f)
     ch = wch - 0xfec0;