2017-01-30 22:11:53 +00:00
|
|
|
/* $NetBSD: chared.c,v 1.49 2016/02/24 14:29:21 christos Exp $ */
|
2015-01-09 07:40:56 +00:00
|
|
|
|
1994-05-27 05:00:24 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Christos Zoulas of Cornell University.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2005-08-07 20:55:59 +00:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-05-27 05:00:24 +00:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
#include "config.h"
|
1994-05-27 05:00:24 +00:00
|
|
|
#if !defined(lint) && !defined(SCCSID)
|
2015-01-09 07:40:56 +00:00
|
|
|
#if 0
|
1994-05-27 05:00:24 +00:00
|
|
|
static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93";
|
2015-01-09 07:40:56 +00:00
|
|
|
#else
|
2017-01-30 22:11:53 +00:00
|
|
|
__RCSID("$NetBSD: chared.c,v 1.49 2016/02/24 14:29:21 christos Exp $");
|
2015-01-09 07:40:56 +00:00
|
|
|
#endif
|
1994-05-27 05:00:24 +00:00
|
|
|
#endif /* not lint && not SCCSID */
|
2001-10-01 08:41:27 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-27 05:00:24 +00:00
|
|
|
|
1995-05-30 05:51:47 +00:00
|
|
|
/*
|
1994-05-27 05:00:24 +00:00
|
|
|
* chared.c: Character editor utilities
|
|
|
|
*/
|
2017-01-30 22:11:53 +00:00
|
|
|
#include <ctype.h>
|
1994-05-27 05:00:24 +00:00
|
|
|
#include <stdlib.h>
|
2017-01-30 22:11:53 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
1994-05-27 05:00:24 +00:00
|
|
|
#include "el.h"
|
2017-01-30 22:11:53 +00:00
|
|
|
#include "common.h"
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
private void ch__clearmacro (EditLine *);
|
2005-08-07 20:55:59 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
/* value to leave unused in line buffer */
|
|
|
|
#define EL_LEAVE 2
|
|
|
|
|
1994-05-27 05:00:24 +00:00
|
|
|
/* cv_undo():
|
|
|
|
* Handle state for the vi undo command
|
|
|
|
*/
|
|
|
|
protected void
|
2005-08-07 20:55:59 +00:00
|
|
|
cv_undo(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
c_undo_t *vu = &el->el_chared.c_undo;
|
2005-08-07 20:55:59 +00:00
|
|
|
c_redo_t *r = &el->el_chared.c_redo;
|
2012-07-06 19:30:50 +00:00
|
|
|
size_t size;
|
2005-08-07 20:55:59 +00:00
|
|
|
|
|
|
|
/* Save entire line for undo */
|
2015-01-09 07:40:56 +00:00
|
|
|
size = (size_t)(el->el_line.lastchar - el->el_line.buffer);
|
|
|
|
vu->len = (ssize_t)size;
|
2012-07-06 19:30:50 +00:00
|
|
|
vu->cursor = (int)(el->el_line.cursor - el->el_line.buffer);
|
2015-01-09 07:40:56 +00:00
|
|
|
(void)memcpy(vu->buf, el->el_line.buffer, size * sizeof(*vu->buf));
|
2005-08-07 20:55:59 +00:00
|
|
|
|
|
|
|
/* save command info for redo */
|
|
|
|
r->count = el->el_state.doingarg ? el->el_state.argument : 0;
|
|
|
|
r->action = el->el_chared.c_vcmd.action;
|
|
|
|
r->pos = r->buf;
|
|
|
|
r->cmd = el->el_state.thiscmd;
|
|
|
|
r->ch = el->el_state.thisch;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cv_yank():
|
|
|
|
* Save yank/delete data for paste
|
|
|
|
*/
|
|
|
|
protected void
|
2015-01-09 07:40:56 +00:00
|
|
|
cv_yank(EditLine *el, const Char *ptr, int size)
|
2005-08-07 20:55:59 +00:00
|
|
|
{
|
|
|
|
c_kill_t *k = &el->el_chared.c_kill;
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
(void)memcpy(k->buf, ptr, (size_t)size * sizeof(*k->buf));
|
2005-08-07 20:55:59 +00:00
|
|
|
k->last = k->buf + size;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1995-05-30 05:51:47 +00:00
|
|
|
/* c_insert():
|
1994-05-27 05:00:24 +00:00
|
|
|
* Insert num characters
|
|
|
|
*/
|
|
|
|
protected void
|
2001-10-01 08:41:27 +00:00
|
|
|
c_insert(EditLine *el, int num)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
Char *cp;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2005-08-07 20:55:59 +00:00
|
|
|
if (el->el_line.lastchar + num >= el->el_line.limit) {
|
2012-07-06 19:30:50 +00:00
|
|
|
if (!ch_enlargebufs(el, (size_t)num))
|
2005-08-07 20:55:59 +00:00
|
|
|
return; /* can't go past end of buffer */
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (el->el_line.cursor < el->el_line.lastchar) {
|
|
|
|
/* if I must move chars */
|
|
|
|
for (cp = el->el_line.lastchar; cp >= el->el_line.cursor; cp--)
|
|
|
|
cp[num] = *cp;
|
|
|
|
}
|
|
|
|
el->el_line.lastchar += num;
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* c_delafter():
|
|
|
|
* Delete num characters after the cursor
|
|
|
|
*/
|
|
|
|
protected void
|
2001-10-01 08:41:27 +00:00
|
|
|
c_delafter(EditLine *el, int num)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (el->el_line.cursor + num > el->el_line.lastchar)
|
2012-07-06 19:30:50 +00:00
|
|
|
num = (int)(el->el_line.lastchar - el->el_line.cursor);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2005-08-07 20:55:59 +00:00
|
|
|
if (el->el_map.current != el->el_map.emacs) {
|
|
|
|
cv_undo(el);
|
|
|
|
cv_yank(el, el->el_line.cursor, num);
|
|
|
|
}
|
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (num > 0) {
|
2015-01-09 07:40:56 +00:00
|
|
|
Char *cp;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
|
|
|
|
*cp = cp[num];
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_line.lastchar -= num;
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-07 20:55:59 +00:00
|
|
|
/* c_delafter1():
|
|
|
|
* Delete the character after the cursor, do not yank
|
|
|
|
*/
|
|
|
|
protected void
|
|
|
|
c_delafter1(EditLine *el)
|
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
Char *cp;
|
2005-08-07 20:55:59 +00:00
|
|
|
|
|
|
|
for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
|
|
|
|
*cp = cp[1];
|
|
|
|
|
|
|
|
el->el_line.lastchar--;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-05-27 05:00:24 +00:00
|
|
|
/* c_delbefore():
|
|
|
|
* Delete num characters before the cursor
|
|
|
|
*/
|
|
|
|
protected void
|
2001-10-01 08:41:27 +00:00
|
|
|
c_delbefore(EditLine *el, int num)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (el->el_line.cursor - num < el->el_line.buffer)
|
2012-07-06 19:30:50 +00:00
|
|
|
num = (int)(el->el_line.cursor - el->el_line.buffer);
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2005-08-07 20:55:59 +00:00
|
|
|
if (el->el_map.current != el->el_map.emacs) {
|
|
|
|
cv_undo(el);
|
|
|
|
cv_yank(el, el->el_line.cursor - num, num);
|
|
|
|
}
|
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (num > 0) {
|
2015-01-09 07:40:56 +00:00
|
|
|
Char *cp;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
for (cp = el->el_line.cursor - num;
|
|
|
|
cp <= el->el_line.lastchar;
|
|
|
|
cp++)
|
|
|
|
*cp = cp[num];
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_line.lastchar -= num;
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-07 20:55:59 +00:00
|
|
|
/* c_delbefore1():
|
|
|
|
* Delete the character before the cursor, do not yank
|
|
|
|
*/
|
|
|
|
protected void
|
|
|
|
c_delbefore1(EditLine *el)
|
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
Char *cp;
|
2005-08-07 20:55:59 +00:00
|
|
|
|
|
|
|
for (cp = el->el_line.cursor - 1; cp <= el->el_line.lastchar; cp++)
|
|
|
|
*cp = cp[1];
|
|
|
|
|
|
|
|
el->el_line.lastchar--;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1994-05-27 05:00:24 +00:00
|
|
|
/* ce__isword():
|
|
|
|
* Return if p is part of a word according to emacs
|
|
|
|
*/
|
|
|
|
protected int
|
2017-01-30 22:11:53 +00:00
|
|
|
ce__isword(wint_t p)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
return Isalnum(p) || Strchr(STR("*?_-.[]~="), p) != NULL;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* cv__isword():
|
2005-08-07 20:55:59 +00:00
|
|
|
* Return if p is part of a word according to vi
|
1994-05-27 05:00:24 +00:00
|
|
|
*/
|
|
|
|
protected int
|
2017-01-30 22:11:53 +00:00
|
|
|
cv__isword(wint_t p)
|
1998-06-27 16:10:40 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
if (Isalnum(p) || p == '_')
|
2005-08-07 20:55:59 +00:00
|
|
|
return 1;
|
2015-01-09 07:40:56 +00:00
|
|
|
if (Isgraph(p))
|
2005-08-07 20:55:59 +00:00
|
|
|
return 2;
|
|
|
|
return 0;
|
1998-06-27 16:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-07 20:55:59 +00:00
|
|
|
/* cv__isWord():
|
|
|
|
* Return if p is part of a big word according to vi
|
1998-06-27 16:10:40 +00:00
|
|
|
*/
|
|
|
|
protected int
|
2017-01-30 22:11:53 +00:00
|
|
|
cv__isWord(wint_t p)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
return !Isspace(p);
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* c__prev_word():
|
|
|
|
* Find the previous word
|
|
|
|
*/
|
2015-01-09 07:40:56 +00:00
|
|
|
protected Char *
|
2017-01-30 22:11:53 +00:00
|
|
|
c__prev_word(Char *p, Char *low, int n, int (*wtest)(wint_t))
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
p--;
|
|
|
|
|
|
|
|
while (n--) {
|
2015-01-09 07:40:56 +00:00
|
|
|
while ((p >= low) && !(*wtest)(*p))
|
2001-10-01 08:41:27 +00:00
|
|
|
p--;
|
2015-01-09 07:40:56 +00:00
|
|
|
while ((p >= low) && (*wtest)(*p))
|
2001-10-01 08:41:27 +00:00
|
|
|
p--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* cp now points to one character before the word */
|
|
|
|
p++;
|
|
|
|
if (p < low)
|
|
|
|
p = low;
|
|
|
|
/* cp now points where we want it */
|
2015-01-09 07:40:56 +00:00
|
|
|
return p;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* c__next_word():
|
|
|
|
* Find the next word
|
|
|
|
*/
|
2015-01-09 07:40:56 +00:00
|
|
|
protected Char *
|
2017-01-30 22:11:53 +00:00
|
|
|
c__next_word(Char *p, Char *high, int n, int (*wtest)(wint_t))
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
while (n--) {
|
2015-01-09 07:40:56 +00:00
|
|
|
while ((p < high) && !(*wtest)(*p))
|
2001-10-01 08:41:27 +00:00
|
|
|
p++;
|
2015-01-09 07:40:56 +00:00
|
|
|
while ((p < high) && (*wtest)(*p))
|
2001-10-01 08:41:27 +00:00
|
|
|
p++;
|
|
|
|
}
|
|
|
|
if (p > high)
|
|
|
|
p = high;
|
|
|
|
/* p now points where we want it */
|
2015-01-09 07:40:56 +00:00
|
|
|
return p;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* cv_next_word():
|
|
|
|
* Find the next word vi style
|
|
|
|
*/
|
2015-01-09 07:40:56 +00:00
|
|
|
protected Char *
|
2017-01-30 22:11:53 +00:00
|
|
|
cv_next_word(EditLine *el, Char *p, Char *high, int n, int (*wtest)(wint_t))
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
int test;
|
|
|
|
|
|
|
|
while (n--) {
|
2015-01-09 07:40:56 +00:00
|
|
|
test = (*wtest)(*p);
|
|
|
|
while ((p < high) && (*wtest)(*p) == test)
|
2001-10-01 08:41:27 +00:00
|
|
|
p++;
|
|
|
|
/*
|
|
|
|
* vi historically deletes with cw only the word preserving the
|
|
|
|
* trailing whitespace! This is not what 'w' does..
|
|
|
|
*/
|
2005-08-07 20:55:59 +00:00
|
|
|
if (n || el->el_chared.c_vcmd.action != (DELETE|INSERT))
|
2015-01-09 07:40:56 +00:00
|
|
|
while ((p < high) && Isspace(*p))
|
2001-10-01 08:41:27 +00:00
|
|
|
p++;
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
/* p now points where we want it */
|
|
|
|
if (p > high)
|
2015-01-09 07:40:56 +00:00
|
|
|
return high;
|
2001-10-01 08:41:27 +00:00
|
|
|
else
|
2015-01-09 07:40:56 +00:00
|
|
|
return p;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* cv_prev_word():
|
|
|
|
* Find the previous word vi style
|
|
|
|
*/
|
2015-01-09 07:40:56 +00:00
|
|
|
protected Char *
|
2017-01-30 22:11:53 +00:00
|
|
|
cv_prev_word(Char *p, Char *low, int n, int (*wtest)(wint_t))
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
int test;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2005-08-07 20:55:59 +00:00
|
|
|
p--;
|
2001-10-01 08:41:27 +00:00
|
|
|
while (n--) {
|
2015-01-09 07:40:56 +00:00
|
|
|
while ((p > low) && Isspace(*p))
|
2005-08-07 20:55:59 +00:00
|
|
|
p--;
|
2015-01-09 07:40:56 +00:00
|
|
|
test = (*wtest)(*p);
|
|
|
|
while ((p >= low) && (*wtest)(*p) == test)
|
2001-10-01 08:41:27 +00:00
|
|
|
p--;
|
|
|
|
}
|
2005-08-07 20:55:59 +00:00
|
|
|
p++;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
/* p now points where we want it */
|
|
|
|
if (p < low)
|
2015-01-09 07:40:56 +00:00
|
|
|
return low;
|
2001-10-01 08:41:27 +00:00
|
|
|
else
|
2015-01-09 07:40:56 +00:00
|
|
|
return p;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* cv_delfini():
|
|
|
|
* Finish vi delete action
|
|
|
|
*/
|
|
|
|
protected void
|
2001-10-01 08:41:27 +00:00
|
|
|
cv_delfini(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
int size;
|
2005-08-07 20:55:59 +00:00
|
|
|
int action = el->el_chared.c_vcmd.action;
|
2001-10-01 08:41:27 +00:00
|
|
|
|
2005-08-07 20:55:59 +00:00
|
|
|
if (action & INSERT)
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_map.current = el->el_map.key;
|
|
|
|
|
|
|
|
if (el->el_chared.c_vcmd.pos == 0)
|
2005-08-07 20:55:59 +00:00
|
|
|
/* sanity */
|
2001-10-01 08:41:27 +00:00
|
|
|
return;
|
|
|
|
|
2012-07-06 19:30:50 +00:00
|
|
|
size = (int)(el->el_line.cursor - el->el_chared.c_vcmd.pos);
|
2005-08-07 20:55:59 +00:00
|
|
|
if (size == 0)
|
2001-10-01 08:41:27 +00:00
|
|
|
size = 1;
|
2005-08-07 20:55:59 +00:00
|
|
|
el->el_line.cursor = el->el_chared.c_vcmd.pos;
|
|
|
|
if (action & YANK) {
|
|
|
|
if (size > 0)
|
|
|
|
cv_yank(el, el->el_line.cursor, size);
|
|
|
|
else
|
|
|
|
cv_yank(el, el->el_line.cursor + size, -size);
|
|
|
|
} else {
|
|
|
|
if (size > 0) {
|
|
|
|
c_delafter(el, size);
|
|
|
|
re_refresh_cursor(el);
|
|
|
|
} else {
|
|
|
|
c_delbefore(el, -size);
|
|
|
|
el->el_line.cursor += size;
|
|
|
|
}
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
2005-08-07 20:55:59 +00:00
|
|
|
el->el_chared.c_vcmd.action = NOP;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* cv__endword():
|
|
|
|
* Go to the end of this word according to vi
|
|
|
|
*/
|
2015-01-09 07:40:56 +00:00
|
|
|
protected Char *
|
2017-01-30 22:11:53 +00:00
|
|
|
cv__endword(Char *p, Char *high, int n, int (*wtest)(wint_t))
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2005-08-07 20:55:59 +00:00
|
|
|
int test;
|
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
p++;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
while (n--) {
|
2015-01-09 07:40:56 +00:00
|
|
|
while ((p < high) && Isspace(*p))
|
2001-10-01 08:41:27 +00:00
|
|
|
p++;
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
test = (*wtest)(*p);
|
|
|
|
while ((p < high) && (*wtest)(*p) == test)
|
2005-08-07 20:55:59 +00:00
|
|
|
p++;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
|
|
|
p--;
|
2015-01-09 07:40:56 +00:00
|
|
|
return p;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ch_init():
|
|
|
|
* Initialize the character editor
|
|
|
|
*/
|
|
|
|
protected int
|
2001-10-01 08:41:27 +00:00
|
|
|
ch_init(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2005-08-07 20:55:59 +00:00
|
|
|
c_macro_t *ma = &el->el_chared.c_macro;
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
el->el_line.buffer = el_malloc(EL_BUFSIZ *
|
|
|
|
sizeof(*el->el_line.buffer));
|
2001-10-01 08:41:27 +00:00
|
|
|
if (el->el_line.buffer == NULL)
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
(void) memset(el->el_line.buffer, 0, EL_BUFSIZ *
|
|
|
|
sizeof(*el->el_line.buffer));
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_line.cursor = el->el_line.buffer;
|
|
|
|
el->el_line.lastchar = el->el_line.buffer;
|
2005-08-07 20:55:59 +00:00
|
|
|
el->el_line.limit = &el->el_line.buffer[EL_BUFSIZ - EL_LEAVE];
|
2001-10-01 08:41:27 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
el->el_chared.c_undo.buf = el_malloc(EL_BUFSIZ *
|
|
|
|
sizeof(*el->el_chared.c_undo.buf));
|
2001-10-01 08:41:27 +00:00
|
|
|
if (el->el_chared.c_undo.buf == NULL)
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
|
|
|
(void) memset(el->el_chared.c_undo.buf, 0, EL_BUFSIZ *
|
|
|
|
sizeof(*el->el_chared.c_undo.buf));
|
2005-08-07 20:55:59 +00:00
|
|
|
el->el_chared.c_undo.len = -1;
|
|
|
|
el->el_chared.c_undo.cursor = 0;
|
2015-01-09 07:40:56 +00:00
|
|
|
el->el_chared.c_redo.buf = el_malloc(EL_BUFSIZ *
|
|
|
|
sizeof(*el->el_chared.c_redo.buf));
|
2005-08-07 20:55:59 +00:00
|
|
|
if (el->el_chared.c_redo.buf == NULL)
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
2005-08-07 20:55:59 +00:00
|
|
|
el->el_chared.c_redo.pos = el->el_chared.c_redo.buf;
|
|
|
|
el->el_chared.c_redo.lim = el->el_chared.c_redo.buf + EL_BUFSIZ;
|
|
|
|
el->el_chared.c_redo.cmd = ED_UNASSIGNED;
|
2001-10-01 08:41:27 +00:00
|
|
|
|
|
|
|
el->el_chared.c_vcmd.action = NOP;
|
|
|
|
el->el_chared.c_vcmd.pos = el->el_line.buffer;
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
el->el_chared.c_kill.buf = el_malloc(EL_BUFSIZ *
|
|
|
|
sizeof(*el->el_chared.c_kill.buf));
|
2001-10-01 08:41:27 +00:00
|
|
|
if (el->el_chared.c_kill.buf == NULL)
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
|
|
|
(void) memset(el->el_chared.c_kill.buf, 0, EL_BUFSIZ *
|
|
|
|
sizeof(*el->el_chared.c_kill.buf));
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_chared.c_kill.mark = el->el_line.buffer;
|
|
|
|
el->el_chared.c_kill.last = el->el_chared.c_kill.buf;
|
2015-01-09 07:40:56 +00:00
|
|
|
el->el_chared.c_resizefun = NULL;
|
|
|
|
el->el_chared.c_resizearg = NULL;
|
|
|
|
el->el_chared.c_aliasfun = NULL;
|
|
|
|
el->el_chared.c_aliasarg = NULL;
|
2001-10-01 08:41:27 +00:00
|
|
|
|
|
|
|
el->el_map.current = el->el_map.key;
|
|
|
|
|
|
|
|
el->el_state.inputmode = MODE_INSERT; /* XXX: save a default */
|
|
|
|
el->el_state.doingarg = 0;
|
|
|
|
el->el_state.metanext = 0;
|
|
|
|
el->el_state.argument = 1;
|
|
|
|
el->el_state.lastcmd = ED_UNASSIGNED;
|
|
|
|
|
2005-08-07 20:55:59 +00:00
|
|
|
ma->level = -1;
|
|
|
|
ma->offset = 0;
|
2015-01-09 07:40:56 +00:00
|
|
|
ma->macro = el_malloc(EL_MAXMACRO * sizeof(*ma->macro));
|
2005-08-07 20:55:59 +00:00
|
|
|
if (ma->macro == NULL)
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
|
|
|
return 0;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ch_reset():
|
|
|
|
* Reset the character editor
|
|
|
|
*/
|
|
|
|
protected void
|
2005-08-07 20:55:59 +00:00
|
|
|
ch_reset(EditLine *el, int mclear)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_line.cursor = el->el_line.buffer;
|
|
|
|
el->el_line.lastchar = el->el_line.buffer;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2005-08-07 20:55:59 +00:00
|
|
|
el->el_chared.c_undo.len = -1;
|
|
|
|
el->el_chared.c_undo.cursor = 0;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_chared.c_vcmd.action = NOP;
|
|
|
|
el->el_chared.c_vcmd.pos = el->el_line.buffer;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_chared.c_kill.mark = el->el_line.buffer;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_map.current = el->el_map.key;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_state.inputmode = MODE_INSERT; /* XXX: save a default */
|
|
|
|
el->el_state.doingarg = 0;
|
|
|
|
el->el_state.metanext = 0;
|
|
|
|
el->el_state.argument = 1;
|
|
|
|
el->el_state.lastcmd = ED_UNASSIGNED;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2005-08-09 13:31:59 +00:00
|
|
|
el->el_history.eventno = 0;
|
|
|
|
|
2005-08-07 20:55:59 +00:00
|
|
|
if (mclear)
|
|
|
|
ch__clearmacro(el);
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2005-08-07 20:55:59 +00:00
|
|
|
private void
|
2012-07-06 19:30:50 +00:00
|
|
|
ch__clearmacro(EditLine *el)
|
2005-08-07 20:55:59 +00:00
|
|
|
{
|
|
|
|
c_macro_t *ma = &el->el_chared.c_macro;
|
|
|
|
while (ma->level >= 0)
|
2015-01-09 07:40:56 +00:00
|
|
|
el_free(ma->macro[ma->level--]);
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
/* ch_enlargebufs():
|
|
|
|
* Enlarge line buffer to be able to hold twice as much characters.
|
|
|
|
* Returns 1 if successful, 0 if not.
|
|
|
|
*/
|
|
|
|
protected int
|
2012-07-06 19:30:50 +00:00
|
|
|
ch_enlargebufs(EditLine *el, size_t addlen)
|
2001-10-01 08:41:27 +00:00
|
|
|
{
|
|
|
|
size_t sz, newsz;
|
2015-01-09 07:40:56 +00:00
|
|
|
Char *newbuffer, *oldbuf, *oldkbuf;
|
2001-10-01 08:41:27 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
sz = (size_t)(el->el_line.limit - el->el_line.buffer + EL_LEAVE);
|
2001-10-01 08:41:27 +00:00
|
|
|
newsz = sz * 2;
|
|
|
|
/*
|
|
|
|
* If newly required length is longer than current buffer, we need
|
|
|
|
* to make the buffer big enough to hold both old and new stuff.
|
|
|
|
*/
|
|
|
|
if (addlen > sz) {
|
|
|
|
while(newsz - sz < addlen)
|
|
|
|
newsz *= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reallocate line buffer.
|
|
|
|
*/
|
2015-01-09 07:40:56 +00:00
|
|
|
newbuffer = el_realloc(el->el_line.buffer, newsz * sizeof(*newbuffer));
|
2001-10-01 08:41:27 +00:00
|
|
|
if (!newbuffer)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* zero the newly added memory, leave old data in */
|
2015-01-09 07:40:56 +00:00
|
|
|
(void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer));
|
2017-01-30 22:11:53 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
oldbuf = el->el_line.buffer;
|
|
|
|
|
|
|
|
el->el_line.buffer = newbuffer;
|
|
|
|
el->el_line.cursor = newbuffer + (el->el_line.cursor - oldbuf);
|
|
|
|
el->el_line.lastchar = newbuffer + (el->el_line.lastchar - oldbuf);
|
2005-08-07 20:55:59 +00:00
|
|
|
/* don't set new size until all buffers are enlarged */
|
|
|
|
el->el_line.limit = &newbuffer[sz - EL_LEAVE];
|
2001-10-01 08:41:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Reallocate kill buffer.
|
|
|
|
*/
|
2015-01-09 07:40:56 +00:00
|
|
|
newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz *
|
|
|
|
sizeof(*newbuffer));
|
2001-10-01 08:41:27 +00:00
|
|
|
if (!newbuffer)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* zero the newly added memory, leave old data in */
|
2015-01-09 07:40:56 +00:00
|
|
|
(void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer));
|
2001-10-01 08:41:27 +00:00
|
|
|
|
|
|
|
oldkbuf = el->el_chared.c_kill.buf;
|
|
|
|
|
|
|
|
el->el_chared.c_kill.buf = newbuffer;
|
|
|
|
el->el_chared.c_kill.last = newbuffer +
|
|
|
|
(el->el_chared.c_kill.last - oldkbuf);
|
|
|
|
el->el_chared.c_kill.mark = el->el_line.buffer +
|
|
|
|
(el->el_chared.c_kill.mark - oldbuf);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reallocate undo buffer.
|
|
|
|
*/
|
2015-01-09 07:40:56 +00:00
|
|
|
newbuffer = el_realloc(el->el_chared.c_undo.buf,
|
|
|
|
newsz * sizeof(*newbuffer));
|
2001-10-01 08:41:27 +00:00
|
|
|
if (!newbuffer)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* zero the newly added memory, leave old data in */
|
2015-01-09 07:40:56 +00:00
|
|
|
(void) memset(&newbuffer[sz], 0, (newsz - sz) * sizeof(*newbuffer));
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_chared.c_undo.buf = newbuffer;
|
2005-08-07 20:55:59 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
newbuffer = el_realloc(el->el_chared.c_redo.buf,
|
|
|
|
newsz * sizeof(*newbuffer));
|
2005-08-07 20:55:59 +00:00
|
|
|
if (!newbuffer)
|
|
|
|
return 0;
|
|
|
|
el->el_chared.c_redo.pos = newbuffer +
|
|
|
|
(el->el_chared.c_redo.pos - el->el_chared.c_redo.buf);
|
|
|
|
el->el_chared.c_redo.lim = newbuffer +
|
|
|
|
(el->el_chared.c_redo.lim - el->el_chared.c_redo.buf);
|
|
|
|
el->el_chared.c_redo.buf = newbuffer;
|
2017-01-30 22:11:53 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (!hist_enlargebuf(el, sz, newsz))
|
|
|
|
return 0;
|
|
|
|
|
2005-08-07 20:55:59 +00:00
|
|
|
/* Safe to set enlarged buffer size */
|
|
|
|
el->el_line.limit = &el->el_line.buffer[newsz - EL_LEAVE];
|
2015-01-09 07:40:56 +00:00
|
|
|
if (el->el_chared.c_resizefun)
|
|
|
|
(*el->el_chared.c_resizefun)(el, el->el_chared.c_resizearg);
|
2001-10-01 08:41:27 +00:00
|
|
|
return 1;
|
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
|
|
|
/* ch_end():
|
|
|
|
* Free the data structures used by the editor
|
|
|
|
*/
|
|
|
|
protected void
|
2001-10-01 08:41:27 +00:00
|
|
|
ch_end(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
el_free(el->el_line.buffer);
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_line.buffer = NULL;
|
|
|
|
el->el_line.limit = NULL;
|
2015-01-09 07:40:56 +00:00
|
|
|
el_free(el->el_chared.c_undo.buf);
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_chared.c_undo.buf = NULL;
|
2015-01-09 07:40:56 +00:00
|
|
|
el_free(el->el_chared.c_redo.buf);
|
2005-08-07 20:55:59 +00:00
|
|
|
el->el_chared.c_redo.buf = NULL;
|
|
|
|
el->el_chared.c_redo.pos = NULL;
|
|
|
|
el->el_chared.c_redo.lim = NULL;
|
|
|
|
el->el_chared.c_redo.cmd = ED_UNASSIGNED;
|
2015-01-09 07:40:56 +00:00
|
|
|
el_free(el->el_chared.c_kill.buf);
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_chared.c_kill.buf = NULL;
|
2005-08-07 20:55:59 +00:00
|
|
|
ch_reset(el, 1);
|
2015-01-09 07:40:56 +00:00
|
|
|
el_free(el->el_chared.c_macro.macro);
|
2001-10-01 08:41:27 +00:00
|
|
|
el->el_chared.c_macro.macro = NULL;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* el_insertstr():
|
|
|
|
* Insert string at cursorI
|
|
|
|
*/
|
|
|
|
public int
|
2015-01-09 07:40:56 +00:00
|
|
|
FUN(el,insertstr)(EditLine *el, const Char *s)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
size_t len;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
if (s == NULL || (len = Strlen(s)) == 0)
|
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
if (el->el_line.lastchar + len >= el->el_line.limit) {
|
|
|
|
if (!ch_enlargebufs(el, len))
|
2015-01-09 07:40:56 +00:00
|
|
|
return -1;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
c_insert(el, (int)len);
|
|
|
|
while (*s)
|
|
|
|
*el->el_line.cursor++ = *s++;
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* el_deletestr():
|
|
|
|
* Delete num characters before the cursor
|
|
|
|
*/
|
|
|
|
public void
|
2001-10-01 08:41:27 +00:00
|
|
|
el_deletestr(EditLine *el, int n)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2001-10-01 08:41:27 +00:00
|
|
|
if (n <= 0)
|
|
|
|
return;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
if (el->el_line.cursor < &el->el_line.buffer[n])
|
|
|
|
return;
|
1994-05-27 05:00:24 +00:00
|
|
|
|
2001-10-01 08:41:27 +00:00
|
|
|
c_delbefore(el, n); /* delete before dot */
|
|
|
|
el->el_line.cursor -= n;
|
|
|
|
if (el->el_line.cursor < el->el_line.buffer)
|
|
|
|
el->el_line.cursor = el->el_line.buffer;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
/* el_cursor():
|
|
|
|
* Move the cursor to the left or the right of the current position
|
|
|
|
*/
|
|
|
|
public int
|
|
|
|
el_cursor(EditLine *el, int n)
|
|
|
|
{
|
|
|
|
if (n == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
el->el_line.cursor += n;
|
|
|
|
|
|
|
|
if (el->el_line.cursor < el->el_line.buffer)
|
|
|
|
el->el_line.cursor = el->el_line.buffer;
|
|
|
|
if (el->el_line.cursor > el->el_line.lastchar)
|
|
|
|
el->el_line.cursor = el->el_line.lastchar;
|
|
|
|
out:
|
|
|
|
return (int)(el->el_line.cursor - el->el_line.buffer);
|
|
|
|
}
|
|
|
|
|
1994-05-27 05:00:24 +00:00
|
|
|
/* c_gets():
|
|
|
|
* Get a string
|
|
|
|
*/
|
|
|
|
protected int
|
2015-01-09 07:40:56 +00:00
|
|
|
c_gets(EditLine *el, Char *buf, const Char *prompt)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2017-01-30 22:11:53 +00:00
|
|
|
wchar_t wch;
|
2012-07-06 19:30:50 +00:00
|
|
|
ssize_t len;
|
2017-01-30 22:11:53 +00:00
|
|
|
Char *cp = el->el_line.buffer, ch;
|
2005-08-07 20:55:59 +00:00
|
|
|
|
|
|
|
if (prompt) {
|
2015-01-09 07:40:56 +00:00
|
|
|
len = (ssize_t)Strlen(prompt);
|
|
|
|
(void)memcpy(cp, prompt, (size_t)len * sizeof(*cp));
|
2005-08-07 20:55:59 +00:00
|
|
|
cp += len;
|
|
|
|
}
|
|
|
|
len = 0;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
el->el_line.cursor = cp;
|
|
|
|
*cp = ' ';
|
|
|
|
el->el_line.lastchar = cp + 1;
|
|
|
|
re_refresh(el);
|
|
|
|
|
2017-01-30 22:11:53 +00:00
|
|
|
if (el_wgetc(el, &wch) != 1) {
|
2005-08-07 20:55:59 +00:00
|
|
|
ed_end_of_file(el, 0);
|
|
|
|
len = -1;
|
|
|
|
break;
|
|
|
|
}
|
2017-01-30 22:11:53 +00:00
|
|
|
ch = (Char)wch;
|
2001-10-01 08:41:27 +00:00
|
|
|
|
|
|
|
switch (ch) {
|
2005-08-07 20:55:59 +00:00
|
|
|
|
2017-01-30 22:11:53 +00:00
|
|
|
case L'\b': /* Delete and backspace */
|
2015-01-09 07:40:56 +00:00
|
|
|
case 0177:
|
2012-07-06 19:30:50 +00:00
|
|
|
if (len == 0) {
|
2005-08-07 20:55:59 +00:00
|
|
|
len = -1;
|
|
|
|
break;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
2017-01-30 22:11:53 +00:00
|
|
|
len--;
|
2005-08-07 20:55:59 +00:00
|
|
|
cp--;
|
|
|
|
continue;
|
2001-10-01 08:41:27 +00:00
|
|
|
|
2015-01-09 07:40:56 +00:00
|
|
|
case 0033: /* ESC */
|
2017-01-30 22:11:53 +00:00
|
|
|
case L'\r': /* Newline */
|
|
|
|
case L'\n':
|
2005-08-07 20:55:59 +00:00
|
|
|
buf[len] = ch;
|
2001-10-01 08:41:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2015-01-09 07:40:56 +00:00
|
|
|
if (len >= (ssize_t)(EL_BUFSIZ - 16))
|
|
|
|
terminal_beep(el);
|
2001-10-01 08:41:27 +00:00
|
|
|
else {
|
|
|
|
buf[len++] = ch;
|
2005-08-07 20:55:59 +00:00
|
|
|
*cp++ = ch;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
2005-08-07 20:55:59 +00:00
|
|
|
continue;
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
2005-08-07 20:55:59 +00:00
|
|
|
break;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
2005-08-07 20:55:59 +00:00
|
|
|
|
|
|
|
el->el_line.buffer[0] = '\0';
|
|
|
|
el->el_line.lastchar = el->el_line.buffer;
|
|
|
|
el->el_line.cursor = el->el_line.buffer;
|
2012-07-06 19:30:50 +00:00
|
|
|
return (int)len;
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* c_hpos():
|
|
|
|
* Return the current horizontal position of the cursor
|
|
|
|
*/
|
|
|
|
protected int
|
2001-10-01 08:41:27 +00:00
|
|
|
c_hpos(EditLine *el)
|
1994-05-27 05:00:24 +00:00
|
|
|
{
|
2015-01-09 07:40:56 +00:00
|
|
|
Char *ptr;
|
2001-10-01 08:41:27 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Find how many characters till the beginning of this line.
|
|
|
|
*/
|
|
|
|
if (el->el_line.cursor == el->el_line.buffer)
|
2015-01-09 07:40:56 +00:00
|
|
|
return 0;
|
2001-10-01 08:41:27 +00:00
|
|
|
else {
|
|
|
|
for (ptr = el->el_line.cursor - 1;
|
|
|
|
ptr >= el->el_line.buffer && *ptr != '\n';
|
|
|
|
ptr--)
|
|
|
|
continue;
|
2012-07-06 19:30:50 +00:00
|
|
|
return (int)(el->el_line.cursor - ptr - 1);
|
2001-10-01 08:41:27 +00:00
|
|
|
}
|
1994-05-27 05:00:24 +00:00
|
|
|
}
|
2015-01-09 07:40:56 +00:00
|
|
|
|
|
|
|
protected int
|
|
|
|
ch_resizefun(EditLine *el, el_zfunc_t f, void *a)
|
|
|
|
{
|
|
|
|
el->el_chared.c_resizefun = f;
|
|
|
|
el->el_chared.c_resizearg = a;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected int
|
|
|
|
ch_aliasfun(EditLine *el, el_afunc_t f, void *a)
|
|
|
|
{
|
|
|
|
el->el_chared.c_aliasfun = f;
|
|
|
|
el->el_chared.c_aliasarg = a;
|
|
|
|
return 0;
|
|
|
|
}
|