Deleted Added
full compact
read.c (238173) read.c (238378)
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Christos Zoulas of Cornell University.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 22 unchanged lines hidden (view full) ---

31 *
32 * $NetBSD: read.c,v 1.52 2009/07/22 15:57:00 christos Exp $
33 */
34
35#if !defined(lint) && !defined(SCCSID)
36static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
37#endif /* not lint && not SCCSID */
38#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Christos Zoulas of Cornell University.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 22 unchanged lines hidden (view full) ---

31 *
32 * $NetBSD: read.c,v 1.52 2009/07/22 15:57:00 christos Exp $
33 */
34
35#if !defined(lint) && !defined(SCCSID)
36static char sccsid[] = "@(#)read.c 8.1 (Berkeley) 6/4/93";
37#endif /* not lint && not SCCSID */
38#include <sys/cdefs.h>
39__FBSDID("$FreeBSD: head/lib/libedit/read.c 238173 2012-07-06 16:43:56Z pfg $");
39__FBSDID("$FreeBSD: head/lib/libedit/read.c 238378 2012-07-11 22:20:19Z pfg $");
40
41/*
42 * read.c: Clean this junk up! This is horrible code.
43 * Terminal read functions
44 */
45#include "sys.h"
46#include <errno.h>
47#include <fcntl.h>

--- 182 unchanged lines hidden (view full) ---

