List:Commits« Previous MessageNext Message »
From:Nirbhay Choubey Date:August 16 2011 9:54am
Subject:bzr push into mysql-trunk branch (nirbhay.choubey:3241 to 3242) WL#5945
View as plain text  
 3242 Nirbhay Choubey	2011-08-15
      WL#5945 : Improve libedit library
      
      * Switched to restartable multibyte routines.
      * Added files to support NARROW and WIDE mode compilation.
      * Added some readline compatible key-bindings.
      * Raised editline buffer size from 1024 to 4096 in order
        to increase the length of commends that can be handled
        by history.

    added:
      cmd-line-utils/libedit/historyn.c
      cmd-line-utils/libedit/tokenizern.c
    modified:
      cmd-line-utils/libedit/CMakeLists.txt
      cmd-line-utils/libedit/chartype.c
      cmd-line-utils/libedit/chartype.h
      cmd-line-utils/libedit/config.h
      cmd-line-utils/libedit/el.c
      cmd-line-utils/libedit/el.h
      cmd-line-utils/libedit/eln.c
      cmd-line-utils/libedit/keymacro.c
      cmd-line-utils/libedit/read.c
      cmd-line-utils/libedit/readline.c
      cmd-line-utils/libedit/terminal.c
      cmd-line-utils/libedit/vi.c
 3241 Nirbhay Choubey	2011-07-29
      WL#5945 : Improve libedit library
      
      Sync with NetBSD CVS head.

    modified:
      cmd-line-utils/libedit/chared.c
      cmd-line-utils/libedit/chartype.c
      cmd-line-utils/libedit/el.c
      cmd-line-utils/libedit/eln.c
      cmd-line-utils/libedit/filecomplete.c
      cmd-line-utils/libedit/hist.c
      cmd-line-utils/libedit/hist.h
      cmd-line-utils/libedit/histedit.h
      cmd-line-utils/libedit/history.c
      cmd-line-utils/libedit/keymacro.c
      cmd-line-utils/libedit/map.c
      cmd-line-utils/libedit/read.c
      cmd-line-utils/libedit/readline.c
      cmd-line-utils/libedit/search.c
      cmd-line-utils/libedit/sig.c
      cmd-line-utils/libedit/sys.h
      cmd-line-utils/libedit/terminal.c
      cmd-line-utils/libedit/tokenizer.c
      cmd-line-utils/libedit/vi.c
