Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Oct 2011 20:02:00 +0000
From:      zy@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r227168 - in soc2011/zy/nvi-iconv/head: contrib/nvi2/common contrib/nvi2/ex rescue/rescue
Message-ID:  <20111028200200.35920106567C@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: zy
Date: Fri Oct 28 20:01:59 2011
New Revision: 227168
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=227168

Log:
  Updates to git:efb98f7
   * Fix linking 'rescue' on stable/8.
   * Handles UTF-16 with less hacks.
   * Handles all CJK encodings with GB18030.
   * Now it's possible to build with widechar but not iconv.

Modified:
  soc2011/zy/nvi-iconv/head/contrib/nvi2/common/conv.c
  soc2011/zy/nvi-iconv/head/contrib/nvi2/common/exf.c
  soc2011/zy/nvi-iconv/head/contrib/nvi2/common/exf.h
  soc2011/zy/nvi-iconv/head/contrib/nvi2/common/key.c
  soc2011/zy/nvi-iconv/head/contrib/nvi2/ex/ex_write.c
  soc2011/zy/nvi-iconv/head/rescue/rescue/Makefile

Modified: soc2011/zy/nvi-iconv/head/contrib/nvi2/common/conv.c
==============================================================================
--- soc2011/zy/nvi-iconv/head/contrib/nvi2/common/conv.c	Fri Oct 28 17:53:34 2011	(r227167)
+++ soc2011/zy/nvi-iconv/head/contrib/nvi2/common/conv.c	Fri Oct 28 20:01:59 2011	(r227168)
@@ -10,7 +10,7 @@
 #include "config.h"
 
 #ifndef lint
