60
60
c_undo_t *vu = &el->el_chared.c_undo;
61
61
c_redo_t *r = &el->el_chared.c_redo;
64
64
/* Save entire line for undo */
65
size = el->el_line.lastchar - el->el_line.buffer;
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));
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
82
cv_yank(EditLine *el, const char *ptr, int size)
82
cv_yank(EditLine *el, const Char *ptr, int size)
84
84
c_kill_t *k = &el->el_chared.c_kill;
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;
222
222
* Return if p is part of a big word according to vi
227
return (!isspace(p));
231
231
/* c__prev_word():
232
232
* Find the previous word
235
c__prev_word(char *p, char *low, int n, int (*wtest)(int))
235
c__prev_word(Char *p, Char *low, int n, int (*wtest)(Int))
240
while ((p >= low) && !(*wtest)((unsigned char) *p))
240
while ((p >= low) && !(*wtest)(*p))
242
while ((p >= low) && (*wtest)((unsigned char) *p))
242
while ((p >= low) && (*wtest)(*p))
250
250
/* cp now points where we want it */
255
255
/* c__next_word():
256
256
* Find the next word
259
c__next_word(char *p, char *high, int n, int (*wtest)(int))
259
c__next_word(Char *p, Char *high, int n, int (*wtest)(Int))
262
while ((p < high) && !(*wtest)((unsigned char) *p))
262
while ((p < high) && !(*wtest)(*p))
264
while ((p < high) && (*wtest)((unsigned char) *p))
264
while ((p < high) && (*wtest)(*p))
269
269
/* p now points where we want it */
273
273
/* cv_next_word():
274
274
* Find the next word vi style
277
cv_next_word(EditLine *el, char *p, char *high, int n, int (*wtest)(int))
277
cv_next_word(EditLine *el, Char *p, Char *high, int n, int (*wtest)(Int))
282
test = (*wtest)((unsigned char) *p);
283
while ((p < high) && (*wtest)((unsigned char) *p) == test)
283
while ((p < high) && (*wtest)(*p) == test)
286
286
* vi historically deletes with cw only the word preserving the
287
287
* trailing whitespace! This is not what 'w' does..
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))
294
294
/* p now points where we want it */
302
302
/* cv_prev_word():
303
303
* Find the previous word vi style
306
cv_prev_word(char *p, char *low, int n, int (*wtest)(int))
306
cv_prev_word(Char *p, Char *low, int n, int (*wtest)(Int))
312
while ((p > low) && isspace((unsigned char) *p))
312
while ((p > low) && Isspace(*p))
314
test = (*wtest)((unsigned char) *p);
315
while ((p >= low) && (*wtest)((unsigned char) *p) == test)
315
while ((p >= low) && (*wtest)(*p) == test)
320
320
/* p now points where we want it */
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.
336
char *p, /* character position */
337
int *num, /* Return value */
338
int dval) /* dval is the number to subtract from like $-3 */
349
*num = 0x7fffffff; /* Handle $ */
352
sign = -1; /* Handle $- */
355
for (i = 0; isdigit((unsigned char) *p); i = 10 * i + *p++ - '0')
357
*num = (sign < 0 ? dval - i : i);
363
329
* Finish vi delete action
402
* Go to the end of this word according to emacs
405
ce__endword(char *p, char *high, int n)
410
while ((p < high) && isspace((unsigned char) *p))
412
while ((p < high) && !isspace((unsigned char) *p))
422
366
/* cv__endword():
423
367
* Go to the end of this word according to vi
426
cv__endword(char *p, char *high, int n, int (*wtest)(int))
370
cv__endword(Char *p, Char *high, int n, int (*wtest)(Int))
433
while ((p < high) && isspace((unsigned char) *p))
377
while ((p < high) && Isspace(*p))
436
test = (*wtest)((unsigned char) *p);
437
while ((p < high) && (*wtest)((unsigned char) *p) == test)
381
while ((p < high) && (*wtest)(*p) == test)
450
394
c_macro_t *ma = &el->el_chared.c_macro;
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)
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];
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)
464
(void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ);
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)
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;
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)
480
(void) memset(el->el_chared.c_kill.buf, 0, EL_BUFSIZ);
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;
484
437
el->el_map.current = el->el_map.key;
542
494
* Returns 1 if successful, 0 if not.
545
ch_enlargebufs(el, addlen)
497
ch_enlargebufs(EditLine *el, size_t addlen)
549
499
size_t sz, newsz;
550
char *newbuffer, *oldbuf, *oldkbuf;
500
Char *newbuffer, *oldbuf, *oldkbuf;
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);
555
505
* If newly required length is longer than current buffer, we need
564
514
* Reallocate line buffer.
566
newbuffer = el_realloc(el->el_line.buffer, newsz);
516
newbuffer = el_realloc(el->el_line.buffer, newsz * sizeof(*newbuffer));
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));
573
523
oldbuf = el->el_line.buffer;
582
532
* Reallocate kill buffer.
584
newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz);
534
newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz *
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));
591
542
oldkbuf = el->el_chared.c_kill.buf;
600
551
* Reallocate undo buffer.
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));
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;
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));
613
566
el->el_chared.c_redo.pos = newbuffer +
631
586
ch_end(EditLine *el)
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;
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;
652
607
* Insert string at cursorI
655
el_insertstr(EditLine *el, const char *s)
610
FUN(el,insertstr)(EditLine *el, const Char *s)
659
if ((len = strlen(s)) == 0)
614
if ((len = Strlen(s)) == 0)
661
616
if (el->el_line.lastchar + len >= el->el_line.limit) {
662
617
if (!ch_enlargebufs(el, len))
666
621
c_insert(el, (int)len);
668
623
*el->el_line.cursor++ = *s++;
695
c_gets(EditLine *el, char *buf, const char *prompt)
650
c_gets(EditLine *el, Char *buf, const Char *prompt)
699
char *cp = el->el_line.buffer;
654
Char *cp = el->el_line.buffer;
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));
760
715
c_hpos(EditLine *el)
765
720
* Find how many characters till the beginning of this line.
767
722
if (el->el_line.cursor == el->el_line.buffer)
770
725
for (ptr = el->el_line.cursor - 1;
771
726
ptr >= el->el_line.buffer && *ptr != '\n';
774
return (el->el_line.cursor - ptr - 1);
729
return (int)(el->el_line.cursor - ptr - 1);
734
ch_resizefun(EditLine *el, el_zfunc_t f, void *a)
736
el->el_chared.c_resizefun = f;
737
el->el_chared.c_resizearg = a;