~vlad-lesin/percona-server/mysql-5.0.33-original

« back to all changes in this revision

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

  • Committer: Vlad Lesin
  • Date: 2012-07-31 09:21:34 UTC
  • Revision ID: vladislav.lesin@percona.com-20120731092134-zfodx022b7992wsi
VirginĀ 5.0.33

Show diffs side-by-side

added added

removed removed

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