230 * Return next command from the input stream.
231 */
232private int
233read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch)
234{
235 el_action_t cmd;
236 int num;
237
40
41/*
42 * read.c: Clean this junk up! This is horrible code.
43 * Terminal read functions
44 */
45#include "sys.h"
46#include <errno.h>
47#include <fcntl.h>

--- 182 unchanged lines hidden (view full) ---

230 * Return next command from the input stream.
231 */
232private int
233read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch)
234{
235 el_action_t cmd;
236 int num;
237
238 el->el_errno = 0;
238 do {
239 do {
239 if ((num = el_getc(el, ch)) != 1) /* if EOF or error */
240 if ((num = el_getc(el, ch)) != 1) { /* if EOF or error */
241 el->el_errno = num == 0 ? 0 : errno;
240 return (num);
242 return (num);
243 }
241
242#ifdef KANJI
243 if ((*ch & 0200)) {
244 el->el_state.metanext = 0;
245 cmd = CcViMap[' '];
246 break;
247 } else
248#endif /* KANJI */

--- 35 unchanged lines hidden (view full) ---

284 * Read a character from the tty.
285 */
286private int
287read_char(EditLine *el, char *cp)
288{
289 ssize_t num_read;
290 int tried = 0;
291
244
245#ifdef KANJI
246 if ((*ch & 0200)) {
247 el->el_state.metanext = 0;
248 cmd = CcViMap[' '];
249 break;
250 } else
251#endif /* KANJI */

--- 35 unchanged lines hidden (view full) ---

287 * Read a character from the tty.
288 */
289private int
290read_char(EditLine *el, char *cp)
291{
292 ssize_t num_read;
293 int tried = 0;
294
292 while ((num_read = read(el->el_infd, cp, 1)) == -1)
295 again:
296 el->el_signal->sig_no = 0;
297 while ((num_read = read(el->el_infd, cp, 1)) == -1) {
298 if (el->el_signal->sig_no == SIGCONT) {
299 sig_set(el);
300 el_set(el, EL_REFRESH);
301 goto again;
302 }
293 if (!tried && read__fixio(el->el_infd, errno) == 0)
294 tried = 1;
295 else {
296 *cp = '\0';
297 return (-1);
298 }
303 if (!tried && read__fixio(el->el_infd, errno) == 0)
304 tried = 1;
305 else {
306 *cp = '\0';
307 return (-1);
308 }
299
309 }
300 return (int)num_read;
301}
302
303/* read_pop():
304 * Pop a macro from the stack
305 */
306private void
307read_pop(c_macro_t *ma)

--- 90 unchanged lines hidden (view full) ---

398public const char *
399el_gets(EditLine *el, int *nread)
400{
401 int retval;
402 el_action_t cmdnum = 0;
403 int num; /* how many chars we have read at NL */
404 char ch;
405 int crlf = 0;
310 return (int)num_read;
311}
312
313/* read_pop():
314 * Pop a macro from the stack
315 */
316private void
317read_pop(c_macro_t *ma)

--- 90 unchanged lines hidden (view full) ---

408public const char *
409el_gets(EditLine *el, int *nread)
410{
411 int retval;
412 el_action_t cmdnum = 0;
413 int num; /* how many chars we have read at NL */
414 char ch;
415 int crlf = 0;
416 int nrb;
406#ifdef FIONREAD
407 c_macro_t *ma = &el->el_chared.c_macro;
408#endif /* FIONREAD */
409
417#ifdef FIONREAD
418 c_macro_t *ma = &el->el_chared.c_macro;
419#endif /* FIONREAD */
420
421 if (nread == NULL)
422 nread = &nrb;
410 *nread = 0;
411
412 if (el->el_flags & NO_TTY) {
413 char *cp = el->el_line.buffer;
414 size_t idx;
415
416 while ((*el->el_read.read_char)(el, cp) == 1) {
417 /* make sure there is space for next character */

--- 4 unchanged lines hidden (view full) ---

422 cp = &el->el_line.buffer[idx];
423 }
424 cp++;
425 if (el->el_flags & UNBUFFERED)
426 break;
427 if (cp[-1] == '\r' || cp[-1] == '\n')
428 break;
429 }
423 *nread = 0;
424
425 if (el->el_flags & NO_TTY) {
426 char *cp = el->el_line.buffer;
427 size_t idx;
428
429 while ((*el->el_read.read_char)(el, cp) == 1) {
430 /* make sure there is space for next character */

--- 4 unchanged lines hidden (view full) ---

435 cp = &el->el_line.buffer[idx];
436 }
437 cp++;
438 if (el->el_flags & UNBUFFERED)
439 break;
440 if (cp[-1] == '\r' || cp[-1] == '\n')
441 break;
442 }
443 if (num == -1)
444 el->el_errno = errno;
430
431 el->el_line.cursor = el->el_line.lastchar = cp;
432 *cp = '\0';
445
446 el->el_line.cursor = el->el_line.lastchar = cp;
447 *cp = '\0';
433 if (nread)
434 *nread = (int)(el->el_line.cursor - el->el_line.buffer);
435 return (*nread ? el->el_line.buffer : NULL);
448 *nread = (int)(el->el_line.cursor - el->el_line.buffer);
449 goto done;
436 }
437
438
439#ifdef FIONREAD
440 if (el->el_tty.t_mode == EX_IO && ma->level < 0) {
441 long chrs = 0;
442
443 (void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
444 if (chrs == 0) {
445 if (tty_rawmode(el) < 0) {
450 }
451
452
453#ifdef FIONREAD
454 if (el->el_tty.t_mode == EX_IO && ma->level < 0) {
455 long chrs = 0;
456
457 (void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
458 if (chrs == 0) {
459 if (tty_rawmode(el) < 0) {
446 if (nread)
447 *nread = 0;
460 errno = 0;
461 *nread = 0;
448 return (NULL);
449 }
450 }
451 }
452#endif /* FIONREAD */
453
454 if ((el->el_flags & UNBUFFERED) == 0)
455 read_prepare(el);
456
457 if (el->el_flags & EDIT_DISABLED) {
458 char *cp;
459 size_t idx;
462 return (NULL);
463 }
464 }
465 }
466#endif /* FIONREAD */
467
468 if ((el->el_flags & UNBUFFERED) == 0)
469 read_prepare(el);
470
471 if (el->el_flags & EDIT_DISABLED) {
472 char *cp;
473 size_t idx;
474
460 if ((el->el_flags & UNBUFFERED) == 0)
461 cp = el->el_line.buffer;
462 else
463 cp = el->el_line.lastchar;
464
465 term__flush(el);
466
467 while ((*el->el_read.read_char)(el, cp) == 1) {

--- 7 unchanged lines hidden (view full) ---

475 cp++;
476 crlf = cp[-1] == '\r' || cp[-1] == '\n';
477 if (el->el_flags & UNBUFFERED)
478 break;
479 if (crlf)
480 break;
481 }
482
475 if ((el->el_flags & UNBUFFERED) == 0)
476 cp = el->el_line.buffer;
477 else
478 cp = el->el_line.lastchar;
479
480 term__flush(el);
481
482 while ((*el->el_read.read_char)(el, cp) == 1) {

--- 7 unchanged lines hidden (view full) ---

490 cp++;
491 crlf = cp[-1] == '\r' || cp[-1] == '\n';
492 if (el->el_flags & UNBUFFERED)
493 break;
494 if (crlf)
495 break;
496 }
497
498 if (num == -1) {
499 el->el_errno = errno;
500 }
501
483 el->el_line.cursor = el->el_line.lastchar = cp;
484 *cp = '\0';
502 el->el_line.cursor = el->el_line.lastchar = cp;
503 *cp = '\0';
485 if (nread)
486 *nread = (int)(el->el_line.cursor - el->el_line.buffer);
487 return (*nread ? el->el_line.buffer : NULL);
504 goto done;
488 }
489
490 for (num = OKCMD; num == OKCMD;) { /* while still editing this
491 * line */
492#ifdef DEBUG_EDIT
493 read_debug(el);
494#endif /* DEBUG_EDIT */
495 /* if EOF or error */

--- 116 unchanged lines hidden (view full) ---

612 if (el->el_flags & UNBUFFERED)
613 break;
614 }
615
616 term__flush(el); /* flush any buffered output */
617 /* make sure the tty is set up correctly */
618 if ((el->el_flags & UNBUFFERED) == 0) {
619 read_finish(el);
505 }
506
507 for (num = OKCMD; num == OKCMD;) { /* while still editing this
508 * line */
509#ifdef DEBUG_EDIT
510 read_debug(el);
511#endif /* DEBUG_EDIT */
512 /* if EOF or error */

--- 116 unchanged lines hidden (view full) ---

629 if (el->el_flags & UNBUFFERED)
630 break;
631 }
632
633 term__flush(el); /* flush any buffered output */
634 /* make sure the tty is set up correctly */
635 if ((el->el_flags & UNBUFFERED) == 0) {
636 read_finish(el);
620 if (nread)
621 *nread = num;
637 *nread = num != -1 ? num : 0;
622 } else {
638 } else {
623 if (nread)
624 *nread =
625 (int)(el->el_line.lastchar - el->el_line.buffer);
639 *nread = (int)(el->el_line.lastchar - el->el_line.buffer);
626 }
640 }
627 return (num ? el->el_line.buffer : NULL);
641done:
642 if (*nread == 0) {
643 if (num == -1) {
644 *nread = -1;
645 errno = el->el_errno;
646 }
647 return NULL;
648 } else
649 return el->el_line.buffer;
628}
650}