Fri Jul 8 15:54:56 2011 UTC ()
Support other non-latin1 single byte character sets.
From: Alexander Barkov and Nirbhay Choubey at oracle dot com


(christos)
diff -r1.58 -r1.59 src/lib/libedit/read.c

cvs diff -r1.58 -r1.59 src/lib/libedit/read.c (expand / switch to unified diff)

--- src/lib/libedit/read.c 2011/02/18 20:53:05 1.58
+++ src/lib/libedit/read.c 2011/07/08 15:54:56 1.59
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: read.c,v 1.58 2011/02/18 20:53:05 christos Exp $ */ 1/* $NetBSD: read.c,v 1.59 2011/07/08 15:54:56 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * Christos Zoulas of Cornell University. 8 * Christos Zoulas of Cornell University.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -27,27 +27,27 @@ @@ -27,27 +27,27 @@
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE. 32 * SUCH DAMAGE.
33 */ 33 */
34 34
35#include "config.h" 35#include "config.h"
36#if !defined(lint) && !defined(SCCSID) 36#if !defined(lint) && !defined(SCCSID)
37#if 0 37#if 0
38static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93"; 38static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
39#else 39#else
40__RCSID("$NetBSD: read.c,v 1.58 2011/02/18 20:53:05 christos Exp $"); 40__RCSID("$NetBSD: read.c,v 1.59 2011/07/08 15:54:56 christos Exp $");
41#endif 41#endif
42#endif /* not lint && not SCCSID */ 42#endif /* not lint && not SCCSID */
43 43
44/* 44/*
45 * read.c: Clean this junk up! This is horrible code. 45 * read.c: Clean this junk up! This is horrible code.
46 * Terminal read functions 46 * Terminal read functions
47 */ 47 */
48#include <errno.h> 48#include <errno.h>
49#include <fcntl.h> 49#include <fcntl.h>
50#include <unistd.h> 50#include <unistd.h>
51#include <stdlib.h> 51#include <stdlib.h>
52#include <limits.h> 52#include <limits.h>
53#include "el.h" 53#include "el.h"
@@ -342,27 +342,31 @@ read_char(EditLine *el, Char *cp) @@ -342,27 +342,31 @@ read_char(EditLine *el, Char *cp)
342#ifdef WIDECHAR 342#ifdef WIDECHAR
343 if (el->el_flags & CHARSET_IS_UTF8) { 343 if (el->el_flags & CHARSET_IS_UTF8) {
344 if (!utf8_islead((unsigned char)cbuf[0])) 344 if (!utf8_islead((unsigned char)cbuf[0]))
345 goto again; /* discard the byte we read and try again */ 345 goto again; /* discard the byte we read and try again */
346 ++cbp; 346 ++cbp;
347 if ((bytes = ct_mbtowc(cp, cbuf, cbp)) == -1) { 347 if ((bytes = ct_mbtowc(cp, cbuf, cbp)) == -1) {
348 ct_mbtowc_reset; 348 ct_mbtowc_reset;
349 if (cbp >= MB_LEN_MAX) { /* "shouldn't happen" */ 349 if (cbp >= MB_LEN_MAX) { /* "shouldn't happen" */
350 *cp = '\0'; 350 *cp = '\0';
351 return (-1); 351 return (-1);
352 } 352 }
353 goto again; 353 goto again;
354 } 354 }
355 } else /* we don't support other multibyte charsets */ 355 } else if (*cbuf >= 0 || /* ASCII */
 356 /* we don't support other multibyte charsets */
 357 ++cbp != 1 ||
 358 /* Try non-ASCII characters in a 8-bit character set */
 359 (bytes = ct_mbtowc(cp, cbuf, cbp)) != 1)
356#endif 360#endif
357 *cp = (unsigned char)cbuf[0]; 361 *cp = (unsigned char)cbuf[0];
358 362
359 if ((el->el_flags & IGNORE_EXTCHARS) && bytes > 1) { 363 if ((el->el_flags & IGNORE_EXTCHARS) && bytes > 1) {
360 cbp = 0; /* skip this character */ 364 cbp = 0; /* skip this character */
361 goto again; 365 goto again;
362 } 366 }
363 367
364 return (int)num_read; 368 return (int)num_read;
365} 369}
366 370
367/* read_pop(): 371/* read_pop():
368 * Pop a macro from the stack 372 * Pop a macro from the stack