2017-09-02 09:48:10 +03:00
|
|
|
.\" $NetBSD: editline.3,v 1.98 2017/09/02 06:48:10 wiz Exp $
|
1997-01-09 16:12:14 +03:00
|
|
|
.\"
|
2014-05-11 05:05:17 +04:00
|
|
|
.\" Copyright (c) 1997-2014 The NetBSD Foundation, Inc.
|
1997-01-09 16:12:14 +03:00
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
|
|
|
|
.\"
|
|
|
|
.\" 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.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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
|
1999-07-02 19:14:07 +04:00
|
|
|
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
1997-07-31 03:53:32 +04:00
|
|
|
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
1997-01-09 16:12:14 +03:00
|
|
|
.\" 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.
|
|
|
|
.\"
|
2017-09-01 13:19:10 +03:00
|
|
|
.Dd September 1, 2017
|
1997-01-09 16:12:14 +03:00
|
|
|
.Dt EDITLINE 3
|
2009-03-09 22:24:26 +03:00
|
|
|
.Os
|
1997-01-09 16:12:14 +03:00
|
|
|
.Sh NAME
|
|
|
|
.Nm editline ,
|
|
|
|
.Nm el_init ,
|
2013-01-23 00:23:21 +04:00
|
|
|
.Nm el_init_fd ,
|
1997-01-09 16:12:14 +03:00
|
|
|
.Nm el_end ,
|
|
|
|
.Nm el_reset ,
|
|
|
|
.Nm el_gets ,
|
2009-12-31 18:58:26 +03:00
|
|
|
.Nm el_wgets ,
|
1997-01-09 16:12:14 +03:00
|
|
|
.Nm el_getc ,
|
2009-12-31 18:58:26 +03:00
|
|
|
.Nm el_wgetc ,
|
1997-01-09 16:12:14 +03:00
|
|
|
.Nm el_push ,
|
2009-12-31 18:58:26 +03:00
|
|
|
.Nm el_wpush ,
|
1997-01-09 16:12:14 +03:00
|
|
|
.Nm el_parse ,
|
2009-12-31 18:58:26 +03:00
|
|
|
.Nm el_wparse ,
|
1997-01-09 16:12:14 +03:00
|
|
|
.Nm el_set ,
|
2009-12-31 18:58:26 +03:00
|
|
|
.Nm el_wset ,
|
2005-10-12 13:29:43 +04:00
|
|
|
.Nm el_get ,
|
2009-12-31 18:58:26 +03:00
|
|
|
.Nm el_wget ,
|
1997-01-09 16:12:14 +03:00
|
|
|
.Nm el_source ,
|
|
|
|
.Nm el_resize ,
|
2013-07-12 21:48:29 +04:00
|
|
|
.Nm el_cursor ,
|
1997-01-09 16:12:14 +03:00
|
|
|
.Nm el_line ,
|
2009-12-31 18:58:26 +03:00
|
|
|
.Nm el_wline ,
|
1997-01-09 16:12:14 +03:00
|
|
|
.Nm el_insertstr ,
|
2009-12-31 18:58:26 +03:00
|
|
|
.Nm el_winsertstr ,
|
1997-01-09 16:12:14 +03:00
|
|
|
.Nm el_deletestr ,
|
2009-12-31 18:58:26 +03:00
|
|
|
.Nm el_wdeletestr ,
|
1997-01-09 16:12:14 +03:00
|
|
|
.Nm history_init ,
|
2009-12-31 18:58:26 +03:00
|
|
|
.Nm history_winit ,
|
1997-01-09 16:12:14 +03:00
|
|
|
.Nm history_end ,
|
2009-12-31 18:58:26 +03:00
|
|
|
.Nm history_wend ,
|
2003-12-05 16:37:48 +03:00
|
|
|
.Nm history ,
|
2010-01-03 21:27:10 +03:00
|
|
|
.Nm history_w ,
|
2003-12-05 16:37:48 +03:00
|
|
|
.Nm tok_init ,
|
2009-12-31 18:58:26 +03:00
|
|
|
.Nm tok_winit ,
|
2003-12-05 16:37:48 +03:00
|
|
|
.Nm tok_end ,
|
2009-12-31 18:58:26 +03:00
|
|
|
.Nm tok_wend ,
|
2003-12-05 16:37:48 +03:00
|
|
|
.Nm tok_reset ,
|
2009-12-31 18:58:26 +03:00
|
|
|
.Nm tok_wreset ,
|
2003-12-05 16:37:48 +03:00
|
|
|
.Nm tok_line ,
|
2009-12-31 18:58:26 +03:00
|
|
|
.Nm tok_wline ,
|
2016-02-24 21:28:54 +03:00
|
|
|
.Nm tok_str ,
|
2009-12-31 18:58:26 +03:00
|
|
|
.Nm tok_wstr
|
2003-12-05 16:37:48 +03:00
|
|
|
.Nd line editor, history and tokenization functions
|
1998-02-05 21:45:17 +03:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libedit
|
1997-01-09 16:12:14 +03:00
|
|
|
.Sh SYNOPSIS
|
2003-04-16 17:34:34 +04:00
|
|
|
.In histedit.h
|
1997-01-09 16:12:14 +03:00
|
|
|
.Ft EditLine *
|
1998-05-20 05:05:27 +04:00
|
|
|
.Fn el_init "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr"
|
2013-01-23 00:23:21 +04:00
|
|
|
.Ft EditLine *
|
|
|
|
.Fn el_init_fd "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr" "int fdin" "int fdout" "int fderr"
|
1997-01-09 16:12:14 +03:00
|
|
|
.Ft void
|
|
|
|
.Fn el_end "EditLine *e"
|
|
|
|
.Ft void
|
|
|
|
.Fn el_reset "EditLine *e"
|
|
|
|
.Ft const char *
|
|
|
|
.Fn el_gets "EditLine *e" "int *count"
|
2009-12-31 18:58:26 +03:00
|
|
|
.Ft const wchar_t *
|
|
|
|
.Fn el_wgets "EditLine *e" "int *count"
|
1997-01-09 16:12:14 +03:00
|
|
|
.Ft int
|
|
|
|
.Fn el_getc "EditLine *e" "char *ch"
|
2009-12-31 18:58:26 +03:00
|
|
|
.Ft int
|
2016-05-21 20:06:44 +03:00
|
|
|
.Fn el_wgetc "EditLine *e" "wchar_t *wc"
|
1997-01-09 16:12:14 +03:00
|
|
|
.Ft void
|
2016-05-23 02:54:20 +03:00
|
|
|
.Fn el_push "EditLine *e" "const char *mbs"
|
2009-12-31 18:58:26 +03:00
|
|
|
.Ft void
|
2016-05-23 02:54:20 +03:00
|
|
|
.Fn el_wpush "EditLine *e" "const wchar_t *wcs"
|
1997-01-09 16:12:14 +03:00
|
|
|
.Ft int
|
2002-08-18 11:23:21 +04:00
|
|
|
.Fn el_parse "EditLine *e" "int argc" "const char *argv[]"
|
1997-01-09 16:12:14 +03:00
|
|
|
.Ft int
|
2009-12-31 18:58:26 +03:00
|
|
|
.Fn el_wparse "EditLine *e" "int argc" "const wchar_t *argv[]"
|
|
|
|
.Ft int
|
1997-01-09 16:12:14 +03:00
|
|
|
.Fn el_set "EditLine *e" "int op" "..."
|
|
|
|
.Ft int
|
2009-12-31 18:58:26 +03:00
|
|
|
.Fn el_wset "EditLine *e" "int op" "..."
|
|
|
|
.Ft int
|
2006-11-24 03:01:17 +03:00
|
|
|
.Fn el_get "EditLine *e" "int op" "..."
|
1998-07-29 06:26:00 +04:00
|
|
|
.Ft int
|
2009-12-31 18:58:26 +03:00
|
|
|
.Fn el_wget "EditLine *e" "int op" "..."
|
|
|
|
.Ft int
|
1997-01-09 16:12:14 +03:00
|
|
|
.Fn el_source "EditLine *e" "const char *file"
|
|
|
|
.Ft void
|
|
|
|
.Fn el_resize "EditLine *e"
|
2016-05-23 02:54:20 +03:00
|
|
|
.Ft int
|
2013-07-12 21:48:29 +04:00
|
|
|
.Fn el_cursor "EditLine *e" "int count"
|
1997-01-09 16:12:14 +03:00
|
|
|
.Ft const LineInfo *
|
|
|
|
.Fn el_line "EditLine *e"
|
2013-07-12 21:48:29 +04:00
|
|
|
.Ft const LineInfoW *
|
|
|
|
.Fn el_wline "EditLine *e"
|
1997-01-09 16:12:14 +03:00
|
|
|
.Ft int
|
2000-02-28 20:41:04 +03:00
|
|
|
.Fn el_insertstr "EditLine *e" "const char *str"
|
2009-12-31 18:58:26 +03:00
|
|
|
.Ft int
|
|
|
|
.Fn el_winsertstr "EditLine *e" "const wchar_t *str"
|
1997-01-09 16:12:14 +03:00
|
|
|
.Ft void
|
|
|
|
.Fn el_deletestr "EditLine *e" "int count"
|
2009-12-31 18:58:26 +03:00
|
|
|
.Ft void
|
|
|
|
.Fn el_wdeletestr "EditLine *e" "int count"
|
1997-01-09 16:12:14 +03:00
|
|
|
.Ft History *
|
2016-02-24 21:28:54 +03:00
|
|
|
.Fn history_init void
|
2009-12-31 18:58:26 +03:00
|
|
|
.Ft HistoryW *
|
2016-02-24 21:28:54 +03:00
|
|
|
.Fn history_winit void
|
1997-01-09 16:12:14 +03:00
|
|
|
.Ft void
|
|
|
|
.Fn history_end "History *h"
|
2009-12-31 18:58:26 +03:00
|
|
|
.Ft void
|
|
|
|
.Fn history_wend "HistoryW *h"
|
1997-10-14 19:05:49 +04:00
|
|
|
.Ft int
|
1999-01-06 01:46:22 +03:00
|
|
|
.Fn history "History *h" "HistEvent *ev" "int op" "..."
|
2009-12-31 18:58:26 +03:00
|
|
|
.Ft int
|
2010-01-03 21:27:10 +03:00
|
|
|
.Fn history_w "HistoryW *h" "HistEventW *ev" "int op" "..."
|
2003-12-05 16:37:48 +03:00
|
|
|
.Ft Tokenizer *
|
|
|
|
.Fn tok_init "const char *IFS"
|
2009-12-31 18:58:26 +03:00
|
|
|
.Ft TokenizerW *
|
|
|
|
.Fn tok_winit "const wchar_t *IFS"
|
2003-12-05 16:37:48 +03:00
|
|
|
.Ft void
|
|
|
|
.Fn tok_end "Tokenizer *t"
|
|
|
|
.Ft void
|
2009-12-31 18:58:26 +03:00
|
|
|
.Fn tok_wend "TokenizerW *t"
|
|
|
|
.Ft void
|
2003-12-05 16:37:48 +03:00
|
|
|
.Fn tok_reset "Tokenizer *t"
|
2009-12-31 18:58:26 +03:00
|
|
|
.Ft void
|
|
|
|
.Fn tok_wreset "TokenizerW *t"
|
2003-12-05 16:37:48 +03:00
|
|
|
.Ft int
|
2005-03-19 20:36:02 +03:00
|
|
|
.Fn tok_line "Tokenizer *t" "const LineInfo *li" "int *argc" "const char **argv[]" "int *cursorc" "int *cursoro"
|
2003-12-05 16:37:48 +03:00
|
|
|
.Ft int
|
2009-12-31 18:58:26 +03:00
|
|
|
.Fn tok_wline "TokenizerW *t" "const LineInfoW *li" "int *argc" "const wchar_t **argv[]" "int *cursorc" "int *cursoro"
|
|
|
|
.Ft int
|
2005-03-19 20:36:02 +03:00
|
|
|
.Fn tok_str "Tokenizer *t" "const char *str" "int *argc" "const char **argv[]"
|
2009-12-31 18:58:26 +03:00
|
|
|
.Ft int
|
|
|
|
.Fn tok_wstr "TokenizerW *t" "const wchar_t *str" "int *argc" "const wchar_t **argv[]"
|
1997-01-09 16:12:14 +03:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Nm
|
2003-12-05 16:37:48 +03:00
|
|
|
library provides generic line editing, history and tokenization functions,
|
1997-01-09 16:12:14 +03:00
|
|
|
similar to those found in
|
|
|
|
.Xr sh 1 .
|
|
|
|
.Pp
|
|
|
|
These functions are available in the
|
|
|
|
.Nm libedit
|
|
|
|
library (which needs the
|
|
|
|
.Nm libtermcap
|
|
|
|
library).
|
|
|
|
Programs should be linked with
|
|
|
|
.Fl ledit ltermcap .
|
2016-02-24 22:45:48 +03:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
library respects the
|
2016-02-25 17:59:22 +03:00
|
|
|
.Ev LC_CTYPE
|
2016-02-24 22:45:48 +03:00
|
|
|
locale set by the application program and never uses
|
|
|
|
.Xr setlocale 3
|
|
|
|
to change the locale.
|
|
|
|
The only locales supported are UTF-8 and the default C or POSIX locale.
|
|
|
|
If any other locale is set, behaviour is undefined.
|
1997-01-09 16:12:14 +03:00
|
|
|
.Sh LINE EDITING FUNCTIONS
|
|
|
|
The line editing functions use a common data structure,
|
|
|
|
.Fa EditLine ,
|
|
|
|
which is created by
|
|
|
|
.Fn el_init
|
2013-01-23 00:23:21 +04:00
|
|
|
or
|
|
|
|
.Fn el_init_fd
|
1997-01-09 16:12:14 +03:00
|
|
|
and freed by
|
|
|
|
.Fn el_end .
|
|
|
|
.Pp
|
2010-12-16 20:42:25 +03:00
|
|
|
The wide-character functions behave the same way as their narrow
|
2009-12-31 18:58:26 +03:00
|
|
|
counterparts.
|
|
|
|
.Pp
|
1997-01-09 16:12:14 +03:00
|
|
|
The following functions are available:
|
|
|
|
.Bl -tag -width 4n
|
|
|
|
.It Fn el_init
|
2015-11-04 00:36:59 +03:00
|
|
|
Initialize the line editor, and return a data structure
|
2014-12-25 16:39:05 +03:00
|
|
|
to be used by all other line editing functions, or
|
|
|
|
.Dv NULL
|
|
|
|
on failure.
|
1997-01-09 16:12:14 +03:00
|
|
|
.Fa prog
|
|
|
|
is the name of the invoking program, used when reading the
|
|
|
|
.Xr editrc 5
|
|
|
|
file to determine which settings to use.
|
1998-05-20 05:05:27 +04:00
|
|
|
.Fa fin ,
|
1997-01-09 16:12:14 +03:00
|
|
|
.Fa fout
|
1998-05-20 05:05:27 +04:00
|
|
|
and
|
|
|
|
.Fa ferr
|
|
|
|
are the input, output, and error streams (respectively) to use.
|
1997-01-09 16:12:14 +03:00
|
|
|
In this documentation, references to
|
|
|
|
.Dq the tty
|
|
|
|
are actually to this input/output stream combination.
|
2013-01-23 00:23:21 +04:00
|
|
|
.It Fn el_init_fd
|
|
|
|
Like
|
|
|
|
.Fn el_init
|
|
|
|
but allows specifying file descriptors for the
|
|
|
|
.Xr stdio 3
|
|
|
|
corresponding streams, in case those were created with
|
|
|
|
.Xr funopen 3 .
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Fn el_end
|
|
|
|
Clean up and finish with
|
|
|
|
.Fa e ,
|
|
|
|
assumed to have been created with
|
2013-01-23 00:23:21 +04:00
|
|
|
.Fn el_init
|
|
|
|
or
|
|
|
|
.Fn el_init_fd .
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Fn el_reset
|
|
|
|
Reset the tty and the parser.
|
|
|
|
This should be called after an error which may have upset the tty's
|
|
|
|
state.
|
|
|
|
.It Fn el_gets
|
|
|
|
Read a line from the tty.
|
|
|
|
.Fa count
|
|
|
|
is modified to contain the number of characters read.
|
|
|
|
Returns the line read if successful, or
|
|
|
|
.Dv NULL
|
|
|
|
if no characters were read or if an error occurred.
|
2009-03-10 23:46:15 +03:00
|
|
|
If an error occurred,
|
|
|
|
.Fa count
|
2009-03-11 01:55:14 +03:00
|
|
|
is set to \-1 and
|
2009-03-10 23:46:15 +03:00
|
|
|
.Dv errno
|
|
|
|
contains the error code that caused it.
|
2009-07-06 01:55:24 +04:00
|
|
|
The return value may not remain valid across calls to
|
|
|
|
.Fn el_gets
|
|
|
|
and must be copied if the data is to be retained.
|
2016-02-24 22:45:48 +03:00
|
|
|
.It Fn el_wgetc
|
|
|
|
Read a wide character from the tty, respecting the current locale,
|
2016-05-23 02:54:20 +03:00
|
|
|
or from the input queue described in
|
|
|
|
.Xr editline 7
|
2016-02-24 22:45:48 +03:00
|
|
|
if that is not empty, and store it in
|
2016-05-21 20:06:44 +03:00
|
|
|
.Fa wc .
|
2016-02-24 22:45:48 +03:00
|
|
|
If an invalid or incomplete character is found, it is discarded,
|
|
|
|
.Va errno
|
|
|
|
is set to
|
2016-02-25 17:59:22 +03:00
|
|
|
.Er EILSEQ ,
|
2016-02-24 22:45:48 +03:00
|
|
|
and the next character is read and stored in
|
2016-05-21 20:06:44 +03:00
|
|
|
.Fa wc .
|
2016-02-25 17:59:22 +03:00
|
|
|
Returns 1 if a valid character was read, 0 on end of file, or \-1 on
|
2016-02-24 22:45:48 +03:00
|
|
|
.Xr read 2
|
|
|
|
failure.
|
|
|
|
In the latter case,
|
|
|
|
.Va errno
|
|
|
|
is set to indicate the error.
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Fn el_getc
|
2016-02-24 22:45:48 +03:00
|
|
|
Read a wide character as described for
|
|
|
|
.Fn el_wgetc
|
2016-02-25 17:59:22 +03:00
|
|
|
and return 0 on end of file or \-1 on failure.
|
2016-02-24 22:45:48 +03:00
|
|
|
If the wide character can be represented as a single-byte character,
|
|
|
|
convert it with
|
|
|
|
.Xr wctob 3 ,
|
|
|
|
store the result in
|
|
|
|
.Fa ch ,
|
|
|
|
and return 1; otherwise, set
|
|
|
|
.Va errno
|
|
|
|
to
|
2016-02-25 17:59:22 +03:00
|
|
|
.Er ERANGE
|
|
|
|
and return \-1.
|
2016-02-24 22:45:48 +03:00
|
|
|
In the C or POSIX locale, this simply reads a byte, but for any other
|
|
|
|
locale, including UTF-8, this is rarely useful.
|
2016-05-23 02:54:20 +03:00
|
|
|
.It Fn el_wpush
|
|
|
|
Push the wide character string
|
|
|
|
.Fa wcs
|
|
|
|
back onto the input queue described in
|
|
|
|
.Xr editline 7 .
|
|
|
|
If the queue overflows, for example due to a recursive macro,
|
|
|
|
or if an error occurs, for example because
|
|
|
|
.Fa wcs
|
|
|
|
is
|
|
|
|
.Dv NULL
|
|
|
|
or memory allocation fails, the function beeps at the user,
|
|
|
|
but does not report the problem to the caller.
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Fn el_push
|
2016-05-23 02:54:20 +03:00
|
|
|
Use the current locale to convert the multibyte string
|
|
|
|
.Fa mbs
|
|
|
|
to a wide character string, and pass the result to
|
|
|
|
.Fn el_wpush .
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Fn el_parse
|
|
|
|
Parses the
|
|
|
|
.Fa argv
|
|
|
|
array (which is
|
|
|
|
.Fa argc
|
|
|
|
elements in size)
|
|
|
|
to execute builtin
|
|
|
|
.Nm
|
|
|
|
commands.
|
|
|
|
If the command is prefixed with
|
2002-01-15 05:46:22 +03:00
|
|
|
.Dq prog :
|
1997-01-09 16:12:14 +03:00
|
|
|
then
|
|
|
|
.Fn el_parse
|
|
|
|
will only execute the command if
|
|
|
|
.Dq prog
|
|
|
|
matches the
|
|
|
|
.Fa prog
|
|
|
|
argument supplied to
|
|
|
|
.Fn el_init .
|
1997-01-11 09:26:30 +03:00
|
|
|
The return value is
|
2003-01-22 02:00:56 +03:00
|
|
|
\-1 if the command is unknown,
|
1997-01-11 09:26:30 +03:00
|
|
|
0 if there was no error or
|
1997-01-09 16:12:14 +03:00
|
|
|
.Dq prog
|
1997-01-11 09:26:30 +03:00
|
|
|
didn't match, or
|
|
|
|
1 if the command returned an error.
|
1997-01-09 16:12:14 +03:00
|
|
|
Refer to
|
|
|
|
.Xr editrc 5
|
|
|
|
for more information.
|
|
|
|
.It Fn el_set
|
|
|
|
Set
|
|
|
|
.Nm
|
|
|
|
parameters.
|
|
|
|
.Fa op
|
|
|
|
determines which parameter to set, and each operation has its
|
|
|
|
own parameter list.
|
2014-12-25 16:39:05 +03:00
|
|
|
Returns 0 on success, \-1 on failure.
|
1997-01-09 16:12:14 +03:00
|
|
|
.Pp
|
|
|
|
The following values for
|
|
|
|
.Fa op
|
|
|
|
are supported, along with the required argument list:
|
|
|
|
.Bl -tag -width 4n
|
2009-05-11 22:33:30 +04:00
|
|
|
.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
|
1997-01-09 16:12:14 +03:00
|
|
|
Define prompt printing function as
|
|
|
|
.Fa f ,
|
|
|
|
which is to return a string that contains the prompt.
|
2009-05-11 22:33:30 +04:00
|
|
|
.It Dv EL_PROMPT_ESC , Fa "char *(*f)(EditLine *)" , Fa "char c"
|
|
|
|
Same as
|
2009-05-12 12:14:07 +04:00
|
|
|
.Dv EL_PROMPT ,
|
2009-05-11 22:33:30 +04:00
|
|
|
but the
|
2009-03-31 21:38:27 +04:00
|
|
|
.Fa c
|
|
|
|
argument indicates the start/stop literal prompt character.
|
|
|
|
.Pp
|
2009-04-01 12:58:47 +04:00
|
|
|
If a start/stop literal character is found in the prompt, the
|
|
|
|
character itself
|
2009-03-31 21:38:27 +04:00
|
|
|
is not printed, but characters after it are printed directly to the
|
|
|
|
terminal without affecting the state of the current line.
|
|
|
|
A subsequent second start/stop literal character ends this behavior.
|
|
|
|
This is typically used to embed literal escape sequences that change the
|
|
|
|
color/style of the terminal in the prompt.
|
2017-06-28 02:22:20 +03:00
|
|
|
Note that the literal escape character cannot be the last character in the
|
|
|
|
prompt, as the escape sequence is attached to the next character in the prompt.
|
2009-03-31 21:38:27 +04:00
|
|
|
.Dv 0
|
|
|
|
unsets it.
|
2008-04-05 19:53:28 +04:00
|
|
|
.It Dv EL_REFRESH
|
|
|
|
Re-display the current line on the next terminal line.
|
1999-11-12 04:05:07 +03:00
|
|
|
.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
|
|
|
|
Define right side prompt printing function as
|
|
|
|
.Fa f ,
|
|
|
|
which is to return a string that contains the prompt.
|
2009-05-11 22:33:30 +04:00
|
|
|
.It Dv EL_RPROMPT_ESC , Fa "char *(*f)(EditLine *)" , Fa "char c"
|
|
|
|
Define the right prompt printing function but with a literal escape character.
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Dv EL_TERMINAL , Fa "const char *type"
|
|
|
|
Define terminal type of the tty to be
|
|
|
|
.Fa type ,
|
|
|
|
or to
|
|
|
|
.Ev TERM
|
|
|
|
if
|
|
|
|
.Fa type
|
|
|
|
is
|
|
|
|
.Dv NULL .
|
|
|
|
.It Dv EL_EDITOR , Fa "const char *mode"
|
|
|
|
Set editing mode to
|
|
|
|
.Fa mode ,
|
|
|
|
which must be one of
|
|
|
|
.Dq emacs
|
|
|
|
or
|
|
|
|
.Dq vi .
|
|
|
|
.It Dv EL_SIGNAL , Fa "int flag"
|
|
|
|
If
|
|
|
|
.Fa flag
|
|
|
|
is non-zero,
|
|
|
|
.Nm
|
|
|
|
will install its own signal handler for the following signals when
|
|
|
|
reading command input:
|
|
|
|
.Dv SIGCONT ,
|
|
|
|
.Dv SIGHUP ,
|
|
|
|
.Dv SIGINT ,
|
|
|
|
.Dv SIGQUIT ,
|
|
|
|
.Dv SIGSTOP ,
|
|
|
|
.Dv SIGTERM ,
|
|
|
|
.Dv SIGTSTP ,
|
|
|
|
and
|
|
|
|
.Dv SIGWINCH .
|
|
|
|
Otherwise, the current signal handlers will be used.
|
2009-04-12 00:48:26 +04:00
|
|
|
.It Dv EL_BIND , Fa "const char *" , Fa "..." , Dv NULL
|
1997-01-09 16:12:14 +03:00
|
|
|
Perform the
|
|
|
|
.Ic bind
|
|
|
|
builtin command.
|
1999-07-02 19:14:07 +04:00
|
|
|
Refer to
|
1997-01-09 16:12:14 +03:00
|
|
|
.Xr editrc 5
|
|
|
|
for more information.
|
2009-04-12 00:48:26 +04:00
|
|
|
.It Dv EL_ECHOTC , Fa "const char *" , Fa "..." , Dv NULL
|
1997-01-09 16:12:14 +03:00
|
|
|
Perform the
|
|
|
|
.Ic echotc
|
|
|
|
builtin command.
|
1999-07-02 19:14:07 +04:00
|
|
|
Refer to
|
1997-01-09 16:12:14 +03:00
|
|
|
.Xr editrc 5
|
|
|
|
for more information.
|
2009-04-12 00:48:26 +04:00
|
|
|
.It Dv EL_SETTC , Fa "const char *" , Fa "..." , Dv NULL
|
1997-01-09 16:12:14 +03:00
|
|
|
Perform the
|
|
|
|
.Ic settc
|
|
|
|
builtin command.
|
1999-07-02 19:14:07 +04:00
|
|
|
Refer to
|
1997-01-09 16:12:14 +03:00
|
|
|
.Xr editrc 5
|
|
|
|
for more information.
|
2009-04-12 00:48:26 +04:00
|
|
|
.It Dv EL_SETTY , Fa "const char *" , Fa "..." , Dv NULL
|
1997-01-09 16:12:14 +03:00
|
|
|
Perform the
|
|
|
|
.Ic setty
|
|
|
|
builtin command.
|
1999-07-02 19:14:07 +04:00
|
|
|
Refer to
|
1997-01-09 16:12:14 +03:00
|
|
|
.Xr editrc 5
|
|
|
|
for more information.
|
2009-04-12 00:48:26 +04:00
|
|
|
.It Dv EL_TELLTC , Fa "const char *" , Fa "..." , Dv NULL
|
1997-01-09 16:12:14 +03:00
|
|
|
Perform the
|
|
|
|
.Ic telltc
|
|
|
|
builtin command.
|
1999-07-02 19:14:07 +04:00
|
|
|
Refer to
|
1997-01-09 16:12:14 +03:00
|
|
|
.Xr editrc 5
|
|
|
|
for more information.
|
2009-04-12 00:48:26 +04:00
|
|
|
.It Dv EL_ADDFN , Fa "const char *name" , Fa "const char *help" , \
|
|
|
|
Fa "unsigned char (*func)(EditLine *e, int ch)"
|
1997-01-09 16:12:14 +03:00
|
|
|
Add a user defined function,
|
|
|
|
.Fn func ,
|
|
|
|
referred to as
|
|
|
|
.Fa name
|
|
|
|
which is invoked when a key which is bound to
|
|
|
|
.Fa name
|
|
|
|
is entered.
|
|
|
|
.Fa help
|
|
|
|
is a description of
|
|
|
|
.Fa name .
|
|
|
|
At invocation time,
|
|
|
|
.Fa ch
|
|
|
|
is the key which caused the invocation.
|
|
|
|
The return value of
|
|
|
|
.Fn func
|
|
|
|
should be one of:
|
1997-01-14 07:17:22 +03:00
|
|
|
.Bl -tag -width "CC_REDISPLAY"
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Dv CC_NORM
|
|
|
|
Add a normal character.
|
|
|
|
.It Dv CC_NEWLINE
|
|
|
|
End of line was entered.
|
|
|
|
.It Dv CC_EOF
|
|
|
|
EOF was entered.
|
|
|
|
.It Dv CC_ARGHACK
|
|
|
|
Expecting further command input as arguments, do nothing visually.
|
|
|
|
.It Dv CC_REFRESH
|
|
|
|
Refresh display.
|
1998-06-01 18:31:26 +04:00
|
|
|
.It Dv CC_REFRESH_BEEP
|
|
|
|
Refresh display, and beep.
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Dv CC_CURSOR
|
1997-01-14 07:17:22 +03:00
|
|
|
Cursor moved, so update and perform
|
2001-10-04 04:45:19 +04:00
|
|
|
.Dv CC_REFRESH .
|
1997-01-14 07:17:22 +03:00
|
|
|
.It Dv CC_REDISPLAY
|
|
|
|
Redisplay entire input line.
|
|
|
|
This is useful if a key binding outputs extra information.
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Dv CC_ERROR
|
|
|
|
An error occurred.
|
|
|
|
Beep, and flush tty.
|
|
|
|
.It Dv CC_FATAL
|
|
|
|
Fatal error, reset tty to known state.
|
|
|
|
.El
|
2009-04-12 00:48:26 +04:00
|
|
|
.It Dv EL_HIST , Fa "History *(*func)(History *, int op, ...)" , \
|
|
|
|
Fa "const char *ptr"
|
1997-01-09 16:12:14 +03:00
|
|
|
Defines which history function to use, which is usually
|
|
|
|
.Fn history .
|
|
|
|
.Fa ptr
|
|
|
|
should be the value returned by
|
|
|
|
.Fn history_init .
|
1998-07-29 06:26:00 +04:00
|
|
|
.It Dv EL_EDITMODE , Fa "int flag"
|
|
|
|
If
|
|
|
|
.Fa flag
|
|
|
|
is non-zero,
|
|
|
|
editing is enabled (the default).
|
|
|
|
Note that this is only an indication, and does not
|
|
|
|
affect the operation of
|
2003-02-25 13:34:36 +03:00
|
|
|
.Nm .
|
1998-07-29 06:26:00 +04:00
|
|
|
At this time, it is the caller's responsibility to
|
|
|
|
check this
|
|
|
|
(using
|
|
|
|
.Fn el_get )
|
|
|
|
to determine if editing should be enabled or not.
|
2012-09-11 15:57:18 +04:00
|
|
|
.It Dv EL_UNBUFFERED , Fa "int flag"
|
|
|
|
If
|
|
|
|
.Fa flag
|
|
|
|
is zero,
|
|
|
|
unbuffered mode is disabled (the default).
|
|
|
|
In unbuffered mode,
|
|
|
|
.Fn el_gets
|
|
|
|
will return immediately after processing a single character.
|
2016-05-21 20:06:44 +03:00
|
|
|
.It Dv EL_GETCFN , Fa "el_rfunc_t f"
|
|
|
|
Whenever reading a character, use the function
|
|
|
|
.Bd -ragged -offset indent -compact
|
|
|
|
.Ft int
|
|
|
|
.Fo f
|
|
|
|
.Fa "EditLine *e"
|
|
|
|
.Fa "wchar_t *wc"
|
|
|
|
.Fc
|
|
|
|
.Ed
|
|
|
|
which stores the character in
|
|
|
|
.Fa wc
|
|
|
|
and returns 1 on success, 0 on end of file, or \-1 on I/O or encoding
|
|
|
|
errors.
|
|
|
|
Functions internally using it include
|
|
|
|
.Fn el_wgets ,
|
|
|
|
.Fn el_wgetc ,
|
|
|
|
.Fn el_gets ,
|
2001-09-27 23:29:50 +04:00
|
|
|
and
|
|
|
|
.Fn el_getc .
|
2016-05-21 20:06:44 +03:00
|
|
|
Initially, a builtin function is installed, and replacing it
|
|
|
|
is discouraged because writing such a function is very error prone.
|
|
|
|
The builtin function can be restored at any time by passing the
|
|
|
|
special value
|
|
|
|
.Dv EL_BUILTIN_GETCFN
|
|
|
|
instead of a function pointer.
|
2001-10-09 17:50:29 +04:00
|
|
|
.It Dv EL_CLIENTDATA , Fa "void *data"
|
2002-01-15 05:46:22 +03:00
|
|
|
Register
|
2001-10-09 17:50:29 +04:00
|
|
|
.Fa data
|
2002-10-01 23:03:15 +04:00
|
|
|
to be associated with this EditLine structure.
|
|
|
|
It can be retrieved with the corresponding
|
2001-10-09 17:50:29 +04:00
|
|
|
.Fn el_get
|
|
|
|
call.
|
2006-12-16 01:13:33 +03:00
|
|
|
.It Dv EL_SETFP , Fa "int fd" , Fa "FILE *fp"
|
|
|
|
Set the current
|
|
|
|
.Nm editline
|
|
|
|
file pointer for
|
|
|
|
.Dq input
|
|
|
|
.Fa fd
|
2006-12-18 03:03:43 +03:00
|
|
|
=
|
2006-12-16 01:13:33 +03:00
|
|
|
.Dv 0 ,
|
|
|
|
.Dq output
|
2006-12-18 03:03:43 +03:00
|
|
|
.Fa fd
|
|
|
|
=
|
2006-12-16 01:13:33 +03:00
|
|
|
.Dv 1 ,
|
|
|
|
or
|
|
|
|
.Dq error
|
|
|
|
.Fa fd
|
2006-12-18 03:03:43 +03:00
|
|
|
=
|
|
|
|
.Dv 2
|
2006-12-16 01:13:33 +03:00
|
|
|
from
|
|
|
|
.Fa fp .
|
1998-07-29 06:26:00 +04:00
|
|
|
.El
|
|
|
|
.It Fn el_get
|
|
|
|
Get
|
|
|
|
.Nm
|
|
|
|
parameters.
|
|
|
|
.Fa op
|
|
|
|
determines which parameter to retrieve into
|
|
|
|
.Fa result .
|
2003-07-15 02:36:22 +04:00
|
|
|
Returns 0 if successful, \-1 otherwise.
|
1998-07-29 06:26:00 +04:00
|
|
|
.Pp
|
|
|
|
The following values for
|
|
|
|
.Fa op
|
|
|
|
are supported, along with actual type of
|
|
|
|
.Fa result :
|
|
|
|
.Bl -tag -width 4n
|
2009-03-31 21:38:27 +04:00
|
|
|
.It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)" , Fa "char *c"
|
2015-11-04 00:36:59 +03:00
|
|
|
Set
|
2016-05-21 20:06:44 +03:00
|
|
|
.Fa f
|
2015-11-04 00:36:59 +03:00
|
|
|
to a pointer to the function that displays the prompt.
|
2009-03-31 21:38:27 +04:00
|
|
|
If
|
|
|
|
.Fa c
|
|
|
|
is not
|
|
|
|
.Dv NULL ,
|
2015-11-04 00:36:59 +03:00
|
|
|
set it to the start/stop literal prompt character.
|
2009-03-31 21:38:27 +04:00
|
|
|
.It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)" , Fa "char *c"
|
2015-11-04 00:36:59 +03:00
|
|
|
Set
|
2016-05-21 20:06:44 +03:00
|
|
|
.Fa f
|
2015-11-04 00:36:59 +03:00
|
|
|
to a pointer to the function that displays the prompt.
|
2009-03-31 21:38:27 +04:00
|
|
|
If
|
|
|
|
.Fa c
|
|
|
|
is not
|
|
|
|
.Dv NULL ,
|
2015-11-04 00:36:59 +03:00
|
|
|
set it to the start/stop literal prompt character.
|
|
|
|
.It Dv EL_EDITOR , Fa "const char **n"
|
|
|
|
Set the name of the editor in
|
|
|
|
.Fa n ,
|
|
|
|
which will be one of
|
1998-07-29 06:26:00 +04:00
|
|
|
.Dq emacs
|
|
|
|
or
|
|
|
|
.Dq vi .
|
2006-11-24 03:01:17 +03:00
|
|
|
.It Dv EL_GETTC , Fa "const char *name" , Fa "void *value"
|
2015-11-04 00:36:59 +03:00
|
|
|
If
|
2006-11-24 03:01:17 +03:00
|
|
|
.Fa name
|
|
|
|
is a valid
|
2006-12-18 03:03:43 +03:00
|
|
|
.Xr termcap 5
|
2015-11-04 00:36:59 +03:00
|
|
|
capability set
|
2006-11-24 03:01:17 +03:00
|
|
|
.Fa value
|
|
|
|
to the current value of that capability.
|
2015-11-04 00:36:59 +03:00
|
|
|
.It Dv EL_SIGNAL , Fa "int *s"
|
|
|
|
Set
|
|
|
|
.Fa s
|
2016-05-21 20:06:44 +03:00
|
|
|
to non-zero if
|
1998-07-29 06:26:00 +04:00
|
|
|
.Nm
|
|
|
|
has installed private signal handlers (see
|
|
|
|
.Fn el_get
|
|
|
|
above).
|
2015-11-04 00:36:59 +03:00
|
|
|
.It Dv EL_EDITMODE , Fa "int *c"
|
|
|
|
Set
|
|
|
|
.Fa c
|
|
|
|
to non-zero if editing is enabled.
|
2016-05-21 20:06:44 +03:00
|
|
|
.It Dv EL_GETCFN , Fa "el_rfunc_t *f"
|
|
|
|
Set
|
|
|
|
.Fa f
|
|
|
|
to a pointer to the function that reads characters, or to
|
|
|
|
.Dv EL_BUILTIN_GETCFN
|
|
|
|
if the builtin function is in use.
|
2001-10-09 17:50:29 +04:00
|
|
|
.It Dv EL_CLIENTDATA , Fa "void **data"
|
2015-11-04 00:36:59 +03:00
|
|
|
Set
|
2001-10-09 17:50:29 +04:00
|
|
|
.Fa data
|
2015-11-04 00:36:59 +03:00
|
|
|
to the previously registered client data set by an
|
2001-10-09 17:50:29 +04:00
|
|
|
.Fn el_set
|
|
|
|
call.
|
2015-11-04 00:36:59 +03:00
|
|
|
.It Dv EL_UNBUFFERED , Fa "int *c"
|
|
|
|
Set
|
|
|
|
.Fa c
|
|
|
|
to non-zero if unbuffered mode is enabled.
|
2006-12-18 03:03:43 +03:00
|
|
|
.It Dv EL_GETFP , Fa "int fd", Fa "FILE **fp"
|
2015-11-04 00:36:59 +03:00
|
|
|
Set
|
2006-12-16 01:13:33 +03:00
|
|
|
.Fa fp
|
2015-11-04 00:36:59 +03:00
|
|
|
to the current
|
2006-12-16 01:13:33 +03:00
|
|
|
.Nm editline
|
|
|
|
file pointer for
|
|
|
|
.Dq input
|
|
|
|
.Fa fd
|
2006-12-18 03:03:43 +03:00
|
|
|
=
|
2006-12-16 01:13:33 +03:00
|
|
|
.Dv 0 ,
|
|
|
|
.Dq output
|
2006-12-18 03:03:43 +03:00
|
|
|
.Fa fd
|
|
|
|
=
|
2006-12-16 01:13:33 +03:00
|
|
|
.Dv 1 ,
|
|
|
|
or
|
|
|
|
.Dq error
|
|
|
|
.Fa fd
|
2006-12-18 03:03:43 +03:00
|
|
|
=
|
2006-12-16 01:13:33 +03:00
|
|
|
.Dv 2 .
|
1997-01-09 16:12:14 +03:00
|
|
|
.El
|
|
|
|
.It Fn el_source
|
2015-11-04 00:36:59 +03:00
|
|
|
Initialize
|
1997-01-09 16:12:14 +03:00
|
|
|
.Nm
|
1999-07-02 19:14:07 +04:00
|
|
|
by reading the contents of
|
1997-01-09 16:12:14 +03:00
|
|
|
.Fa file .
|
|
|
|
.Fn el_parse
|
|
|
|
is called for each line in
|
|
|
|
.Fa file .
|
|
|
|
If
|
|
|
|
.Fa file
|
|
|
|
is
|
|
|
|
.Dv NULL ,
|
|
|
|
try
|
2017-06-27 04:22:58 +03:00
|
|
|
.Pa $EDITRC
|
|
|
|
and if that is not set
|
1997-01-09 16:12:14 +03:00
|
|
|
.Pa $HOME/.editrc .
|
|
|
|
Refer to
|
|
|
|
.Xr editrc 5
|
|
|
|
for details on the format of
|
|
|
|
.Fa file .
|
2014-12-25 16:39:05 +03:00
|
|
|
.Fn el_source
|
|
|
|
returns 0 on success and \-1 on error.
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Fn el_resize
|
|
|
|
Must be called if the terminal size changes.
|
|
|
|
If
|
|
|
|
.Dv EL_SIGNAL
|
|
|
|
has been set with
|
|
|
|
.Fn el_set ,
|
|
|
|
then this is done automatically.
|
|
|
|
Otherwise, it's the responsibility of the application to call
|
|
|
|
.Fn el_resize
|
|
|
|
on the appropriate occasions.
|
2013-07-12 21:48:29 +04:00
|
|
|
.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.
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Fn el_line
|
|
|
|
Return the editing information for the current line in a
|
|
|
|
.Fa LineInfo
|
|
|
|
structure, which is defined as follows:
|
|
|
|
.Bd -literal
|
|
|
|
typedef struct lineinfo {
|
|
|
|
const char *buffer; /* address of buffer */
|
|
|
|
const char *cursor; /* address of cursor */
|
|
|
|
const char *lastchar; /* address of last character */
|
|
|
|
} LineInfo;
|
|
|
|
.Ed
|
2003-12-05 16:37:48 +03:00
|
|
|
.Pp
|
|
|
|
.Fa buffer
|
|
|
|
is not NUL terminated.
|
|
|
|
This function may be called after
|
|
|
|
.Fn el_gets
|
|
|
|
to obtain the
|
|
|
|
.Fa LineInfo
|
|
|
|
structure pertaining to line returned by that function,
|
|
|
|
and from within user defined functions added with
|
|
|
|
.Dv EL_ADDFN .
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Fn el_insertstr
|
|
|
|
Insert
|
|
|
|
.Fa str
|
|
|
|
into the line at the cursor.
|
2003-01-22 02:00:56 +03:00
|
|
|
Returns \-1 if
|
1997-01-09 16:12:14 +03:00
|
|
|
.Fa str
|
|
|
|
is empty or won't fit, and 0 otherwise.
|
|
|
|
.It Fn el_deletestr
|
|
|
|
Delete
|
2007-01-12 19:31:13 +03:00
|
|
|
.Fa count
|
1997-01-09 16:12:14 +03:00
|
|
|
characters before the cursor.
|
|
|
|
.El
|
|
|
|
.Sh HISTORY LIST FUNCTIONS
|
|
|
|
The history functions use a common data structure,
|
|
|
|
.Fa History ,
|
|
|
|
which is created by
|
|
|
|
.Fn history_init
|
|
|
|
and freed by
|
|
|
|
.Fn history_end .
|
|
|
|
.Pp
|
|
|
|
The following functions are available:
|
|
|
|
.Bl -tag -width 4n
|
|
|
|
.It Fn history_init
|
2015-11-04 00:36:59 +03:00
|
|
|
Initialize the history list, and return a data structure
|
2014-12-25 16:39:05 +03:00
|
|
|
to be used by all other history list functions, or
|
|
|
|
.Dv NULL
|
|
|
|
on failure.
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Fn history_end
|
|
|
|
Clean up and finish with
|
|
|
|
.Fa h ,
|
|
|
|
assumed to have been created with
|
|
|
|
.Fn history_init .
|
|
|
|
.It Fn history
|
|
|
|
Perform operation
|
|
|
|
.Fa op
|
|
|
|
on the history list, with optional arguments as needed by the
|
|
|
|
operation.
|
1997-10-14 19:05:49 +04:00
|
|
|
.Fa ev
|
|
|
|
is changed accordingly to operation.
|
1997-01-09 16:12:14 +03:00
|
|
|
The following values for
|
|
|
|
.Fa op
|
|
|
|
are supported, along with the required argument list:
|
|
|
|
.Bl -tag -width 4n
|
1998-05-20 05:05:27 +04:00
|
|
|
.It Dv H_SETSIZE , Fa "int size"
|
1997-01-09 16:12:14 +03:00
|
|
|
Set size of history to
|
|
|
|
.Fa size
|
|
|
|
elements.
|
1997-10-14 19:05:49 +04:00
|
|
|
.It Dv H_GETSIZE
|
|
|
|
Get number of events currently in history.
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Dv H_END
|
|
|
|
Cleans up and finishes with
|
|
|
|
.Fa h ,
|
|
|
|
assumed to be created with
|
|
|
|
.Fn history_init .
|
|
|
|
.It Dv H_CLEAR
|
|
|
|
Clear the history.
|
2009-04-12 00:48:26 +04:00
|
|
|
.It Dv H_FUNC , Fa "void *ptr" , Fa "history_gfun_t first" , \
|
|
|
|
Fa "history_gfun_t next" , Fa "history_gfun_t last" , \
|
|
|
|
Fa "history_gfun_t prev" , Fa "history_gfun_t curr" , \
|
|
|
|
Fa "history_sfun_t set" , Fa "history_vfun_t clear" , \
|
|
|
|
Fa "history_efun_t enter" , Fa "history_efun_t add"
|
1997-01-09 16:12:14 +03:00
|
|
|
Define functions to perform various history operations.
|
|
|
|
.Fa ptr
|
|
|
|
is the argument given to a function when it's invoked.
|
|
|
|
.It Dv H_FIRST
|
|
|
|
Return the first element in the history.
|
|
|
|
.It Dv H_LAST
|
|
|
|
Return the last element in the history.
|
|
|
|
.It Dv H_PREV
|
|
|
|
Return the previous element in the history.
|
GNU readline(3) regards history chronologically, that is, from the
perspective of the dawn of time, so "next" means "newer" and "previous"
means "older". Libedit, by contrast, uses reverse chronology and
regards history from the perspective of the present, such that "next"
means "longer ago" and "previous" means "not so long ago".
The following patch fixes previous_history() and next_history()
as proposed by Bastian Maerkisch.
But there is a related problem demonstrated by Bastian's regression
tests that his patch did not fix: next_history() can advance not
only to the newest entry, but beyond it, which core libedit cannot
do. So that feature must be implemented locally in readline.c.
With that, the last of Bastians tests is fixed, test_movement_direction().
This patch also improves libedit documentation to more clearly state
what "previous" and "next" mean. GNU readline documentation is
just as unclear, but we can't easily fix that since libedit doesn't
include its own readline.3 manual.
(Ingo Schwarze)
2016-05-10 00:27:55 +03:00
|
|
|
It is newer than the current one.
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Dv H_NEXT
|
|
|
|
Return the next element in the history.
|
GNU readline(3) regards history chronologically, that is, from the
perspective of the dawn of time, so "next" means "newer" and "previous"
means "older". Libedit, by contrast, uses reverse chronology and
regards history from the perspective of the present, such that "next"
means "longer ago" and "previous" means "not so long ago".
The following patch fixes previous_history() and next_history()
as proposed by Bastian Maerkisch.
But there is a related problem demonstrated by Bastian's regression
tests that his patch did not fix: next_history() can advance not
only to the newest entry, but beyond it, which core libedit cannot
do. So that feature must be implemented locally in readline.c.
With that, the last of Bastians tests is fixed, test_movement_direction().
This patch also improves libedit documentation to more clearly state
what "previous" and "next" mean. GNU readline documentation is
just as unclear, but we can't easily fix that since libedit doesn't
include its own readline.3 manual.
(Ingo Schwarze)
2016-05-10 00:27:55 +03:00
|
|
|
It is older than the current one.
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Dv H_CURR
|
|
|
|
Return the current element in the history.
|
2017-04-10 18:02:40 +03:00
|
|
|
.It Dv H_SET , Fa "int position"
|
1998-05-20 05:05:27 +04:00
|
|
|
Set the cursor to point to the requested element.
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Dv H_ADD , Fa "const char *str"
|
|
|
|
Append
|
|
|
|
.Fa str
|
2003-11-02 02:37:30 +03:00
|
|
|
to the current element of the history, or perform the
|
|
|
|
.Dv H_ENTER
|
2003-11-04 16:22:19 +03:00
|
|
|
operation with argument
|
2003-11-02 02:37:30 +03:00
|
|
|
.Fa str
|
|
|
|
if there is no current element.
|
1998-05-20 05:37:54 +04:00
|
|
|
.It Dv H_APPEND , Fa "const char *str"
|
|
|
|
Append
|
|
|
|
.Fa str
|
|
|
|
to the last new element of the history.
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Dv H_ENTER , Fa "const char *str"
|
|
|
|
Add
|
|
|
|
.Fa str
|
2016-02-24 21:28:54 +03:00
|
|
|
as a new element to the history and, if necessary,
|
1997-01-09 16:12:14 +03:00
|
|
|
removing the oldest entry to keep the list to the created size.
|
2003-01-22 02:00:56 +03:00
|
|
|
If
|
2003-01-21 21:40:23 +03:00
|
|
|
.Dv H_SETUNIQUE
|
2014-12-25 16:39:05 +03:00
|
|
|
has been called with a non-zero argument, the element
|
2003-01-21 21:40:23 +03:00
|
|
|
will not be entered into the history if its contents match
|
|
|
|
the ones of the current history element.
|
|
|
|
If the element is entered
|
|
|
|
.Fn history
|
2014-12-25 16:39:05 +03:00
|
|
|
returns 1; if it is ignored as a duplicate returns 0.
|
2003-01-21 21:40:23 +03:00
|
|
|
Finally
|
|
|
|
.Fn history
|
2003-01-22 02:00:56 +03:00
|
|
|
returns \-1 if an error occurred.
|
1997-01-09 16:12:14 +03:00
|
|
|
.It Dv H_PREV_STR , Fa "const char *str"
|
|
|
|
Return the closest previous event that starts with
|
|
|
|
.Fa str .
|
|
|
|
.It Dv H_NEXT_STR , Fa "const char *str"
|
|
|
|
Return the closest next event that starts with
|
|
|
|
.Fa str .
|
|
|
|
.It Dv H_PREV_EVENT , Fa "int e"
|
|
|
|
Return the previous event numbered
|
|
|
|
.Fa e .
|
|
|
|
.It Dv H_NEXT_EVENT , Fa "int e"
|
|
|
|
Return the next event numbered
|
|
|
|
.Fa e .
|
|
|
|
.It Dv H_LOAD , Fa "const char *file"
|
|
|
|
Load the history list stored in
|
|
|
|
.Fa file .
|
|
|
|
.It Dv H_SAVE , Fa "const char *file"
|
|
|
|
Save the history list to
|
|
|
|
.Fa file .
|
2014-05-11 05:05:17 +04:00
|
|
|
.It Dv H_SAVE_FP , Fa "FILE *fp"
|
|
|
|
Save the history list to the opened
|
|
|
|
.Ft FILE
|
2014-05-11 13:01:42 +04:00
|
|
|
pointer
|
|
|
|
.Fa fp .
|
2017-09-01 13:19:10 +03:00
|
|
|
.It Dv H_NSAVE_FP , Fa "size_t n" , Fa "FILE *fp"
|
2017-09-02 09:48:10 +03:00
|
|
|
Save the last
|
2017-09-01 13:19:10 +03:00
|
|
|
.Ft n
|
|
|
|
history entries to the opened
|
|
|
|
.Ft FILE
|
|
|
|
pointer
|
|
|
|
.Fa fp .
|
2003-01-21 21:40:23 +03:00
|
|
|
.It Dv H_SETUNIQUE , Fa "int unique"
|
2005-09-10 02:32:56 +04:00
|
|
|
Set flag that adjacent identical event strings should not be entered
|
|
|
|
into the history.
|
2003-01-21 21:40:23 +03:00
|
|
|
.It Dv H_GETUNIQUE
|
2005-09-10 02:32:56 +04:00
|
|
|
Retrieve the current setting if adjacent identical elements should
|
|
|
|
be entered into the history.
|
2007-01-12 19:31:13 +03:00
|
|
|
.It Dv H_DEL , Fa "int e"
|
2005-07-14 19:00:58 +04:00
|
|
|
Delete the event numbered
|
|
|
|
.Fa e .
|
|
|
|
This function is only provided for
|
2017-09-02 09:48:10 +03:00
|
|
|
.Nm readline
|
2005-07-14 19:00:58 +04:00
|
|
|
compatibility.
|
2005-07-14 19:02:37 +04:00
|
|
|
The caller is responsible for free'ing the string in the returned
|
2005-07-14 19:00:58 +04:00
|
|
|
.Fa HistEvent .
|
1997-01-09 16:12:14 +03:00
|
|
|
.El
|
1997-11-09 03:13:52 +03:00
|
|
|
.Pp
|
|
|
|
.Fn history
|
2017-07-04 00:28:48 +03:00
|
|
|
returns >= 0 if the operation
|
1997-11-09 03:13:52 +03:00
|
|
|
.Fa op
|
2002-10-01 23:03:15 +04:00
|
|
|
succeeds.
|
2003-01-22 02:00:56 +03:00
|
|
|
Otherwise, \-1 is returned and
|
1997-11-09 03:13:52 +03:00
|
|
|
.Fa ev
|
|
|
|
is updated to contain more details about the error.
|
1997-01-09 16:12:14 +03:00
|
|
|
.El
|
2003-12-05 16:37:48 +03:00
|
|
|
.Sh TOKENIZATION FUNCTIONS
|
|
|
|
The tokenization functions use a common data structure,
|
|
|
|
.Fa Tokenizer ,
|
|
|
|
which is created by
|
|
|
|
.Fn tok_init
|
|
|
|
and freed by
|
|
|
|
.Fn tok_end .
|
|
|
|
.Pp
|
|
|
|
The following functions are available:
|
|
|
|
.Bl -tag -width 4n
|
|
|
|
.It Fn tok_init
|
2015-11-04 00:36:59 +03:00
|
|
|
Initialize the tokenizer, and return a data structure
|
2003-12-05 16:37:48 +03:00
|
|
|
to be used by all other tokenizer functions.
|
|
|
|
.Fa IFS
|
|
|
|
contains the Input Field Separators, which defaults to
|
2003-12-05 16:46:39 +03:00
|
|
|
.Aq space ,
|
|
|
|
.Aq tab ,
|
|
|
|
and
|
|
|
|
.Aq newline
|
|
|
|
if
|
2003-12-05 16:37:48 +03:00
|
|
|
.Dv NULL .
|
|
|
|
.It Fn tok_end
|
|
|
|
Clean up and finish with
|
|
|
|
.Fa t ,
|
|
|
|
assumed to have been created with
|
|
|
|
.Fn tok_init .
|
|
|
|
.It Fn tok_reset
|
|
|
|
Reset the tokenizer state.
|
|
|
|
Use after a line has been successfully tokenized
|
|
|
|
by
|
|
|
|
.Fn tok_line
|
|
|
|
or
|
|
|
|
.Fn tok_str
|
|
|
|
and before a new line is to be tokenized.
|
|
|
|
.It Fn tok_line
|
|
|
|
Tokenize
|
|
|
|
.Fa li ,
|
|
|
|
If successful, modify:
|
|
|
|
.Fa argv
|
|
|
|
to contain the words,
|
|
|
|
.Fa argc
|
|
|
|
to contain the number of words,
|
|
|
|
.Fa cursorc
|
|
|
|
(if not
|
|
|
|
.Dv NULL )
|
|
|
|
to contain the index of the word containing the cursor,
|
|
|
|
and
|
|
|
|
.Fa cursoro
|
|
|
|
(if not
|
|
|
|
.Dv NULL )
|
|
|
|
to contain the offset within
|
|
|
|
.Fa argv[cursorc]
|
|
|
|
of the cursor.
|
|
|
|
.Pp
|
|
|
|
Returns
|
|
|
|
0 if successful,
|
2003-12-05 16:46:39 +03:00
|
|
|
\-1 for an internal error,
|
2003-12-05 16:37:48 +03:00
|
|
|
1 for an unmatched single quote,
|
|
|
|
2 for an unmatched double quote,
|
|
|
|
and
|
2003-12-05 16:46:39 +03:00
|
|
|
3 for a backslash quoted
|
|
|
|
.Aq newline .
|
2003-12-05 16:37:48 +03:00
|
|
|
A positive exit code indicates that another line should be read
|
|
|
|
and tokenization attempted again.
|
|
|
|
.
|
|
|
|
.It Fn tok_str
|
2003-12-05 16:46:39 +03:00
|
|
|
A simpler form of
|
2003-12-05 16:37:48 +03:00
|
|
|
.Fn tok_line ;
|
|
|
|
.Fa str
|
|
|
|
is a NUL terminated string to tokenize.
|
|
|
|
.El
|
|
|
|
.
|
1997-01-09 16:12:14 +03:00
|
|
|
.\"XXX.Sh EXAMPLES
|
|
|
|
.\"XXX: provide some examples
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr sh 1 ,
|
|
|
|
.Xr signal 3 ,
|
2001-10-04 04:45:19 +04:00
|
|
|
.Xr termcap 3 ,
|
2006-12-18 03:03:43 +03:00
|
|
|
.Xr editrc 5 ,
|
2016-04-28 18:50:33 +03:00
|
|
|
.Xr termcap 5 ,
|
|
|
|
.Xr editline 7
|
1997-01-09 16:12:14 +03:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
library first appeared in
|
1997-01-11 09:47:47 +03:00
|
|
|
.Bx 4.4 .
|
1999-11-12 04:05:07 +03:00
|
|
|
.Dv CC_REDISPLAY
|
|
|
|
appeared in
|
|
|
|
.Nx 1.3 .
|
|
|
|
.Dv CC_REFRESH_BEEP ,
|
|
|
|
.Dv EL_EDITMODE
|
|
|
|
and the readline emulation appeared in
|
|
|
|
.Nx 1.4 .
|
|
|
|
.Dv EL_RPROMPT
|
|
|
|
appeared in
|
|
|
|
.Nx 1.5 .
|
1997-01-09 16:12:14 +03:00
|
|
|
.Sh AUTHORS
|
2014-05-11 13:01:42 +04:00
|
|
|
.An -nosplit
|
1997-01-09 16:12:14 +03:00
|
|
|
The
|
|
|
|
.Nm
|
2014-05-11 13:01:42 +04:00
|
|
|
library was written by
|
|
|
|
.An Christos Zoulas .
|
|
|
|
.An Luke Mewburn
|
|
|
|
wrote this manual and implemented
|
1999-11-12 04:05:07 +03:00
|
|
|
.Dv CC_REDISPLAY ,
|
1999-11-26 21:38:27 +03:00
|
|
|
.Dv CC_REFRESH_BEEP ,
|
1999-11-12 04:05:07 +03:00
|
|
|
.Dv EL_EDITMODE ,
|
|
|
|
and
|
|
|
|
.Dv EL_RPROMPT .
|
2014-05-11 13:01:42 +04:00
|
|
|
.An Jaromir Dolecek
|
|
|
|
implemented the readline emulation.
|
|
|
|
.An Johny Mattsson
|
|
|
|
implemented wide-character support.
|
1997-01-09 16:12:14 +03:00
|
|
|
.Sh BUGS
|
1998-07-29 06:26:00 +04:00
|
|
|
At this time, it is the responsibility of the caller to
|
|
|
|
check the result of the
|
|
|
|
.Dv EL_EDITMODE
|
|
|
|
operation of
|
|
|
|
.Fn el_get
|
|
|
|
(after an
|
|
|
|
.Fn el_source
|
|
|
|
or
|
|
|
|
.Fn el_parse )
|
|
|
|
to determine if
|
|
|
|
.Nm
|
|
|
|
should be used for further input.
|
|
|
|
I.e.,
|
|
|
|
.Dv EL_EDITMODE
|
|
|
|
is purely an indication of the result of the most recent
|
|
|
|
.Xr editrc 5
|
|
|
|
.Ic edit
|
|
|
|
command.
|