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.
17 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 .\" POSSIBILITY OF SUCH DAMAGE.
58 .Nd line editor, history and tokenization functions
64 .Fn el_init "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr"
66 .Fn el_end "EditLine *e"
68 .Fn el_reset "EditLine *e"
70 .Fn el_gets "EditLine *e" "int *count"
72 .Fn el_getc "EditLine *e" "char *ch"
74 .Fn el_push "EditLine *e" "char *str"
76 .Fn el_parse "EditLine *e" "int argc" "const char *argv[]"
78 .Fn el_set "EditLine *e" "int op" "..."
80 .Fn el_get "EditLine *e" "int op" "..."
82 .Fn el_source "EditLine *e" "const char *file"
84 .Fn el_resize "EditLine *e"
86 .Fn el_line "EditLine *e"
88 .Fn el_insertstr "EditLine *e" "const char *str"
90 .Fn el_deletestr "EditLine *e" "int count"
94 .Fn history_end "History *h"
96 .Fn history "History *h" "HistEvent *ev" "int op" "..."
98 .Fn tok_init "const char *IFS"
100 .Fn tok_end "Tokenizer *t"
102 .Fn tok_reset "Tokenizer *t"
105 .Fa "Tokenizer *t" "const LineInfo *li" "int *argc" "const char **argv[]"
106 .Fa "int *cursorc" "int *cursoro"
109 .Fn tok_str "Tokenizer *t" "const char *str" "int *argc" "const char **argv[]"
113 library provides generic line editing, history and tokenization functions,
114 similar to those found in
117 These functions are available in the
119 library (which needs the
122 Programs should be linked with
124 .Sh LINE EDITING FUNCTIONS
125 The line editing functions use a common data structure,
132 The following functions are available:
135 Initialise the line editor, and return a data structure
136 to be used by all other line editing functions.
138 is the name of the invoking program, used when reading the
140 file to determine which settings to use.
145 are the input, output, and error streams (respectively) to use.
146 In this documentation, references to
148 are actually to this input/output stream combination.
150 Clean up and finish with
152 assumed to have been created with
155 Reset the tty and the parser.
156 This should be called after an error which may have upset the tty's
159 Read a line from the tty.
161 is modified to contain the number of characters read.
162 Returns the line read if successful, or
164 if no characters were read or if an error occurred.
166 Read a character from the tty.
168 is modified to contain the character read.
169 Returns the number of characters read if successful, \-1 otherwise.
173 back onto the input stream.
174 This is used by the macro expansion mechanism.
175 Refer to the description of
180 for more information.
190 If the command is prefixed with
194 will only execute the command if
201 \-1 if the command is unknown,
202 0 if there was no error or
205 1 if the command returned an error.
208 for more information.
214 determines which parameter to set, and each operation has its
217 The following values for
219 are supported, along with the required argument list:
221 .It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
222 Define prompt printing function as
224 which is to return a string that contains the prompt.
225 .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
226 Define right side prompt printing function as
228 which is to return a string that contains the prompt.
229 .It Dv EL_TERMINAL , Fa "const char *type"
230 Define terminal type of the tty to be
238 .It Dv EL_EDITOR , Fa "const char *mode"
245 .It Dv EL_SIGNAL , Fa "int flag"
250 will install its own signal handler for the following signals when
251 reading command input:
261 Otherwise, the current signal handlers will be used.
272 for more information.
273 .It Dv EL_ECHOTC , Xo
283 for more information.
294 for more information.
305 for more information.
306 .It Dv EL_TELLTC , Xo
316 for more information.
318 .Fa "const char *name" ,
319 .Fa "const char *help" ,
320 .Fa "unsigned char (*func)(EditLine *e, int ch)"
322 Add a user defined function,
326 which is invoked when a key which is bound to
334 is the key which caused the invocation.
338 .Bl -tag -width "CC_REDISPLAY"
340 Add a normal character.
342 End of line was entered.
346 Expecting further command input as arguments, do nothing visually.
349 .It Dv CC_REFRESH_BEEP
350 Refresh display, and beep.
352 Cursor moved, so update and perform
355 Redisplay entire input line.
356 This is useful if a key binding outputs extra information.
361 Fatal error, reset tty to known state.
364 .Fa "History *(*func)(History *, int op, ...)" ,
365 .Fa "const char *ptr"
367 Defines which history function to use, which is usually
370 should be the value returned by
372 .It Dv EL_EDITMODE , Fa "int flag"
376 editing is enabled (the default).
377 Note that this is only an indication, and does not
378 affect the operation of
380 At this time, it is the caller's responsibility to
384 to determine if editing should be enabled or not.
385 .It Dv EL_GETCFN , Fa "int (*f)(EditLine *, char *c)"
386 Define the character reading function as
388 which is to return the number of characters read and store them in
390 This function is called internally by
394 The builtin function can be set or restored with the special function
396 .Dv EL_BUILTIN_GETCFN .
397 .It Dv EL_CLIENTDATA , Fa "void *data"
400 to be associated with this EditLine structure.
401 It can be retrieved with the corresponding
404 .It Dv EL_SETFP , Fa "int fd" , Fa "FILE *fp"
429 determines which parameter to retrieve into
431 Returns 0 if successful, \-1 otherwise.
433 The following values for
435 are supported, along with actual type of
438 .It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
439 Return a pointer to the function that displays the prompt.
440 .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
441 Return a pointer to the function that displays the rightside prompt.
442 .It Dv EL_EDITOR , Fa "const char *"
443 Return the name of the editor, which will be one of
447 .It Dv EL_GETTC , Fa "const char *name" , Fa "void *value"
455 to the current value of that capability.
456 .It Dv EL_SIGNAL , Fa "int *"
459 has installed private signal handlers (see
462 .It Dv EL_EDITMODE , Fa "int *"
463 Return non-zero if editing is enabled.
464 .It Dv EL_GETCFN , Fa "int (**f)(EditLine *, char *)"
465 Return a pointer to the function that read characters, which is equal to
466 .Dv EL_BUILTIN_GETCFN
467 in the case of the default builtin function.
468 .It Dv EL_CLIENTDATA , Fa "void **data"
471 previously registered with the corresponding
474 .It Dv EL_UNBUFFERED , Fa "int"
475 Sets or clears unbuffered mode.
478 will return immediately after processing a single character.
479 .It Dv EL_PREP_TERM , Fa "int"
480 Sets or clears terminal editing mode.
481 .It Dv EL_GETFP , Fa "int fd", Fa "FILE **fp"
504 by reading the contents of
507 is called for each line in
519 for details on the format of
522 Must be called if the terminal size changes.
527 then this is done automatically.
528 Otherwise, it is the responsibility of the application to call
530 on the appropriate occasions.
532 Return the editing information for the current line in a
534 structure, which is defined as follows:
536 typedef struct lineinfo {
537 const char *buffer; /* address of buffer */
538 const char *cursor; /* address of cursor */
539 const char *lastchar; /* address of last character */
544 is not NUL terminated.
545 This function may be called after
549 structure pertaining to line returned by that function,
550 and from within user defined functions added with
555 into the line at the cursor.
558 is empty or will not fit, and 0 otherwise.
562 characters before the cursor.
564 .Sh HISTORY LIST FUNCTIONS
565 The history functions use a common data structure,
572 The following functions are available:
575 Initialise the history list, and return a data structure
576 to be used by all other history list functions.
578 Clean up and finish with
580 assumed to have been created with
585 on the history list, with optional arguments as needed by the
588 is changed accordingly to operation.
589 The following values for
591 are supported, along with the required argument list:
593 .It Dv H_SETSIZE , Fa "int size"
594 Set size of history to
598 Get number of events currently in history.
600 Cleans up and finishes with
602 assumed to be created with
608 .Fa "history_gfun_t first" ,
609 .Fa "history_gfun_t next" ,
610 .Fa "history_gfun_t last" ,
611 .Fa "history_gfun_t prev" ,
612 .Fa "history_gfun_t curr" ,
613 .Fa "history_sfun_t set" ,
614 .Fa "history_vfun_t clear" ,
615 .Fa "history_efun_t enter" ,
616 .Fa "history_efun_t add"
618 Define functions to perform various history operations.
620 is the argument given to a function when it is invoked.
622 Return the first element in the history.
624 Return the last element in the history.
626 Return the previous element in the history.
628 Return the next element in the history.
630 Return the current element in the history.
632 Set the cursor to point to the requested element.
633 .It Dv H_ADD , Fa "const char *str"
636 to the current element of the history, or perform the
638 operation with argument
640 if there is no current element.
641 .It Dv H_APPEND , Fa "const char *str"
644 to the last new element of the history.
645 .It Dv H_ENTER , Fa "const char *str"
648 as a new element to the history, and, if necessary,
649 removing the oldest entry to keep the list to the created size.
652 was has been called with a non-zero arguments, the element
653 will not be entered into the history if its contents match
654 the ones of the current history element.
655 If the element is entered
657 returns 1, if it is ignored as a duplicate returns 0.
660 returns \-1 if an error occurred.
661 .It Dv H_PREV_STR , Fa "const char *str"
662 Return the closest previous event that starts with
664 .It Dv H_NEXT_STR , Fa "const char *str"
665 Return the closest next event that starts with
667 .It Dv H_PREV_EVENT , Fa "int e"
668 Return the previous event numbered
670 .It Dv H_NEXT_EVENT , Fa "int e"
671 Return the next event numbered
673 .It Dv H_LOAD , Fa "const char *file"
674 Load the history list stored in
676 .It Dv H_SAVE , Fa "const char *file"
677 Save the history list to
679 .It Dv H_SETUNIQUE , Fa "int unique"
680 Set flag that adjacent identical event strings should not be entered
683 Retrieve the current setting if adjacent identical elements should
684 be entered into the history.
685 .It Dv H_DEL , Fa "int e"
686 Delete the event numbered
688 This function is only provided for
691 The caller is responsible for free'ing the string in the returned
697 function returns \*[Ge] 0 if the operation
700 Otherwise, \-1 is returned and
702 is updated to contain more details about the error.
704 .Sh TOKENIZATION FUNCTIONS
705 The tokenization functions use a common data structure,
712 The following functions are available:
715 Initialise the tokenizer, and return a data structure
716 to be used by all other tokenizer functions.
718 contains the Input Field Separators, which defaults to
726 Clean up and finish with
728 assumed to have been created with
731 Reset the tokenizer state.
732 Use after a line has been successfully tokenized
737 and before a new line is to be tokenized.
741 if successful, modify
743 to contain the words,
745 to contain the number of words,
749 to contain the index of the word containing the cursor,
754 to contain the offset within
760 \-1 for an internal error,
761 1 for an unmatched single quote,
762 2 for an unmatched double quote,
764 3 for a backslash quoted
766 A positive exit code indicates that another line should be read
767 and tokenization attempted again.
772 is a NUL terminated string to tokenize.
775 .\"XXX: provide some examples
785 library first appeared in
802 library was written by
803 .An Christos Zoulas .
805 wrote this manual and implemented
807 .Dv CC_REFRESH_BEEP ,
812 At this time, it is the responsibility of the caller to
813 check the result of the
823 should be used for further input.
826 is purely an indication of the result of the most recent