1 .\" Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
2 .\" All rights reserved.
4 .\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 .\" POSSIBILITY OF SUCH DAMAGE.
27 .\" $NetBSD: editline.3,v 1.57 2008/04/30 13:10:51 martin Exp $
28 .\" $DragonFly: src/lib/libedit/editline.3,v 1.5 2008/05/17 22:48:04 pavalos Exp $
57 .Nd line editor, history and tokenization functions
63 .Fn el_init "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr"
65 .Fn el_end "EditLine *e"
67 .Fn el_reset "EditLine *e"
69 .Fn el_gets "EditLine *e" "int *count"
71 .Fn el_getc "EditLine *e" "char *ch"
73 .Fn el_push "EditLine *e" "const char *str"
75 .Fn el_parse "EditLine *e" "int argc" "const char *argv[]"
77 .Fn el_set "EditLine *e" "int op" "..."
79 .Fn el_get "EditLine *e" "int op" "..."
81 .Fn el_source "EditLine *e" "const char *file"
83 .Fn el_resize "EditLine *e"
85 .Fn el_line "EditLine *e"
87 .Fn el_insertstr "EditLine *e" "const char *str"
89 .Fn el_deletestr "EditLine *e" "int count"
93 .Fn history_end "History *h"
95 .Fn history "History *h" "HistEvent *ev" "int op" "..."
97 .Fn tok_init "const char *IFS"
99 .Fn tok_end "Tokenizer *t"
101 .Fn tok_reset "Tokenizer *t"
103 .Fn tok_line "Tokenizer *t" "const LineInfo *li" "int *argc" "const char **argv[]" "int *cursorc" "int *cursoro"
105 .Fn tok_str "Tokenizer *t" "const char *str" "int *argc" "const char **argv[]"
109 library provides generic line editing, history and tokenization functions,
110 similar to those found in
113 These functions are available in the
115 library (which needs the
118 Programs should be linked with
120 .Sh LINE EDITING FUNCTIONS
121 The line editing functions use a common data structure,
128 The following functions are available:
131 Initialise the line editor, and return a data structure
132 to be used by all other line editing functions.
134 is the name of the invoking program, used when reading the
136 file to determine which settings to use.
141 are the input, output, and error streams (respectively) to use.
142 In this documentation, references to
144 are actually to this input/output stream combination.
146 Clean up and finish with
148 assumed to have been created with
151 Reset the tty and the parser.
152 This should be called after an error which may have upset the tty's
155 Read a line from the tty.
157 is modified to contain the number of characters read.
158 Returns the line read if successful, or
160 if no characters were read or if an error occurred.
162 Read a character from the tty.
164 is modified to contain the character read.
165 Returns the number of characters read if successful, \-1 otherwise.
169 back onto the input stream.
170 This is used by the macro expansion mechanism.
171 Refer to the description of
176 for more information.
186 If the command is prefixed with
190 will only execute the command if
197 \-1 if the command is unknown,
198 0 if there was no error or
201 1 if the command returned an error.
204 for more information.
210 determines which parameter to set, and each operation has its
213 The following values for
215 are supported, along with the required argument list:
217 .It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
218 Define prompt printing function as
220 which is to return a string that contains the prompt.
222 Re-display the current line on the next terminal line.
223 .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
224 Define right side prompt printing function as
226 which is to return a string that contains the prompt.
227 .It Dv EL_TERMINAL , Fa "const char *type"
228 Define terminal type of the tty to be
236 .It Dv EL_EDITOR , Fa "const char *mode"
243 .It Dv EL_SIGNAL , Fa "int flag"
248 will install its own signal handler for the following signals when
249 reading command input:
259 Otherwise, the current signal handlers will be used.
270 for more information.
271 .It Dv EL_ECHOTC , Xo
281 for more information.
292 for more information.
303 for more information.
304 .It Dv EL_TELLTC , Xo
314 for more information.
316 .Fa "const char *name" ,
317 .Fa "const char *help" ,
318 .Fa "unsigned char (*func)(EditLine *e, int ch)"
320 Add a user defined function,
324 which is invoked when a key which is bound to
332 is the key which caused the invocation.
336 .Bl -tag -width "CC_REDISPLAY"
338 Add a normal character.
340 End of line was entered.
344 Expecting further command input as arguments, do nothing visually.
347 .It Dv CC_REFRESH_BEEP
348 Refresh display, and beep.
350 Cursor moved, so update and perform
353 Redisplay entire input line.
354 This is useful if a key binding outputs extra information.
359 Fatal error, reset tty to known state.
362 .Fa "History *(*func)(History *, int op, ...)" ,
363 .Fa "const char *ptr"
365 Defines which history function to use, which is usually
368 should be the value returned by
370 .It Dv EL_EDITMODE , Fa "int flag"
374 editing is enabled (the default).
375 Note that this is only an indication, and does not
376 affect the operation of
378 At this time, it is the caller's responsibility to
382 to determine if editing should be enabled or not.
383 .It Dv EL_GETCFN , Fa "int (*f)(EditLine *, char *c)"
384 Define the character reading function as
386 which is to return the number of characters read and store them in
388 This function is called internally by
392 The builtin function can be set or restored with the special function
393 name ``EL_BUILTIN_GETCFN''.
394 .It Dv EL_CLIENTDATA , Fa "void *data"
397 to be associated with this EditLine structure.
398 It can be retrieved with the corresponding
401 .It Dv EL_SETFP , Fa "int fd" , Fa "FILE *fp"
426 determines which parameter to retrieve into
428 Returns 0 if successful, \-1 otherwise.
430 The following values for
432 are supported, along with actual type of
435 .It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
436 Return a pointer to the function that displays the prompt.
437 .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
438 Return a pointer to the function that displays the rightside prompt.
439 .It Dv EL_EDITOR , Fa "const char *"
440 Return the name of the editor, which will be one of
444 .It Dv EL_GETTC , Fa "const char *name" , Fa "void *value"
452 to the current value of that capability.
453 .It Dv EL_SIGNAL , Fa "int *"
456 has installed private signal handlers (see
459 .It Dv EL_EDITMODE , Fa "int *"
460 Return non-zero if editing is enabled.
461 .It Dv EL_GETCFN , Fa "int (**f)(EditLine *, char *)"
462 Return a pointer to the function that read characters, which is equal to
463 ``EL_BUILTIN_GETCFN'' in the case of the default builtin function.
464 .It Dv EL_CLIENTDATA , Fa "void **data"
467 previously registered with the corresponding
470 .It Dv EL_UNBUFFERED , Fa "int"
471 Sets or clears unbuffered mode.
474 will return immediately after processing a single character.
475 .It Dv EL_PREP_TERM , Fa "int"
476 Sets or clears terminal editing mode.
477 .It Dv EL_GETFP , Fa "int fd", Fa "FILE **fp"
500 by reading the contents of
503 is called for each line in
515 for details on the format of
518 Must be called if the terminal size changes.
523 then this is done automatically.
524 Otherwise, it's the responsibility of the application to call
526 on the appropriate occasions.
528 Return the editing information for the current line in a
530 structure, which is defined as follows:
532 typedef struct lineinfo {
533 const char *buffer; /* address of buffer */
534 const char *cursor; /* address of cursor */
535 const char *lastchar; /* address of last character */
540 is not NUL terminated.
541 This function may be called after
545 structure pertaining to line returned by that function,
546 and from within user defined functions added with
551 into the line at the cursor.
554 is empty or won't fit, and 0 otherwise.
558 characters before the cursor.
560 .Sh HISTORY LIST FUNCTIONS
561 The history functions use a common data structure,
568 The following functions are available:
571 Initialise the history list, and return a data structure
572 to be used by all other history list functions.
574 Clean up and finish with
576 assumed to have been created with
581 on the history list, with optional arguments as needed by the
584 is changed accordingly to operation.
585 The following values for
587 are supported, along with the required argument list:
589 .It Dv H_SETSIZE , Fa "int size"
590 Set size of history to
594 Get number of events currently in history.
596 Cleans up and finishes with
598 assumed to be created with
604 .Fa "history_gfun_t first" ,
605 .Fa "history_gfun_t next" ,
606 .Fa "history_gfun_t last" ,
607 .Fa "history_gfun_t prev" ,
608 .Fa "history_gfun_t curr" ,
609 .Fa "history_sfun_t set" ,
610 .Fa "history_vfun_t clear" ,
611 .Fa "history_efun_t enter" ,
612 .Fa "history_efun_t add"
614 Define functions to perform various history operations.
616 is the argument given to a function when it's invoked.
618 Return the first element in the history.
620 Return the last element in the history.
622 Return the previous element in the history.
624 Return the next element in the history.
626 Return the current element in the history.
628 Set the cursor to point to the requested element.
629 .It Dv H_ADD , Fa "const char *str"
632 to the current element of the history, or perform the
634 operation with argument
636 if there is no current element.
637 .It Dv H_APPEND , Fa "const char *str"
640 to the last new element of the history.
641 .It Dv H_ENTER , Fa "const char *str"
644 as a new element to the history, and, if necessary,
645 removing the oldest entry to keep the list to the created size.
648 was has been called with a non-zero arguments, the element
649 will not be entered into the history if its contents match
650 the ones of the current history element.
651 If the element is entered
653 returns 1, if it is ignored as a duplicate returns 0.
656 returns \-1 if an error occurred.
657 .It Dv H_PREV_STR , Fa "const char *str"
658 Return the closest previous event that starts with
660 .It Dv H_NEXT_STR , Fa "const char *str"
661 Return the closest next event that starts with
663 .It Dv H_PREV_EVENT , Fa "int e"
664 Return the previous event numbered
666 .It Dv H_NEXT_EVENT , Fa "int e"
667 Return the next event numbered
669 .It Dv H_LOAD , Fa "const char *file"
670 Load the history list stored in
672 .It Dv H_SAVE , Fa "const char *file"
673 Save the history list to
675 .It Dv H_SETUNIQUE , Fa "int unique"
676 Set flag that adjacent identical event strings should not be entered
679 Retrieve the current setting if adjacent identical elements should
680 be entered into the history.
681 .It Dv H_DEL , Fa "int e"
682 Delete the event numbered
684 This function is only provided for
687 The caller is responsible for free'ing the string in the returned
692 returns \*[Gt]= 0 if the operation
695 Otherwise, \-1 is returned and
697 is updated to contain more details about the error.
699 .Sh TOKENIZATION FUNCTIONS
700 The tokenization functions use a common data structure,
707 The following functions are available:
710 Initialise the tokenizer, and return a data structure
711 to be used by all other tokenizer functions.
713 contains the Input Field Separators, which defaults to
721 Clean up and finish with
723 assumed to have been created with
726 Reset the tokenizer state.
727 Use after a line has been successfully tokenized
732 and before a new line is to be tokenized.
736 If successful, modify:
738 to contain the words,
740 to contain the number of words,
744 to contain the index of the word containing the cursor,
749 to contain the offset within
755 \-1 for an internal error,
756 1 for an unmatched single quote,
757 2 for an unmatched double quote,
759 3 for a backslash quoted
761 A positive exit code indicates that another line should be read
762 and tokenization attempted again.
768 is a NUL terminated string to tokenize.
772 .\"XXX: provide some examples
782 library first appeared in
787 .Dv CC_REFRESH_BEEP ,
789 and the readline emulation appeared in
797 library was written by Christos Zoulas.
798 Luke Mewburn wrote this manual and implemented
800 .Dv CC_REFRESH_BEEP ,
804 Jaromir Dolecek implemented the readline emulation.
806 At this time, it is the responsibility of the caller to
807 check the result of the
817 should be used for further input.
820 is purely an indication of the result of the most recent