~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to cmd-line-utils/libedit/read.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*      $NetBSD: read.c,v 1.43 2009/02/05 19:15:44 christos Exp $       */
 
2
 
 
3
/*-
 
4
 * Copyright (c) 1992, 1993
 
5
 *      The Regents of the University of California.  All rights reserved.
 
6
 *
 
7
 * This code is derived from software contributed to Berkeley by
 
8
 * Christos Zoulas of Cornell University.
 
9
 *
 
10
 * Redistribution and use in source and binary forms, with or without
 
11
 * modification, are permitted provided that the following conditions
 
12
 * are met:
 
13
 * 1. Redistributions of source code must retain the above copyright
 
14
 *    notice, this list of conditions and the following disclaimer.
 
15
 * 2. Redistributions in binary form must reproduce the above copyright
 
16
 *    notice, this list of conditions and the following disclaimer in the
 
17
 *    documentation and/or other materials provided with the distribution.
 
18
 * 3. Neither the name of the University nor the names of its contributors
 
19
 *    may be used to endorse or promote products derived from this software
 
20
 *    without specific prior written permission.
 
21
 *
 
22
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 
23
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 
24
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 
25
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 
26
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
27
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
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
 
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
 
32
 * SUCH DAMAGE.
 
33
 */
 
34
 
 
35
#include "config.h"
 
36
#if !defined(lint) && !defined(SCCSID)
 
37
#if 0
 
38
static char sccsid[] = "@(#)read.c      8.1 (Berkeley) 6/4/93";
 
39
#else
 
40
#endif
 
41
#endif /* not lint && not SCCSID */
 
42
 
 
43
/*
 
44
 * read.c: Clean this junk up! This is horrible code.
 
45
 *         Terminal read functions
 
46
 */
 
47
#include <errno.h>
 
48
#include <fcntl.h>
 
49
#include <unistd.h>
 
50
#include <stdlib.h>
 
51
#include "el.h"
 
52
 
 
53
#define OKCMD   -1
 
54
 
 
55
private int     read__fixio(int, int);
 
56
private int     read_preread(EditLine *);
 
57
private int     read_char(EditLine *, char *);
 
58
private int     read_getcmd(EditLine *, el_action_t *, char *);
 
59
private void    read_pop(c_macro_t *);
 
60
 
 
61
/* read_init():
 
62
 *      Initialize the read stuff
 
63
 */
 
64
protected int
 
65
read_init(EditLine *el)
 
66
{
 
67
        /* builtin read_char */
 
68
        el->el_read.read_char = read_char;
 
69
        return 0;
 
70
}
 
71
 
 
72
 
 
73
/* el_read_setfn():
 
74
 *      Set the read char function to the one provided.
 
75
 *      If it is set to EL_BUILTIN_GETCFN, then reset to the builtin one.
 
76
 */
 
77
protected int
 
78
el_read_setfn(EditLine *el, el_rfunc_t rc)
 
79
{
 
80
        el->el_read.read_char = (rc == EL_BUILTIN_GETCFN) ? read_char : rc;
 
81
        return 0;
 
82
}
 
83
 
 
84
 
 
85
/* el_read_getfn():
 
86
 *      return the current read char function, or EL_BUILTIN_GETCFN
 
87
 *      if it is the default one
 
88
 */
 
89
protected el_rfunc_t
 
90
el_read_getfn(EditLine *el)
 
91
{
 
92
       return (el->el_read.read_char == read_char) ?
 
93
            EL_BUILTIN_GETCFN : el->el_read.read_char;
 
94
}
 
95
 
 
96
 
 
97
#ifndef MIN
 
98
#define MIN(A,B) ((A) < (B) ? (A) : (B))
 
99
#endif
 
100
 
 
101
#ifdef DEBUG_EDIT
 
102
private void
 
103
read_debug(EditLine *el)
 
