1 .\" $NetBSD: editline.3,v 1.55 2007/01/12 16:31:13 christos Exp $
3 .\" Copyright (c) 1997-2003 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
11 .\" 1. Redistributions of source code must retain the above copyright
12 .\" notice, this list of conditions and the following disclaimer.
13 .\" 2. Redistributions in binary form must reproduce the above copyright
14 .\" notice, this list of conditions and the following disclaimer in the
15 .\" documentation and/or other materials provided with the distribution.
16 .\" 3. Neither the name of The NetBSD Foundation nor the names of its
17 .\" contributors may be used to endorse or promote products derived
18 .\" from this software without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 .\" POSSIBILITY OF SUCH DAMAGE.
61 .Nd line editor, history and tokenization functions
67 .Fn el_init "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr"
69 .Fn el_end "EditLine *e"
71 .Fn el_reset "EditLine *e"
73 .Fn el_gets "EditLine *e" "int *count"
75 .Fn el_getc "EditLine *e" "char *ch"
77 .Fn el_push "EditLine *e" "char *str"
79 .Fn el_parse "EditLine *e" "int argc" "const char *argv[]"
81 .Fn el_set "EditLine *e" "int op" "..."
83 .Fn el_get "EditLine *e" "int op" "..."
85 .Fn el_source "EditLine *e" "const char *file"
87 .Fn el_resize "EditLine *e"
89 .Fn el_line "EditLine *e"
91 .Fn el_insertstr "EditLine *e" "const char *str"
93 .Fn el_deletestr "EditLine *e" "int count"
97 .Fn history_end "History *h"
99 .Fn history "History *h" "HistEvent *ev" "int op" "..."
101 .Fn tok_init "const char *IFS"
103 .Fn tok_end "Tokenizer *t"
105 .Fn tok_reset "Tokenizer *t"
108 .Fa "Tokenizer *t" "const LineInfo *li" "int *argc" "const char **argv[]"
109 .Fa "int *cursorc" "int *cursoro"
112 .Fn tok_str "Tokenizer *t" "const char *str" "int *argc" "const char **argv[]"
116 library provides generic line editing, history and tokenization functions,
117 similar to those found in
120 These functions are available in the
122 library (which needs the
125 Programs should be linked with
127 .Sh LINE EDITING FUNCTIONS
128 The line editing functions use a common data structure,
135 The following functions are available:
138 Initialise the line editor, and return a data structure
139 to be used by all other line editing functions.
141 is the name of the invoking program, used when reading the
143 file to determine which settings to use.
148 are the input, output, and error streams (respectively) to use.
149 In this documentation, references to
151 are actually to this input/output stream combination.
153 Clean up and finish with
155 assumed to have been created with
158 Reset the tty and the parser.
159 This should be called after an error which may have upset the tty's
162 Read a line from the tty.
164 is modified to contain the number of characters read.
165 Returns the line read if successful, or
167 if no characters were read or if an error occurred.
169 Read a character from the tty.
171 is modified to contain the character read.
172 Returns the number of characters read if successful, \-1 otherwise.
176 back onto the input stream.
177 This is used by the macro expansion mechanism.
178 Refer to the description of
183 for more information.
193 If the command is prefixed with
197 will only execute the command if
204 \-1 if the command is unknown,
205 0 if there was no error or
208 1 if the command returned an error.
211 for more information.
217 determines which parameter to set, and each operation has its
220 The following values for
222 are supported, along with the required argument list:
224 .It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
225 Define prompt printing function as
227 which is to return a string that contains the prompt.
228 .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
229 Define right side prompt printing function as
231 which is to return a string that contains the prompt.
232 .It Dv EL_TERMINAL , Fa "const char *type"
233 Define terminal type of the tty to be
241 .It Dv EL_EDITOR , Fa "const char *mode"
248 .It Dv EL_SIGNAL , Fa "int flag"
253 will install its own signal handler for the following signals when
254 reading command input:
264 Otherwise, the current signal handlers will be used.
275 for more information.
276 .It Dv EL_ECHOTC , Xo
286 for more information.
297 for more information.
308 for more information.
309 .It Dv EL_TELLTC , Xo
319 for more information.
321 .Fa "const char *name" ,
322 .Fa "const char *help" ,
323 .Fa "unsigned char (*func)(EditLine *e, int ch)"
325 Add a user defined function,
329 which is invoked when a key which is bound to
337 is the key which caused the invocation.
341 .Bl -tag -width "CC_REDISPLAY"
343 Add a normal character.
345 End of line was entered.
349 Expecting further command input as arguments, do nothing visually.
352 .It Dv CC_REFRESH_BEEP
353 Refresh display, and beep.
355 Cursor moved, so update and perform
358 Redisplay entire input line.
359 This is useful if a key binding outputs extra information.
364 Fatal error, reset tty to known state.
367 .Fa "History *(*func)(History *, int op, ...)" ,
368 .Fa "const char *ptr"
370 Defines which history function to use, which is usually
373 should be the value returned by
375 .It Dv EL_EDITMODE , Fa "int flag"
379 editing is enabled (the default).
380 Note that this is only an indication, and does not
381 affect the operation of
383 At this time, it is the caller's responsibility to
387 to determine if editing should be enabled or not.
388 .It Dv EL_GETCFN , Fa "int (*f)(EditLine *, char *c)"
389 Define the character reading function as
391 which is to return the number of characters read and store them in
393 This function is called internally by
397 The builtin function can be set or restored with the special function
399 .Dv EL_BUILTIN_GETCFN .
400 .It Dv EL_CLIENTDATA , Fa "void *data"
403 to be associated with this EditLine structure.
404 It can be retrieved with the corresponding
407 .It Dv EL_SETFP , Fa "int fd" , Fa "FILE *fp"
432 determines which parameter to retrieve into
434 Returns 0 if successful, \-1 otherwise.
436 The following values for
438 are supported, along with actual type of
441 .It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
442 Return a pointer to the function that displays the prompt.
443 .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
444 Return a pointer to the function that displays the rightside prompt.
445 .It Dv EL_EDITOR , Fa "const char *"
446 Return the name of the editor, which will be one of
450 .It Dv EL_GETTC , Fa "const char *name" , Fa "void *value"
458 to the current value of that capability.
459 .It Dv EL_SIGNAL , Fa "int *"
462 has installed private signal handlers (see
465 .It Dv EL_EDITMODE , Fa "int *"
466 Return non-zero if editing is enabled.
467 .It Dv EL_GETCFN , Fa "int (**f)(EditLine *, char *)"
468 Return a pointer to the function that read characters, which is equal to
469 .Dv EL_BUILTIN_GETCFN
470 in the case of the default builtin function.
471 .It Dv EL_CLIENTDATA , Fa "void **data"
474 previously registered with the corresponding
477 .It Dv EL_UNBUFFERED , Fa "int"
478 Sets or clears unbuffered mode.
481 will return immediately after processing a single character.
482 .It Dv EL_PREP_TERM , Fa "int"
483 Sets or clears terminal editing mode.
484 .It Dv EL_GETFP , Fa "int fd", Fa "FILE **fp"
507 by reading the contents of
510 is called for each line in
522 for details on the format of
525 Must be called if the terminal size changes.
530 then this is done automatically.
531 Otherwise, it is the responsibility of the application to call
533 on the appropriate occasions.
535 Return the editing information for the current line in a
537 structure, which is defined as follows:
539 typedef struct lineinfo {
540 const char *buffer; /* address of buffer */
541 const char *cursor; /* address of cursor */
542 const char *lastchar; /* address of last character */
547 is not NUL terminated.
548 This function may be called after
552 structure pertaining to line returned by that function,
553 and from within user defined functions added with
558 into the line at the cursor.
561 is empty or will not fit, and 0 otherwise.
565 characters before the cursor.
567 .Sh HISTORY LIST FUNCTIONS
568 The history functions use a common data structure,
575 The following functions are available:
578 Initialise the history list, and return a data structure
579 to be used by all other history list functions.
581 Clean up and finish with
583 assumed to have been created with
588 on the history list, with optional arguments as needed by the
591 is changed accordingly to operation.
592 The following values for
594 are supported, along with the required argument list:
596 .It Dv H_SETSIZE , Fa "int size"
597 Set size of history to
601 Get number of events currently in history.
603 Cleans up and finishes with
605 assumed to be created with
611 .Fa "history_gfun_t first" ,
612 .Fa "history_gfun_t next" ,
613 .Fa "history_gfun_t last" ,
614 .Fa "history_gfun_t prev" ,
615 .Fa "history_gfun_t curr" ,
616 .Fa "history_sfun_t set" ,
617 .Fa "history_vfun_t clear" ,
618 .Fa "history_efun_t enter" ,
619 .Fa "history_efun_t add"
621 Define functions to perform various history operations.
623 is the argument given to a function when it is invoked.
625 Return the first element in the history.
627 Return the last element in the history.
629 Return the previous element in the history.
631 Return the next element in the history.
633 Return the current element in the history.
635 Set the cursor to point to the requested element.
636 .It Dv H_ADD , Fa "const char *str"
639 to the current element of the history, or perform the
641 operation with argument
643 if there is no current element.
644 .It Dv H_APPEND , Fa "const char *str"
647 to the last new element of the history.
648 .It Dv H_ENTER , Fa "const char *str"
651 as a new element to the history, and, if necessary,
652 removing the oldest entry to keep the list to the created size.
655 was has been called with a non-zero arguments, the element
656 will not be entered into the history if its contents match
657 the ones of the current history element.
658 If the element is entered
660 returns 1, if it is ignored as a duplicate returns 0.
663 returns \-1 if an error occurred.
664 .It Dv H_PREV_STR , Fa "const char *str"
665 Return the closest previous event that starts with
667 .It Dv H_NEXT_STR , Fa "const char *str"
668 Return the closest next event that starts with
670 .It Dv H_PREV_EVENT , Fa "int e"
671 Return the previous event numbered
673 .It Dv H_NEXT_EVENT , Fa "int e"
674 Return the next event numbered
676 .It Dv H_LOAD , Fa "const char *file"
677 Load the history list stored in
679 .It Dv H_SAVE , Fa "const char *file"
680 Save the history list to
682 .It Dv H_SETUNIQUE , Fa "int unique"
683 Set flag that adjacent identical event strings should not be entered
686 Retrieve the current setting if adjacent identical elements should
687 be entered into the history.
688 .It Dv H_DEL , Fa "int e"
689 Delete the event numbered
691 This function is only provided for
694 The caller is responsible for free'ing the string in the returned
700 function returns \*[Ge] 0 if the operation
703 Otherwise, \-1 is returned and
705 is updated to contain more details about the error.
707 .Sh TOKENIZATION FUNCTIONS
708 The tokenization functions use a common data structure,
715 The following functions are available:
718 Initialise the tokenizer, and return a data structure
719 to be used by all other tokenizer functions.
721 contains the Input Field Separators, which defaults to
729 Clean up and finish with
731 assumed to have been created with
734 Reset the tokenizer state.
735 Use after a line has been successfully tokenized
740 and before a new line is to be tokenized.
744 If successful, modify:
746 to contain the words,
748 to contain the number of words,
752 to contain the index of the word containing the cursor,
757 to contain the offset within
763 \-1 for an internal error,
764 1 for an unmatched single quote,
765 2 for an unmatched double quote,
767 3 for a backslash quoted
769 A positive exit code indicates that another line should be read
770 and tokenization attempted again.
775 is a NUL terminated string to tokenize.
778 .\"XXX: provide some examples
788 library first appeared in
805 library was written by
806 .An Christos Zoulas .
808 wrote this manual and implemented
810 .Dv CC_REFRESH_BEEP ,
815 At this time, it is the responsibility of the caller to
816 check the result of the
826 should be used for further input.
829 is purely an indication of the result of the most recent