[asterisk-commits] murf: branch murf/utf8-whatif r93064 - in /team/murf/utf8-whatif: ./ doc/tex/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 14 13:01:24 CST 2007


Author: murf
Date: Fri Dec 14 13:01:23 2007
New Revision: 93064

URL: http://svn.digium.com/view/asterisk?view=rev&rev=93064
Log:
Finally located why utf8 was getting chopped out in the cli stuff. It's the editing command stuff. It's in emacs mode, and the meta-whatever commands cover the whole upper half of the byte range. So, I set up a new option in asterisk.conf to turn on utf8 processing. If on, you lose most of the meta- editing commands, M-@ thru M-x.  It now treats these via the ed_insert facility. In a UTF-8 multibyte sequence, the first byte indicates how many bytes are in the sequence, from 1 to 3 more. All the remaining bytes have 10 in the high-order bits. Still, with this in place, the utf-8 sequences got into the incoming data, but they would be echoed as escaped octal. There were like 5 places to fix that, based on the setting of option_utf8cli, the new option. That cleared up that mess, but all editing commands need to be updated to handle the fact that 2 to 4 chars show up as a single char. backspacing, char delete, all of these need to handle the multi-byte sequences so these ops work
  right. It'll be a bit of work.

Modified:
    team/murf/utf8-whatif/Makefile
    team/murf/utf8-whatif/doc/tex/asterisk-conf.tex
    team/murf/utf8-whatif/main/asterisk.c
    team/murf/utf8-whatif/main/editline/common.c
    team/murf/utf8-whatif/main/editline/np/vis.c
    team/murf/utf8-whatif/main/editline/read.c
    team/murf/utf8-whatif/main/editline/refresh.c

Modified: team/murf/utf8-whatif/Makefile
URL: http://svn.digium.com/view/asterisk/team/murf/utf8-whatif/Makefile?view=diff&rev=93064&r1=93063&r2=93064
==============================================================================
--- team/murf/utf8-whatif/Makefile (original)
+++ team/murf/utf8-whatif/Makefile Fri Dec 14 13:01:23 2007
@@ -636,6 +636,7 @@
 		echo ";transcode_via_sln = yes ; Build transcode paths via SLINEAR, instead of directly" ; \
 		echo ";runuser = asterisk ; The user to run as" ; \
 		echo ";rungroup = asterisk ; The group to run as" ; \
+		echo ";utf8cli = no ; force the CLI to accept utf8 character sequences as normal characters" ; \
 		echo "" ; \
 		echo "; Changing the following lines may compromise your security." ; \
 		echo ";[files]" ; \

Modified: team/murf/utf8-whatif/doc/tex/asterisk-conf.tex
URL: http://svn.digium.com/view/asterisk/team/murf/utf8-whatif/doc/tex/asterisk-conf.tex?view=diff&rev=93064&r1=93063&r2=93064
==============================================================================
--- team/murf/utf8-whatif/doc/tex/asterisk-conf.tex (original)
+++ team/murf/utf8-whatif/doc/tex/asterisk-conf.tex Fri Dec 14 13:01:23 2007
@@ -123,7 +123,15 @@
 ;  - flock: for where the lockfile locking method doesn't work
 ;           eh. on SMB/CIFS mounts
 lockmode = lockfile | flock
-  
+
+; UTF-8 in the CLI
+;  - By default, the high-order being "on", means a Meta- (Alt-?) 
+;    key was depressed, and a Meta-something editing command is
+;    being specified. With this option set to "yes", you
+;    turn off the the M-@ thru M-x commands, and UTF-8 is
+;    then transparently passed into asterisk from the CLI.
+;    it is "no" by default for historical reasons.
+utf8cli = no  
 
 [files]
 ; Changing the following lines may compromise your security

Modified: team/murf/utf8-whatif/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/murf/utf8-whatif/main/asterisk.c?view=diff&rev=93064&r1=93063&r2=93064
==============================================================================
--- team/murf/utf8-whatif/main/asterisk.c (original)
+++ team/murf/utf8-whatif/main/asterisk.c Fri Dec 14 13:01:23 2007
@@ -158,6 +158,8 @@
 double option_maxload;				/*!< Max load avg on system */
 int option_maxcalls;				/*!< Max number of active calls */
 int option_maxfiles;				/*!< Max number of open file handles (files, sockets) */
+int option_utf8cli;
+
 #if defined(HAVE_SYSINFO)
 long option_minmemfree;				/*!< Minimum amount of free system memory - stop accepting calls if free memory falls below this watermark */
 #endif
@@ -380,6 +382,11 @@
 #if defined(HAVE_SYSINFO)
 	ast_cli(a->fd, "  Min Free Memory:             %ld MB\n", option_minmemfree);
 #endif
