EditLine
*
el_init(
const char *prog
, FILE *fin
, FILE *fout
, FILE *ferr
)
void
el_end(
EditLine *e
)
void
el_reset(
EditLine *e
)
const
char
*
el_gets(
EditLine *e
, int *count
)
int
el_getc(
EditLine *e
, char *ch
)
void
el_push(
EditLine *e
, const char *str
)
int
el_parse(
EditLine *e
, int argc
, const char *argv[]
)
int
el_set(
EditLine *e
, int op
, ...
)
int
el_get(
EditLine *e
, int op
, ...
)
int
el_source(
EditLine *e
, const char *file
)
void
el_resize(
EditLine *e
)
const
LineInfo
*
el_line(
EditLine *e
)
int
el_insertstr(
EditLine *e
, const char *str
)
void
el_deletestr(
EditLine *e
, int count
)
History
*
history_init(
)
void
history_end(
History *h
)
int
history(
History *h
, HistEvent *ev
, int op
, ...
)
Tokenizer
*
tok_init(
const char *IFS
)
void
tok_end(
Tokenizer *t
)
void
tok_reset(
Tokenizer *t
)
int
tok_line(
Tokenizer *t
, const LineInfo *li
, int *argc
, const char **argv[]
, int *cursorc
, int *cursoro
)
int
tok_str(
Tokenizer *t
, const char *str
, int *argc
, const char **argv[]
)
These functions are available in the libedit library (which needs the libtermcap library). Programs should be linked with -ledit ltermcap.
EditLine
,
which is created by
el_init(
)
and freed by
el_end(
).
The following functions are available:
)
prog
is the name of the invoking program, used when reading the
editrc(5)
file to determine which settings to use.
fin
,
fout
and
ferr
are the input, output, and error streams (respectively) to use.
In this documentation, references to
``the tty''
are actually to this input/output stream combination.
)
e
,
assumed to have been created with
el_init(
).
)
)
count
is modified to contain the number of characters read.
Returns the line read if successful, or
NULL
if no characters were read or if an error occurred.
)
ch
is modified to contain the character read.
Returns the number of characters read if successful, -1 otherwise.
)
str
back onto the input stream.
This is used by the macro expansion mechanism.
Refer to the description of
bind
-s
in
editrc(5)
for more information.
)
argv
array (which is
argc
elements in size)
to execute builtin
editline
commands.
If the command is prefixed with
``prog'':
then
el_parse(
)
will only execute the command if
``prog''
matches the
prog
argument supplied to
el_init(
).
The return value is
-1 if the command is unknown,
0 if there was no error or
``prog''
didn't match, or
1 if the command returned an error.
Refer to
editrc(5)
for more information.
)
op
determines which parameter to set, and each operation has its
own parameter list.
The following values for
op
are supported, along with the required argument list:
EL_PROMPT
, char *(*f)(EditLine *)
f
,
which is to return a string that contains the prompt.
EL_REFRESH
EL_RPROMPT
, char *(*f)(EditLine *)
f
,
which is to return a string that contains the prompt.
EL_TERMINAL
, const char *type
type
,
or to
TERM
if
type
is
NULL
.
EL_EDITOR
, const char *mode
mode
,
which must be one of
``emacs''
or
``vi''.
EL_SIGNAL
, int flag
flag
is non-zero,
editline
will install its own signal handler for the following signals when
reading command input:
SIGCONT
,
SIGHUP
,
SIGINT
,
SIGQUIT
,
SIGSTOP
,
SIGTERM
,
SIGTSTP
,
and
SIGWINCH
.
Otherwise, the current signal handlers will be used.
EL_BIND
, Xo
const char *
,
...
,
NULL
Perform the
bind
builtin command.
Refer to
editrc(5)
for more information.
EL_ECHOTC
, Xo
const char *
,
...
,
NULL
Perform the
echotc
builtin command.
Refer to
editrc(5)
for more information.
EL_SETTC
, Xo
const char *
,
...
,
NULL
Perform the
settc
builtin command.
Refer to
editrc(5)
for more information.
EL_SETTY
, Xo
const char *
,
...
,
NULL
Perform the
setty
builtin command.
Refer to
editrc(5)
for more information.
EL_TELLTC
, Xo
const char *
,
...
,
NULL
Perform the
telltc
builtin command.
Refer to
editrc(5)
for more information.
EL_ADDFN
, Xo
const char *name
,
const char *help
,
unsigned char (*func)(EditLine *e, int ch)
Add a user defined function,
func(
),
referred to as
name
which is invoked when a key which is bound to
name
is entered.
help
is a description of
name
.
At invocation time,
ch
is the key which caused the invocation.
The return value of
func(
)
should be one of:
CC_NORM
CC_NEWLINE
CC_EOF
CC_ARGHACK
CC_REFRESH
CC_REFRESH_BEEP
CC_CURSOR
CC_REFRESH
.
CC_REDISPLAY
CC_ERROR
CC_FATAL
EL_HIST
, Xo
History *(*func)(History *, int op, ...)
,
const char *ptr
Defines which history function to use, which is usually
history(
).
ptr
should be the value returned by
history_init(
).
EL_EDITMODE
, int flag
flag
is non-zero,
editing is enabled (the default).
Note that this is only an indication, and does not
affect the operation of
.
At this time, it is the caller's responsibility to
check this
(using
el_get(
))
to determine if editing should be enabled or not.
EL_GETCFN
, int (*f)(EditLine *, char *c)
f
,
which is to return the number of characters read and store them in
c
.
This function is called internally by
el_gets(
)
and
el_getc(
).
The builtin function can be set or restored with the special function
name ``EL_BUILTIN_GETCFN''.
EL_CLIENTDATA
, void *data
data
to be associated with this EditLine structure.
It can be retrieved with the corresponding
el_get(
)
call.
EL_SETFP
, int fd
, FILE *fp
fd
=
0
,
``output''
fd
=
1
,
or
``error''
fd
=
2
from
fp
.
)
op
determines which parameter to retrieve into
result
.
Returns 0 if successful, -1 otherwise.
The following values for
op
are supported, along with actual type of
result
:
EL_PROMPT
, char *(*f)(EditLine *)
EL_RPROMPT
, char *(*f)(EditLine *)
EL_EDITOR
, const char *
EL_GETTC
, const char *name
, void *value
name
is a valid
termcap(5)
capability
and set
value
to the current value of that capability.
EL_SIGNAL
, int *
)
above).
EL_EDITMODE
, int *
EL_GETCFN
, int (**f)(EditLine *, char *)
EL_CLIENTDATA
, void **data
data
previously registered with the corresponding
el_set(
)
call.
EL_UNBUFFERED
, int
)
will return immediately after processing a single character.
EL_PREP_TERM
, int
EL_GETFP
, int fd
, FILE **fp
fp
the current
editline
file pointer for
``input''
fd
=
0
,
``output''
fd
=
1
,
or
``error''
fd
=
2
.
)
file
.
el_parse(
)
is called for each line in
file
.
If
file
is
NULL
,
try
$PWD/.editrc
then
$HOME/.editrc
.
Refer to
editrc(5)
for details on the format of
file
.
)
EL_SIGNAL
has been set with
el_set(
),
then this is done automatically.
Otherwise, it's the responsibility of the application to call
el_resize(
)
on the appropriate occasions.
)
LineInfo
structure, which is defined as follows:
typedef struct lineinfo {
const char *buffer; /* address of buffer */
const char *cursor; /* address of cursor */
const char *lastchar; /* address of last character */
} LineInfo;
buffer
is not NUL terminated.
This function may be called after
el_gets()
to obtain the
LineInfo
structure pertaining to line returned by that function,
and from within user defined functions added with
EL_ADDFN
.
)
str
into the line at the cursor.
Returns -1 if
str
is empty or won't fit, and 0 otherwise.
)
count
characters before the cursor.
History
,
which is created by
history_init(
)
and freed by
history_end(
).
The following functions are available:
)
)
h
,
assumed to have been created with
history_init(
).
)
op
on the history list, with optional arguments as needed by the
operation.
ev
is changed accordingly to operation.
The following values for
op
are supported, along with the required argument list:
H_SETSIZE
, int size
size
elements.
H_GETSIZE
H_END
h
,
assumed to be created with
history_init(
).
H_CLEAR
H_FUNC
, Xo
void *ptr
,
history_gfun_t first
,
history_gfun_t next
,
history_gfun_t last
,
history_gfun_t prev
,
history_gfun_t curr
,
history_sfun_t set
,
history_vfun_t clear
,
history_efun_t enter
,
history_efun_t add
Define functions to perform various history operations.
ptr
is the argument given to a function when it's invoked.
H_FIRST
H_LAST
H_PREV
H_NEXT
H_CURR
H_SET
H_ADD
, const char *str
str
to the current element of the history, or perform the
H_ENTER
operation with argument
str
if there is no current element.
H_APPEND
, const char *str
str
to the last new element of the history.
H_ENTER
, const char *str
str
as a new element to the history, and, if necessary,
removing the oldest entry to keep the list to the created size.
If
H_SETUNIQUE
was has been called with a non-zero arguments, the element
will not be entered into the history if its contents match
the ones of the current history element.
If the element is entered
history(
)
returns 1, if it is ignored as a duplicate returns 0.
Finally
history(
)
returns -1 if an error occurred.
H_PREV_STR
, const char *str
str
.
H_NEXT_STR
, const char *str
str
.
H_PREV_EVENT
, int e
e
.
H_NEXT_EVENT
, int e
e
.
H_LOAD
, const char *file
file
.
H_SAVE
, const char *file
file
.
H_SETUNIQUE
, int unique
H_GETUNIQUE
H_DEL
, int e
e
.
This function is only provided for
readline(3)
compatibility.
The caller is responsible for free'ing the string in the returned
HistEvent
.
history()
returns >= 0 if the operation
op
succeeds.
Otherwise, -1 is returned and
ev
is updated to contain more details about the error.
Tokenizer
,
which is created by
tok_init(
)
and freed by
tok_end(
).
The following functions are available:
)
IFS
contains the Input Field Separators, which defaults to
<space>,
<tab>,
and
<newline>
if
NULL
.
)
t
,
assumed to have been created with
tok_init(
).
)
)
or
tok_str(
)
and before a new line is to be tokenized.
)
li
,
If successful, modify:
argv
to contain the words,
argc
to contain the number of words,
cursorc
(if not
NULL
)
to contain the index of the word containing the cursor,
and
cursoro
(if not
NULL
)
to contain the offset within
argv[cursorc]
of the cursor.
Returns 0 if successful, -1 for an internal error, 1 for an unmatched single quote, 2 for an unmatched double quote, and 3 for a backslash quoted <newline>. A positive exit code indicates that another line should be read and tokenization attempted again.
)
);
str
is a NUL terminated string to tokenize.
CC_REDISPLAY
appeared in
NetBSD1.3.
CC_REFRESH_BEEP
,
EL_EDITMODE
and the readline emulation appeared in
NetBSD1.4.
EL_RPROMPT
appeared in
NetBSD1.5.
CC_REDISPLAY
,
CC_REFRESH_BEEP
,
EL_EDITMODE
,
and
EL_RPROMPT
.
Jaromir Dolecek implemented the readline emulation.
EL_EDITMODE
operation of
el_get(
)
(after an
el_source(
)
or
el_parse(
))
to determine if
editline
should be used for further input.
I.e.,
EL_EDITMODE
is purely an indication of the result of the most recent
editrc(5)
edit
command.