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.
14 .\" 3. Neither the name of The NetBSD Foundation nor the names of its
15 .\" contributors may be used to endorse or promote products derived
16 .\" from this software without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
30 .\" $NetBSD: editline.3,v 1.55 2007/01/12 16:31:13 christos Exp $
31 .\" $DragonFly: src/lib/libedit/editline.3,v 1.4 2007/05/05 00:27:39 pavalos Exp $
60 .Nd line editor, history and tokenization functions
66 .Fn el_init "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr"
68 .Fn el_end "EditLine *e"
70 .Fn el_reset "EditLine *e"
72 .Fn el_gets "EditLine *e" "int *count"
74 .Fn el_getc "EditLine *e" "char *ch"
76 .Fn el_push "EditLine *e" "const char *str"
78 .Fn el_parse "EditLine *e" "int argc" "const char *argv[]"
80 .Fn el_set "EditLine *e" "int op" "..."
82 .Fn el_get "EditLine *e" "int op" "..."
84 .Fn el_source "EditLine *e" "const char *file"
86 .Fn el_resize "EditLine *e"
88 .Fn el_line "EditLine *e"
90 .Fn el_insertstr "EditLine *e" "const char *str"
92 .Fn el_deletestr "EditLine *e" "int count"
96 .Fn history_end "History *h"
98 .Fn history "History *h" "HistEvent *ev" "int op" "..."
100 .Fn tok_init "const char *IFS"
102 .Fn tok_end "Tokenizer *t"
104 .Fn tok_reset "Tokenizer *t"
106 .Fn tok_line "Tokenizer *t" "const LineInfo *li" "int *argc" "const char **argv[]" "int *cursorc" "int *cursoro"
108 .Fn tok_str "Tokenizer *t" "const char *str" "int *argc" "const char **argv[]"
112 library provides generic line editing, history and tokenization functions,
113 similar to those found in
116 These functions are available in the
118 library (which needs the
121 Programs should be linked with
123 .Sh LINE EDITING FUNCTIONS
124 The line editing functions use a common data structure,
131 The following functions are available:
134 Initialise the line editor, and return a data structure
135 to be used by all other line editing functions.
137 is the name of the invoking program, used when reading the
139 file to determine which settings to use.
144 are the input, output, and error streams (respectively) to use.
145 In this documentation, references to
147 are actually to this input/output stream combination.
149 Clean up and finish with
151 assumed to have been created with
154 Reset the tty and the parser.
155 This should be called after an error which may have upset the tty's
158 Read a line from the tty.
160 is modified to contain the number of characters read.
161 Returns the line read if successful, or
163 if no characters were read or if an error occurred.
165 Read a character from the tty.
167 is modified to contain the character read.
168 Returns the number of characters read if successful, \-1 otherwise.
172 back onto the input stream.
173 This is used by the macro expansion mechanism.
174 Refer to the description of
179 for more information.
189 If the command is prefixed with
193 will only execute the command if
200 \-1 if the command is unknown,
201 0 if there was no error or
204 1 if the command returned an error.
207 for more information.
213 determines which parameter to set, and each operation has its
216 The following values for
218 are supported, along with the required argument list:
220 .It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
221 Define prompt printing function as
223 which is to return a string that contains the prompt.
224 .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
225 Define right side prompt printing function as
227 which is to return a string that contains the prompt.
228 .It Dv EL_TERMINAL , Fa "const char *type"
229 Define terminal type of the tty to be
237 .It Dv EL_EDITOR , Fa "const char *mode"
244 .It Dv EL_SIGNAL , Fa "int flag"
249 will install its own signal handler for the following signals when
250 reading command input:
260 Otherwise, the current signal handlers will be used.
271 for more information.
272 .It Dv EL_ECHOTC , Xo
282 for more information.
293 for more information.
304 for more information.
305 .It Dv EL_TELLTC , Xo
315 for more information.
317 .Fa "const char *name" ,
318 .Fa "const char *help" ,
319 .Fa "unsigned char (*func)(EditLine *e, int ch)"
321 Add a user defined function,
325 which is invoked when a key which is bound to
333 is the key which caused the invocation.
337 .Bl -tag -width "CC_REDISPLAY"
339 Add a normal character.
341 End of line was entered.
345 Expecting further command input as arguments, do nothing visually.
348 .It Dv CC_REFRESH_BEEP
349 Refresh display, and beep.
351 Cursor moved, so update and perform
354 Redisplay entire input line.
355 This is useful if a key binding outputs extra information.
360 Fatal error, reset tty to known state.
363 .Fa "History *(*func)(History *, int op, ...)" ,
364 .Fa "const char *ptr"
366 Defines which history function to use, which is usually
369 should be the value returned by
371 .It Dv EL_EDITMODE , Fa "int flag"
375 editing is enabled (the default).
376 Note that this is only an indication, and does not
377 affect the operation of
379 At this time, it is the caller's responsibility to
383 to determine if editing should be enabled or not.
384 .It Dv EL_GETCFN , Fa "int (*f)(EditLine *, char *c)"
385 Define the character reading function as
387 which is to return the number of characters read and store them in
389 This function is called internally by
393 The builtin function can be set or restored with the special function
394 name ``EL_BUILTIN_GETCFN''.
395 .It Dv EL_CLIENTDATA , Fa "void *data"
398 to be associated with this EditLine structure.
399 It can be retrieved with the corresponding
402 .It Dv EL_SETFP , Fa "int fd" , Fa "FILE *fp"
427 determines which parameter to retrieve into
429 Returns 0 if successful, \-1 otherwise.
431 The following values for
433 are supported, along with actual type of
436 .It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
437 Return a pointer to the function that displays the prompt.
438 .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
439 Return a pointer to the function that displays the rightside prompt.
440 .It Dv EL_EDITOR , Fa "const char *"
441 Return the name of the editor, which will be one of
445 .It Dv EL_GETTC , Fa "const char *name" , Fa "void *value"
453 to the current value of that capability.
454 .It Dv EL_SIGNAL , Fa "int *"
457 has installed private signal handlers (see
460 .It Dv EL_EDITMODE , Fa "int *"
461 Return non-zero if editing is enabled.
462 .It Dv EL_GETCFN , Fa "int (**f)(EditLine *, char *)"
463 Return a pointer to the function that read characters, which is equal to
464 ``EL_BUILTIN_GETCFN'' in the case of the default builtin function.
465 .It Dv EL_CLIENTDATA , Fa "void **data"
468 previously registered with the corresponding
471 .It Dv EL_UNBUFFERED , Fa "int"
472 Sets or clears unbuffered mode.
475 will return immediately after processing a single character.
476 .It Dv EL_PREP_TERM , Fa "int"
477 Sets or clears terminal editing mode.
478 .It Dv EL_GETFP , Fa "int fd", Fa "FILE **fp"
501 by reading the contents of
504 is called for each line in
516 for details on the format of
519 Must be called if the terminal size changes.
524 then this is done automatically.
525 Otherwise, it's the responsibility of the application to call
527 on the appropriate occasions.
529 Return the editing information for the current line in a
531 structure, which is defined as follows:
533 typedef struct lineinfo {
534 const char *buffer; /* address of buffer */
535 const char *cursor; /* address of cursor */
536 const char *lastchar; /* address of last character */
541 is not NUL terminated.
542 This function may be called after
546 structure pertaining to line returned by that function,
547 and from within user defined functions added with
552 into the line at the cursor.
555 is empty or won't fit, and 0 otherwise.
559 characters before the cursor.
561 .Sh HISTORY LIST FUNCTIONS
562 The history functions use a common data structure,
569 The following functions are available:
572 Initialise the history list, and return a data structure
573 to be used by all other history list functions.
575 Clean up and finish with
577 assumed to have been created with
582 on the history list, with optional arguments as needed by the
585 is changed accordingly to operation.
586 The following values for
588 are supported, along with the required argument list:
590 .It Dv H_SETSIZE , Fa "int size"
591 Set size of history to
595 Get number of events currently in history.
597 Cleans up and finishes with
599 assumed to be created with
605 .Fa "history_gfun_t first" ,
606 .Fa "history_gfun_t next" ,
607 .Fa "history_gfun_t last" ,
608 .Fa "history_gfun_t prev" ,
609 .Fa "history_gfun_t curr" ,
610 .Fa "history_sfun_t set" ,
611 .Fa "history_vfun_t clear" ,
612 .Fa "history_efun_t enter" ,
613 .Fa "history_efun_t add"
615 Define functions to perform various history operations.
617 is the argument given to a function when it's invoked.
619 Return the first element in the history.
621 Return the last element in the history.
623 Return the previous element in the history.
625 Return the next element in the history.
627 Return the current element in the history.
629 Set the cursor to point to the requested element.
630 .It Dv H_ADD , Fa "const char *str"
633 to the current element of the history, or perform the
635 operation with argument
637 if there is no current element.
638 .It Dv H_APPEND , Fa "const char *str"
641 to the last new element of the history.
642 .It Dv H_ENTER , Fa "const char *str"
645 as a new element to the history, and, if necessary,
646 removing the oldest entry to keep the list to the created size.
649 was has been called with a non-zero arguments, the element
650 will not be entered into the history if its contents match
651 the ones of the current history element.
652 If the element is entered
654 returns 1, if it is ignored as a duplicate returns 0.
657 returns \-1 if an error occurred.
658 .It Dv H_PREV_STR , Fa "const char *str"
659 Return the closest previous event that starts with
661 .It Dv H_NEXT_STR , Fa "const char *str"
662 Return the closest next event that starts with
664 .It Dv H_PREV_EVENT , Fa "int e"
665 Return the previous event numbered
667 .It Dv H_NEXT_EVENT , Fa "int e"
668 Return the next event numbered
670 .It Dv H_LOAD , Fa "const char *file"
671 Load the history list stored in
673 .It Dv H_SAVE , Fa "const char *file"
674 Save the history list to
676 .It Dv H_SETUNIQUE , Fa "int unique"
677 Set flag that adjacent identical event strings should not be entered
680 Retrieve the current setting if adjacent identical elements should
681 be entered into the history.
682 .It Dv H_DEL , Fa "int e"
683 Delete the event numbered
685 This function is only provided for
688 The caller is responsible for free'ing the string in the returned
693 returns \*[Gt]= 0 if the operation
696 Otherwise, \-1 is returned and
698 is updated to contain more details about the error.
700 .Sh TOKENIZATION FUNCTIONS
701 The tokenization functions use a common data structure,
708 The following functions are available:
711 Initialise the tokenizer, and return a data structure
712 to be used by all other tokenizer functions.
714 contains the Input Field Separators, which defaults to
722 Clean up and finish with
724 assumed to have been created with
727 Reset the tokenizer state.
728 Use after a line has been successfully tokenized
733 and before a new line is to be tokenized.
737 If successful, modify:
739 to contain the words,
741 to contain the number of words,
745 to contain the index of the word containing the cursor,
750 to contain the offset within
756 \-1 for an internal error,
757 1 for an unmatched single quote,
758 2 for an unmatched double quote,
760 3 for a backslash quoted
762 A positive exit code indicates that another line should be read
763 and tokenization attempted again.
769 is a NUL terminated string to tokenize.
773 .\"XXX: provide some examples
783 library first appeared in
788 .Dv CC_REFRESH_BEEP ,
790 and the readline emulation appeared in
798 library was written by Christos Zoulas.
799 Luke Mewburn wrote this manual and implemented
801 .Dv CC_REFRESH_BEEP ,
805 Jaromir Dolecek implemented the readline emulation.
807 At this time, it is the responsibility of the caller to
808 check the result of the
818 should be used for further input.
821 is purely an indication of the result of the most recent