+	if (option_utf8cli)
+		ast_cli(a->fd, "  CLI in utf-8 mode:           yes\n");
+	else
+		ast_cli(a->fd, "  CLI in utf-8 mode:           no\n");
+
 	if (ast_localtime(&ast_startuptime, &tm, NULL)) {
 		ast_strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
 		ast_cli(a->fd, "  Startup time:                %s\n", buf);
@@ -2391,6 +2398,7 @@
 	printf("                   belong after they are done\n");
 	printf("   -T              Display the time in [Mmm dd hh:mm:ss] format for each line\n");
 	printf("                   of output to the CLI\n");
+	printf("   -u              Make the CLI accept UTF-8 characters as normal characters.\n");
 	printf("   -v              Increase verbosity (multiple v's = more verbose)\n");
 	printf("   -x <cmd>        Execute command <cmd> (only valid with -r)\n");
 	printf("\n");
@@ -2578,6 +2586,8 @@
 			}
 		} else if (!strcasecmp(v->name, "languageprefix")) {
 			ast_language_is_prefix = ast_true(v->value);
+		} else if (!strcasecmp(v->name, "utf8cli")) {
+			option_utf8cli = ast_true(v->value);
  		} else if (!strcasecmp(v->name, "lockmode")) {
  			if (!strcasecmp(v->value, "lockfile")) {
  				ast_set_lock_type(AST_LOCK_TYPE_LOCKFILE);
@@ -2751,6 +2761,9 @@
 		case 'U':
 			runuser = optarg;
 			break;
+		case 'u':
+			option_utf8cli = 1;
+			break;
 		case 'G':
 			rungroup = optarg;
 			break;

Modified: team/murf/utf8-whatif/main/editline/common.c
URL: http://svn.digium.com/view/asterisk/team/murf/utf8-whatif/main/editline/common.c?view=diff&rev=93064&r1=93063&r2=93064
==============================================================================
--- team/murf/utf8-whatif/main/editline/common.c (original)
+++ team/murf/utf8-whatif/main/editline/common.c Fri Dec 14 13:01:23 2007
@@ -76,7 +76,7 @@
 
 	if (c == '\0')
 		return (CC_ERROR);
-
+	
 	if (el->el_line.lastchar + el->el_state.argument >=
 	    el->el_line.limit) {
 		/* end of buffer space, try to allocate more */

Modified: team/murf/utf8-whatif/main/editline/np/vis.c
URL: http://svn.digium.com/view/asterisk/team/murf/utf8-whatif/main/editline/np/vis.c?view=diff&rev=93064&r1=93063&r2=93064
==============================================================================
--- team/murf/utf8-whatif/main/editline/np/vis.c (original)
+++ team/murf/utf8-whatif/main/editline/np/vis.c Fri Dec 14 13:01:23 2007
@@ -166,10 +166,15 @@
 	}								      \
 	if (isc) break;							      \
 	if (isextra || ((c & 0177) == ' ') || (flag & VIS_OCTAL)) {	      \
-		*dst++ = '\\';						      \
-		*dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + '0';    \
-		*dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + '0';    \
-		*dst++ =			     (c	      & 07) + '0';    \
+        printf("Hey, option_utf8cli is set to %d\n", option_utf8cli); \
+		if (option_utf8cli)                                           \
+			*dst++ = c;												  \
+		else {                                        \
+ 		  *dst++ = '\\';						      \
+		  *dst++ = (u_char)(((u_int32_t)(u_char)c >> 6) & 03) + '0';   \
+          *dst++ = (u_char)(((u_int32_t)(u_char)c >> 3) & 07) + '0';    \
+		  *dst++ =			     (c	      & 07) + '0';    \
+		}                                                 \
 	} else {							      \
 		if ((flag & VIS_NOSLASH) == 0) *dst++ = '\\';		      \
 		if (c & 0200) {						      \
@@ -199,6 +204,7 @@
 	const char *extra;
 {
 	char *nextra;
+	extern int option_utf8cli;
 	_DIAGASSERT(dst != NULL);
 	_DIAGASSERT(extra != NULL);
 	MAKEEXTRALIST(flag, nextra, extra);
@@ -236,7 +242,8 @@
 	char c;
 	char *start;
 	char *nextra;
-
+	extern int option_utf8cli;
+	
 	_DIAGASSERT(dst != NULL);
 	_DIAGASSERT(src != NULL);
 	_DIAGASSERT(extra != NULL);
@@ -264,6 +271,7 @@
 	char c;
 	char *start;
 	char *nextra;
+	extern int option_utf8cli;
 
 	_DIAGASSERT(dst != NULL);
 	_DIAGASSERT(src != NULL);
@@ -296,6 +304,7 @@
 	
 {
 	char *extra;
+	extern int option_utf8cli;
 
 	_DIAGASSERT(dst != NULL);
 

Modified: team/murf/utf8-whatif/main/editline/read.c
URL: http://svn.digium.com/view/asterisk/team/murf/utf8-whatif/main/editline/read.c?view=diff&rev=93064&r1=93063&r2=93064
==============================================================================
--- team/murf/utf8-whatif/main/editline/read.c (original)
+++ team/murf/utf8-whatif/main/editline/read.c Fri Dec 14 13:01:23 2007
@@ -229,6 +229,8 @@
 	}
 }
 
+extern int option_utf8cli; /* forgive me... this would be an asterisk.conf option */
+static int utf8_remaining = 0;
 
 /* read_getcmd():
  *	Return next command from the input stream.
@@ -238,6 +240,7 @@
 {
 	el_action_t cmd = ED_UNASSIGNED;
 	int num;
+	unsigned char ch2;
 
 	while (cmd == ED_UNASSIGNED || cmd == ED_SEQUENCE_LEAD_IN) {
 		if ((num = el_getc(el, ch)) != 1)	/* if EOF or error */
@@ -255,7 +258,27 @@
 			el->el_state.metanext = 0;
 			*ch |= 0200;
 		}
-		cmd = el->el_map.current[(unsigned char) *ch];
+		ch2 = (unsigned char) *ch;
+
+		if (option_utf8cli && utf8_remaining && (ch2 & 0xc0) == 0x80) {
+			cmd = ED_INSERT;
+			utf8_remaining--;
+		} else if (option_utf8cli && utf8_remaining) {
+			utf8_remaining = 0;
+			printf("Bad UTF-8 character sequence-- are you using UTF-8 enabled terminals?\n");
+		} else if (option_utf8cli && (ch2 & 0xe0) == 0xc0) {/* two byte utf8 */
+			cmd = ED_INSERT;
+			utf8_remaining = 1;
+		} else if (option_utf8cli && (ch2 & 0xf0) == 0xe0) {/* three byte utf8 */
+			cmd = ED_INSERT;
+			utf8_remaining = 2;
+			
+		} else if (option_utf8cli && (ch2 & 0xf8) == 0xf0) {/* four byte utf8 */
+			cmd = ED_INSERT;
+			utf8_remaining = 3;
+		} else
+			cmd = el->el_map.current[(unsigned char) *ch];
+
 		if (cmd == ED_SEQUENCE_LEAD_IN) {
 			key_value_t val;
 			switch (key_get(el, ch, &val)) {
@@ -543,8 +566,7 @@
 			break;
 		}
 	}
-
-				/* make sure the tty is set up correctly */
+	/* make sure the tty is set up correctly */
 	(void) tty_cookedmode(el);
 	term__flush();		/* flush any buffered output */
 	if (el->el_flags & HANDLE_SIGNALS)

Modified: team/murf/utf8-whatif/main/editline/refresh.c
URL: http://svn.digium.com/view/asterisk/team/murf/utf8-whatif/main/editline/refresh.c?view=diff&rev=93064&r1=93063&r2=93064
==============================================================================
--- team/murf/utf8-whatif/main/editline/refresh.c (original)
+++ team/murf/utf8-whatif/main/editline/refresh.c Fri Dec 14 13:01:23 2007
@@ -98,6 +98,7 @@
 private void
 re_addc(EditLine *el, int c)
 {
+	extern int option_utf8cli;
 
 	if (isprint(c)) {
 		re_putc(el, c, 1);
@@ -126,10 +127,15 @@
 		    /* uncontrolify it; works only for iso8859-1 like sets */
 			re_putc(el, (c | 0100), 1);
 	} else {
-		re_putc(el, '\\', 1);
-		re_putc(el, (int) ((((unsigned int) c >> 6) & 07) + '0'), 1);
-		re_putc(el, (int) ((((unsigned int) c >> 3) & 07) + '0'), 1);
-		re_putc(el, (c & 07) + '0', 1);
+		if (option_utf8cli)
+			re_putc(el, c, 1);
+		else {
+			re_putc(el, '\\', 1);
+			re_putc(el, (int) ((((unsigned int) c >> 6) & 07) + '0'), 1);
+			re_putc(el, (int) ((((unsigned int) c >> 3) & 07) + '0'), 1);
+			re_putc(el, (c & 07) + '0', 1);
+		}
+		
 	}
 }
 
@@ -1034,7 +1040,8 @@
 {
 	char c;
 	int rhdiff;
-
+	extern int option_utf8cli;
+	
 	c = el->el_line.cursor[-1];
 
 	if (c == '\t' || el->el_line.cursor != el->el_line.lastchar) {
@@ -1054,10 +1061,14 @@
 	} else if (isprint((unsigned char) c)) {	/* normal char */
 		re_fastputc(el, c);
 	} else {
-		re_fastputc(el, '\\');
-		re_fastputc(el, (int) ((((unsigned int) c >> 6) & 7) + '0'));
-		re_fastputc(el, (int) ((((unsigned int) c >> 3) & 7) + '0'));
-		re_fastputc(el, (c & 7) + '0');
+		if (option_utf8cli)
+			re_fastputc(el, c);
+		else {
+			re_fastputc(el, '\\');
+			re_fastputc(el, (int) ((((unsigned int) c >> 6) & 7) + '0'));
+			re_fastputc(el, (int) ((((unsigned int) c >> 3) & 7) + '0'));
+			re_fastputc(el, (c & 7) + '0');
+		}
 	}
 	term__flush();
 }




More information about the asterisk-commits mailing list