104
{
 
105
 
 
106
        if (el->el_line.cursor > el->el_line.lastchar)
 
107
                (void) fprintf(el->el_errfile, "cursor > lastchar\r\n");
 
108
        if (el->el_line.cursor < el->el_line.buffer)
 
109
                (void) fprintf(el->el_errfile, "cursor < buffer\r\n");
 
110
        if (el->el_line.cursor > el->el_line.limit)
 
111
                (void) fprintf(el->el_errfile, "cursor > limit\r\n");
 
112
        if (el->el_line.lastchar > el->el_line.limit)
 
113
                (void) fprintf(el->el_errfile, "lastchar > limit\r\n");
 
114
        if (el->el_line.limit != &el->el_line.buffer[EL_BUFSIZ - 2])
 
115
                (void) fprintf(el->el_errfile, "limit != &buffer[EL_BUFSIZ-2]\r\n");
 
116
}
 
117
#endif /* DEBUG_EDIT */
 
118
 
 
119
 
 
120
/* read__fixio():
 
121
 *      Try to recover from a read error
 
122
 */
 
123
/* ARGSUSED */
 
124
private int
 
125
read__fixio(int fd __attribute__((__unused__)), int e)
 
126
{
 
127
 
 
128
        switch (e) {
 
129
        case -1:                /* Make sure that the code is reachable */
 
130
 
 
131
#ifdef EWOULDBLOCK
 
132
        case EWOULDBLOCK:
 
133
#ifndef TRY_AGAIN
 
134
#define TRY_AGAIN
 
135
#endif
 
136
#endif /* EWOULDBLOCK */
 
137
 
 
138
#if defined(POSIX) && defined(EAGAIN)
 
139
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
 
140
        case EAGAIN:
 
141
#ifndef TRY_AGAIN
 
142
#define TRY_AGAIN
 
143
#endif
 
144
#endif /* EWOULDBLOCK && EWOULDBLOCK != EAGAIN */
 
145
#endif /* POSIX && EAGAIN */
 
146
 
 
147
                e = 0;
 
148
#ifdef TRY_AGAIN
 
149
#if defined(F_SETFL) && defined(O_NDELAY)
 
150
                if ((e = fcntl(fd, F_GETFL, 0)) == -1)
 
151
                        return (-1);
 
152
 
 
153
                if (fcntl(fd, F_SETFL, e & ~O_NDELAY) == -1)
 
154
                        return (-1);
 
155
                else
 
156
                        e = 1;
 
157
#endif /* F_SETFL && O_NDELAY */
 
158
 
 
159
#ifdef FIONBIO
 
160
                {
 
161
                        int zero = 0;
 
162
 
 
163
                        if (ioctl(fd, FIONBIO, (ioctl_t) & zero) == -1)
 
164
                                return (-1);
 
165
                        else
 
166
                                e = 1;
 
167
                }
 
168
#endif /* FIONBIO */
 
169
 
 
170
#endif /* TRY_AGAIN */
 
171
                return (e ? 0 : -1);
 
172
 
 
173
        case EINTR:
 
174
                return (0);
 
175
 
 
176
        default:
 
177
                return (-1);
 
178
        }
 
179
}
 
180
 
 
181
 
 
182
/* read_preread():
 
183
 *      Try to read the stuff in the input queue;
 
184
 */
 
185
private int
 
186
read_preread(EditLine *el)
 
