Module Name: src
Committed By: christos
Date: Fri Jul 12 17:48:29 UTC 2013
Modified Files:
src/lib/libedit: chared.c editline.3 histedit.h
Log Message:
Add a function to move the cursor.
To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/lib/libedit/chared.c
cvs rdiff -u -r1.79 -r1.80 src/lib/libedit/editline.3
cvs rdiff -u -r1.50 -r1.51 src/lib/libedit/histedit.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libedit/chared.c
diff -u src/lib/libedit/chared.c:1.37 src/lib/libedit/chared.c:1.38
--- src/lib/libedit/chared.c:1.37 Wed Jul 18 13:12:39 2012
+++ src/lib/libedit/chared.c Fri Jul 12 13:48:29 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: chared.c,v 1.37 2012/07/18 17:12:39 christos Exp $ */
+/* $NetBSD: chared.c,v 1.38 2013/07/12 17:48:29 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
#if 0
static char sccsid[] = "@(#)chared.c 8.1 (Berkeley) 6/4/93";
#else
-__RCSID("$NetBSD: chared.c,v 1.37 2012/07/18 17:12:39 christos Exp $");
+__RCSID("$NetBSD: chared.c,v 1.38 2013/07/12 17:48:29 christos Exp $");
#endif
#endif /* not lint && not SCCSID */
@@ -644,6 +644,25 @@ el_deletestr(EditLine *el, int n)
el->el_line.cursor = el->el_line.buffer;
}
+/* 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 el->el_line.cursor - el->el_line.buffer;
+}
+
/* c_gets():
* Get a string
*/
Index: src/lib/libedit/editline.3
diff -u src/lib/libedit/editline.3:1.79 src/lib/libedit/editline.3:1.80
--- src/lib/libedit/editline.3:1.79 Tue Jan 22 15:23:21 2013
+++ src/lib/libedit/editline.3 Fri Jul 12 13:48:29 2013
@@ -1,4 +1,4 @@
-.\" $NetBSD: editline.3,v 1.79 2013/01/22 20:23:21 christos Exp $
+.\" $NetBSD: editline.3,v 1.80 2013/07/12 17:48:29 christos Exp $
.\"
.\" Copyright (c) 1997-2013 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -26,7 +26,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd January 22, 2013
+.Dd July 12, 2013
.Dt EDITLINE 3
.Os
.Sh NAME
@@ -49,6 +49,7 @@
.Nm el_wget ,
.Nm el_source ,
.Nm el_resize ,
+.Nm el_cursor ,
.Nm el_line ,
.Nm el_wline ,
.Nm el_insertstr ,
@@ -112,8 +113,12 @@
.Fn el_source "EditLine *e" "const char *file"
.Ft void
.Fn el_resize "EditLine *e"
+.Fn int
+.Fn el_cursor "EditLine *e" "int count"
.Ft const LineInfo *
.Fn el_line "EditLine *e"
+.Ft const LineInfoW *
+.Fn el_wline "EditLine *e"
.Ft int
.Fn el_insertstr "EditLine *e" "const char *str"
.Ft int
@@ -610,6 +615,11 @@ then this is done automatically.
Otherwise, it's the responsibility of the application to call
.Fn el_resize
on the appropriate occasions.
+.It Fn el_cursor
+Move the cursor to the right (if positive) or to the left (if negative)
+.Fa count
+characters.
+Returns the resulting offset of the cursor from the beginning of the line.
.It Fn el_line
Return the editing information for the current line in a
.Fa LineInfo
Index: src/lib/libedit/histedit.h
diff -u src/lib/libedit/histedit.h:1.50 src/lib/libedit/histedit.h:1.51
--- src/lib/libedit/histedit.h:1.50 Tue Jan 22 15:23:21 2013
+++ src/lib/libedit/histedit.h Fri Jul 12 13:48:29 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: histedit.h,v 1.50 2013/01/22 20:23:21 christos Exp $ */
+/* $NetBSD: histedit.h,v 1.51 2013/07/12 17:48:29 christos Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -279,6 +279,7 @@ int el_wparse(EditLine *, int, const w
int el_wset(EditLine *, int, ...);
int el_wget(EditLine *, int, ...);
+int el_cursor(EditLine *, int);
const LineInfoW *el_wline(EditLine *);
int el_winsertstr(EditLine *, const wchar_t *);
#define el_wdeletestr el_deletestr