=== modified file 'cmd-line-utils/libedit/CMakeLists.txt'
--- a/cmd-line-utils/libedit/CMakeLists.txt	2011-07-28 08:06:45 +0000
+++ b/cmd-line-utils/libedit/CMakeLists.txt	2011-08-15 06:46:56 +0000
@@ -152,12 +152,15 @@ ${CURSES_INCLUDE_PATH}
 SET(LIBEDIT_SOURCES
   chared.c 
   el.c 
+  eln.c 
   history.c
+  historyn.c
   map.c
   prompt.c
   readline.c 
   search.c
   tokenizer.c
+  tokenizern.c
   vi.c
   common.c
   emacs.c 

=== modified file 'cmd-line-utils/libedit/chartype.c'
--- a/cmd-line-utils/libedit/chartype.c	2011-07-29 10:02:07 +0000
+++ b/cmd-line-utils/libedit/chartype.c	2011-08-15 06:46:56 +0000
@@ -78,6 +78,9 @@ ct_encode_string(const Char *s, ct_buffe
 {
 	char *dst;
 	ssize_t used = 0;
+	mbstate_t state;
+
+	memset(&state, 0, sizeof(mbstate_t));
 
 	if (!s)
 		return NULL;
@@ -96,7 +99,7 @@ ct_encode_string(const Char *s, ct_buffe
 				return NULL;
 			dst = conv->cbuff + used;
 		}
-		used = ct_encode_char(dst, 5, *s);
+		used = ct_encode_char(dst, 5, *s, &state);
 		if (used == -1) /* failed to encode, need more buffer space */
 			abort();
 		++s;
@@ -138,6 +141,7 @@ ct_decode_argv(int argc, const char *arg
 	Char *p;
 	Char **wargv;
 	ssize_t bytes;
+	mbstate_t state;
 
 	/* Make sure we have enough space in the conversion buffer to store all
 	 * the argv strings. */
@@ -150,12 +154,13 @@ ct_decode_argv(int argc, const char *arg
 	wargv = el_malloc(argc * sizeof(*wargv));
 
 	for (i = 0, p = conv->wbuff; i < argc; ++i) {
-		if (!argv[i]) {   /* don't pass null pointers to mbstowcs */
+		if (!argv[i]) {   /* don't pass null pointers to mbsrtowcs */
 			wargv[i] = NULL;
 			continue;
 		} else {
 			wargv[i] = p;
-			bytes = mbstowcs(p, argv[i], bufspace);
+			memset(&state, 0, sizeof(mbstate_t));
+			bytes = mbsrtowcs(p, argv + i, bufspace, &state);
 		}
 		if (bytes == -1) {
 			el_free(wargv);
@@ -187,15 +192,17 @@ ct_enc_width(Char c)
 }
 
 protected ssize_t
-ct_encode_char(char *dst, size_t len, Char c)
+ct_encode_char(char *dst, size_t len, Char c, mbstate_t *state)
 {
 	ssize_t l = 0;
+
 	if (len < ct_enc_width(c))
 		return -1;
-	l = ct_wctomb(dst, c);
+
+	l = wcrtomb(dst, c, state);
 
 	if (l < 0) {
-		ct_wctomb_reset;
+		memset (state, 0, sizeof (mbstate_t));
 		l = 0;
 	}
 	return l;

=== modified file 'cmd-line-utils/libedit/chartype.h'
--- a/cmd-line-utils/libedit/chartype.h	2011-05-13 08:32:47 +0000
+++ b/cmd-line-utils/libedit/chartype.h	2011-08-15 06:46:56 +0000
@@ -60,8 +60,6 @@
 #warning Build environment does not support non-BMP characters
 #endif
 
-#define ct_mbtowc            mbtowc
-#define ct_mbtowc_reset      mbtowc(0,0,0)
 #define ct_wctomb            wctomb
 #define ct_wctomb_reset      wctomb(0,0)
 #define ct_wcstombs          wcstombs
@@ -185,7 +183,7 @@ protected Char **ct_decode_argv(int, con
 
 /* Resizes the conversion buffer(s) if needed. */
 protected void ct_conv_buff_resize(ct_buffer_t *, size_t, size_t);
-protected ssize_t ct_encode_char(char *, size_t, Char);
+protected ssize_t ct_encode_char(char *, size_t, Char, mbstate_t *);
 protected size_t ct_enc_width(Char);
 
 #define ct_free_argv(s)	el_free(s)
@@ -195,7 +193,7 @@ protected size_t ct_enc_width(Char);
 #define ct_decode_string(s, b)	(s)
 #define ct_decode_argv(l, s, b)	(s)
 #define ct_conv_buff_resize(b, os, ns)
-#define ct_encode_char(d, l, s)	(*d = s, 1)
+#define ct_encode_char(d, l, s, ps)	(*d = s, 1)
 #define ct_free_argv(s)
 #endif
 

=== modified file 'cmd-line-utils/libedit/config.h'
--- a/cmd-line-utils/libedit/config.h	2009-06-11 16:21:32 +0000
+++ b/cmd-line-utils/libedit/config.h	2011-08-15 06:46:56 +0000
@@ -1,2 +1,5 @@
 #include "my_config.h"
 #include "sys.h"
+#ifndef NARROW_WRAPPER
+#define WIDECHAR
+#endif

=== modified file 'cmd-line-utils/libedit/el.c'
--- a/cmd-line-utils/libedit/el.c	2011-07-29 10:02:07 +0000
+++ b/cmd-line-utils/libedit/el.c	2011-08-15 06:46:56 +0000
@@ -85,10 +85,9 @@ el_init(const char *prog, FILE *fin, FIL
          */
 	el->el_flags = 0;
 #ifdef WIDECHAR
-	if (setlocale(LC_CTYPE, NULL) != NULL){
-		if (strcmp(nl_langinfo(CODESET), "UTF-8") == 0)
-			el->el_flags |= CHARSET_IS_UTF8;
-	}
+	setlocale(LC_CTYPE, NULL);
+        if (MB_CUR_MAX > 1)
+		el->el_flags |= CHARSET_IS_MULTIBYTE;
 #endif
 
 	if (terminal_init(el) == -1) {
@@ -272,7 +271,7 @@ FUN(el,set)(EditLine *el, int op, ...)
 		void *ptr = va_arg(ap, void *);
 
 		rv = hist_set(el, func, ptr);
-		if (!(el->el_flags & CHARSET_IS_UTF8))
+		if (!(el->el_flags & CHARSET_IS_MULTIBYTE))
 			el->el_flags &= ~NARROW_HISTORY;
 		break;
 	}

=== modified file 'cmd-line-utils/libedit/el.h'
--- a/cmd-line-utils/libedit/el.h	2011-07-28 08:06:45 +0000
+++ b/cmd-line-utils/libedit/el.h	2011-08-15 06:46:56 +0000
@@ -51,16 +51,16 @@
 #include <stdio.h>
 #include <sys/types.h>
 
-#define	EL_BUFSIZ	1024		/* Maximum line size		*/
+#define	EL_BUFSIZ            4096            /* Maximum line size */
 
-#define	HANDLE_SIGNALS	0x01
-#define	NO_TTY		0x02
-#define	EDIT_DISABLED	0x04
-#define	UNBUFFERED	0x08
-#define	CHARSET_IS_UTF8 0x10
-#define	IGNORE_EXTCHARS 0x20            /* Ignore characters read > 0xff */
-#define	NARROW_HISTORY	0x40
-#define	NARROW_READ	0x80
+#define	HANDLE_SIGNALS       0x01
+#define	NO_TTY               0x02
+#define	EDIT_DISABLED        0x04
+#define	UNBUFFERED           0x08
+#define	CHARSET_IS_MULTIBYTE 0x10
+#define	IGNORE_EXTCHARS      0x20            /* Ignore characters read > 0xff */
+#define	NARROW_HISTORY       0x40
+#define	NARROW_READ          0x80
 
 typedef int bool_t;			/* True or not			*/
 

=== modified file 'cmd-line-utils/libedit/eln.c'
--- a/cmd-line-utils/libedit/eln.c	2011-07-29 10:02:07 +0000
+++ b/cmd-line-utils/libedit/eln.c	2011-08-15 06:46:56 +0000
@@ -49,11 +49,7 @@ el_getc(EditLine *el, char *cp)
 	int num_read;
 	wchar_t wc = 0;
 
-	if (!(el->el_flags & CHARSET_IS_UTF8))
-		el->el_flags |= IGNORE_EXTCHARS;
 	num_read = el_wgetc (el, &wc);
-	if (!(el->el_flags & CHARSET_IS_UTF8))
-		el->el_flags &= ~IGNORE_EXTCHARS;
 
 	if (num_read > 0)
 		*cp = (unsigned char)wc;
@@ -75,9 +71,7 @@ el_gets(EditLine *el, int *nread)
 {
 	const wchar_t *tmp;
 
-	el->el_flags |= IGNORE_EXTCHARS;
 	tmp = el_wgets(el, nread);
-	el->el_flags &= ~IGNORE_EXTCHARS;
 	return ct_encode_string(tmp, &el->el_lgcyconv);
 }
 

=== added file 'cmd-line-utils/libedit/historyn.c'
--- a/cmd-line-utils/libedit/historyn.c	1970-01-01 00:00:00 +0000
+++ b/cmd-line-utils/libedit/historyn.c	2011-08-15 06:46:56 +0000
@@ -0,0 +1,5 @@
+#define NARROW_WRAPPER
+#include "config.h"
+#undef WIDECHAR
+#define NARROWCHAR
+#include "./history.c"

=== modified file 'cmd-line-utils/libedit/keymacro.c'
--- a/cmd-line-utils/libedit/keymacro.c	2011-07-29 10:02:07 +0000
+++ b/cmd-line-utils/libedit/keymacro.c	2011-08-15 06:46:56 +0000
@@ -587,7 +587,9 @@ keymacro_kprint(EditLine *el, const Char
 	el_bindings_t *fp;
 	char unparsbuf[EL_BUFSIZ];
 	static const char fmt[] = "%-15s->  %s\n";
+	mbstate_t state;
 
+	memset(&state, 0, sizeof(mbstate_t));
 	if (val != NULL)
 		switch (ntype) {
 		case XK_STR:
@@ -601,7 +603,9 @@ keymacro_kprint(EditLine *el, const Char
 		case XK_CMD:
 			for (fp = el->el_map.help; fp->name; fp++)
 				if (val->cmd == fp->func) {
-                    ct_wcstombs(unparsbuf, fp->name, sizeof(unparsbuf));
+                    memset(&state, 0, sizeof(mbstate_t));
+                    wcsrtombs(unparsbuf, (const wchar_t **) &fp->name,
+                              sizeof(unparsbuf), &state);
                     unparsbuf[sizeof(unparsbuf) -1] = '\0';
 					(void) fprintf(el->el_outfile, fmt,
                         ct_encode_string(key, &el->el_scratch), unparsbuf);
@@ -637,7 +641,9 @@ keymacro__decode_str(const Char *str, ch
 {
 	char *b = buf, *eb = b + len;
 	const Char *p;
+	mbstate_t state;
 
+	memset(&state, 0, sizeof(mbstate_t));
 	b = buf;
 	if (sep[0] != '\0') {
 		ADDC(sep[0]);
@@ -652,7 +658,8 @@ keymacro__decode_str(const Char *str, ch
 		Char *p2 = dbuf;
 		ssize_t l = ct_visual_char(dbuf, VISUAL_WIDTH_MAX, *p);
 		while (l-- > 0) {
-			ssize_t n = ct_encode_char(b, (size_t)(eb - b), *p2++);
+			ssize_t n = ct_encode_char(b, (size_t)(eb - b), *p2++,
+                                                   &state);
 			if (n == -1) /* ran out of space */
 				goto add_endsep;
 			else

=== modified file 'cmd-line-utils/libedit/read.c'
--- a/cmd-line-utils/libedit/read.c	2011-07-29 10:02:07 +0000
+++ b/cmd-line-utils/libedit/read.c	2011-08-15 06:46:56 +0000
@@ -293,18 +293,6 @@ read_getcmd(EditLine *el, el_action_t *c
 	return (OKCMD);
 }
 
-#ifdef WIDECHAR
-/* utf8_islead():
- *      Test whether a byte is a leading byte of a UTF-8 sequence.
- */
-private int
-utf8_islead(unsigned char c)
-{
-        return (c < 0x80) ||             /* single byte char */
-               (c >= 0xc2 && c <= 0xf4); /* start of multibyte sequence */
-}
-#endif
-
 /* read_char():
  *	Read a character from the tty.
  */
@@ -314,8 +302,13 @@ read_char(EditLine *el, Char *cp)
 	ssize_t num_read;
 	int tried = 0;
         char cbuf[MB_LEN_MAX];
-        int cbp = 0;
-        int bytes = 0;
+        size_t cbp = 0;
+        size_t bytes = 0;
+
+#ifdef WIDECHAR
+static mbstate_t state, temp_state;
+memset(&state, 0, sizeof(mbstate_t));
+#endif
 
  again:
 	el->el_signal->sig_no = 0;
@@ -339,30 +332,38 @@ read_char(EditLine *el, Char *cp)
 	}
 
 #ifdef WIDECHAR
-	if (el->el_flags & CHARSET_IS_UTF8) {
-		if (!utf8_islead((unsigned char)cbuf[0]))
-			goto again; /* discard the byte we read and try again */
-		++cbp;
-		if ((bytes = ct_mbtowc(cp, cbuf, cbp)) == -1) {
-			ct_mbtowc_reset;
-			if (cbp >= MB_LEN_MAX) { /* "shouldn't happen" */
-				*cp = '\0';
-				return (-1);
-			}
-			goto again;
-		}
-	} else if (isascii((unsigned char)cbuf[0]) ||
-		/* we don't support other multibyte charsets */
-		++cbp != 1 ||
-		/* Try non-ASCII characters in a 8-bit character set */
-		(bytes = ct_mbtowc(cp, cbuf, cbp)) != 1)
+        ++cbp;
+        if (cbp >= MB_CUR_MAX) { /* "shouldn't happen" */
+          *cp = '\0';
+          return (-1);
+        }
+
+        temp_state= state;
+
+        if ((bytes = mbrtowc(cp, cbuf, cbp, &state)) == -2)
+        {
+          /* Incomplete sequence, restore the state and scan more bytes. */
+          state= temp_state;
+          goto again;
+        }
+        else if (bytes == -1)
+        {
+          /* Invalid sequence, reset the state and continue. */
+          cbp= 0;
+          memset(&state, 0, sizeof(mbstate_t));
+          goto again;
+        }
+        /* We successfully read one single or multi-byte character */
+#else
+        *cp = (unsigned char)cbuf[0];
 #endif
-		*cp = (unsigned char)cbuf[0];
 
+#if 0
 	if ((el->el_flags & IGNORE_EXTCHARS) && bytes > 1) {
 		cbp = 0; /* skip this character */
 		goto again;
 	}
+#endif
 
 	return (int)num_read;
 }

=== modified file 'cmd-line-utils/libedit/readline.c'
--- a/cmd-line-utils/libedit/readline.c	2011-07-29 10:02:07 +0000
+++ b/cmd-line-utils/libedit/readline.c	2011-08-15 06:46:56 +0000
@@ -351,7 +351,38 @@ rl_initialize(void)
 	    "ReadLine compatible suspend function",
 	    _el_rl_tstp);
 	el_set(e, EL_BIND, "^Z", "rl_tstp", NULL);
-		
+
+        /*
+         * Set some readline compatible key-bindings.
+         */
+        el_set(e, EL_BIND, "^R", "em-inc-search-prev", NULL);
+
+        /*
+         * Allow the use of Home/End keys.
+         */
+        el_set(e, EL_BIND, "\\e[1~", "ed-move-to-beg", NULL);
+        el_set(e, EL_BIND, "\\e[4~", "ed-move-to-end", NULL);
+        el_set(e, EL_BIND, "\\e[7~", "ed-move-to-beg", NULL);
+        el_set(e, EL_BIND, "\\e[8~", "ed-move-to-end", NULL);
+        el_set(e, EL_BIND, "\\e[H", "ed-move-to-beg", NULL);
+        el_set(e, EL_BIND, "\\e[F", "ed-move-to-end", NULL);
+
+        /*
+         * Allow the use of the Delete/Insert keys.
+         */
+        el_set(e, EL_BIND, "\\e[3~", "ed-delete-next-char", NULL);
+        el_set(e, EL_BIND, "\\e[2~", "ed-quoted-insert", NULL);
+
+        /*
+         * Ctrl-left-arrow and Ctrl-right-arrow for word moving.
+         */
+        el_set(e, EL_BIND, "\\e[1;5C", "em-next-word", NULL);
+        el_set(e, EL_BIND, "\\e[1;5D", "ed-prev-word", NULL);
+        el_set(e, EL_BIND, "\\e[5C", "em-next-word", NULL);
+        el_set(e, EL_BIND, "\\e[5D", "ed-prev-word", NULL);
+        el_set(e, EL_BIND, "\\e\\e[C", "em-next-word", NULL);
+        el_set(e, EL_BIND, "\\e\\e[D", "ed-prev-word", NULL);
+
 	/* read settings from configuration file */
 	el_source(e, NULL);
 

=== modified file 'cmd-line-utils/libedit/terminal.c'
--- a/cmd-line-utils/libedit/terminal.c	2011-07-29 10:02:07 +0000
+++ b/cmd-line-utils/libedit/terminal.c	2011-08-15 06:46:56 +0000
@@ -715,6 +715,10 @@ mc_again:
 protected void
 terminal_overwrite(EditLine *el, const Char *cp, size_t n)
 {
+#ifdef WIDECHAR
+	int width;
+#endif
+
 	if (n == 0)
 		return;
 
@@ -727,9 +731,15 @@ terminal_overwrite(EditLine *el, const C
 	}
 
         do {
+#ifdef WIDECHAR
+                width = wcwidth(*cp);    /* Returns -1 for faux character. */
+                if (width != -1)
+                  el->el_cursor.h += width;
+#else
+                el->el_cursor.h++;
+#endif
                 /* terminal__putc() ignores any MB_FILL_CHARs */
                 terminal__putc(el, *cp++);
-                el->el_cursor.h++;
         } while (--n);
 
 	if (el->el_cursor.h >= el->el_terminal.t_size.h) {	/* wrap? */
@@ -1321,9 +1331,12 @@ terminal__putc(EditLine *el, Int c)
 {
 	char buf[MB_LEN_MAX +1];
 	ssize_t i;
+	mbstate_t state;
+
+	memset(&state, 0, sizeof(mbstate_t));
 	if (c == MB_FILL_CHAR)
 		return 0;
-	i = ct_encode_char(buf, MB_LEN_MAX, c);
+	i = ct_encode_char(buf, MB_CUR_MAX, c, &state);
 	if (i <= 0)
 		return (int)i;
 	buf[i] = '\0';

=== added file 'cmd-line-utils/libedit/tokenizern.c'
--- a/cmd-line-utils/libedit/tokenizern.c	1970-01-01 00:00:00 +0000
+++ b/cmd-line-utils/libedit/tokenizern.c	2011-08-15 06:46:56 +0000
@@ -0,0 +1,5 @@
+#define NARROW_WRAPPER
+#include "config.h"
+#undef WIDECHAR
+#define NARROWCHAR
+#include "./tokenizer.c"

=== modified file 'cmd-line-utils/libedit/vi.c'
--- a/cmd-line-utils/libedit/vi.c	2011-07-29 10:02:07 +0000
+++ b/cmd-line-utils/libedit/vi.c	2011-08-15 06:46:56 +0000
@@ -1009,7 +1009,9 @@ vi_histedit(EditLine *el, Int c __attrib
 	char *cp;
 	size_t len;
 	Char *line;
+	mbstate_t state;
 
+	memset(&state, 0, sizeof(mbstate_t));
 	if (el->el_state.doingarg) {
 		if (vi_to_history_line(el, 0) == CC_ERROR)
 			return CC_ERROR;
@@ -1033,7 +1035,7 @@ vi_histedit(EditLine *el, Int c __attrib
 	}
 	Strncpy(line, el->el_line.buffer, len);
 	line[len] = '\0';
-	ct_wcstombs(cp, line, TMP_BUFSIZ - 1);
+	wcsrtombs(cp, (const wchar_t **) &line, TMP_BUFSIZ - 1, &state);
 	cp[TMP_BUFSIZ - 1] = '\0';
 	len = strlen(cp);
 	if (write(fd, cp, len) == -1)
@@ -1061,7 +1063,9 @@ vi_histedit(EditLine *el, Int c __attrib
 		if (st > 0) {
 			len = (size_t)(el->el_line.lastchar -
 			    el->el_line.buffer);
-			len = ct_mbstowcs(el->el_line.buffer, cp, len);
+			memset(&state, 0, sizeof(mbstate_t));
+			len = mbsrtowcs(el->el_line.buffer,
+                                        (const char**) &cp, len, &state);
 			if (len > 0 && el->el_line.buffer[len -1] == '\n')
 				--len;
 		}

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-trunk branch (nirbhay.choubey:3241 to 3242) WL#5945Nirbhay Choubey17 Aug