-static const char sccsid[] = "$Id: conv.c,v 1.29 2011/08/13 12:53:23 zy Exp $ (Berkeley) $Date: 2011/08/13 12:53:23 $";
+static const char sccsid[] = "$Id: conv.c,v 1.30 2011/10/27 17:38:13 zy Exp $ (Berkeley) $Date: 2011/10/27 17:38:13 $";
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -91,11 +91,9 @@
 		size_t *tolen, CHAR_T **dst, char *enc)
 {
 	/* XXX UTF-16 linesep hack */
-#ifdef USE_ICONV
-    if (!strncasecmp(enc, "utf-16", 6) && len % 2)
-	if (str[--len] != '\0')		/* shortern by 1 */
+    if (enc && !strncasecmp(enc, "utf-16", 6) && len % 2)
+	if (--len, !strncasecmp(enc, "utf-16le", 8))
 	    str++;			/* shift if LE */
-#endif
 
     int i = 0, j;
     CHAR_T **tostr = &cw->bp1.wc;
@@ -113,7 +111,7 @@
     BINC_RETW(NULL, *tostr, *blen, nlen);
 
 #ifdef USE_ICONV
-    if (strcmp(nl_langinfo(CODESET), enc)) {
+    if (strcasecmp(nl_langinfo(CODESET), enc)) {
 	id = iconv_open(nl_langinfo(CODESET), enc);
 	if (id == (iconv_t)-1)
 	    goto err;
@@ -139,16 +137,20 @@
     }
     *tolen = i;
 
+#ifdef USE_ICONV
     if (id != (iconv_t)-1)
 	iconv_close(id);
+#endif
 
     *dst = cw->bp1.wc;
 
     return 0;
 err:
     *tolen = i;
+#ifdef USE_ICONV
     if (id != (iconv_t)-1)
 	iconv_close(id);
+#endif
     *dst = cw->bp1.wc;
 
     return error;
@@ -262,7 +264,7 @@
     dst = *tostr; buflen = *blen;
 
 #ifdef USE_ICONV
-    if (strcmp(nl_langinfo(CODESET), enc)) {
+    if (strcasecmp(nl_langinfo(CODESET), enc)) {
 	id = iconv_open(enc, nl_langinfo(CODESET));
 	if (id == (iconv_t)-1)
 	    goto err;
@@ -333,13 +335,30 @@
     if (orig != NULL)
 	MEMCPY(&sp->conv, &orig->conv, 1);
     else {
+	char *ctp;
 	setlocale(LC_ALL, "");
 #ifdef USE_WIDECHAR
+	ctp = strchr(setlocale(LC_CTYPE, NULL), '.');
+	if (ctp) ++ctp;
+	/*
+	 * The CJK hacks try to use GB18030 to handle
+	 * eucCN, eucJP, eucKR, GB2312, GBK, CP949, CP936.
+	 *
+	 * XXX
+	 * This fixes the libncursesw limitaions (GB2312, GBK, and CP949
+	 * do not work) on FreeBSD at the same time.
+	 */
+	if (!strncmp(ctp, "euc", 3) || !strncmp(ctp, "GB", 2) ||
+	    !strcmp(ctp, "CP949") || !strcmp(ctp, "CP936"))
+		setlocale(LC_CTYPE, "zh_CN.GB18030");
+
 	sp->conv.sys2int = cs_char2int;
 	sp->conv.int2sys = cs_int2char;
 	sp->conv.file2int = fe_char2int;
 	sp->conv.int2file = fe_int2char;
 	sp->conv.input2int = ie_char2int;
+#elif __linux__
+	setlocale(LC_CTYPE, "");
 #endif
 #ifdef USE_ICONV
 	o_set(sp, O_INPUTENCODING, OS_STRDUP, nl_langinfo(CODESET), 0);
@@ -415,6 +434,7 @@
 
     return 0;
 err:
+#endif
     switch (option) {
     case O_FILEENCODING:
 	msgq(sp, M_ERR,
@@ -425,7 +445,6 @@
 	    "322|Input encoding conversion not supported");
 	break;
     }
-#endif
     return 1;
 }
 

Modified: soc2011/zy/nvi-iconv/head/contrib/nvi2/common/exf.c
==============================================================================
--- soc2011/zy/nvi-iconv/head/contrib/nvi2/common/exf.c	Fri Oct 28 17:53:34 2011	(r227167)
+++ soc2011/zy/nvi-iconv/head/contrib/nvi2/common/exf.c	Fri Oct 28 20:01:59 2011	(r227168)
@@ -1251,7 +1251,6 @@
 			char *np;
 			db_rget(sp, 1, &p, &len);
 			if ((np = malloc(len-2))) {
-				memcpy(ep->bom.c, p, 2);
 				memcpy(np, p+2, len-2);
 				db_rset(sp, 1, np, len-2);	/* store w/o the BOM */
 				free(np);

Modified: soc2011/zy/nvi-iconv/head/contrib/nvi2/common/exf.h
==============================================================================
--- soc2011/zy/nvi-iconv/head/contrib/nvi2/common/exf.h	Fri Oct 28 17:53:34 2011	(r227167)
+++ soc2011/zy/nvi-iconv/head/contrib/nvi2/common/exf.h	Fri Oct 28 20:01:59 2011	(r227168)
@@ -6,7 +6,7 @@
  *
  * See the LICENSE file for redistribution information.
  *
- *	$Id: exf.h,v 10.8 2011/08/13 17:59:41 zy Exp $ (Berkeley) $Date: 2011/08/13 17:59:41 $
+ *	$Id: exf.h,v 10.8 2011/10/27 00:35:26 zy Exp $ (Berkeley) $Date: 2011/10/27 00:35:26 $
  */
 					/* Undo direction. */
 /*
@@ -17,10 +17,6 @@
 	int	 refcnt;		/* Reference count. */
 
 					/* Underlying database state. */
-	union {
-		uint16_t	i;	/* Byte-order-mark */
-		char	c[2];
-	}	bom;
 	DB	*db;			/* File db structure. */
 	CHAR_T	*c_lp;			/* Cached line. */
 	size_t	 c_len;			/* Cached line length. */

Modified: soc2011/zy/nvi-iconv/head/contrib/nvi2/common/key.c
==============================================================================
--- soc2011/zy/nvi-iconv/head/contrib/nvi2/common/key.c	Fri Oct 28 17:53:34 2011	(r227167)
+++ soc2011/zy/nvi-iconv/head/contrib/nvi2/common/key.c	Fri Oct 28 20:01:59 2011	(r227168)
@@ -21,7 +21,6 @@
 #include <ctype.h>
 #include <errno.h>
 #include <limits.h>
-#include <locale.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -109,22 +108,6 @@
 
 	gp = sp->gp;
 
-	/*
-	 * XXX
-	 * 8-bit only, for now.  Recompilation should get you any 8-bit
-	 * character set, as long as nul isn't a character.
-	 */
-	(void)setlocale(LC_ALL, "");
-#if __linux__
-	/*
-	 * In libc 4.5.26, setlocale(LC_ALL, ""), doesn't setup the table
-	 * for ctype(3c) correctly.  This bug is fixed in libc 4.6.x.
-	 *
-	 * This code works around this problem for libc 4.5.x users.
-	 * Note that this code is harmless if you're using libc 4.6.x.
-	 */
-	(void)setlocale(LC_CTYPE, "");
-#endif
 	v_key_ilookup(sp);
 
 	v_keyval(sp, K_CNTRLD, KEY_VEOF);

Modified: soc2011/zy/nvi-iconv/head/contrib/nvi2/ex/ex_write.c
==============================================================================
--- soc2011/zy/nvi-iconv/head/contrib/nvi2/ex/ex_write.c	Fri Oct 28 17:53:34 2011	(r227167)
+++ soc2011/zy/nvi-iconv/head/contrib/nvi2/ex/ex_write.c	Fri Oct 28 20:01:59 2011	(r227168)
@@ -10,7 +10,7 @@
 #include "config.h"
 
 #ifndef lint
-static const char sccsid[] = "$Id: ex_write.c,v 10.39 2011/08/13 18:28:15 zy Exp $ (Berkeley) $Date: 2011/08/13 18:28:15 $";
+static const char sccsid[] = "$Id: ex_write.c,v 10.40 2011/10/27 00:28:35 zy Exp $ (Berkeley) $Date: 2011/10/27 00:28:35 $";
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -318,14 +318,15 @@
 	lcnt = 0;
 	msg = "253|Writing...";
 
-#ifdef USE_ICONV
-	isutf16 = !strncasecmp(O_STR(sp, O_FILEENCODING), "utf-16", 6);
-#else
-	isutf16 = 0;
-#endif
+	if (O_STR(sp, O_FILEENCODING)) {
+		isutf16 = !strncasecmp(O_STR(sp, O_FILEENCODING), "utf-16", 6);
+		isutf16 += !strncasecmp(O_STR(sp, O_FILEENCODING), "utf-16le", 8);
+	} else isutf16 = 0;
 
 	if (tline != 0) {
-		if (sp->ep->bom.i && fwrite(&sp->ep->bom.i, 2, 1, fp) != 1)
+		if (isutf16 == 1 && fwrite("\xfe\xff", 1, 2, fp) != 2)
+			goto err;
+		if (isutf16 == 2 && fwrite("\xff\xfe", 1, 2, fp) != 2)
 			goto err;
 		for (; fline <= tline; ++fline, ++lcnt) {
 			/* Caller has to provide any interrupt message. */
@@ -345,10 +346,10 @@
 				goto err;
 			ccnt += len;
 			/* UTF-16 w/o BOM is big-endian */
-			if (isutf16 && sp->ep->bom.c[0] != '\xff') {	/* UTF-16BE */
+			if (isutf16 == 1) {	/* UTF-16BE */
 				if (fwrite("\0\x0a", 1, 2, fp) != 2)
 					break;
-			} else if (sp->ep->bom.c[0] == '\xff') {	/* UTF-16LE */
+			} else if (isutf16 == 2) {	/* UTF-16LE */
 				if (fwrite("\x0a\0", 1, 2, fp) != 2)
 					break;
 			} else if (putc('\n', fp) != '\n')

Modified: soc2011/zy/nvi-iconv/head/rescue/rescue/Makefile
==============================================================================
--- soc2011/zy/nvi-iconv/head/rescue/rescue/Makefile	Fri Oct 28 17:53:34 2011	(r227167)
+++ soc2011/zy/nvi-iconv/head/rescue/rescue/Makefile	Fri Oct 28 20:01:59 2011	(r227168)
@@ -118,13 +118,13 @@
 # crunchgen does not like C++ programs; this should be fixed someday
 # CRUNCH_PROGS+= devd
 
+CRUNCH_LIBS+= -lalias -lcam -ldevstat -lipsec
 .ifdef (WITH_ICONV)
 CRUNCH_LIBS+= -lcursesw
 .else
 CRUNCH_LIBS+= -lcurses -ltermcap
 .endif
 
-CRUNCH_LIBS+= -lalias -lcam -ldevstat -lipsec
 .if ${MK_IPX} != "no"
 CRUNCH_LIBS+= -lipx
 .endif



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20111028200200.35920106567C>