jpayne@68: .TH EDITLINE 3 "August 15, 2021" "" jpayne@68: .SH NAME jpayne@68: \fBeditline\fP, jpayne@68: \fBel_init\fP, jpayne@68: \fBel_init_fd\fP, jpayne@68: \fBel_end\fP, jpayne@68: \fBel_reset\fP, jpayne@68: \fBel_gets\fP, jpayne@68: \fBel_wgets\fP, jpayne@68: \fBel_getc\fP, jpayne@68: \fBel_wgetc\fP, jpayne@68: \fBel_push\fP, jpayne@68: \fBel_wpush\fP, jpayne@68: \fBel_parse\fP, jpayne@68: \fBel_wparse\fP, jpayne@68: \fBel_set\fP, jpayne@68: \fBel_wset\fP, jpayne@68: \fBel_get\fP, jpayne@68: \fBel_wget\fP, jpayne@68: \fBel_source\fP, jpayne@68: \fBel_resize\fP, jpayne@68: \fBel_cursor\fP, jpayne@68: \fBel_line\fP, jpayne@68: \fBel_wline\fP, jpayne@68: \fBel_insertstr\fP, jpayne@68: \fBel_winsertstr\fP, jpayne@68: \fBel_deletestr\fP, jpayne@68: \fBel_wdeletestr\fP, jpayne@68: \fBhistory_init\fP, jpayne@68: \fBhistory_winit\fP, jpayne@68: \fBhistory_end\fP, jpayne@68: \fBhistory_wend\fP, jpayne@68: \fBhistory\fP, jpayne@68: \fBhistory_w\fP, jpayne@68: \fBtok_init\fP, jpayne@68: \fBtok_winit\fP, jpayne@68: \fBtok_end\fP, jpayne@68: \fBtok_wend\fP, jpayne@68: \fBtok_reset\fP, jpayne@68: \fBtok_wreset\fP, jpayne@68: \fBtok_line\fP, jpayne@68: \fBtok_wline\fP, jpayne@68: \fBtok_str\fP, jpayne@68: \fBtok_wstr\fP jpayne@68: \- line editor, history and tokenization functions jpayne@68: .SH LIBRARY jpayne@68: Command Line Editor Library (libedit, -ledit) jpayne@68: .SH SYNOPSIS jpayne@68: .PP jpayne@68: \fB#include \fP jpayne@68: .PP jpayne@68: \fIEditLine *\fP jpayne@68: .br jpayne@68: \fBel_init\fP(\fIconst char *prog\fP, \fIFILE *fin\fP, \fIFILE *fout\fP, \fIFILE *ferr\fP); jpayne@68: .PP jpayne@68: \fIEditLine *\fP jpayne@68: .br jpayne@68: \fBel_init_fd\fP(\fIconst char *prog\fP, \fIFILE *fin\fP, \fIFILE *fout\fP, \fIFILE *ferr\fP, \fIint fdin\fP, \fIint fdout\fP, \fIint fderr\fP); jpayne@68: .PP jpayne@68: \fIvoid\fP jpayne@68: .br jpayne@68: \fBel_end\fP(\fIEditLine *e\fP); jpayne@68: .PP jpayne@68: \fIvoid\fP jpayne@68: .br jpayne@68: \fBel_reset\fP(\fIEditLine *e\fP); jpayne@68: .PP jpayne@68: \fIconst char *\fP jpayne@68: .br jpayne@68: \fBel_gets\fP(\fIEditLine *e\fP, \fIint *count\fP); jpayne@68: .PP jpayne@68: \fIconst wchar_t *\fP jpayne@68: .br jpayne@68: \fBel_wgets\fP(\fIEditLine *e\fP, \fIint *count\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBel_getc\fP(\fIEditLine *e\fP, \fIchar *ch\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBel_wgetc\fP(\fIEditLine *e\fP, \fIwchar_t *wc\fP); jpayne@68: .PP jpayne@68: \fIvoid\fP jpayne@68: .br jpayne@68: \fBel_push\fP(\fIEditLine *e\fP, \fIconst char *mbs\fP); jpayne@68: .PP jpayne@68: \fIvoid\fP jpayne@68: .br jpayne@68: \fBel_wpush\fP(\fIEditLine *e\fP, \fIconst wchar_t *wcs\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBel_parse\fP(\fIEditLine *e\fP, \fIint argc\fP, \fIconst char *argv[]\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBel_wparse\fP(\fIEditLine *e\fP, \fIint argc\fP, \fIconst wchar_t *argv[]\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBel_set\fP(\fIEditLine *e\fP, \fIint op\fP, \fI...\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBel_wset\fP(\fIEditLine *e\fP, \fIint op\fP, \fI...\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBel_get\fP(\fIEditLine *e\fP, \fIint op\fP, \fI...\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBel_wget\fP(\fIEditLine *e\fP, \fIint op\fP, \fI...\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBel_source\fP(\fIEditLine *e\fP, \fIconst char *file\fP); jpayne@68: .PP jpayne@68: \fIvoid\fP jpayne@68: .br jpayne@68: \fBel_resize\fP(\fIEditLine *e\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBel_cursor\fP(\fIEditLine *e\fP, \fIint count\fP); jpayne@68: .PP jpayne@68: \fIconst LineInfo *\fP jpayne@68: .br jpayne@68: \fBel_line\fP(\fIEditLine *e\fP); jpayne@68: .PP jpayne@68: \fIconst LineInfoW *\fP jpayne@68: .br jpayne@68: \fBel_wline\fP(\fIEditLine *e\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBel_insertstr\fP(\fIEditLine *e\fP, \fIconst char *str\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBel_winsertstr\fP(\fIEditLine *e\fP, \fIconst wchar_t *str\fP); jpayne@68: .PP jpayne@68: \fIvoid\fP jpayne@68: .br jpayne@68: \fBel_deletestr\fP(\fIEditLine *e\fP, \fIint count\fP); jpayne@68: .PP jpayne@68: \fIvoid\fP jpayne@68: .br jpayne@68: \fBel_wdeletestr\fP(\fIEditLine *e\fP, \fIint count\fP); jpayne@68: .PP jpayne@68: \fIHistory *\fP jpayne@68: .br jpayne@68: \fBhistory_init\fP(void ); jpayne@68: .PP jpayne@68: \fIHistoryW *\fP jpayne@68: .br jpayne@68: \fBhistory_winit\fP(void ); jpayne@68: .PP jpayne@68: \fIvoid\fP jpayne@68: .br jpayne@68: \fBhistory_end\fP(\fIHistory *h\fP); jpayne@68: .PP jpayne@68: \fIvoid\fP jpayne@68: .br jpayne@68: \fBhistory_wend\fP(\fIHistoryW *h\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBhistory\fP(\fIHistory *h\fP, \fIHistEvent *ev\fP, \fIint op\fP, \fI...\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBhistory_w\fP(\fIHistoryW *h\fP, \fIHistEventW *ev\fP, \fIint op\fP, \fI...\fP); jpayne@68: .PP jpayne@68: \fITokenizer *\fP jpayne@68: .br jpayne@68: \fBtok_init\fP(\fIconst char *IFS\fP); jpayne@68: .PP jpayne@68: \fITokenizerW *\fP jpayne@68: .br jpayne@68: \fBtok_winit\fP(\fIconst wchar_t *IFS\fP); jpayne@68: .PP jpayne@68: \fIvoid\fP jpayne@68: .br jpayne@68: \fBtok_end\fP(\fITokenizer *t\fP); jpayne@68: .PP jpayne@68: \fIvoid\fP jpayne@68: .br jpayne@68: \fBtok_wend\fP(\fITokenizerW *t\fP); jpayne@68: .PP jpayne@68: \fIvoid\fP jpayne@68: .br jpayne@68: \fBtok_reset\fP(\fITokenizer *t\fP); jpayne@68: .PP jpayne@68: \fIvoid\fP jpayne@68: .br jpayne@68: \fBtok_wreset\fP(\fITokenizerW *t\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBtok_line\fP(\fITokenizer *t\fP, \fIconst LineInfo *li\fP, \fIint *argc\fP, \fIconst char **argv[]\fP, \fIint *cursorc\fP, \fIint *cursoro\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBtok_wline\fP(\fITokenizerW *t\fP, \fIconst LineInfoW *li\fP, \fIint *argc\fP, \fIconst wchar_t **argv[]\fP, \fIint *cursorc\fP, \fIint *cursoro\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBtok_str\fP(\fITokenizer *t\fP, \fIconst char *str\fP, \fIint *argc\fP, \fIconst char **argv[]\fP); jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: \fBtok_wstr\fP(\fITokenizerW *t\fP, \fIconst wchar_t *str\fP, \fIint *argc\fP, \fIconst wchar_t **argv[]\fP); jpayne@68: .SH DESCRIPTION jpayne@68: The jpayne@68: \fBeditline\fP jpayne@68: library provides generic line editing, history and tokenization functions, jpayne@68: similar to those found in jpayne@68: \fBsh\fP(1). jpayne@68: jpayne@68: These functions are available in the jpayne@68: \fBlibedit\fP jpayne@68: library (which needs the jpayne@68: \fBlibtermcap\fP jpayne@68: library). jpayne@68: Programs should be linked with jpayne@68: \fB\-ledit\fP ltermcap . jpayne@68: jpayne@68: The jpayne@68: \fBeditline\fP jpayne@68: library respects the jpayne@68: .IR LC_CTYPE jpayne@68: locale set by the application program and never uses jpayne@68: \fBsetlocale\fP(3) jpayne@68: to change the locale. jpayne@68: .SH LINE EDITING FUNCTIONS jpayne@68: The line editing functions use a common data structure, jpayne@68: \fIEditLine\fP, jpayne@68: which is created by jpayne@68: \fBel_init\fP() jpayne@68: or jpayne@68: \fBel_init_fd\fP() jpayne@68: and freed by jpayne@68: \fBel_end\fP(). jpayne@68: jpayne@68: The wide-character functions behave the same way as their narrow jpayne@68: counterparts. jpayne@68: jpayne@68: The following functions are available: jpayne@68: .TP jpayne@68: \fBel_init\fP() jpayne@68: Initialize the line editor, and return a data structure jpayne@68: to be used by all other line editing functions, or jpayne@68: NULL jpayne@68: on failure. jpayne@68: \fIprog \fP jpayne@68: is the name of the invoking program, used when reading the jpayne@68: \fBeditrc\fP(5) jpayne@68: file to determine which settings to use. jpayne@68: \fIfin\fP, jpayne@68: \fIfout \fP jpayne@68: and jpayne@68: \fIferr \fP jpayne@68: are the input, output, and error streams (respectively) to use. jpayne@68: In this documentation, references to jpayne@68: ``the tty'' jpayne@68: are actually to this input/output stream combination. jpayne@68: .TP jpayne@68: \fBel_init_fd\fP() jpayne@68: Like jpayne@68: \fBel_init\fP() jpayne@68: but allows specifying file descriptors for the jpayne@68: \fBstdio\fP(3) jpayne@68: corresponding streams, in case those were created with jpayne@68: \fBfunopen\fP(3). jpayne@68: .TP jpayne@68: \fBel_end\fP() jpayne@68: Clean up and finish with jpayne@68: \fIe\fP, jpayne@68: assumed to have been created with jpayne@68: \fBel_init\fP() jpayne@68: or jpayne@68: \fBel_init_fd\fP(). jpayne@68: .TP jpayne@68: \fBel_reset\fP() jpayne@68: Reset the tty and the parser. jpayne@68: This should be called after an error which may have upset the tty's jpayne@68: state. jpayne@68: .TP jpayne@68: \fBel_gets\fP() jpayne@68: Read a line from the tty. jpayne@68: \fIcount \fP jpayne@68: is modified to contain the number of characters read. jpayne@68: Returns the line read if successful, or jpayne@68: NULL jpayne@68: if no characters were read or if an error occurred. jpayne@68: If an error occurred, jpayne@68: \fIcount \fP jpayne@68: is set to \-1 and jpayne@68: errno jpayne@68: contains the error code that caused it. jpayne@68: The return value may not remain valid across calls to jpayne@68: \fBel_gets\fP() jpayne@68: and must be copied if the data is to be retained. jpayne@68: .TP jpayne@68: \fBel_wgetc\fP() jpayne@68: Read a wide character from the tty, respecting the current locale, jpayne@68: or from the input queue described in jpayne@68: \fBeditline\fP(7) jpayne@68: if that is not empty, and store it in jpayne@68: \fIwc\fP. jpayne@68: If an invalid or incomplete character is found, it is discarded, jpayne@68: \fIerrno\fP jpayne@68: is set to jpayne@68: Er EILSEQ , jpayne@68: and the next character is read and stored in jpayne@68: \fIwc\fP. jpayne@68: Returns 1 if a valid character was read, 0 on end of file, or \-1 on jpayne@68: \fBread\fP(2) jpayne@68: failure. jpayne@68: In the latter case, jpayne@68: \fIerrno\fP jpayne@68: is set to indicate the error. jpayne@68: .TP jpayne@68: \fBel_getc\fP() jpayne@68: Read a wide character as described for jpayne@68: \fBel_wgetc\fP() jpayne@68: and return 0 on end of file or \-1 on failure. jpayne@68: If the wide character can be represented as a single-byte character, jpayne@68: convert it with jpayne@68: \fBwctob\fP(3), jpayne@68: store the result in jpayne@68: \fIch\fP, jpayne@68: and return 1; otherwise, set jpayne@68: \fIerrno\fP jpayne@68: to jpayne@68: Er ERANGE jpayne@68: and return \-1. jpayne@68: In the C or POSIX locale, this simply reads a byte, but for any other jpayne@68: locale, including UTF-8, this is rarely useful. jpayne@68: .TP jpayne@68: \fBel_wpush\fP() jpayne@68: Push the wide character string jpayne@68: \fIwcs \fP jpayne@68: back onto the input queue described in jpayne@68: \fBeditline\fP(7). jpayne@68: If the queue overflows, for example due to a recursive macro, jpayne@68: or if an error occurs, for example because jpayne@68: \fIwcs \fP jpayne@68: is jpayne@68: NULL jpayne@68: or memory allocation fails, the function beeps at the user, jpayne@68: but does not report the problem to the caller. jpayne@68: .TP jpayne@68: \fBel_push\fP() jpayne@68: Use the current locale to convert the multibyte string jpayne@68: \fImbs \fP jpayne@68: to a wide character string, and pass the result to jpayne@68: \fBel_wpush\fP(). jpayne@68: .TP jpayne@68: \fBel_parse\fP() jpayne@68: Parses the jpayne@68: \fIargv \fP jpayne@68: array (which is jpayne@68: \fIargc \fP jpayne@68: elements in size) jpayne@68: to execute builtin jpayne@68: \fBeditline\fP jpayne@68: commands. jpayne@68: If the command is prefixed with jpayne@68: ``prog :'' jpayne@68: then jpayne@68: \fBel_parse\fP() jpayne@68: will only execute the command if jpayne@68: ``prog'' jpayne@68: matches the jpayne@68: \fIprog \fP jpayne@68: argument supplied to jpayne@68: \fBel_init\fP(). jpayne@68: The return value is jpayne@68: \-1 if the command is unknown, jpayne@68: 0 if there was no error or jpayne@68: ``prog'' jpayne@68: didn't match, or jpayne@68: 1 if the command returned an error. jpayne@68: Refer to jpayne@68: \fBeditrc\fP(5) jpayne@68: for more information. jpayne@68: .TP jpayne@68: \fBel_set\fP() jpayne@68: Set jpayne@68: \fBeditline\fP jpayne@68: parameters. jpayne@68: \fIop \fP jpayne@68: determines which parameter to set, and each operation has its jpayne@68: own parameter list. jpayne@68: Returns 0 on success, \-1 on failure. jpayne@68: jpayne@68: The following values for jpayne@68: \fIop \fP jpayne@68: are supported, along with the required argument list: jpayne@68: .RS jpayne@68: .TP jpayne@68: EL_PROMPT , \fIchar *(*f)(EditLine *)\fP jpayne@68: Define prompt printing function as jpayne@68: \fIf\fP, jpayne@68: which is to return a string that contains the prompt. jpayne@68: .TP jpayne@68: EL_PROMPT_ESC , \fIchar *(*f)(EditLine *), Fa char c\fP jpayne@68: Same as jpayne@68: EL_PROMPT , jpayne@68: but the jpayne@68: \fIc \fP jpayne@68: argument indicates the start/stop literal prompt character. jpayne@68: jpayne@68: If a start/stop literal character is found in the prompt, the jpayne@68: character itself jpayne@68: is not printed, but characters after it are printed directly to the jpayne@68: terminal without affecting the state of the current line. jpayne@68: A subsequent second start/stop literal character ends this behavior. jpayne@68: This is typically used to embed literal escape sequences that change the jpayne@68: color/style of the terminal in the prompt. jpayne@68: Note that the literal escape character cannot be the last character in the jpayne@68: prompt, as the escape sequence is attached to the next character in the prompt. jpayne@68: 0 jpayne@68: unsets it. jpayne@68: .TP jpayne@68: EL_REFRESH jpayne@68: Re-display the current line on the next terminal line. jpayne@68: .TP jpayne@68: EL_RPROMPT , \fIchar *(*f)(EditLine *)\fP jpayne@68: Define right side prompt printing function as jpayne@68: \fIf\fP, jpayne@68: which is to return a string that contains the prompt. jpayne@68: .TP jpayne@68: EL_RPROMPT_ESC , \fIchar *(*f)(EditLine *), Fa char c\fP jpayne@68: Define the right prompt printing function but with a literal escape character. jpayne@68: .TP jpayne@68: EL_TERMINAL , \fIconst char *type\fP jpayne@68: Define terminal type of the tty to be jpayne@68: \fItype\fP, jpayne@68: or to jpayne@68: .IR TERM jpayne@68: if jpayne@68: \fItype \fP jpayne@68: is jpayne@68: NULL . jpayne@68: .TP jpayne@68: EL_EDITOR , \fIconst char *mode\fP jpayne@68: Set editing mode to jpayne@68: \fImode\fP, jpayne@68: which must be one of jpayne@68: ``emacs'' jpayne@68: or jpayne@68: ``vi''. jpayne@68: .TP jpayne@68: EL_SIGNAL , \fIint flag\fP jpayne@68: If jpayne@68: \fIflag \fP jpayne@68: is non-zero, jpayne@68: \fBeditline\fP jpayne@68: will install its own signal handler for the following signals when jpayne@68: reading command input: jpayne@68: SIGCONT , jpayne@68: SIGHUP , jpayne@68: SIGINT , jpayne@68: SIGQUIT , jpayne@68: SIGSTOP , jpayne@68: SIGTERM , jpayne@68: SIGTSTP , jpayne@68: and jpayne@68: SIGWINCH . jpayne@68: Otherwise, the current signal handlers will be used. jpayne@68: .TP jpayne@68: EL_BIND , \fIconst char *, Fa ..., Dv NULL \fP jpayne@68: Perform the jpayne@68: \fBbind\fP jpayne@68: builtin command. jpayne@68: Refer to jpayne@68: \fBeditrc\fP(5) jpayne@68: for more information. jpayne@68: .TP jpayne@68: EL_ECHOTC , \fIconst char *, Fa ..., Dv NULL \fP jpayne@68: Perform the jpayne@68: \fBechotc\fP jpayne@68: builtin command. jpayne@68: Refer to jpayne@68: \fBeditrc\fP(5) jpayne@68: for more information. jpayne@68: .TP jpayne@68: EL_SETTC , \fIconst char *, Fa ..., Dv NULL \fP jpayne@68: Perform the jpayne@68: \fBsettc\fP jpayne@68: builtin command. jpayne@68: Refer to jpayne@68: \fBeditrc\fP(5) jpayne@68: for more information. jpayne@68: .TP jpayne@68: EL_SETTY , \fIconst char *, Fa ..., Dv NULL \fP jpayne@68: Perform the jpayne@68: \fBsetty\fP jpayne@68: builtin command. jpayne@68: Refer to jpayne@68: \fBeditrc\fP(5) jpayne@68: for more information. jpayne@68: .TP jpayne@68: EL_TELLTC , \fIconst char *, Fa ..., Dv NULL \fP jpayne@68: Perform the jpayne@68: \fBtelltc\fP jpayne@68: builtin command. jpayne@68: Refer to jpayne@68: \fBeditrc\fP(5) jpayne@68: for more information. jpayne@68: .TP jpayne@68: EL_ADDFN , \fIconst char *name, Fa const char *help, \ \fP jpayne@68: Fa "unsigned char (*func)(EditLine *e, int ch)" jpayne@68: Add a user defined function, jpayne@68: \fBfunc\fP(), jpayne@68: referred to as jpayne@68: \fIname \fP jpayne@68: which is invoked when a key which is bound to jpayne@68: \fIname \fP jpayne@68: is entered. jpayne@68: \fIhelp \fP jpayne@68: is a description of jpayne@68: \fIname\fP. jpayne@68: At invocation time, jpayne@68: \fIch \fP jpayne@68: is the key which caused the invocation. jpayne@68: The return value of jpayne@68: \fBfunc\fP() jpayne@68: should be one of: jpayne@68: .RS jpayne@68: .TP jpayne@68: CC_NORM jpayne@68: Add a normal character. jpayne@68: .TP jpayne@68: CC_NEWLINE jpayne@68: End of line was entered. jpayne@68: .TP jpayne@68: CC_EOF jpayne@68: EOF was entered. jpayne@68: .TP jpayne@68: CC_ARGHACK jpayne@68: Expecting further command input as arguments, do nothing visually. jpayne@68: .TP jpayne@68: CC_REFRESH jpayne@68: Refresh display. jpayne@68: .TP jpayne@68: CC_REFRESH_BEEP jpayne@68: Refresh display, and beep. jpayne@68: .TP jpayne@68: CC_CURSOR jpayne@68: Cursor moved, so update and perform jpayne@68: CC_REFRESH . jpayne@68: .TP jpayne@68: CC_REDISPLAY jpayne@68: Redisplay entire input line. jpayne@68: This is useful if a key binding outputs extra information. jpayne@68: .TP jpayne@68: CC_ERROR jpayne@68: An error occurred. jpayne@68: Beep, and flush tty. jpayne@68: .TP jpayne@68: CC_FATAL jpayne@68: Fatal error, reset tty to known state. jpayne@68: .RE jpayne@68: .TP jpayne@68: EL_HIST , \fIHistory *(*func)(History *, int op, ...), \ \fP jpayne@68: Fa "const char *ptr" jpayne@68: Defines which history function to use, which is usually jpayne@68: \fBhistory\fP(). jpayne@68: \fIptr \fP jpayne@68: should be the value returned by jpayne@68: \fBhistory_init\fP(). jpayne@68: .TP jpayne@68: EL_EDITMODE , \fIint flag\fP jpayne@68: If jpayne@68: \fIflag \fP jpayne@68: is non-zero, jpayne@68: editing is enabled (the default). jpayne@68: Note that this is only an indication, and does not jpayne@68: affect the operation of jpayne@68: \fB.\fP jpayne@68: At this time, it is the caller's responsibility to jpayne@68: check this jpayne@68: (using jpayne@68: \fBel_get\fP() ) jpayne@68: to determine if editing should be enabled or not. jpayne@68: .TP jpayne@68: EL_UNBUFFERED , \fIint flag\fP jpayne@68: If jpayne@68: \fIflag \fP jpayne@68: is zero, jpayne@68: unbuffered mode is disabled (the default). jpayne@68: In unbuffered mode, jpayne@68: \fBel_gets\fP() jpayne@68: will return immediately after processing a single character. jpayne@68: .TP jpayne@68: EL_SAFEREAD , \fIint flag\fP jpayne@68: If the jpayne@68: \fIflag \fP jpayne@68: argument is non-zero, then jpayne@68: \fBeditline\fP jpayne@68: attempts to recover from read errors, ignoring the first interrupted jpayne@68: error, and trying to reset the input file descriptor to reset non-blocking I/O. jpayne@68: This is disabled by default, and desirable only when jpayne@68: \fBeditline\fP jpayne@68: is used in shell-like applications. jpayne@68: .TP jpayne@68: EL_GETCFN , \fIel_rfunc_t f\fP jpayne@68: Whenever reading a character, use the function jpayne@68: -ragged -offset indent -compact jpayne@68: .PP jpayne@68: \fIint\fP jpayne@68: .br jpayne@68: Fo f jpayne@68: \fIEditLine *e\fP jpayne@68: \fIwchar_t *wc\fP jpayne@68: Fc jpayne@68: which stores the character in jpayne@68: \fIwc \fP jpayne@68: and returns 1 on success, 0 on end of file, or \-1 on I/O or encoding jpayne@68: errors. jpayne@68: Functions internally using it include jpayne@68: \fBel_wgets\fP(), jpayne@68: \fBel_wgetc\fP(), jpayne@68: \fBel_gets\fP(), jpayne@68: and jpayne@68: \fBel_getc\fP(). jpayne@68: Initially, a builtin function is installed, and replacing it jpayne@68: is discouraged because writing such a function is very error prone. jpayne@68: The builtin function can be restored at any time by passing the jpayne@68: special value jpayne@68: EL_BUILTIN_GETCFN jpayne@68: instead of a function pointer. jpayne@68: .TP jpayne@68: EL_CLIENTDATA , \fIvoid *data\fP jpayne@68: Register jpayne@68: \fIdata \fP jpayne@68: to be associated with this EditLine structure. jpayne@68: It can be retrieved with the corresponding jpayne@68: \fBel_get\fP(); jpayne@68: call. jpayne@68: .TP jpayne@68: EL_SETFP , \fIint fd, Fa FILE *fp\fP jpayne@68: Set the current jpayne@68: \fBeditline\fP jpayne@68: file pointer for jpayne@68: ``input'' jpayne@68: \fIfd \fP jpayne@68: = jpayne@68: 0 , jpayne@68: ``output'' jpayne@68: \fIfd \fP jpayne@68: = jpayne@68: 1 , jpayne@68: or jpayne@68: ``error'' jpayne@68: \fIfd \fP jpayne@68: = jpayne@68: 2 jpayne@68: from jpayne@68: \fIfp\fP. jpayne@68: .RE jpayne@68: .TP jpayne@68: \fBel_get\fP() jpayne@68: Get jpayne@68: \fBeditline\fP jpayne@68: parameters. jpayne@68: \fIop \fP jpayne@68: determines which parameter to retrieve into jpayne@68: \fIresult\fP. jpayne@68: Returns 0 if successful, \-1 otherwise. jpayne@68: jpayne@68: The following values for jpayne@68: \fIop \fP jpayne@68: are supported, along with actual type of jpayne@68: \fIresult : \fP jpayne@68: .RS jpayne@68: .TP jpayne@68: EL_PROMPT , \fIchar *(*f)(EditLine *), Fa char *c\fP jpayne@68: Set jpayne@68: \fIf \fP jpayne@68: to a pointer to the function that displays the prompt. jpayne@68: If jpayne@68: \fIc \fP jpayne@68: is not jpayne@68: NULL , jpayne@68: set it to the start/stop literal prompt character. jpayne@68: .TP jpayne@68: EL_RPROMPT , \fIchar *(*f)(EditLine *), Fa char *c\fP jpayne@68: Set jpayne@68: \fIf \fP jpayne@68: to a pointer to the function that displays the prompt. jpayne@68: If jpayne@68: \fIc \fP jpayne@68: is not jpayne@68: NULL , jpayne@68: set it to the start/stop literal prompt character. jpayne@68: .TP jpayne@68: EL_EDITOR , \fIconst char **n\fP jpayne@68: Set the name of the editor in jpayne@68: \fIn\fP, jpayne@68: which will be one of jpayne@68: ``emacs'' jpayne@68: or jpayne@68: ``vi''. jpayne@68: .TP jpayne@68: EL_GETTC , \fIconst char *name, Fa void *value\fP jpayne@68: If jpayne@68: \fIname \fP jpayne@68: is a valid jpayne@68: \fBtermcap\fP(5) jpayne@68: capability set jpayne@68: \fIvalue \fP jpayne@68: to the current value of that capability. jpayne@68: .TP jpayne@68: EL_SIGNAL , \fIint *s\fP jpayne@68: Set jpayne@68: \fIs \fP jpayne@68: to non-zero if jpayne@68: \fBeditline\fP jpayne@68: has installed private signal handlers (see jpayne@68: \fBel_get\fP() jpayne@68: above). jpayne@68: .TP jpayne@68: EL_EDITMODE , \fIint *c\fP jpayne@68: Set jpayne@68: \fIc \fP jpayne@68: to non-zero if editing is enabled. jpayne@68: .TP jpayne@68: EL_GETCFN , \fIel_rfunc_t *f\fP jpayne@68: Set jpayne@68: \fIf \fP jpayne@68: to a pointer to the function that reads characters, or to jpayne@68: EL_BUILTIN_GETCFN jpayne@68: if the builtin function is in use. jpayne@68: .TP jpayne@68: EL_CLIENTDATA , \fIvoid **data\fP jpayne@68: Set jpayne@68: \fIdata \fP jpayne@68: to the previously registered client data set by an jpayne@68: \fBel_set\fP() jpayne@68: call. jpayne@68: .TP jpayne@68: EL_UNBUFFERED , \fIint *c\fP jpayne@68: Set jpayne@68: \fIc \fP jpayne@68: to non-zero if unbuffered mode is enabled. jpayne@68: .TP jpayne@68: EL_SAFEREAD , \fIint *c\fP jpayne@68: Set jpayne@68: \fIc \fP jpayne@68: to non-zero if safe read is set. jpayne@68: .TP jpayne@68: EL_GETFP , \fIint fd", Fa FILE **fp\fP jpayne@68: Set jpayne@68: \fIfp \fP jpayne@68: to the current jpayne@68: \fBeditline\fP jpayne@68: file pointer for jpayne@68: ``input'' jpayne@68: \fIfd \fP jpayne@68: = jpayne@68: 0 , jpayne@68: ``output'' jpayne@68: \fIfd \fP jpayne@68: = jpayne@68: 1 , jpayne@68: or jpayne@68: ``error'' jpayne@68: \fIfd \fP jpayne@68: = jpayne@68: 2 . jpayne@68: .RE jpayne@68: .TP jpayne@68: \fBel_source\fP() jpayne@68: Initialize jpayne@68: \fBeditline\fP jpayne@68: by reading the contents of jpayne@68: \fIfile\fP. jpayne@68: \fBel_parse\fP() jpayne@68: is called for each line in jpayne@68: \fIfile\fP. jpayne@68: If jpayne@68: \fIfile \fP jpayne@68: is jpayne@68: NULL , jpayne@68: try jpayne@68: \fI$EDITRC\fP jpayne@68: and if that is not set jpayne@68: \fI$HOME/.editrc\fP. jpayne@68: Refer to jpayne@68: \fBeditrc\fP(5) jpayne@68: for details on the format of jpayne@68: \fIfile\fP. jpayne@68: \fBel_source\fP() jpayne@68: returns 0 on success and \-1 on error. jpayne@68: .TP jpayne@68: \fBel_resize\fP() jpayne@68: Must be called if the terminal size changes. jpayne@68: If jpayne@68: EL_SIGNAL jpayne@68: has been set with jpayne@68: \fBel_set\fP(), jpayne@68: then this is done automatically. jpayne@68: Otherwise, it's the responsibility of the application to call jpayne@68: \fBel_resize\fP() jpayne@68: on the appropriate occasions. jpayne@68: .TP jpayne@68: \fBel_cursor\fP() jpayne@68: Move the cursor to the right (if positive) or to the left (if negative) jpayne@68: \fIcount \fP jpayne@68: characters. jpayne@68: Returns the resulting offset of the cursor from the beginning of the line. jpayne@68: .TP jpayne@68: \fBel_line\fP() jpayne@68: Return the editing information for the current line in a jpayne@68: \fILineInfo \fP jpayne@68: structure, which is defined as follows: jpayne@68: jpayne@68: typedef struct lineinfo { jpayne@68: .br jpayne@68: const char *buffer; /* address of buffer */ jpayne@68: .br jpayne@68: const char *cursor; /* address of cursor */ jpayne@68: .br jpayne@68: const char *lastchar; /* address of last character */ jpayne@68: .br jpayne@68: } LineInfo; jpayne@68: .br jpayne@68: jpayne@68: \fIbuffer \fP jpayne@68: is not NUL terminated. jpayne@68: This function may be called after jpayne@68: \fBel_gets\fP() jpayne@68: to obtain the jpayne@68: \fILineInfo \fP jpayne@68: structure pertaining to line returned by that function, jpayne@68: and from within user defined functions added with jpayne@68: EL_ADDFN . jpayne@68: .TP jpayne@68: \fBel_insertstr\fP() jpayne@68: Insert jpayne@68: \fIstr \fP jpayne@68: into the line at the cursor. jpayne@68: Returns \-1 if jpayne@68: \fIstr \fP jpayne@68: is empty or won't fit, and 0 otherwise. jpayne@68: .TP jpayne@68: \fBel_deletestr\fP() jpayne@68: Delete jpayne@68: \fIcount \fP jpayne@68: characters before the cursor. jpayne@68: .SH HISTORY LIST FUNCTIONS jpayne@68: The history functions use a common data structure, jpayne@68: \fIHistory\fP, jpayne@68: which is created by jpayne@68: \fBhistory_init\fP() jpayne@68: and freed by jpayne@68: \fBhistory_end\fP(). jpayne@68: jpayne@68: The following functions are available: jpayne@68: .TP jpayne@68: \fBhistory_init\fP() jpayne@68: Initialize the history list, and return a data structure jpayne@68: to be used by all other history list functions, or jpayne@68: NULL jpayne@68: on failure. jpayne@68: .TP jpayne@68: \fBhistory_end\fP() jpayne@68: Clean up and finish with jpayne@68: \fIh\fP, jpayne@68: assumed to have been created with jpayne@68: \fBhistory_init\fP(). jpayne@68: .TP jpayne@68: \fBhistory\fP() jpayne@68: Perform operation jpayne@68: \fIop \fP jpayne@68: on the history list, with optional arguments as needed by the jpayne@68: operation. jpayne@68: \fIev \fP jpayne@68: is changed accordingly to operation. jpayne@68: The following values for jpayne@68: \fIop \fP jpayne@68: are supported, along with the required argument list: jpayne@68: .RS jpayne@68: .TP jpayne@68: H_SETSIZE , \fIint size\fP jpayne@68: Set size of history to jpayne@68: \fIsize \fP jpayne@68: elements. jpayne@68: .TP jpayne@68: H_GETSIZE jpayne@68: Get number of events currently in history. jpayne@68: .TP jpayne@68: H_END jpayne@68: Cleans up and finishes with jpayne@68: \fIh\fP, jpayne@68: assumed to be created with jpayne@68: \fBhistory_init\fP(). jpayne@68: .TP jpayne@68: H_CLEAR jpayne@68: Clear the history. jpayne@68: .TP jpayne@68: H_FUNC , \fIvoid *ptr, Fa history_gfun_t first, \ \fP jpayne@68: Fa "history_gfun_t next" , Fa "history_gfun_t last" , \ jpayne@68: Fa "history_gfun_t prev" , Fa "history_gfun_t curr" , \ jpayne@68: Fa "history_sfun_t set" , Fa "history_vfun_t clear" , \ jpayne@68: Fa "history_efun_t enter" , Fa "history_efun_t add" jpayne@68: Define functions to perform various history operations. jpayne@68: \fIptr \fP jpayne@68: is the argument given to a function when it's invoked. jpayne@68: .TP jpayne@68: H_FIRST jpayne@68: Return the first element in the history. jpayne@68: .TP jpayne@68: H_LAST jpayne@68: Return the last element in the history. jpayne@68: .TP jpayne@68: H_PREV jpayne@68: Return the previous element in the history. jpayne@68: It is newer than the current one. jpayne@68: .TP jpayne@68: H_NEXT jpayne@68: Return the next element in the history. jpayne@68: It is older than the current one. jpayne@68: .TP jpayne@68: H_CURR jpayne@68: Return the current element in the history. jpayne@68: .TP jpayne@68: H_SET , \fIint position\fP jpayne@68: Set the cursor to point to the requested element. jpayne@68: .TP jpayne@68: H_ADD , \fIconst char *str\fP jpayne@68: Append jpayne@68: \fIstr \fP jpayne@68: to the current element of the history, or perform the jpayne@68: H_ENTER jpayne@68: operation with argument jpayne@68: \fIstr \fP jpayne@68: if there is no current element. jpayne@68: .TP jpayne@68: H_APPEND , \fIconst char *str\fP jpayne@68: Append jpayne@68: \fIstr \fP jpayne@68: to the last new element of the history. jpayne@68: .TP jpayne@68: H_ENTER , \fIconst char *str\fP jpayne@68: Add jpayne@68: \fIstr \fP jpayne@68: as a new element to the history and, if necessary, jpayne@68: removing the oldest entry to keep the list to the created size. jpayne@68: If jpayne@68: H_SETUNIQUE jpayne@68: has been called with a non-zero argument, the element jpayne@68: will not be entered into the history if its contents match jpayne@68: the ones of the current history element. jpayne@68: If the element is entered jpayne@68: \fBhistory\fP() jpayne@68: returns 1; if it is ignored as a duplicate returns 0. jpayne@68: Finally jpayne@68: \fBhistory\fP() jpayne@68: returns \-1 if an error occurred. jpayne@68: .TP jpayne@68: H_PREV_STR , \fIconst char *str\fP jpayne@68: Return the closest previous event that starts with jpayne@68: \fIstr\fP. jpayne@68: .TP jpayne@68: H_NEXT_STR , \fIconst char *str\fP jpayne@68: Return the closest next event that starts with jpayne@68: \fIstr\fP. jpayne@68: .TP jpayne@68: H_PREV_EVENT , \fIint e\fP jpayne@68: Return the previous event numbered jpayne@68: \fIe\fP. jpayne@68: .TP jpayne@68: H_NEXT_EVENT , \fIint e\fP jpayne@68: Return the next event numbered jpayne@68: \fIe\fP. jpayne@68: .TP jpayne@68: H_LOAD , \fIconst char *file\fP jpayne@68: Load the history list stored in jpayne@68: \fIfile\fP. jpayne@68: .TP jpayne@68: H_SAVE , \fIconst char *file\fP jpayne@68: Save the history list to jpayne@68: \fIfile\fP. jpayne@68: .TP jpayne@68: H_SAVE_FP , \fIFILE *fp\fP jpayne@68: Save the history list to the opened jpayne@68: .PP jpayne@68: \fIFILE\fP jpayne@68: .br jpayne@68: pointer jpayne@68: \fIfp\fP. jpayne@68: .TP jpayne@68: H_NSAVE_FP , \fIsize_t n, Fa FILE *fp\fP jpayne@68: Save the last jpayne@68: .PP jpayne@68: \fIn\fP jpayne@68: .br jpayne@68: history entries to the opened jpayne@68: .PP jpayne@68: \fIFILE\fP jpayne@68: .br jpayne@68: pointer jpayne@68: \fIfp\fP. jpayne@68: .TP jpayne@68: H_SETUNIQUE , \fIint unique\fP jpayne@68: Set flag that adjacent identical event strings should not be entered jpayne@68: into the history. jpayne@68: .TP jpayne@68: H_GETUNIQUE jpayne@68: Retrieve the current setting if adjacent identical elements should jpayne@68: be entered into the history. jpayne@68: .TP jpayne@68: H_DEL , \fIint e\fP jpayne@68: Delete the event numbered jpayne@68: \fIe\fP. jpayne@68: This function is only provided for jpayne@68: \fBreadline\fP jpayne@68: compatibility. jpayne@68: The caller is responsible for free'ing the string in the returned jpayne@68: \fIHistEvent\fP. jpayne@68: .RE jpayne@68: jpayne@68: \fBhistory\fP(); jpayne@68: returns >= 0 if the operation jpayne@68: \fIop \fP jpayne@68: succeeds. jpayne@68: Otherwise, \-1 is returned and jpayne@68: \fIev \fP jpayne@68: is updated to contain more details about the error. jpayne@68: .SH TOKENIZATION FUNCTIONS jpayne@68: The tokenization functions use a common data structure, jpayne@68: \fITokenizer\fP, jpayne@68: which is created by jpayne@68: \fBtok_init\fP() jpayne@68: and freed by jpayne@68: \fBtok_end\fP(). jpayne@68: jpayne@68: The following functions are available: jpayne@68: .TP jpayne@68: \fBtok_init\fP() jpayne@68: Initialize the tokenizer, and return a data structure jpayne@68: to be used by all other tokenizer functions. jpayne@68: \fIIFS \fP jpayne@68: contains the Input Field Separators, which defaults to jpayne@68: jpayne@68: jpayne@68: and jpayne@68: jpayne@68: if jpayne@68: NULL . jpayne@68: .TP jpayne@68: \fBtok_end\fP() jpayne@68: Clean up and finish with jpayne@68: \fIt\fP, jpayne@68: assumed to have been created with jpayne@68: \fBtok_init\fP(). jpayne@68: .TP jpayne@68: \fBtok_reset\fP() jpayne@68: Reset the tokenizer state. jpayne@68: Use after a line has been successfully tokenized jpayne@68: by jpayne@68: \fBtok_line\fP() jpayne@68: or jpayne@68: \fBtok_str\fP() jpayne@68: and before a new line is to be tokenized. jpayne@68: .TP jpayne@68: \fBtok_line\fP() jpayne@68: Tokenize jpayne@68: \fIli\fP, jpayne@68: If successful, modify: jpayne@68: \fIargv \fP jpayne@68: to contain the words, jpayne@68: \fIargc \fP jpayne@68: to contain the number of words, jpayne@68: \fIcursorc \fP jpayne@68: (if not jpayne@68: NULL ) jpayne@68: to contain the index of the word containing the cursor, jpayne@68: and jpayne@68: \fIcursoro \fP jpayne@68: (if not jpayne@68: NULL ) jpayne@68: to contain the offset within jpayne@68: \fIargv[cursorc] \fP jpayne@68: of the cursor. jpayne@68: jpayne@68: Returns jpayne@68: 0 if successful, jpayne@68: \-1 for an internal error, jpayne@68: 1 for an unmatched single quote, jpayne@68: 2 for an unmatched double quote, jpayne@68: and jpayne@68: 3 for a backslash quoted jpayne@68: jpayne@68: A positive exit code indicates that another line should be read jpayne@68: and tokenization attempted again. jpayne@68: .TP jpayne@68: \fBtok_str\fP() jpayne@68: A simpler form of jpayne@68: \fBtok_line\fP(; ) jpayne@68: \fIstr \fP jpayne@68: is a NUL terminated string to tokenize. jpayne@68: .SH SEE ALSO jpayne@68: \fBsh\fP(1), jpayne@68: \fBsignal\fP(3), jpayne@68: \fBtermcap\fP(3), jpayne@68: \fBeditrc\fP(5), jpayne@68: \fBtermcap\fP(5), jpayne@68: \fBeditline\fP(7) jpayne@68: .SH HISTORY jpayne@68: The jpayne@68: \fBeditline\fP jpayne@68: library first appeared in jpayne@68: Bx 4.4 . jpayne@68: CC_REDISPLAY jpayne@68: appeared in jpayne@68: Nx 1.3 . jpayne@68: CC_REFRESH_BEEP , jpayne@68: EL_EDITMODE jpayne@68: and the readline emulation appeared in jpayne@68: Nx 1.4 . jpayne@68: EL_RPROMPT jpayne@68: appeared in jpayne@68: Nx 1.5 . jpayne@68: .SH AUTHORS jpayne@68: jpayne@68: -nosplit jpayne@68: The jpayne@68: \fBeditline\fP jpayne@68: library was written by jpayne@68: jpayne@68: Christos Zoulas . jpayne@68: jpayne@68: Luke Mewburn jpayne@68: wrote this manual and implemented jpayne@68: CC_REDISPLAY , jpayne@68: CC_REFRESH_BEEP , jpayne@68: EL_EDITMODE , jpayne@68: and jpayne@68: EL_RPROMPT . jpayne@68: jpayne@68: Jaromir Dolecek jpayne@68: implemented the readline emulation. jpayne@68: jpayne@68: Johny Mattsson jpayne@68: implemented wide-character support. jpayne@68: .SH BUGS jpayne@68: At this time, it is the responsibility of the caller to jpayne@68: check the result of the jpayne@68: EL_EDITMODE jpayne@68: operation of jpayne@68: \fBel_get\fP() jpayne@68: (after an jpayne@68: \fBel_source\fP() jpayne@68: or jpayne@68: \fBel_parse\fP() ) jpayne@68: to determine if jpayne@68: \fBeditline\fP jpayne@68: should be used for further input. jpayne@68: I.e., jpayne@68: EL_EDITMODE jpayne@68: is purely an indication of the result of the most recent jpayne@68: \fBeditrc\fP(5) jpayne@68: \fBedit\fP jpayne@68: command.