| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: read.c,v 1.51 2009/06/09 13:04:33 christos Exp $ */ | | 1 | /* $NetBSD: read.c,v 1.52 2009/07/22 15:57:00 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 |
38 | static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93"; | | 38 | static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93"; |
39 | #else | | 39 | #else |
40 | __RCSID("$NetBSD: read.c,v 1.51 2009/06/09 13:04:33 christos Exp $"); | | 40 | __RCSID("$NetBSD: read.c,v 1.52 2009/07/22 15:57:00 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 "el.h" | | 52 | #include "el.h" |
53 | | | 53 | |
| @@ -412,26 +412,27 @@ el_gets(EditLine *el, int *nread) | | | @@ -412,26 +412,27 @@ el_gets(EditLine *el, int *nread) |
412 | { | | 412 | { |
413 | int retval; | | 413 | int retval; |
414 | el_action_t cmdnum = 0; | | 414 | el_action_t cmdnum = 0; |
415 | int num; /* how many chars we have read at NL */ | | 415 | int num; /* how many chars we have read at NL */ |
416 | char ch; | | 416 | char ch; |
417 | int crlf = 0; | | 417 | int crlf = 0; |
418 | int nrb; | | 418 | int nrb; |
419 | #ifdef FIONREAD | | 419 | #ifdef FIONREAD |
420 | c_macro_t *ma = &el->el_chared.c_macro; | | 420 | c_macro_t *ma = &el->el_chared.c_macro; |
421 | #endif /* FIONREAD */ | | 421 | #endif /* FIONREAD */ |
422 | | | 422 | |
423 | if (nread == NULL) | | 423 | if (nread == NULL) |
424 | nread = &nrb; | | 424 | nread = &nrb; |
| | | 425 | *nread = 0; |
425 | | | 426 | |
426 | if (el->el_flags & NO_TTY) { | | 427 | if (el->el_flags & NO_TTY) { |
427 | char *cp = el->el_line.buffer; | | 428 | char *cp = el->el_line.buffer; |
428 | size_t idx; | | 429 | size_t idx; |
429 | | | 430 | |
430 | while ((num = (*el->el_read.read_char)(el, cp)) == 1) { | | 431 | while ((num = (*el->el_read.read_char)(el, cp)) == 1) { |
431 | /* make sure there is space for next character */ | | 432 | /* make sure there is space for next character */ |
432 | if (cp + 1 >= el->el_line.limit) { | | 433 | if (cp + 1 >= el->el_line.limit) { |
433 | idx = (cp - el->el_line.buffer); | | 434 | idx = (cp - el->el_line.buffer); |
434 | if (!ch_enlargebufs(el, 2)) | | 435 | if (!ch_enlargebufs(el, 2)) |
435 | break; | | 436 | break; |
436 | cp = &el->el_line.buffer[idx]; | | 437 | cp = &el->el_line.buffer[idx]; |
437 | } | | 438 | } |