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. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the NetBSD
17 .\" Foundation, Inc. and its contributors.
18 .\" 4. Neither the name of The NetBSD Foundation nor the names of its
19 .\" contributors may be used to endorse or promote products derived
20 .\" from this software without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 .\" POSSIBILITY OF SUCH DAMAGE.
34 .\" $NetBSD: editline.3,v 1.46 2005/03/19 17:36:02 christos Exp $
35 .\" $DragonFly: src/lib/libedit/editline.3,v 1.3 2005/11/13 11:58:30 corecode Exp $
63 .Nd line editor, history and tokenization functions
69 .Fn el_init "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr"
71 .Fn el_end "EditLine *e"
73 .Fn el_reset "EditLine *e"
75 .Fn el_gets "EditLine *e" "int *count"
77 .Fn el_getc "EditLine *e" "char *ch"
79 .Fn el_push "EditLine *e" "const char *str"
81 .Fn el_parse "EditLine *e" "int argc" "const char *argv[]"
83 .Fn el_set "EditLine *e" "int op" "..."
85 .Fn el_get "EditLine *e" "int op" "void *result"
87 .Fn el_source "EditLine *e" "const char *file"
89 .Fn el_resize "EditLine *e"
91 .Fn el_line "EditLine *e"
93 .Fn el_insertstr "EditLine *e" "const char *str"
95 .Fn el_deletestr "EditLine *e" "int count"
99 .Fn history_end "History *h"
101 .Fn history "History *h" "HistEvent *ev" "int op" "..."
103 .Fn tok_init "const char *IFS"
105 .Fn tok_end "Tokenizer *t"
107 .Fn tok_reset "Tokenizer *t"
109 .Fn tok_line "Tokenizer *t" "const LineInfo *li" "int *argc" "const char **argv[]" "int *cursorc" "int *cursoro"
111 .Fn tok_str "Tokenizer *t" "const char *str" "int *argc" "const char **argv[]"
115 library provides generic line editing, history and tokenization functions,
116 similar to those found in
119 These functions are available in the
121 library (which needs the
124 Programs should be linked with
126 .Sh LINE EDITING FUNCTIONS
127 The line editing functions use a common data structure,
134 The following functions are available:
137 Initialise the line editor, and return a data structure
138 to be used by all other line editing functions.
140 is the name of the invoking program, used when reading the
142 file to determine which settings to use.
147 are the input, output, and error streams (respectively) to use.
148 In this documentation, references to
150 are actually to this input/output stream combination.
152 Clean up and finish with
154 assumed to have been created with
157 Reset the tty and the parser.
158 This should be called after an error which may have upset the tty's
161 Read a line from the tty.
163 is modified to contain the number of characters read.
164 Returns the line read if successful, or
166 if no characters were read or if an error occurred.
168 Read a character from the tty.
170 is modified to contain the character read.
171 Returns the number of characters read if successful, \-1 otherwise.
175 back onto the input stream.
176 This is used by the macro expansion mechanism.
177 Refer to the description of
182 for more information.
192 If the command is prefixed with
196 will only execute the command if
203 \-1 if the command is unknown,
204 0 if there was no error or
207 1 if the command returned an error.
210 for more information.
216 determines which parameter to set, and each operation has its
219 The following values for
221 are supported, along with the required argument list:
223 .It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
224 Define prompt printing function as
226 which is to return a string that contains the prompt.
227 .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
228 Define right side prompt printing function as
230 which is to return a string that contains the prompt.
231 .It Dv EL_TERMINAL , Fa "const char *type"
232 Define terminal type of the tty to be
240 .It Dv EL_EDITOR , Fa "const char *mode"
247 .It Dv EL_SIGNAL , Fa "int flag"
252 will install its own signal handler for the following signals when
253 reading command input:
263 Otherwise, the current signal handlers will be used.
274 for more information.
275 .It Dv EL_ECHOTC , Xo
285 for more information.
296 for more information.
307 for more information.
308 .It Dv EL_TELLTC , Xo
318 for more information.
320 .Fa "const char *name" ,
321 .Fa "const char *help" ,
322 .Fa "unsigned char (*func)(EditLine *e, int ch)"
324 Add a user defined function,
328 which is invoked when a key which is bound to
336 is the key which caused the invocation.
340 .Bl -tag -width "CC_REDISPLAY"
342 Add a normal character.
344 End of line was entered.
348 Expecting further command input as arguments, do nothing visually.
351 .It Dv CC_REFRESH_BEEP
352 Refresh display, and beep.
354 Cursor moved, so update and perform
357 Redisplay entire input line.
358 This is useful if a key binding outputs extra information.
363 Fatal error, reset tty to known state.
366 .Fa "History *(*func)(History *, int op, ...)" ,
367 .Fa "const char *ptr"
369 Defines which history function to use, which is usually
372 should be the value returned by
374 .It Dv EL_EDITMODE , Fa "int flag"
378 editing is enabled (the default).
379 Note that this is only an indication, and does not
380 affect the operation of
382 At this time, it is the caller's responsibility to
386 to determine if editing should be enabled or not.
387 .It Dv EL_GETCFN , Fa "int (*f)(EditLine *, char *c)"
388 Define the character reading function as
390 which is to return the number of characters read and store them in
392 This function is called internally by
396 The builtin function can be set or restored with the special function
397 name ``EL_BUILTIN_GETCFN''.
398 .It Dv EL_CLIENTDATA , Fa "void *data"
401 to be associated with this EditLine structure.
402 It can be retrieved with the corresponding
411 determines which parameter to retrieve into
413 Returns 0 if successful, \-1 otherwise.
415 The following values for
417 are supported, along with actual type of
420 .It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
421 Return a pointer to the function that displays the prompt.
422 .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
423 Return a pointer to the function that displays the rightside prompt.
424 .It Dv EL_EDITOR , Fa "const char *"
425 Return the name of the editor, which will be one of
429 .It Dv EL_SIGNAL , Fa "int *"
432 has installed private signal handlers (see
435 .It Dv EL_EDITMODE, Fa "int *"
436 Return non-zero if editing is enabled.
437 .It Dv EL_GETCFN, Fa "int (**f)(EditLine *, char *)"
438 Return a pointer to the function that read characters, which is equal to
439 ``EL_BUILTIN_GETCFN'' in the case of the default builtin function.
440 .It Dv EL_CLIENTDATA , Fa "void **data"
443 previously registered with the corresponding
446 .It Dv EL_UNBUFFERED, Fa "int"
447 Sets or clears unbuffered mode.
450 will return immediately after processing a single character.
451 .It Dv EL_PREP_TERM, Fa "int"
452 Sets or clears terminal editing mode.
457 by reading the contents of
460 is called for each line in
472 for details on the format of
475 Must be called if the terminal size changes.
480 then this is done automatically.
481 Otherwise, it's the responsibility of the application to call
483 on the appropriate occasions.
485 Return the editing information for the current line in a
487 structure, which is defined as follows:
489 typedef struct lineinfo {
490 const char *buffer; /* address of buffer */
491 const char *cursor; /* address of cursor */
492 const char *lastchar; /* address of last character */
497 is not NUL terminated.
498 This function may be called after
502 structure pertaining to line returned by that function,
503 and from within user defined functions added with
508 into the line at the cursor.
511 is empty or won't fit, and 0 otherwise.
515 characters before the cursor.
517 .Sh HISTORY LIST FUNCTIONS
518 The history functions use a common data structure,
525 The following functions are available:
528 Initialise the history list, and return a data structure
529 to be used by all other history list functions.
531 Clean up and finish with
533 assumed to have been created with
538 on the history list, with optional arguments as needed by the
541 is changed accordingly to operation.
542 The following values for
544 are supported, along with the required argument list:
546 .It Dv H_SETSIZE , Fa "int size"
547 Set size of history to
551 Get number of events currently in history.
553 Cleans up and finishes with
555 assumed to be created with
561 .Fa "history_gfun_t first" ,
562 .Fa "history_gfun_t next" ,
563 .Fa "history_gfun_t last" ,
564 .Fa "history_gfun_t prev" ,
565 .Fa "history_gfun_t curr" ,
566 .Fa "history_sfun_t set" ,
567 .Fa "history_vfun_t clear" ,
568 .Fa "history_efun_t enter" ,
569 .Fa "history_efun_t add"
571 Define functions to perform various history operations.
573 is the argument given to a function when it's invoked.
575 Return the first element in the history.
577 Return the last element in the history.
579 Return the previous element in the history.
581 Return the next element in the history.
583 Return the current element in the history.
585 Set the cursor to point to the requested element.
586 .It Dv H_ADD , Fa "const char *str"
589 to the current element of the history, or perform the
591 operation with argument
593 if there is no current element.
594 .It Dv H_APPEND , Fa "const char *str"
597 to the last new element of the history.
598 .It Dv H_ENTER , Fa "const char *str"
601 as a new element to the history, and, if necessary,
602 removing the oldest entry to keep the list to the created size.
605 was has been called with a non-zero arguments, the element
606 will not be entered into the history if its contents match
607 the ones of the current history element.
608 If the element is entered
610 returns 1, if it is ignored as a duplicate returns 0.
613 returns \-1 if an error occurred.
614 .It Dv H_PREV_STR , Fa "const char *str"
615 Return the closest previous event that starts with
617 .It Dv H_NEXT_STR , Fa "const char *str"
618 Return the closest next event that starts with
620 .It Dv H_PREV_EVENT , Fa "int e"
621 Return the previous event numbered
623 .It Dv H_NEXT_EVENT , Fa "int e"
624 Return the next event numbered
626 .It Dv H_LOAD , Fa "const char *file"
627 Load the history list stored in
629 .It Dv H_SAVE , Fa "const char *file"
630 Save the history list to
632 .It Dv H_SETUNIQUE , Fa "int unique"
633 Set if the adjacent identical event strings should not be entered into
636 Retrieve the current setting if if adjacent elements should be entered into
641 returns \*[Gt]= 0 if the operation
644 Otherwise, \-1 is returned and
646 is updated to contain more details about the error.
648 .Sh TOKENIZATION FUNCTIONS
649 The tokenization functions use a common data structure,
656 The following functions are available:
659 Initialise the tokenizer, and return a data structure
660 to be used by all other tokenizer functions.
662 contains the Input Field Separators, which defaults to
670 Clean up and finish with
672 assumed to have been created with
675 Reset the tokenizer state.
676 Use after a line has been successfully tokenized
681 and before a new line is to be tokenized.
685 If successful, modify:
687 to contain the words,
689 to contain the number of words,
693 to contain the index of the word containing the cursor,
698 to contain the offset within
704 \-1 for an internal error,
705 1 for an unmatched single quote,
706 2 for an unmatched double quote,
708 3 for a backslash quoted
710 A positive exit code indicates that another line should be read
711 and tokenization attempted again.
717 is a NUL terminated string to tokenize.
721 .\"XXX: provide some examples
730 library first appeared in
735 .Dv CC_REFRESH_BEEP ,
737 and the readline emulation appeared in
745 library was written by Christos Zoulas.
746 Luke Mewburn wrote this manual and implemented
748 .Dv CC_REFRESH_BEEP ,
752 Jaromir Dolecek implemented the readline emulation.
754 At this time, it is the responsibility of the caller to
755 check the result of the
765 should be used for further input.
768 is purely an indication of the result of the most recent