1 .\" $NetBSD: editline.3,v 1.51 2006/08/21 12:45:30 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" "void *result"
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
413 determines which parameter to retrieve into
415 Returns 0 if successful, \-1 otherwise.
417 The following values for
419 are supported, along with actual type of
422 .It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
423 Return a pointer to the function that displays the prompt.
424 .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
425 Return a pointer to the function that displays the rightside prompt.
426 .It Dv EL_EDITOR , Fa "const char *"
427 Return the name of the editor, which will be one of
431 .It Dv EL_SIGNAL , Fa "int *"
434 has installed private signal handlers (see
437 .It Dv EL_EDITMODE, Fa "int *"
438 Return non-zero if editing is enabled.
439 .It Dv EL_GETCFN, Fa "int (**f)(EditLine *, char *)"
440 Return a pointer to the function that read characters, which is equal to
441 .Dv EL_BUILTIN_GETCFN
442 in the case of the default builtin function.
443 .It Dv EL_CLIENTDATA , Fa "void **data"
446 previously registered with the corresponding
449 .It Dv EL_UNBUFFERED, Fa "int"
450 Sets or clears unbuffered mode.
453 will return immediately after processing a single character.
454 .It Dv EL_PREP_TERM, Fa "int"
455 Sets or clears terminal editing mode.
460 by reading the contents of
463 is called for each line in
475 for details on the format of
478 Must be called if the terminal size changes.
483 then this is done automatically.
484 Otherwise, it is the responsibility of the application to call
486 on the appropriate occasions.
488 Return the editing information for the current line in a
490 structure, which is defined as follows:
492 typedef struct lineinfo {
493 const char *buffer; /* address of buffer */
494 const char *cursor; /* address of cursor */
495 const char *lastchar; /* address of last character */
500 is not NUL terminated.
501 This function may be called after
505 structure pertaining to line returned by that function,
506 and from within user defined functions added with
511 into the line at the cursor.
514 is empty or will not fit, and 0 otherwise.
518 characters before the cursor.
520 .Sh HISTORY LIST FUNCTIONS
521 The history functions use a common data structure,
528 The following functions are available:
531 Initialise the history list, and return a data structure
532 to be used by all other history list functions.
534 Clean up and finish with
536 assumed to have been created with
541 on the history list, with optional arguments as needed by the
544 is changed accordingly to operation.
545 The following values for
547 are supported, along with the required argument list:
549 .It Dv H_SETSIZE , Fa "int size"
550 Set size of history to
554 Get number of events currently in history.
556 Cleans up and finishes with
558 assumed to be created with
564 .Fa "history_gfun_t first" ,
565 .Fa "history_gfun_t next" ,
566 .Fa "history_gfun_t last" ,
567 .Fa "history_gfun_t prev" ,
568 .Fa "history_gfun_t curr" ,
569 .Fa "history_sfun_t set" ,
570 .Fa "history_vfun_t clear" ,
571 .Fa "history_efun_t enter" ,
572 .Fa "history_efun_t add"
574 Define functions to perform various history operations.
576 is the argument given to a function when it is invoked.
578 Return the first element in the history.
580 Return the last element in the history.
582 Return the previous element in the history.
584 Return the next element in the history.
586 Return the current element in the history.
588 Set the cursor to point to the requested element.
589 .It Dv H_ADD , Fa "const char *str"
592 to the current element of the history, or perform the
594 operation with argument
596 if there is no current element.
597 .It Dv H_APPEND , Fa "const char *str"
600 to the last new element of the history.
601 .It Dv H_ENTER , Fa "const char *str"
604 as a new element to the history, and, if necessary,
605 removing the oldest entry to keep the list to the created size.
608 was has been called with a non-zero arguments, the element
609 will not be entered into the history if its contents match
610 the ones of the current history element.
611 If the element is entered
613 returns 1, if it is ignored as a duplicate returns 0.
616 returns \-1 if an error occurred.
617 .It Dv H_PREV_STR , Fa "const char *str"
618 Return the closest previous event that starts with
620 .It Dv H_NEXT_STR , Fa "const char *str"
621 Return the closest next event that starts with
623 .It Dv H_PREV_EVENT , Fa "int e"
624 Return the previous event numbered
626 .It Dv H_NEXT_EVENT , Fa "int e"
627 Return the next event numbered
629 .It Dv H_LOAD , Fa "const char *file"
630 Load the history list stored in
632 .It Dv H_SAVE , Fa "const char *file"
633 Save the history list to
635 .It Dv H_SETUNIQUE , Fa "int unique"
636 Set flag that adjacent identical event strings should not be entered
639 Retrieve the current setting if adjacent identical elements should
640 be entered into the history.
641 .It Dv H_DEL , Fa "int num"
642 Delete the event numbered
644 This function is only provided for
647 The caller is responsible for free'ing the string in the returned
653 function returns \*[Ge] 0 if the operation
656 Otherwise, \-1 is returned and
658 is updated to contain more details about the error.
660 .Sh TOKENIZATION FUNCTIONS
661 The tokenization functions use a common data structure,
668 The following functions are available:
671 Initialise the tokenizer, and return a data structure
672 to be used by all other tokenizer functions.
674 contains the Input Field Separators, which defaults to
682 Clean up and finish with
684 assumed to have been created with
687 Reset the tokenizer state.
688 Use after a line has been successfully tokenized
693 and before a new line is to be tokenized.
697 If successful, modify:
699 to contain the words,
701 to contain the number of words,
705 to contain the index of the word containing the cursor,
710 to contain the offset within
716 \-1 for an internal error,
717 1 for an unmatched single quote,
718 2 for an unmatched double quote,
720 3 for a backslash quoted
722 A positive exit code indicates that another line should be read
723 and tokenization attempted again.
728 is a NUL terminated string to tokenize.
731 .\"XXX: provide some examples
740 library first appeared in
757 library was written by
758 .An Christos Zoulas .
760 wrote this manual and implemented
762 .Dv CC_REFRESH_BEEP ,
767 At this time, it is the responsibility of the caller to
768 check the result of the
778 should be used for further input.
781 is purely an indication of the result of the most recent