~ubuntu-branches/ubuntu/natty/mysql-5.1/natty-proposed

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 08:30:45 UTC
  • mfrom: (1.4.1)
  • Revision ID: package-import@ubuntu.com-20120222083045-2rd53r4bnyx7qus4
Tags: 5.1.61-0ubuntu0.11.04.1
* SECURITY UPDATE: Update to 5.1.61 to fix multiple security issues
  (LP: #937869)
  - http://www.oracle.com/technetwork/topics/security/cpujan2012-366304.html
  - CVE-2011-2262
  - CVE-2012-0075
  - CVE-2012-0112
  - CVE-2012-0113
  - CVE-2012-0114
  - CVE-2012-0115
  - CVE-2012-0116
  - CVE-2012-0117
  - CVE-2012-0118
  - CVE-2012-0119
  - CVE-2012-0120
  - CVE-2012-0484
  - CVE-2012-0485
  - CVE-2012-0486
  - CVE-2012-0487
  - CVE-2012-0488
  - CVE-2012-0489
  - CVE-2012-0490
  - CVE-2012-0491
  - CVE-2012-0492
  - CVE-2012-0493
  - CVE-2012-0494
  - CVE-2012-0495
  - CVE-2012-0496

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*      $NetBSD: chared.c,v 1.26 2009/02/06 12:45:25 sketch Exp $       */
 
1
/*      $NetBSD: chared.c,v 1.36 2011/10/23 17:37:55 christos Exp $     */
2
2
 
3
3
/*-
4
4
 * Copyright (c) 1992, 1993
59
59
{
60
60
        c_undo_t *vu = &el->el_chared.c_undo;
61
61
        c_redo_t *r = &el->el_chared.c_redo;
62
 
        unsigned int size;
 
62
        size_t size;
63
63
 
64
64
        /* Save entire line for undo */
65
 
        size = el->el_line.lastchar - el->el_line.buffer;
66
 
        vu->len = size;
67
 
        vu->cursor = el->el_line.cursor - el->el_line.buffer;
68
 
        memcpy(vu->buf, el->el_line.buffer, size);
 
65
        size = (size_t)(el->el_line.lastchar - el->el_line.buffer);
 
66
        vu->len = (ssize_t)size;
 
67
        vu->cursor = (int)(el->el_line.cursor - el->el_line.buffer);
 
68
        (void)memcpy(vu->buf, el->el_line.buffer, size * sizeof(*vu->buf));
69
69
 
70
70
        /* save command info for redo */
71
71
        r->count = el->el_state.doingarg ? el->el_state.argument : 0;
79
79
 *      Save yank/delete data for paste
80
80
 */
81
81
protected void
82
 
cv_yank(EditLine *el, const char *ptr, int size)
 
82
cv_yank(EditLine *el, const Char *ptr, int size)
83
83
{
84
84
        c_kill_t *k = &el->el_chared.c_kill;
85
85
 
86
 
        memcpy(k->buf, ptr, size +0u);
 
86
        (void)memcpy(k->buf, ptr, (size_t)size * sizeof(*k->buf));
87
87
        k->last = k->buf + size;
88
88
}
89
89
 
94
94
protected void
95
95
c_insert(EditLine *el, int num)
96
96
{
97
 
        char *cp;
 
97
        Char *cp;
98
98
 
99
99
        if (el->el_line.lastchar + num >= el->el_line.limit) {
100
 
                if (!ch_enlargebufs(el, num +0u))
 
100
                if (!ch_enlargebufs(el, (size_t)num))
101
101
                        return;         /* can't go past end of buffer */
102
102
        }
103
103
 
118
118
{
119
119
 
120
120
        if (el->el_line.cursor + num > el->el_line.lastchar)
121
 
                num = el->el_line.lastchar - el->el_line.cursor;
 
121
                num = (int)(el->el_line.lastchar - el->el_line.cursor);
122
122
 
123
123
        if (el->el_map.current != el->el_map.emacs) {
124
124
                cv_undo(el);
126
126
        }
127
127
 
128
128
        if (num > 0) {
129
 
                char *cp;
 
129
                Char *cp;
130
130
 
131
131
                for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
132
132
                        *cp = cp[num];
142
142
protected void
143
143
c_delafter1(EditLine *el)
144
144
{
145
 
        char *cp;
 
145
        Char *cp;
146
146
 
147
147
        for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
148
148
                *cp = cp[1];
159
159
{
160
160
 
161
161
        if (el->el_line.cursor - num < el->el_line.buffer)
162
 
                num = el->el_line.cursor - el->el_line.buffer;
 
162
                num = (int)(el->el_line.cursor - el->el_line.buffer);
163
163
 
164
164
        if (el->el_map.current != el->el_map.emacs) {
165
165
                cv_undo(el);
167
167
        }
168
168
 
169
169
        if (num > 0) {
170
 
                char *cp;
 
170
                Char *cp;
171
171
 
172
172
                for (cp = el->el_line.cursor - num;
173
173
                    cp <= el->el_line.lastchar;
185
185
protected void
186
186
c_delbefore1(EditLine *el)
187
187
{
188
 
        char *cp;
 
188
        Char *cp;
189
189
 
190
190
        for (cp = el->el_line.cursor - 1; cp <= el->el_line.lastchar; cp++)
191
191
                *cp = cp[1];
198
198
 *      Return if p is part of a word according to emacs
199
199
 */
200
200
protected int
201
 
ce__isword(int p)
 
201
ce__isword(Int p)
202
202
{
203
 
        return (isalnum(p) || strchr("*?_-.[]~=", p) != NULL);
 
203
        return Isalnum(p) || Strchr(STR("*?_-.[]~="), p) != NULL;
204
204
}
205
205
 
206
206
 
208
208
 *      Return if p is part of a word according to vi
209
209
 */
210
210
protected int
211
 
cv__isword(int p)
 
211
cv__isword(Int p)
212
212
{
213
 
        if (isalnum(p) || p == '_')
 
213
        if (Isalnum(p) || p == '_')
214
214
                return 1;
215
 
        if (isgraph(p))
 
215
        if (Isgraph(p))
216
216
                return 2;
217
217
        return 0;
218
218
}
222
222
 *      Return if p is part of a big word according to vi
223
223
 */
224
224
protected int
225
 
cv__isWord(int p)
 
225
cv__isWord(Int p)
226
226
{
227
 
        return (!isspace(p));
 
227
        return !Isspace(p);
228
228
}
229
229
 
230
230
 
231
231
/* c__prev_word():
232
232
 *      Find the previous word
233
233
 */
234
 
protected char *
235
 
c__prev_word(char *p, char *low, int n, int (*wtest)(int))
 
234
protected Char *
 
235
c__prev_word(Char *p, Char *low, int n, int (*wtest)(Int))
236
236
{
237
237
        p--;
238
238
 
239
239
        while (n--) {
240
 
                while ((p >= low) && !(*wtest)((unsigned char) *p))
 
240
                while ((p >= low) && !(*wtest)(*p))
241
241
                        p--;
242
 
                while ((p >= low) && (*wtest)((unsigned char) *p))
 
242
                while ((p >= low) && (*wtest)(*p))
243
243
                        p--;
244
244
        }
245
245
 
248
248
        if (p < low)
249
249
                p = low;
250
250
        /* cp now points where we want it */
251
 
        return (p);
 
251
        return p;
252
252
}
253
253
 
254
254
 
255
255
/* c__next_word():
256
256
 *      Find the next word
257
257
 */
258
 
protected char *
259
 
c__next_word(char *p, char *high, int n, int (*wtest)(int))
 
258
protected Char *
 
259
c__next_word(Char *p, Char *high, int n, int (*wtest)(Int))
260
260
{
261
261
        while (n--) {
262
 
                while ((p < high) && !(*wtest)((unsigned char) *p))
 
262
                while ((p < high) && !(*wtest)(*p))
263
263
                        p++;
264
 
                while ((p < high) && (*wtest)((unsigned char) *p))
 
264
                while ((p < high) && (*wtest)(*p))
265
265
                        p++;
266
266
        }
267
267
        if (p > high)
268
268
                p = high;
269
269
        /* p now points where we want it */
270
 
        return (p);
 
270
        return p;
271
271
}
272
272
 
273
273
/* cv_next_word():
274
274
 *      Find the next word vi style
275
275
 */
276
 
protected char *
277
 
cv_next_word(EditLine *el, char *p, char *high, int n, int (*wtest)(int))
 
276
protected Char *
 
277
cv_next_word(EditLine *el, Char *p, Char *high, int n, int (*wtest)(Int))
278
278
{
279
279
        int test;
280
280
 
281
281
        while (n--) {
282
 
                test = (*wtest)((unsigned char) *p);
283
 
                while ((p < high) && (*wtest)((unsigned char) *p) == test)
 
282
                test = (*wtest)(*p);
 
283
                while ((p < high) && (*wtest)(*p) == test)
284
284
                        p++;
285
285
                /*
286
286
                 * vi historically deletes with cw only the word preserving the
287
287
                 * trailing whitespace! This is not what 'w' does..
288
288
                 */
289
289
                if (n || el->el_chared.c_vcmd.action != (DELETE|INSERT))
290
 
                        while ((p < high) && isspace((unsigned char) *p))
 
290
                        while ((p < high) && Isspace(*p))
291
291
                                p++;
292
292
        }
293
293
 
294
294
        /* p now points where we want it */
295
295
        if (p > high)
296
 
                return (high);
 
296
                return high;
297
297
        else
298
 
                return (p);
 
298
                return p;
299
299
}
300
300
 
301
301
 
302
302
/* cv_prev_word():
303
303
 *      Find the previous word vi style
304
304
 */
305
 
protected char *
306
 
cv_prev_word(char *p, char *low, int n, int (*wtest)(int))
 
305
protected Char *
 
306
cv_prev_word(Char *p, Char *low, int n, int (*wtest)(Int))
307
307
{
308
308
        int test;
309
309
 
310
310
        p--;
311
311
        while (n--) {
312
 
                while ((p > low) && isspace((unsigned char) *p))
 
312
                while ((p > low) && Isspace(*p))
313
313
                        p--;
314
 
                test = (*wtest)((unsigned char) *p);
315
 
                while ((p >= low) && (*wtest)((unsigned char) *p) == test)
 
314
                test = (*wtest)(*p);
 
315
                while ((p >= low) && (*wtest)(*p) == test)
316
316
                        p--;
317
317
        }
318
318
        p++;
319
319
 
320
320
        /* p now points where we want it */
321
321
        if (p < low)
322
 
                return (low);
 
322
                return low;
323
323
        else
324
 
                return (p);
325
 
}
326
 
 
327
 
 
328
 
#ifdef notdef
329
 
/* c__number():
330
 
 *      Ignore character p points to, return number appearing after that.
331
 
 *      A '$' by itself means a big number; "$-" is for negative; '^' means 1.
332
 
 *      Return p pointing to last char used.
333
 
 */
334
 
protected char *
335
 
c__number(
336
 
    char *p,    /* character position */
337
 
    int *num,   /* Return value */
338
 
    int dval)   /* dval is the number to subtract from like $-3 */
339
 
{
340
 
        int i;
341
 
        int sign = 1;
342
 
 
343
 
        if (*++p == '^') {
344
 
                *num = 1;
345
 
                return (p);
346
 
        }
347
 
        if (*p == '$') {
348
 
                if (*++p != '-') {
349
 
                        *num = 0x7fffffff;      /* Handle $ */
350
 
                        return (--p);
351
 
                }
352
 
                sign = -1;                      /* Handle $- */
353
 
                ++p;
354
 
        }
355
 
        for (i = 0; isdigit((unsigned char) *p); i = 10 * i + *p++ - '0')
356
 
                continue;
357
 
        *num = (sign < 0 ? dval - i : i);
358
 
        return (--p);
359
 
}
360
 
#endif
 
324
                return p;
 
325
}
 
326
 
361
327
 
362
328
/* cv_delfini():
363
329
 *      Finish vi delete action
375
341
                /* sanity */
376
342
                return;
377
343
 
378
 
        size = el->el_line.cursor - el->el_chared.c_vcmd.pos;
 
344
        size = (int)(el->el_line.cursor - el->el_chared.c_vcmd.pos);
379
345
        if (size == 0)
380
346
                size = 1;
381
347
        el->el_line.cursor = el->el_chared.c_vcmd.pos;
397
363
}
398
364
 
399
365
 
400
 
#ifdef notdef
401
 
/* ce__endword():
402
 
 *      Go to the end of this word according to emacs
403
 
 */
404
 
protected char *
405
 
ce__endword(char *p, char *high, int n)
406
 
{
407
 
        p++;
408
 
 
409
 
        while (n--) {
410
 
                while ((p < high) && isspace((unsigned char) *p))
411
 
                        p++;
412
 
                while ((p < high) && !isspace((unsigned char) *p))
413
 
                        p++;
414
 
        }
415
 
 
416
 
        p--;
417
 
        return (p);
418
 
}
419
 
#endif
420
 
 
421
 
 
422
366
/* cv__endword():
423
367
 *      Go to the end of this word according to vi
424
368
 */
425
 
protected char *
426
 
cv__endword(char *p, char *high, int n, int (*wtest)(int))
 
369
protected Char *
 
370
cv__endword(Char *p, Char *high, int n, int (*wtest)(Int))
427
371
{
428
372
        int test;
429
373
 
430
374
        p++;
431
375
 
432
376
        while (n--) {
433
 
                while ((p < high) && isspace((unsigned char) *p))
 
377
                while ((p < high) && Isspace(*p))
434
378
                        p++;
435
379
 
436
 
                test = (*wtest)((unsigned char) *p);
437
 
                while ((p < high) && (*wtest)((unsigned char) *p) == test)
 
380
                test = (*wtest)(*p);
 
381
                while ((p < high) && (*wtest)(*p) == test)
438
382
                        p++;
439
383
        }
440
384
        p--;
441
 
        return (p);
 
385
        return p;
442
386
}
443
387
 
444
388
/* ch_init():
449
393
{
450
394
        c_macro_t *ma = &el->el_chared.c_macro;
451
395
 
452
 
        el->el_line.buffer              = (char *) el_malloc(EL_BUFSIZ);
 
396
        el->el_line.buffer              = el_malloc(EL_BUFSIZ *
 
397
            sizeof(*el->el_line.buffer));
453
398
        if (el->el_line.buffer == NULL)
454
 
                return (-1);
 
399
                return -1;
455
400
 
456
 
        (void) memset(el->el_line.buffer, 0, EL_BUFSIZ);
 
401
        (void) memset(el->el_line.buffer, 0, EL_BUFSIZ *
 
402
            sizeof(*el->el_line.buffer));
457
403
        el->el_line.cursor              = el->el_line.buffer;
458
404
        el->el_line.lastchar            = el->el_line.buffer;
459
405
        el->el_line.limit               = &el->el_line.buffer[EL_BUFSIZ - EL_LEAVE];
460
406
 
461
 
        el->el_chared.c_undo.buf        = (char *) el_malloc(EL_BUFSIZ);
 
407
        el->el_chared.c_undo.buf        = el_malloc(EL_BUFSIZ *
 
408
            sizeof(*el->el_chared.c_undo.buf));
462
409
        if (el->el_chared.c_undo.buf == NULL)
463
 
                return (-1);
464
 
        (void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ);
 
410
                return -1;
 
411
        (void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ *
 
412
            sizeof(*el->el_chared.c_undo.buf));
465
413
        el->el_chared.c_undo.len        = -1;
466
414
        el->el_chared.c_undo.cursor     = 0;
467
 
        el->el_chared.c_redo.buf        = (char *) el_malloc(EL_BUFSIZ);
 
415
        el->el_chared.c_redo.buf        = el_malloc(EL_BUFSIZ *
 
416
            sizeof(*el->el_chared.c_redo.buf));
468
417
        if (el->el_chared.c_redo.buf == NULL)
469
 
                return (-1);
 
418
                return -1;
470
419
        el->el_chared.c_redo.pos        = el->el_chared.c_redo.buf;
471
420
        el->el_chared.c_redo.lim        = el->el_chared.c_redo.buf + EL_BUFSIZ;
472
421
        el->el_chared.c_redo.cmd        = ED_UNASSIGNED;
474
423
        el->el_chared.c_vcmd.action     = NOP;
475
424
        el->el_chared.c_vcmd.pos        = el->el_line.buffer;
476
425
 
477
 
        el->el_chared.c_kill.buf        = (char *) el_malloc(EL_BUFSIZ);
 
426
        el->el_chared.c_kill.buf        = el_malloc(EL_BUFSIZ *
 
427
            sizeof(*el->el_chared.c_kill.buf));
478
428
        if (el->el_chared.c_kill.buf == NULL)
479
 
                return (-1);
480
 
        (void) memset(el->el_chared.c_kill.buf, 0, EL_BUFSIZ);
 
429
                return -1;
 
430
        (void) memset(el->el_chared.c_kill.buf, 0, EL_BUFSIZ *
 
431
            sizeof(*el->el_chared.c_kill.buf));
481
432
        el->el_chared.c_kill.mark       = el->el_line.buffer;
482
433
        el->el_chared.c_kill.last       = el->el_chared.c_kill.buf;
 
434
        el->el_chared.c_resizefun       = NULL;
 
435
        el->el_chared.c_resizearg       = NULL;
483
436
 
484
437
        el->el_map.current              = el->el_map.key;
485
438
 
491
444
 
492
445
        ma->level       = -1;
493
446
        ma->offset      = 0;
494
 
        ma->macro       = (char **) el_malloc(EL_MAXMACRO * sizeof(char *));
 
447
        ma->macro       = el_malloc(EL_MAXMACRO * sizeof(*ma->macro));
495
448
        if (ma->macro == NULL)
496
 
                return (-1);
497
 
        return (0);
 
449
                return -1;
 
450
        return 0;
498
451
}
499
452
 
500
453
/* ch_reset():
529
482
}
530
483
 
531
484
private void
532
 
ch__clearmacro(el)
533
 
        EditLine *el;
 
485
ch__clearmacro(EditLine *el)
534
486
{
535
487
        c_macro_t *ma = &el->el_chared.c_macro;
536
488
        while (ma->level >= 0)
537
 
                el_free((ptr_t)ma->macro[ma->level--]);
 
489
                el_free(ma->macro[ma->level--]);
538
490
}
539
491
 
540
492
/* ch_enlargebufs():
542
494
 *      Returns 1 if successful, 0 if not.
543
495
 */
544
496
protected int
545
 
ch_enlargebufs(el, addlen)
546
 
        EditLine *el;
547
 
        size_t addlen;
 
497
ch_enlargebufs(EditLine *el, size_t addlen)
548
498
{
549
499
        size_t sz, newsz;
550
 
        char *newbuffer, *oldbuf, *oldkbuf;
 
500
        Char *newbuffer, *oldbuf, *oldkbuf;
551
501
 
552
 
        sz = el->el_line.limit - el->el_line.buffer + EL_LEAVE;
 
502
        sz = (size_t)(el->el_line.limit - el->el_line.buffer + EL_LEAVE);
553
503
        newsz = sz * 2;
554
504
        /*
555
505
         * If newly required length is longer than current buffer, we need
563
513
        /*
564
514
         * Reallocate line buffer.
565
515
         */
566
 
        newbuffer = el_realloc(el->el_line.buffer, newsz);
 
516
        newbuffer = el_realloc(el->el_line.buffer, newsz * sizeof(*newbuffer));
567
517
        if (!newbuffer)
568
518
                return 0;
569
519
 
570
520
        /* zero the newly added memory, leave old data in */
571
 
        (void) memset(&newbuffer[sz], 0, newsz - sz);
 
521
        (void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer));
572
522
            
573
523
        oldbuf = el->el_line.buffer;
574
524
 
581
531
        /*
582
532
         * Reallocate kill buffer.
583
533
         */
584
 
        newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz);
 
534
        newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz *
 
535
            sizeof(*newbuffer));
585
536
        if (!newbuffer)
586
537
                return 0;
587
538
 
588
539
        /* zero the newly added memory, leave old data in */
589
 
        (void) memset(&newbuffer[sz], 0, newsz - sz);
 
540
        (void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer));
590
541
 
591
542
        oldkbuf = el->el_chared.c_kill.buf;
592
543
 
599
550
        /*
600
551
         * Reallocate undo buffer.
601
552
         */
602
 
        newbuffer = el_realloc(el->el_chared.c_undo.buf, newsz);
 
553
        newbuffer = el_realloc(el->el_chared.c_undo.buf,
 
554
            newsz * sizeof(*newbuffer));
603
555
        if (!newbuffer)
604
556
                return 0;
605
557
 
606
558
        /* zero the newly added memory, leave old data in */
607
 
        (void) memset(&newbuffer[sz], 0, newsz - sz);
 
559
        (void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer));
608
560
        el->el_chared.c_undo.buf = newbuffer;
609
561
 
610
 
        newbuffer = el_realloc(el->el_chared.c_redo.buf, newsz);
 
562
        newbuffer = el_realloc(el->el_chared.c_redo.buf,
 
563
            newsz * sizeof(*newbuffer));
611
564
        if (!newbuffer)
612
565
                return 0;
613
566
        el->el_chared.c_redo.pos = newbuffer +
621
574
 
622
575
        /* Safe to set enlarged buffer size */
623
576
        el->el_line.limit  = &el->el_line.buffer[newsz - EL_LEAVE];
 
577
        if (el->el_chared.c_resizefun)
 
578
                (*el->el_chared.c_resizefun)(el, el->el_chared.c_resizearg);
624
579
        return 1;
625
580
}
626
581
 
630
585
protected void
631
586
ch_end(EditLine *el)
632
587
{
633
 
        el_free((ptr_t) el->el_line.buffer);
 
588
        el_free(el->el_line.buffer);
634
589
        el->el_line.buffer = NULL;
635
590
        el->el_line.limit = NULL;
636
 
        el_free((ptr_t) el->el_chared.c_undo.buf);
 
591
        el_free(el->el_chared.c_undo.buf);
637
592
        el->el_chared.c_undo.buf = NULL;
638
 
        el_free((ptr_t) el->el_chared.c_redo.buf);
 
593
        el_free(el->el_chared.c_redo.buf);
639
594
        el->el_chared.c_redo.buf = NULL;
640
595
        el->el_chared.c_redo.pos = NULL;
641
596
        el->el_chared.c_redo.lim = NULL;
642
597
        el->el_chared.c_redo.cmd = ED_UNASSIGNED;
643
 
        el_free((ptr_t) el->el_chared.c_kill.buf);
 
598
        el_free(el->el_chared.c_kill.buf);
644
599
        el->el_chared.c_kill.buf = NULL;
645
600
        ch_reset(el, 1);
646
 
        el_free((ptr_t) el->el_chared.c_macro.macro);
 
601
        el_free(el->el_chared.c_macro.macro);
647
602
        el->el_chared.c_macro.macro = NULL;
648
603
}
649
604
 
652
607
 *      Insert string at cursorI
653
608
 */
654
609
public int
655
 
el_insertstr(EditLine *el, const char *s)
 
610
FUN(el,insertstr)(EditLine *el, const Char *s)
656
611
{
657
612
        size_t len;
658
613
 
659
 
        if ((len = strlen(s)) == 0)
660
 
                return (-1);
 
614
        if ((len = Strlen(s)) == 0)
 
615
                return -1;
661
616
        if (el->el_line.lastchar + len >= el->el_line.limit) {
662
617
                if (!ch_enlargebufs(el, len))
663
 
                        return (-1);
 
618
                        return -1;
664
619
        }
665
620
 
666
621
        c_insert(el, (int)len);
667
622
        while (*s)
668
623
                *el->el_line.cursor++ = *s++;
669
 
        return (0);
 
624
        return 0;
670
625
}
671
626
 
672
627
 
692
647
 *      Get a string
693
648
 */
694
649
protected int
695
 
c_gets(EditLine *el, char *buf, const char *prompt)
 
650
c_gets(EditLine *el, Char *buf, const Char *prompt)
696
651
{
697
 
        char ch;
698
 
        int len;
699
 
        char *cp = el->el_line.buffer;
 
652
        Char ch;
 
653
        ssize_t len;
 
654
        Char *cp = el->el_line.buffer;
700
655
 
701
656
        if (prompt) {
702
 
                len = strlen(prompt);
703
 
                memcpy(cp, prompt, len + 0u);
 
657
                len = (ssize_t)Strlen(prompt);
 
658
                (void)memcpy(cp, prompt, (size_t)len * sizeof(*cp));
704
659
                cp += len;
705
660
        }
706
661
        len = 0;
711
666
                el->el_line.lastchar = cp + 1;
712
667
                re_refresh(el);
713
668
 
714
 
                if (el_getc(el, &ch) != 1) {
 
669
                if (FUN(el,getc)(el, &ch) != 1) {
715
670
                        ed_end_of_file(el, 0);
716
671
                        len = -1;
717
672
                        break;
721
676
 
722
677
                case 0010:      /* Delete and backspace */
723
678
                case 0177:
724
 
                        if (len <= 0) {
 
679
                        if (len == 0) {
725
680
                                len = -1;
726
681
                                break;
727
682
                        }
735
690
                        break;
736
691
 
737
692
                default:
738
 
                        if (len >= EL_BUFSIZ - 16)
739
 
                                term_beep(el);
 
693
                        if (len >= (ssize_t)(EL_BUFSIZ - 16))
 
694
                                terminal_beep(el);
740
695
                        else {
741
696
                                buf[len++] = ch;
742
697
                                *cp++ = ch;
749
704
        el->el_line.buffer[0] = '\0';
750
705
        el->el_line.lastchar = el->el_line.buffer;
751
706
        el->el_line.cursor = el->el_line.buffer;
752
 
        return len;
 
707
        return (int)len;
753
708
}
754
709
 
755
710
 
759
714
protected int
760
715
c_hpos(EditLine *el)
761
716
{
762
 
        char *ptr;
 
717
        Char *ptr;
763
718
 
764
719
        /*
765
720
         * Find how many characters till the beginning of this line.
766
721
         */
767
722
        if (el->el_line.cursor == el->el_line.buffer)
768
 
                return (0);
 
723
                return 0;
769
724
        else {
770
725
                for (ptr = el->el_line.cursor - 1;
771
726
                     ptr >= el->el_line.buffer && *ptr != '\n';
772
727
                     ptr--)
773
728
                        continue;
774
 
                return (el->el_line.cursor - ptr - 1);
 
729
                return (int)(el->el_line.cursor - ptr - 1);
775
730
        }
776
731
}
 
732
 
 
733
protected int
 
734
ch_resizefun(EditLine *el, el_zfunc_t f, void *a)
 
735
{
 
736
        el->el_chared.c_resizefun = f;
 
737
        el->el_chared.c_resizearg = a;
 
738
        return 0;
 
739
}