187
{
 
188
        int chrs = 0;
 
189
 
 
190
        if (el->el_tty.t_mode == ED_IO)
 
191
                return (0);
 
192
 
 
193
#ifdef FIONREAD
 
194
        (void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
 
195
        if (chrs > 0) {
 
196
                char buf[EL_BUFSIZ];
 
197
 
 
198
                chrs = read(el->el_infd, buf,
 
199
                    (size_t) MIN(chrs, EL_BUFSIZ - 1));
 
200
                if (chrs > 0) {
 
201
                        buf[chrs] = '\0';
 
202
                        el_push(el, buf);
 
203
                }
 
204
        }
 
205
#endif /* FIONREAD */
 
206
 
 
207
        return (chrs > 0);
 
208
}
 
209
 
 
210
 
 
211
/* el_push():
 
212
 *      Push a macro
 
213
 */
 
214
public void
 
215
el_push(EditLine *el, const char *str)
 
216
{
 
217
        c_macro_t *ma = &el->el_chared.c_macro;
 
218
 
 
219
        if (str != NULL && ma->level + 1 < EL_MAXMACRO) {
 
220
                ma->level++;
 
221
                if ((ma->macro[ma->level] = el_strdup(str)) != NULL)
 
222
                        return;
 
223
                ma->level--;
 
224
        }
 
225
        term_beep(el);
 
226
        term__flush(el);
 
227
}
 
228
 
 
229
 
 
230
/* read_getcmd():
 
231
 *      Return next command from the input stream.
 
232
 */
 
233
private int
 
234
read_getcmd(EditLine *el, el_action_t *cmdnum, char *ch)
 
235
{
 
236
        el_action_t cmd;
 
237
        int num;
 
238
 
 
239
        do {
 
240
                if ((num = el_getc(el, ch)) != 1)       /* if EOF or error */
 
241
                        return (num);
 
242
 
 
243
#ifdef  KANJI
 
244
                if ((*ch & 0200)) {
 
245
                        el->el_state.metanext = 0;
 
246
                        cmd = CcViMap[' '];
 
247
                        break;
 
248
                } else
 
249
#endif /* KANJI */
 
250
 
 
251
                if (el->el_state.metanext) {
 
252
                        el->el_state.metanext = 0;
 
253
                        *ch |= 0200;
 
254
                }
 
255
                cmd = el->el_map.current[(unsigned char) *ch];
 
256
                if (cmd == ED_SEQUENCE_LEAD_IN) {
 
257
                        key_value_t val;
 
258
                        switch (key_get(el, ch, &val)) {
 
259
                        case XK_CMD:
 
260
                                cmd = val.cmd;
 
261
                                break;
 
262
                        case XK_STR:
 
263
                                el_push(el, val.str);
 
264
                                break;
 
265
#ifdef notyet
 
266
                        case XK_EXE:
 
267
                                /* XXX: In the future to run a user function */
 
268
                                RunCommand(val.str);
 
269
                                break;
 
270
#endif
 
271
                        default:
 
272
                                EL_ABORT((el->el_errfile, "Bad XK_ type \n"));
 
273
                                break;
 
274
                        }
 
275
                }
 
276
                if (el->el_map.alt == NULL)
 
277
                        el->el_map.current = el->el_map.key;
 
278
        } while (cmd == ED_SEQUENCE_LEAD_IN);
 
279
        *cmdnum = cmd;
 
280
        return (OKCMD);
 
281
}
 
282
 
 
283
 
 
284
/* read_char():
 
285
 *      Read a character from the tty.
 
286
 */
 
287
private int
 
288
read_char(EditLine *el, char *cp)
 
289
{
 
290
        int num_read;
 
291
        int tried = 0;
 
292
 
 
293
        while ((num_read = read(el->el_infd, cp, 1)) == -1)
 
294
                if (!tried && read__fixio(el->el_infd, errno) == 0)
 
295
                        tried = 1;
 
296
                else {
 
297
                        *cp = '\0';
 
298
                        return (-1);
 
299
                }
 
300
 
 
301
        return (num_read);
 
302
}
 
303
 
 
304
/* read_pop():
 
305
 *      Pop a macro from the stack
 
306
 */
 
307
private void
 
308
read_pop(c_macro_t *ma)
 
309
{
 
310
        int i;
 
311
 
 
312
        el_free(ma->macro[0]);
 
313
        for (i = ma->level--; i > 0; i--)
 
314
                ma->macro[i - 1] = ma->macro[i];
 
315
        ma->offset = 0;
 
316
}
 
317
 
 
318
/* el_getc():
 
319
 *      Read a character
 
320
 */
 
321
public int
 
322
el_getc(EditLine *el, char *cp)
 
323
{
 
324
        int num_read;
 
325
        c_macro_t *ma = &el->el_chared.c_macro;
 
326
 
 
327
        term__flush(el);
 
328
        for (;;) {
 
329
                if (ma->level < 0) {
 
330
                        if (!read_preread(el))
 
331
                                break;
 
332
                }
 
333
 
 
334
                if (ma->level < 0)
 
335
                        break;
 
336
 
 
337
                if (ma->macro[0][ma->offset] == '\0') {
 
338
                        read_pop(ma);
 
339
                        continue;
 
340
                }
 
341
 
 
342
                *cp = ma->macro[0][ma->offset++] & 0377;
 
343
 
 
344
                if (ma->macro[0][ma->offset] == '\0') {
 
345
                        /* Needed for QuoteMode On */
 
346
                        read_pop(ma);
 
347
                }
 
348
 
 
349
                return (1);
 
350
        }
 
351
 
 
352
#ifdef DEBUG_READ
 
353
        (void) fprintf(el->el_errfile, "Turning raw mode on\n");
 
354
#endif /* DEBUG_READ */
 
355
        if (tty_rawmode(el) < 0)/* make sure the tty is set up correctly */
 
356
                return (0);
 
357
 
 
358
#ifdef DEBUG_READ
 
359
        (void) fprintf(el->el_errfile, "Reading a character\n");
 
360
#endif /* DEBUG_READ */
 
361
        num_read = (*el->el_read.read_char)(el, cp);
 
362
#ifdef DEBUG_READ
 
363
        (void) fprintf(el->el_errfile, "Got it %c\n", *cp);
 
364
#endif /* DEBUG_READ */
 
365
        return (num_read);
 
366
}
 
367
 
 
368
protected void
 
369
read_prepare(EditLine *el)
 
370
{
 
371
        if (el->el_flags & HANDLE_SIGNALS)
 
372
                sig_set(el);
 
373
        if (el->el_flags & NO_TTY)
 
374
                return;
 
375
        if ((el->el_flags & (UNBUFFERED|EDIT_DISABLED)) == UNBUFFERED)
 
376
                tty_rawmode(el);
 
377
 
 
378
        /* This is relatively cheap, and things go terribly wrong if
 
379
           we have the wrong size. */
 
380
        el_resize(el);
 
381
        re_clear_display(el);   /* reset the display stuff */
 
382
        ch_reset(el, 0);
 
383
        re_refresh(el);         /* print the prompt */
 
384
 
 
385
        if (el->el_flags & UNBUFFERED)
 
386
                term__flush(el);
 
387
}
 
388
 
 
389
protected void
 
390
read_finish(EditLine *el)
 
391
{
 
392
        if ((el->el_flags & UNBUFFERED) == 0)
 
393
                (void) tty_cookedmode(el);
 
394
        if (el->el_flags & HANDLE_SIGNALS)
 
395
                sig_clr(el);
 
396
}
 
397
 
 
398
public const char *
 
399
el_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;
 
406
#ifdef FIONREAD
 
407
        c_macro_t *ma = &el->el_chared.c_macro;
 
408
#endif /* FIONREAD */
 
409
 
 
410
        if (el->el_flags & NO_TTY) {
 
411
                char *cp = el->el_line.buffer;
 
412
                size_t idx;
 
413
 
 
414
                while ((*el->el_read.read_char)(el, cp) == 1) {
 
415
                        /* make sure there is space for next character */
 
416
                        if (cp + 1 >= el->el_line.limit) {
 
417
                                idx = (cp - el->el_line.buffer);
 
418
                                if (!ch_enlargebufs(el, 2))
 
419
                                        break;
 
420
                                cp = &el->el_line.buffer[idx];
 
421
                        }
 
422
                        cp++;
 
423
                        if (el->el_flags & UNBUFFERED)
 
424
                                break;
 
425
                        if (cp[-1] == '\r' || cp[-1] == '\n')
 
426
                                break;
 
427
                }
 
428
 
 
429
                el->el_line.cursor = el->el_line.lastchar = cp;
 
430
                *cp = '\0';
 
431
                if (nread)
 
432
                        *nread = el->el_line.cursor - el->el_line.buffer;
 
433
                return (el->el_line.buffer);
 
434
        }
 
435
 
 
436
 
 
437
#ifdef FIONREAD
 
438
        if (el->el_tty.t_mode == EX_IO && ma->level < 0) {
 
439
                long chrs = 0;
 
440
 
 
441
                (void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
 
442
                if (chrs == 0) {
 
443
                        if (tty_rawmode(el) < 0) {
 
444
                                if (nread)
 
445
                                        *nread = 0;
 
446
                                return (NULL);
 
447
                        }
 
448
                }
 
449
        }
 
450
#endif /* FIONREAD */
 
451
 
 
452
        if ((el->el_flags & UNBUFFERED) == 0)
 
453
                read_prepare(el);
 
454
 
 
455
        if (el->el_flags & EDIT_DISABLED) {
 
456
                char *cp;
 
457
                size_t idx;
 
458
                if ((el->el_flags & UNBUFFERED) == 0)
 
459
                        cp = el->el_line.buffer;
 
460
                else
 
461
                        cp = el->el_line.lastchar;
 
462
 
 
463
                term__flush(el);
 
464
 
 
465
                while ((*el->el_read.read_char)(el, cp) == 1) {
 
466
                        /* make sure there is space next character */
 
467
                        if (cp + 1 >= el->el_line.limit) {
 
468
                                idx = (cp - el->el_line.buffer);
 
469
                                if (!ch_enlargebufs(el, 2))
 
470
                                        break;
 
471
                                cp = &el->el_line.buffer[idx];
 
472
                        }
 
473
                        if (*cp == 4)   /* ought to be stty eof */
 
474
                                break;
 
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
 
 
483
                el->el_line.cursor = el->el_line.lastchar = cp;
 
484
                *cp = '\0';
 
485
                if (nread)
 
486
                        *nread = el->el_line.cursor - el->el_line.buffer;
 
487
                return (el->el_line.buffer);
 
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 */
 
496
                if ((num = read_getcmd(el, &cmdnum, &ch)) != OKCMD) {
 
497
#ifdef DEBUG_READ
 
498
                        (void) fprintf(el->el_errfile,
 
499
                            "Returning from el_gets %d\n", num);
 
500
#endif /* DEBUG_READ */
 
501
                        break;
 
502
                }
 
503
                if ((unsigned int)cmdnum >= (unsigned int)el->el_map.nfunc) {   /* BUG CHECK command */
 
504
#ifdef DEBUG_EDIT
 
505
                        (void) fprintf(el->el_errfile,
 
506
                            "ERROR: illegal command from key 0%o\r\n", ch);
 
507
#endif /* DEBUG_EDIT */
 
508
                        continue;       /* try again */
 
509
                }
 
510
                /* now do the real command */
 
511
#ifdef DEBUG_READ
 
512
                {
 
513
                        el_bindings_t *b;
 
514
                        for (b = el->el_map.help; b->name; b++)
 
515
                                if (b->func == cmdnum)
 
516
                                        break;
 
517
                        if (b->name)
 
518
                                (void) fprintf(el->el_errfile,
 
519
                                    "Executing %s\n", b->name);
 
520
                        else
 
521
                                (void) fprintf(el->el_errfile,
 
522
                                    "Error command = %d\n", cmdnum);
 
523
                }
 
524
#endif /* DEBUG_READ */
 
525
                /* vi redo needs these way down the levels... */
 
526
                el->el_state.thiscmd = cmdnum;
 
527
                el->el_state.thisch = ch;
 
528
                if (el->el_map.type == MAP_VI &&
 
529
                    el->el_map.current == el->el_map.key &&
 
530
                    el->el_chared.c_redo.pos < el->el_chared.c_redo.lim) {
 
531
                        if (cmdnum == VI_DELETE_PREV_CHAR &&
 
532
                            el->el_chared.c_redo.pos != el->el_chared.c_redo.buf
 
533
                            && el_isprint((unsigned char)el->el_chared.c_redo.pos[-1]))
 
534
                                el->el_chared.c_redo.pos--;
 
535
                        else
 
536
                                *el->el_chared.c_redo.pos++ = ch;
 
537
                }
 
538
                retval = (*el->el_map.func[cmdnum]) (el, ch);
 
539
#ifdef DEBUG_READ
 
540
                (void) fprintf(el->el_errfile,
 
541
                        "Returned state %d\n", retval );
 
542
#endif /* DEBUG_READ */
 
543
 
 
544
                /* save the last command here */
 
545
                el->el_state.lastcmd = cmdnum;
 
546
 
 
547
                /* use any return value */
 
548
                switch (retval) {
 
549
                case CC_CURSOR:
 
550
                        re_refresh_cursor(el);
 
551
                        break;
 
552
 
 
553
                case CC_REDISPLAY:
 
554
                        re_clear_lines(el);
 
555
                        re_clear_display(el);
 
556
                        /* FALLTHROUGH */
 
557
 
 
558
                case CC_REFRESH:
 
559
                        re_refresh(el);
 
560
                        break;
 
561
 
 
562
                case CC_REFRESH_BEEP:
 
563
                        re_refresh(el);
 
564
                        term_beep(el);
 
565
                        break;
 
566
 
 
567
                case CC_NORM:   /* normal char */
 
568
                        break;
 
569
 
 
570
                case CC_ARGHACK:        /* Suggested by Rich Salz */
 
571
                        /* <rsalz@pineapple.bbn.com> */
 
572
                        continue;       /* keep going... */
 
573
 
 
574
                case CC_EOF:    /* end of file typed */
 
575
                        if ((el->el_flags & UNBUFFERED) == 0)
 
576
                                num = 0;
 
577
                        else if (num == -1) {
 
578
                                *el->el_line.lastchar++ = CONTROL('d');
 
579
                                el->el_line.cursor = el->el_line.lastchar;
 
580
                                num = 1;
 
581
                        }
 
582
                        break;
 
583
 
 
584
                case CC_NEWLINE:        /* normal end of line */
 
585
                        num = el->el_line.lastchar - el->el_line.buffer;
 
586
                        break;
 
587
 
 
588
                case CC_FATAL:  /* fatal error, reset to known state */
 
589
#ifdef DEBUG_READ
 
590
                        (void) fprintf(el->el_errfile,
 
591
                            "*** editor fatal ERROR ***\r\n\n");
 
592
#endif /* DEBUG_READ */
 
593
                        /* put (real) cursor in a known place */
 
594
                        re_clear_display(el);   /* reset the display stuff */
 
595
                        ch_reset(el, 1);        /* reset the input pointers */
 
596
                        re_refresh(el); /* print the prompt again */
 
597
                        break;
 
598
 
 
599
                case CC_ERROR:
 
600
                default:        /* functions we don't know about */
 
601
#ifdef DEBUG_READ
 
602
                        (void) fprintf(el->el_errfile,
 
603
                            "*** editor ERROR ***\r\n\n");
 
604
#endif /* DEBUG_READ */
 
605
                        term_beep(el);
 
606
                        term__flush(el);
 
607
                        break;
 
608
                }
 
609
                el->el_state.argument = 1;
 
610
                el->el_state.doingarg = 0;
 
611
                el->el_chared.c_vcmd.action = NOP;
 
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);
 
620
                if (nread)
 
621
                        *nread = num;
 
622
        } else {
 
623
                if (nread)
 
624
                        *nread = el->el_line.lastchar - el->el_line.buffer;
 
625
        }
 
626
        return (num ? el->el_line.buffer : NULL);
 
627
}