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 $
56 .Nd line editor, history and tokenization functions
62 .Fn el_init "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr"
64 .Fn el_end "EditLine *e"
66 .Fn el_reset "EditLine *e"
68 .Fn el_gets "EditLine *e" "int *count"
70 .Fn el_getc "EditLine *e" "char *ch"
72 .Fn el_push "EditLine *e" "const char *str"
74 .Fn el_parse "EditLine *e" "int argc" "const char *argv[]"
76 .Fn el_set "EditLine *e" "int op" "..."
78 .Fn el_get "EditLine *e" "int op" "..."
80 .Fn el_source "EditLine *e" "const char *file"
82 .Fn el_resize "EditLine *e"
84 .Fn el_line "EditLine *e"
86 .Fn el_insertstr "EditLine *e" "const char *str"
88 .Fn el_deletestr "EditLine *e" "int count"
92 .Fn history_end "History *h"
94 .Fn history "History *h" "HistEvent *ev" "int op" "..."
96 .Fn tok_init "const char *IFS"
98 .Fn tok_end "Tokenizer *t"
100 .Fn tok_reset "Tokenizer *t"
102 .Fn tok_line "Tokenizer *t" "const LineInfo *li" "int *argc" "const char **argv[]" "int *cursorc" "int *cursoro"
104 .Fn tok_str "Tokenizer *t" "const char *str" "int *argc" "const char **argv[]"
108 library provides generic line editing, history and tokenization functions,
109 similar to those found in
112 These functions are available in the
114 library (which needs the
117 Programs should be linked with
119 .Sh LINE EDITING FUNCTIONS
120 The line editing functions use a common data structure,
127 The following functions are available:
130 Initialise the line editor, and return a data structure
131 to be used by all other line editing functions.
133 is the name of the invoking program, used when reading the
135 file to determine which settings to use.
140 are the input, output, and error streams (respectively) to use.
141 In this documentation, references to
143 are actually to this input/output stream combination.
145 Clean up and finish with
147 assumed to have been created with
150 Reset the tty and the parser.
151 This should be called after an error which may have upset the tty's
154 Read a line from the tty.
156 is modified to contain the number of characters read.
157 Returns the line read if successful, or
159 if no characters were read or if an error occurred.
161 Read a character from the tty.
163 is modified to contain the character read.
164 Returns the number of characters read if successful, \-1 otherwise.
168 back onto the input stream.
169 This is used by the macro expansion mechanism.
170 Refer to the description of
175 for more information.
185 If the command is prefixed with
189 will only execute the command if
196 \-1 if the command is unknown,
197 0 if there was no error or
200 1 if the command returned an error.
203 for more information.
209 determines which parameter to set, and each operation has its
212 The following values for
214 are supported, along with the required argument list:
216 .It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
217 Define prompt printing function as
219 which is to return a string that contains the prompt.
221 Re-display the current line on the next terminal line.
222 .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
223 Define right side prompt printing function as
225 which is to return a string that contains the prompt.
226 .It Dv EL_TERMINAL , Fa "const char *type"
227 Define terminal type of the tty to be
235 .It Dv EL_EDITOR , Fa "const char *mode"
242 .It Dv EL_SIGNAL , Fa "int flag"
247 will install its own signal handler for the following signals when
248 reading command input:
258 Otherwise, the current signal handlers will be used.
269 for more information.
270 .It Dv EL_ECHOTC , Xo
280 for more information.
291 for more information.
302 for more information.
303 .It Dv EL_TELLTC , Xo
313 for more information.
315 .Fa "const char *name" ,
316 .Fa "const char *help" ,
317 .Fa "unsigned char (*func)(EditLine *e, int ch)"
319 Add a user defined function,
323 which is invoked when a key which is bound to
331 is the key which caused the invocation.
335 .Bl -tag -width "CC_REDISPLAY"
337 Add a normal character.
339 End of line was entered.
343 Expecting further command input as arguments, do nothing visually.
346 .It Dv CC_REFRESH_BEEP
347 Refresh display, and beep.
349 Cursor moved, so update and perform
352 Redisplay entire input line.
353 This is useful if a key binding outputs extra information.
358 Fatal error, reset tty to known state.
361 .Fa "History *(*func)(History *, int op, ...)" ,
362 .Fa "const char *ptr"
364 Defines which history function to use, which is usually
367 should be the value returned by
369 .It Dv EL_EDITMODE , Fa "int flag"
373 editing is enabled (the default).
374 Note that this is only an indication, and does not
375 affect the operation of
377 At this time, it is the caller's responsibility to
381 to determine if editing should be enabled or not.
382 .It Dv EL_GETCFN , Fa "int (*f)(EditLine *, char *c)"
383 Define the character reading function as
385 which is to return the number of characters read and store them in
387 This function is called internally by
391 The builtin function can be set or restored with the special function
392 name ``EL_BUILTIN_GETCFN''.
393 .It Dv EL_CLIENTDATA , Fa "void *data"
396 to be associated with this EditLine structure.
397 It can be retrieved with the corresponding
400 .It Dv EL_SETFP , Fa "int fd" , Fa "FILE *fp"
425 determines which parameter to retrieve into
427 Returns 0 if successful, \-1 otherwise.
429 The following values for
431 are supported, along with actual type of
434 .It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
435 Return a pointer to the function that displays the prompt.
436 .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
437 Return a pointer to the function that displays the rightside prompt.
438 .It Dv EL_EDITOR , Fa "const char *"
439 Return the name of the editor, which will be one of
443 .It Dv EL_GETTC , Fa "const char *name" , Fa "void *value"
451 to the current value of that capability.
452 .It Dv EL_SIGNAL , Fa "int *"
455 has installed private signal handlers (see
458 .It Dv EL_EDITMODE , Fa "int *"
459 Return non-zero if editing is enabled.
460 .It Dv EL_GETCFN , Fa "int (**f)(EditLine *, char *)"
461 Return a pointer to the function that read characters, which is equal to
462 ``EL_BUILTIN_GETCFN'' in the case of the default builtin function.
463 .It Dv EL_CLIENTDATA , Fa "void **data"
466 previously registered with the corresponding
469 .It Dv EL_UNBUFFERED , Fa "int"
470 Sets or clears unbuffered mode.
473 will return immediately after processing a single character.
474 .It Dv EL_PREP_TERM , Fa "int"
475 Sets or clears terminal editing mode.
476 .It Dv EL_GETFP , Fa "int fd", Fa "FILE **fp"
499 by reading the contents of
502 is called for each line in
514 for details on the format of
517 Must be called if the terminal size changes.
522 then this is done automatically.
523 Otherwise, it's the responsibility of the application to call
525 on the appropriate occasions.
527 Return the editing information for the current line in a
529 structure, which is defined as follows:
531 typedef struct lineinfo {
532 const char *buffer; /* address of buffer */
533 const char *cursor; /* address of cursor */
534 const char *lastchar; /* address of last character */
539 is not NUL terminated.
540 This function may be called after
544 structure pertaining to line returned by that function,
545 and from within user defined functions added with
550 into the line at the cursor.
553 is empty or won't fit, and 0 otherwise.
557 characters before the cursor.
559 .Sh HISTORY LIST FUNCTIONS
560 The history functions use a common data structure,
567 The following functions are available:
570 Initialise the history list, and return a data structure
571 to be used by all other history list functions.
573 Clean up and finish with
575 assumed to have been created with
580 on the history list, with optional arguments as needed by the
583 is changed accordingly to operation.
584 The following values for
586 are supported, along with the required argument list:
588 .It Dv H_SETSIZE , Fa "int size"
589 Set size of history to
593 Get number of events currently in history.
595 Cleans up and finishes with
597 assumed to be created with
603 .Fa "history_gfun_t first" ,
604 .Fa "history_gfun_t next" ,
605 .Fa "history_gfun_t last" ,
606 .Fa "history_gfun_t prev" ,
607 .Fa "history_gfun_t curr" ,
608 .Fa "history_sfun_t set" ,
609 .Fa "history_vfun_t clear" ,
610 .Fa "history_efun_t enter" ,
611 .Fa "history_efun_t add"
613 Define functions to perform various history operations.
615 is the argument given to a function when it's invoked.
617 Return the first element in the history.
619 Return the last element in the history.
621 Return the previous element in the history.
623 Return the next element in the history.
625 Return the current element in the history.
627 Set the cursor to point to the requested element.
628 .It Dv H_ADD , Fa "const char *str"
631 to the current element of the history, or perform the
633 operation with argument
635 if there is no current element.
636 .It Dv H_APPEND , Fa "const char *str"
639 to the last new element of the history.
640 .It Dv H_ENTER , Fa "const char *str"
643 as a new element to the history, and, if necessary,
644 removing the oldest entry to keep the list to the created size.
647 was has been called with a non-zero arguments, the element
648 will not be entered into the history if its contents match
649 the ones of the current history element.
650 If the element is entered
652 returns 1, if it is ignored as a duplicate returns 0.
655 returns \-1 if an error occurred.
656 .It Dv H_PREV_STR , Fa "const char *str"
657 Return the closest previous event that starts with
659 .It Dv H_NEXT_STR , Fa "const char *str"
660 Return the closest next event that starts with
662 .It Dv H_PREV_EVENT , Fa "int e"
663 Return the previous event numbered
665 .It Dv H_NEXT_EVENT , Fa "int e"
666 Return the next event numbered
668 .It Dv H_LOAD , Fa "const char *file"
669 Load the history list stored in
671 .It Dv H_SAVE , Fa "const char *file"
672 Save the history list to
674 .It Dv H_SETUNIQUE , Fa "int unique"
675 Set flag that adjacent identical event strings should not be entered
678 Retrieve the current setting if adjacent identical elements should
679 be entered into the history.
680 .It Dv H_DEL , Fa "int e"
681 Delete the event numbered
683 This function is only provided for
686 The caller is responsible for free'ing the string in the returned
691 returns \*[Gt]= 0 if the operation
694 Otherwise, \-1 is returned and
696 is updated to contain more details about the error.
698 .Sh TOKENIZATION FUNCTIONS
699 The tokenization functions use a common data structure,
706 The following functions are available:
709 Initialise the tokenizer, and return a data structure
710 to be used by all other tokenizer functions.
712 contains the Input Field Separators, which defaults to
720 Clean up and finish with
722 assumed to have been created with
725 Reset the tokenizer state.
726 Use after a line has been successfully tokenized
731 and before a new line is to be tokenized.
735 If successful, modify:
737 to contain the words,
739 to contain the number of words,
743 to contain the index of the word containing the cursor,
748 to contain the offset within
754 \-1 for an internal error,
755 1 for an unmatched single quote,
756 2 for an unmatched double quote,
758 3 for a backslash quoted
760 A positive exit code indicates that another line should be read
761 and tokenization attempted again.
767 is a NUL terminated string to tokenize.
771 .\"XXX: provide some examples
781 library first appeared in
786 .Dv CC_REFRESH_BEEP ,
788 and the readline emulation appeared in
796 library was written by Christos Zoulas.
797 Luke Mewburn wrote this manual and implemented
799 .Dv CC_REFRESH_BEEP ,
803 Jaromir Dolecek implemented the readline emulation.
805 At this time, it is the responsibility of the caller to
806 check the result of the
816 should be used for further input.
819 is purely an indication of the result of the most recent