Tue Jan 12 19:37:18 2010 UTC ()
- in the argv conversion, handle NULL as NULL
- when printing tab/nl print them, don't handle them specially.


(christos)
diff -r1.2 -r1.3 src/lib/libedit/chartype.c

cvs diff -r1.2 -r1.3 src/lib/libedit/chartype.c (expand / switch to unified diff)

--- src/lib/libedit/chartype.c 2009/12/31 18:32:37 1.2
+++ src/lib/libedit/chartype.c 2010/01/12 19:37:18 1.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: chartype.c,v 1.2 2009/12/31 18:32:37 christos Exp $ */ 1/* $NetBSD: chartype.c,v 1.3 2010/01/12 19:37:18 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2009 The NetBSD Foundation, Inc. 4 * Copyright (c) 2009 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE. 33 * POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35 35
36/* 36/*
37 * chartype.c: character classification and meta information 37 * chartype.c: character classification and meta information
38 */ 38 */
39#include "config.h" 39#include "config.h"
40#if !defined(lint) && !defined(SCCSID) 40#if !defined(lint) && !defined(SCCSID)
41__RCSID("$NetBSD: chartype.c,v 1.2 2009/12/31 18:32:37 christos Exp $"); 41__RCSID("$NetBSD: chartype.c,v 1.3 2010/01/12 19:37:18 christos Exp $");
42#endif /* not lint && not SCCSID */ 42#endif /* not lint && not SCCSID */
43#include "el.h" 43#include "el.h"
44#include <stdlib.h> 44#include <stdlib.h>
45 45
46#define CT_BUFSIZ 1024 46#define CT_BUFSIZ 1024
47 47
48 48
49#ifdef WIDECHAR 49#ifdef WIDECHAR
50protected void 50protected void
51ct_conv_buff_resize(ct_buffer_t *conv, size_t mincsize, size_t minwsize) 51ct_conv_buff_resize(ct_buffer_t *conv, size_t mincsize, size_t minwsize)
52{ 52{
53 void *p; 53 void *p;
54 if (mincsize > conv->csize) { 54 if (mincsize > conv->csize) {
@@ -149,27 +149,27 @@ ct_decode_argv(int argc, const char *arg @@ -149,27 +149,27 @@ ct_decode_argv(int argc, const char *arg
149 /* Make sure we have enough space in the conversion buffer to store all 149 /* Make sure we have enough space in the conversion buffer to store all
150 * the argv strings. */ 150 * the argv strings. */
151 for (i = 0, bufspace = 0; i < argc; ++i) 151 for (i = 0, bufspace = 0; i < argc; ++i)
152 bufspace += argv[i] ? strlen(argv[i]) + 1 : 0; 152 bufspace += argv[i] ? strlen(argv[i]) + 1 : 0;
153 ct_conv_buff_resize(conv, 0, bufspace); 153 ct_conv_buff_resize(conv, 0, bufspace);
154 if (!conv->wsize) 154 if (!conv->wsize)
155 return NULL; 155 return NULL;
156 156
157 wargv = el_malloc(argc * sizeof(*wargv)); 157 wargv = el_malloc(argc * sizeof(*wargv));
158 158
159 for (i = 0, p = conv->wbuff; i < argc; ++i) { 159 for (i = 0, p = conv->wbuff; i < argc; ++i) {
160 if (!argv[i]) { /* don't pass null pointers to mbstowcs */ 160 if (!argv[i]) { /* don't pass null pointers to mbstowcs */
161 wargv[i] = NULL; 161 wargv[i] = NULL;
162 bytes = -1; 162 continue;
163 } else { 163 } else {
164 wargv[i] = p; 164 wargv[i] = p;
165 bytes = mbstowcs(p, argv[i], bufspace); 165 bytes = mbstowcs(p, argv[i], bufspace);
166 } 166 }
167 if (bytes == -1) { 167 if (bytes == -1) {
168 el_free(wargv); 168 el_free(wargv);
169 return NULL; 169 return NULL;
170 } else 170 } else
171 bytes++; /* include '\0' in the count */ 171 bytes++; /* include '\0' in the count */
172 bufspace -= bytes; 172 bufspace -= bytes;
173 p += bytes; 173 p += bytes;
174 } 174 }
175 175
@@ -285,26 +285,28 @@ ct_visual_width(Char c) @@ -285,26 +285,28 @@ ct_visual_width(Char c)
285 return 4; /* \123 */ 285 return 4; /* \123 */
286#endif 286#endif
287 default: 287 default:
288 return 0; /* should not happen */ 288 return 0; /* should not happen */
289 } 289 }
290} 290}
291 291
292 292
293protected ssize_t 293protected ssize_t
294ct_visual_char(Char *dst, size_t len, Char c) 294ct_visual_char(Char *dst, size_t len, Char c)
295{ 295{
296 int t = ct_chr_class(c); 296 int t = ct_chr_class(c);
297 switch (t) { 297 switch (t) {
 298 case CHTYPE_TAB:
 299 case CHTYPE_NL:
298 case CHTYPE_ASCIICTL: 300 case CHTYPE_ASCIICTL:
299 if (len < 2) 301 if (len < 2)
300 return -1; /* insufficient space */ 302 return -1; /* insufficient space */
301 *dst++ = '^'; 303 *dst++ = '^';
302 if (c == '\177') 304 if (c == '\177')
303 *dst = '?'; /* DEL -> ^? */ 305 *dst = '?'; /* DEL -> ^? */
304 else 306 else
305 *dst = c | 0100; /* uncontrolify it */ 307 *dst = c | 0100; /* uncontrolify it */
306 return 2; 308 return 2;
307 case CHTYPE_PRINT: 309 case CHTYPE_PRINT:
308 if (len < 1) 310 if (len < 1)
309 return -1; /* insufficient space */ 311 return -1; /* insufficient space */
310 *dst = c; 312 *dst = c;
@@ -325,28 +327,26 @@ ct_visual_char(Char *dst, size_t len, Ch @@ -325,28 +327,26 @@ ct_visual_char(Char *dst, size_t len, Ch
325 *dst++ = tohexdigit(((unsigned int) c >> 8) & 0xf); 327 *dst++ = tohexdigit(((unsigned int) c >> 8) & 0xf);
326 *dst++ = tohexdigit(((unsigned int) c >> 4) & 0xf); 328 *dst++ = tohexdigit(((unsigned int) c >> 4) & 0xf);
327 *dst = tohexdigit(((unsigned int) c ) & 0xf); 329 *dst = tohexdigit(((unsigned int) c ) & 0xf);
328 return (c > 0xffff) ? 8 : 7; 330 return (c > 0xffff) ? 8 : 7;
329#else 331#else
330 *dst++ = '\\'; 332 *dst++ = '\\';
331#define tooctaldigit(v) ((v) + '0') 333#define tooctaldigit(v) ((v) + '0')
332 *dst++ = tooctaldigit(((unsigned int) c >> 6) & 0x7); 334 *dst++ = tooctaldigit(((unsigned int) c >> 6) & 0x7);
333 *dst++ = tooctaldigit(((unsigned int) c >> 3) & 0x7); 335 *dst++ = tooctaldigit(((unsigned int) c >> 3) & 0x7);
334 *dst++ = tooctaldigit(((unsigned int) c ) & 0x7); 336 *dst++ = tooctaldigit(((unsigned int) c ) & 0x7);
335#endif 337#endif
336 /*FALLTHROUGH*/ 338 /*FALLTHROUGH*/
337 /* these two should be handled outside this function */ 339 /* these two should be handled outside this function */
338 case CHTYPE_TAB: 
339 case CHTYPE_NL: 
340 default: /* we should never hit the default */ 340 default: /* we should never hit the default */
341 return 0; 341 return 0;
342 } 342 }
343} 343}
344 344
345 345
346 346
347 347
348protected int 348protected int
349ct_chr_class(Char c) 349ct_chr_class(Char c)
350{ 350{
351 if (c == '\t') 351 if (c == '\t')
352 return CHTYPE_TAB; 352 return CHTYPE_TAB;