Lines 49-61
__FBSDID("$FreeBSD$");
Link Here
|
49 |
#include <stdlib.h> |
49 |
#include <stdlib.h> |
50 |
#include "el.h" |
50 |
#include "el.h" |
51 |
|
51 |
|
52 |
#define OKCMD -1 |
52 |
enum rcmd { |
53 |
|
53 |
OKCMD = -1, |
54 |
private int read__fixio(int, int); |
54 |
EOFCMD = 0, |
55 |
private int read_preread(EditLine *); |
55 |
ERRCMD = 1 |
56 |
private int read_char(EditLine *, char *); |
56 |
}; |
57 |
private int read_getcmd(EditLine *, el_action_t *, char *); |
57 |
|
58 |
private void read_pop(c_macro_t *); |
58 |
private int read__fixio(int, int); |
|
|
59 |
private int read_preread(EditLine *); |
60 |
private int read_char(EditLine *, char *); |
61 |
private enum rcmd read_getcmd(EditLine *, el_action_t *, char *); |
62 |
private void read_pop(c_macro_t *); |
59 |
|
63 |
|
60 |
/* read_init(): |
64 |
/* read_init(): |
61 |
* Initialize the read stuff |
65 |
* Initialize the read stuff |
Lines 227-235
el_push(EditLine *el, const char *str)
Link Here
|
227 |
|
231 |
|
228 |
|
232 |
|
229 |
/* read_getcmd(): |
233 |
/* read_getcmd(): |
230 |
* Return next command from the input stream. |
234 |
* Get next command from the input stream. |
231 |
*/ |
235 |
*/ |
232 |
private int |
236 |
private enum rcmd |
233 |
read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch) |
237 |
read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch) |
234 |
{ |
238 |
{ |
235 |
el_action_t cmd; |
239 |
el_action_t cmd; |
Lines 238-245
read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch)
Link Here
|
238 |
el->el_errno = 0; |
242 |
el->el_errno = 0; |
239 |
do { |
243 |
do { |
240 |
if ((num = el_getc(el, ch)) != 1) { /* if EOF or error */ |
244 |
if ((num = el_getc(el, ch)) != 1) { /* if EOF or error */ |
241 |
el->el_errno = num == 0 ? 0 : errno; |
245 |
return (num < 0 ? ERRCMD : EOFCMD); |
242 |
return (num); |
|
|
243 |
} |
246 |
} |
244 |
|
247 |
|
245 |
#ifdef KANJI |
248 |
#ifdef KANJI |
Lines 294-309
read_char(EditLine *el, char *cp)
Link Here
|
294 |
|
297 |
|
295 |
again: |
298 |
again: |
296 |
el->el_signal->sig_no = 0; |
299 |
el->el_signal->sig_no = 0; |
297 |
while ((num_read = read(el->el_infd, cp, 1)) == -1) { |
300 |
while ((num_read = read(el->el_infd, cp, 1)) < 0) { |
|
|
301 |
int e = errno; |
298 |
if (el->el_signal->sig_no == SIGCONT) { |
302 |
if (el->el_signal->sig_no == SIGCONT) { |
299 |
sig_set(el); |
303 |
sig_set(el); |
300 |
el_set(el, EL_REFRESH); |
304 |
el_set(el, EL_REFRESH); |
301 |
goto again; |
305 |
goto again; |
302 |
} |
306 |
} |
303 |
if (!tried && read__fixio(el->el_infd, errno) == 0) |
307 |
if (!tried && read__fixio(el->el_infd, e) == 0) |
304 |
tried = 1; |
308 |
tried = 1; |
305 |
else { |
309 |
else { |
306 |
*cp = '\0'; |
310 |
*cp = '\0'; |
|
|
311 |
errno = e; |
307 |
return (-1); |
312 |
return (-1); |
308 |
} |
313 |
} |
309 |
} |
314 |
} |
Lines 369-376
el_getc(EditLine *el, char *cp)
Link Here
|
369 |
(void) fprintf(el->el_errfile, "Reading a character\n"); |
374 |
(void) fprintf(el->el_errfile, "Reading a character\n"); |
370 |
#endif /* DEBUG_READ */ |
375 |
#endif /* DEBUG_READ */ |
371 |
num_read = (*el->el_read.read_char)(el, cp); |
376 |
num_read = (*el->el_read.read_char)(el, cp); |
|
|
377 |
el->el_errno = (num_read < 0) ? errno : 0; |
372 |
#ifdef DEBUG_READ |
378 |
#ifdef DEBUG_READ |
373 |
(void) fprintf(el->el_errfile, "Got it %c\n", *cp); |
379 |
(void) fprintf(el->el_errfile, "Got <%c> (return %d)\n", *cp, num_read); |
374 |
#endif /* DEBUG_READ */ |
380 |
#endif /* DEBUG_READ */ |
375 |
return (num_read); |
381 |
return (num_read); |
376 |
} |
382 |
} |
Lines 426-432
el_gets(EditLine *el, int *nread)
Link Here
|
426 |
char *cp = el->el_line.buffer; |
432 |
char *cp = el->el_line.buffer; |
427 |
size_t idx; |
433 |
size_t idx; |
428 |
|
434 |
|
429 |
while ((*el->el_read.read_char)(el, cp) == 1) { |
435 |
while ((num = (*el->el_read.read_char)(el, cp)) == 1) { |
430 |
/* make sure there is space for next character */ |
436 |
/* make sure there is space for next character */ |
431 |
if (cp + 1 >= el->el_line.limit) { |
437 |
if (cp + 1 >= el->el_line.limit) { |
432 |
idx = (cp - el->el_line.buffer); |
438 |
idx = (cp - el->el_line.buffer); |
Lines 479-485
el_gets(EditLine *el, int *nread)
Link Here
|
479 |
|
485 |
|
480 |
term__flush(el); |
486 |
term__flush(el); |
481 |
|
487 |
|
482 |
while ((*el->el_read.read_char)(el, cp) == 1) { |
488 |
while ((num = (*el->el_read.read_char)(el, cp)) == 1) { |
483 |
/* make sure there is space next character */ |
489 |
/* make sure there is space next character */ |
484 |
if (cp + 1 >= el->el_line.limit) { |
490 |
if (cp + 1 >= el->el_line.limit) { |
485 |
idx = (cp - el->el_line.buffer); |
491 |
idx = (cp - el->el_line.buffer); |
Lines 504-516
el_gets(EditLine *el, int *nread)
Link Here
|
504 |
goto done; |
510 |
goto done; |
505 |
} |
511 |
} |
506 |
|
512 |
|
507 |
for (num = OKCMD; num == OKCMD;) { /* while still editing this |
513 |
/* While still editing this line */ |
508 |
* line */ |
514 |
for (num = 0;; num = 0) { |
|
|
515 |
enum rcmd rcmd; |
509 |
#ifdef DEBUG_EDIT |
516 |
#ifdef DEBUG_EDIT |
510 |
read_debug(el); |
517 |
read_debug(el); |
511 |
#endif /* DEBUG_EDIT */ |
518 |
#endif /* DEBUG_EDIT */ |
512 |
/* if EOF or error */ |
519 |
if ((rcmd = read_getcmd(el, &cmdnum, &ch)) != OKCMD) { |
513 |
if ((num = read_getcmd(el, &cmdnum, &ch)) != OKCMD) { |
520 |
num = (rcmd == ERRCMD) ? -1 : 0; |
514 |
#ifdef DEBUG_READ |
521 |
#ifdef DEBUG_READ |
515 |
(void) fprintf(el->el_errfile, |
522 |
(void) fprintf(el->el_errfile, |
516 |
"Returning from el_gets %d\n", num); |
523 |
"Returning from el_gets %d\n", num); |
Lines 589-597
el_gets(EditLine *el, int *nread)
Link Here
|
589 |
continue; /* keep going... */ |
596 |
continue; /* keep going... */ |
590 |
|
597 |
|
591 |
case CC_EOF: /* end of file typed */ |
598 |
case CC_EOF: /* end of file typed */ |
|
|
599 |
rcmd = EOFCMD; |
592 |
if ((el->el_flags & UNBUFFERED) == 0) |
600 |
if ((el->el_flags & UNBUFFERED) == 0) |
593 |
num = 0; |
601 |
num = 0; |
594 |
else if (num == -1) { |
602 |
else { |
595 |
*el->el_line.lastchar++ = CONTROL('d'); |
603 |
*el->el_line.lastchar++ = CONTROL('d'); |
596 |
el->el_line.cursor = el->el_line.lastchar; |
604 |
el->el_line.cursor = el->el_line.lastchar; |
597 |
num = 1; |
605 |
num = 1; |
Lines 599-604
el_gets(EditLine *el, int *nread)
Link Here
|
599 |
break; |
607 |
break; |
600 |
|
608 |
|
601 |
case CC_NEWLINE: /* normal end of line */ |
609 |
case CC_NEWLINE: /* normal end of line */ |
|
|
610 |
rcmd = EOFCMD; |
602 |
num = (int)(el->el_line.lastchar - el->el_line.buffer); |
611 |
num = (int)(el->el_line.lastchar - el->el_line.buffer); |
603 |
break; |
612 |
break; |
604 |
|
613 |
|
Lines 628-633
el_gets(EditLine *el, int *nread)
Link Here
|
628 |
el->el_chared.c_vcmd.action = NOP; |
637 |
el->el_chared.c_vcmd.action = NOP; |
629 |
if (el->el_flags & UNBUFFERED) |
638 |
if (el->el_flags & UNBUFFERED) |
630 |
break; |
639 |
break; |
|
|
640 |
if (rcmd != OKCMD) |
641 |
break; |
631 |
} |
642 |
} |
632 |
|
643 |
|
633 |
term__flush(el); /* flush any buffered output */ |
644 |
term__flush(el); /* flush any buffered output */ |
634 |
- |
|
|