]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libedit/editline.3
MFC 302860: Fix aio system call wrappers in librt.
[FreeBSD/FreeBSD.git] / lib / libedit / editline.3
1 .\"     $NetBSD: editline.3,v 1.85 2015/11/03 21:36:59 christos Exp $
2 .\"
3 .\" Copyright (c) 1997-2014 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
5 .\"
6 .\" This file was contributed to The NetBSD Foundation by Luke Mewburn.
7 .\"
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
10 .\" are met:
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 .\"
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.
28 .\"
29 .\" $FreeBSD$
30 .\"
31 .Dd November 3, 2015
32 .Dt EDITLINE 3
33 .Os
34 .Sh NAME
35 .Nm editline ,
36 .Nm el_init ,
37 .Nm el_init_fd ,
38 .Nm el_end ,
39 .Nm el_reset ,
40 .Nm el_gets ,
41 .Nm el_wgets ,
42 .Nm el_getc ,
43 .Nm el_wgetc ,
44 .Nm el_push ,
45 .Nm el_wpush ,
46 .Nm el_parse ,
47 .Nm el_wparse ,
48 .Nm el_set ,
49 .Nm el_wset ,
50 .Nm el_get ,
51 .Nm el_wget ,
52 .Nm el_source ,
53 .Nm el_resize ,
54 .Nm el_cursor ,
55 .Nm el_line ,
56 .Nm el_wline ,
57 .Nm el_insertstr ,
58 .Nm el_winsertstr ,
59 .Nm el_deletestr ,
60 .Nm el_wdeletestr ,
61 .Nm history_init ,
62 .Nm history_winit ,
63 .Nm history_end ,
64 .Nm history_wend ,
65 .Nm history ,
66 .Nm history_w ,
67 .Nm tok_init ,
68 .Nm tok_winit ,
69 .Nm tok_end ,
70 .Nm tok_wend ,
71 .Nm tok_reset ,
72 .Nm tok_wreset ,
73 .Nm tok_line ,
74 .Nm tok_wline ,
75 .Nm tok_str
76 .Nm tok_wstr
77 .Nd line editor, history and tokenization functions
78 .Sh LIBRARY
79 .Lb libedit
80 .Sh SYNOPSIS
81 .In histedit.h
82 .Ft EditLine *
83 .Fn el_init "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr"
84 .Ft EditLine *
85 .Fn el_init_fd "const char *prog" "FILE *fin" "FILE *fout" "FILE *ferr" "int fdin" "int fdout" "int fderr"
86 .Ft void
87 .Fn el_end "EditLine *e"
88 .Ft void
89 .Fn el_reset "EditLine *e"
90 .Ft const char *
91 .Fn el_gets "EditLine *e" "int *count"
92 .Ft const wchar_t *
93 .Fn el_wgets "EditLine *e" "int *count"
94 .Ft int
95 .Fn el_getc "EditLine *e" "char *ch"
96 .Ft int
97 .Fn el_wgetc "EditLine *e" "wchar_t *ch"
98 .Ft void
99 .Fn el_push "EditLine *e" "const char *str"
100 .Ft void
101 .Fn el_wpush "EditLine *e" "const wchar_t *str"
102 .Ft int
103 .Fn el_parse "EditLine *e" "int argc" "const char *argv[]"
104 .Ft int
105 .Fn el_wparse "EditLine *e" "int argc" "const wchar_t *argv[]"
106 .Ft int
107 .Fn el_set "EditLine *e" "int op" "..."
108 .Ft int
109 .Fn el_wset "EditLine *e" "int op" "..."
110 .Ft int
111 .Fn el_get "EditLine *e" "int op" "..."
112 .Ft int
113 .Fn el_wget "EditLine *e" "int op" "..."
114 .Ft int
115 .Fn el_source "EditLine *e" "const char *file"
116 .Ft void
117 .Fn el_resize "EditLine *e"
118 .Fn int
119 .Fn el_cursor "EditLine *e" "int count"
120 .Ft const LineInfo *
121 .Fn el_line "EditLine *e"
122 .Ft const LineInfoW *
123 .Fn el_wline "EditLine *e"
124 .Ft int
125 .Fn el_insertstr "EditLine *e" "const char *str"
126 .Ft int
127 .Fn el_winsertstr "EditLine *e" "const wchar_t *str"
128 .Ft void
129 .Fn el_deletestr "EditLine *e" "int count"
130 .Ft void
131 .Fn el_wdeletestr "EditLine *e" "int count"
132 .Ft History *
133 .Fn history_init
134 .Ft HistoryW *
135 .Fn history_winit
136 .Ft void
137 .Fn history_end "History *h"
138 .Ft void
139 .Fn history_wend "HistoryW *h"
140 .Ft int
141 .Fn history "History *h" "HistEvent *ev" "int op" "..."
142 .Ft int
143 .Fn history_w "HistoryW *h" "HistEventW *ev" "int op" "..."
144 .Ft Tokenizer *
145 .Fn tok_init "const char *IFS"
146 .Ft TokenizerW *
147 .Fn tok_winit "const wchar_t *IFS"
148 .Ft void
149 .Fn tok_end "Tokenizer *t"
150 .Ft void
151 .Fn tok_wend "TokenizerW *t"
152 .Ft void
153 .Fn tok_reset "Tokenizer *t"
154 .Ft void
155 .Fn tok_wreset "TokenizerW *t"
156 .Ft int
157 .Fn tok_line "Tokenizer *t" "const LineInfo *li" "int *argc" "const char **argv[]" "int *cursorc" "int *cursoro"
158 .Ft int
159 .Fn tok_wline "TokenizerW *t" "const LineInfoW *li" "int *argc" "const wchar_t **argv[]" "int *cursorc" "int *cursoro"
160 .Ft int
161 .Fn tok_str "Tokenizer *t" "const char *str" "int *argc" "const char **argv[]"
162 .Ft int
163 .Fn tok_wstr "TokenizerW *t" "const wchar_t *str" "int *argc" "const wchar_t **argv[]"
164 .Sh DESCRIPTION
165 The
166 .Nm
167 library provides generic line editing, history and tokenization functions,
168 similar to those found in
169 .Xr sh 1 .
170 .Pp
171 These functions are available in the
172 .Nm libedit
173 library (which needs the
174 .Nm libtermcap
175 library).
176 Programs should be linked with
177 .Fl ledit ltermcap .
178 .Sh LINE EDITING FUNCTIONS
179 The line editing functions use a common data structure,
180 .Fa EditLine ,
181 which is created by
182 .Fn el_init
183 or
184 .Fn el_init_fd
185 and freed by
186 .Fn el_end .
187 .Pp
188 The wide-character functions behave the same way as their narrow
189 counterparts.
190 .Pp
191 The following functions are available:
192 .Bl -tag -width 4n
193 .It Fn el_init
194 Initialize the line editor, and return a data structure
195 to be used by all other line editing functions, or
196 .Dv NULL
197 on failure.
198 .Fa prog
199 is the name of the invoking program, used when reading the
200 .Xr editrc 5
201 file to determine which settings to use.
202 .Fa fin ,
203 .Fa fout
204 and
205 .Fa ferr
206 are the input, output, and error streams (respectively) to use.
207 In this documentation, references to
208 .Dq the tty
209 are actually to this input/output stream combination.
210 .It Fn el_init_fd
211 Like
212 .Fn el_init
213 but allows specifying file descriptors for the
214 .Xr stdio 3
215 corresponding streams, in case those were created with
216 .Xr funopen 3 .
217 .It Fn el_end
218 Clean up and finish with
219 .Fa e ,
220 assumed to have been created with
221 .Fn el_init
222 or
223 .Fn el_init_fd .
224 .It Fn el_reset
225 Reset the tty and the parser.
226 This should be called after an error which may have upset the tty's
227 state.
228 .It Fn el_gets
229 Read a line from the tty.
230 .Fa count
231 is modified to contain the number of characters read.
232 Returns the line read if successful, or
233 .Dv NULL
234 if no characters were read or if an error occurred.
235 If an error occurred,
236 .Fa count
237 is set to \-1 and
238 .Dv errno
239 contains the error code that caused it.
240 The return value may not remain valid across calls to
241 .Fn el_gets
242 and must be copied if the data is to be retained.
243 .It Fn el_getc
244 Read a character from the tty.
245 .Fa ch
246 is modified to contain the character read.
247 Returns the number of characters read if successful, \-1 otherwise,
248 in which case
249 .Dv errno
250 can be inspected for the cause.
251 .It Fn el_push
252 Pushes
253 .Fa str
254 back onto the input stream.
255 This is used by the macro expansion mechanism.
256 Refer to the description of
257 .Ic bind
258 .Fl s
259 in
260 .Xr editrc 5
261 for more information.
262 .It Fn el_parse
263 Parses the
264 .Fa argv
265 array (which is
266 .Fa argc
267 elements in size)
268 to execute builtin
269 .Nm
270 commands.
271 If the command is prefixed with
272 .Dq prog :
273 then
274 .Fn el_parse
275 will only execute the command if
276 .Dq prog
277 matches the
278 .Fa prog
279 argument supplied to
280 .Fn el_init .
281 The return value is
282 \-1 if the command is unknown,
283 0 if there was no error or
284 .Dq prog
285 didn't match, or
286 1 if the command returned an error.
287 Refer to
288 .Xr editrc 5
289 for more information.
290 .It Fn el_set
291 Set
292 .Nm
293 parameters.
294 .Fa op
295 determines which parameter to set, and each operation has its
296 own parameter list.
297 Returns 0 on success, \-1 on failure.
298 .Pp
299 The following values for
300 .Fa op
301 are supported, along with the required argument list:
302 .Bl -tag -width 4n
303 .It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)"
304 Define prompt printing function as
305 .Fa f ,
306 which is to return a string that contains the prompt.
307 .It Dv EL_PROMPT_ESC , Fa "char *(*f)(EditLine *)" , Fa "char c"
308 Same as
309 .Dv EL_PROMPT ,
310 but the
311 .Fa c
312 argument indicates the start/stop literal prompt character.
313 .Pp
314 If a start/stop literal character is found in the prompt, the
315 character itself
316 is not printed, but characters after it are printed directly to the
317 terminal without affecting the state of the current line.
318 A subsequent second start/stop literal character ends this behavior.
319 This is typically used to embed literal escape sequences that change the
320 color/style of the terminal in the prompt.
321 .Dv 0
322 unsets it.
323 .It Dv EL_REFRESH
324 Re-display the current line on the next terminal line.
325 .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)"
326 Define right side prompt printing function as
327 .Fa f ,
328 which is to return a string that contains the prompt.
329 .It Dv EL_RPROMPT_ESC , Fa "char *(*f)(EditLine *)" , Fa "char c"
330 Define the right prompt printing function but with a literal escape character.
331 .It Dv EL_TERMINAL , Fa "const char *type"
332 Define terminal type of the tty to be
333 .Fa type ,
334 or to
335 .Ev TERM
336 if
337 .Fa type
338 is
339 .Dv NULL .
340 .It Dv EL_EDITOR , Fa "const char *mode"
341 Set editing mode to
342 .Fa mode ,
343 which must be one of
344 .Dq emacs
345 or
346 .Dq vi .
347 .It Dv EL_SIGNAL , Fa "int flag"
348 If
349 .Fa flag
350 is non-zero,
351 .Nm
352 will install its own signal handler for the following signals when
353 reading command input:
354 .Dv SIGCONT ,
355 .Dv SIGHUP ,
356 .Dv SIGINT ,
357 .Dv SIGQUIT ,
358 .Dv SIGSTOP ,
359 .Dv SIGTERM ,
360 .Dv SIGTSTP ,
361 and
362 .Dv SIGWINCH .
363 Otherwise, the current signal handlers will be used.
364 .It Dv EL_BIND , Fa "const char *" , Fa "..." , Dv NULL
365 Perform the
366 .Ic bind
367 builtin command.
368 Refer to
369 .Xr editrc 5
370 for more information.
371 .It Dv EL_ECHOTC , Fa "const char *" , Fa "..." , Dv NULL
372 Perform the
373 .Ic echotc
374 builtin command.
375 Refer to
376 .Xr editrc 5
377 for more information.
378 .It Dv EL_SETTC , Fa "const char *" , Fa "..." , Dv NULL
379 Perform the
380 .Ic settc
381 builtin command.
382 Refer to
383 .Xr editrc 5
384 for more information.
385 .It Dv EL_SETTY , Fa "const char *" , Fa "..." , Dv NULL
386 Perform the
387 .Ic setty
388 builtin command.
389 Refer to
390 .Xr editrc 5
391 for more information.
392 .It Dv EL_TELLTC , Fa "const char *" , Fa "..." , Dv NULL
393 Perform the
394 .Ic telltc
395 builtin command.
396 Refer to
397 .Xr editrc 5
398 for more information.
399 .It Dv EL_ADDFN , Fa "const char *name" , Fa "const char *help" , \
400 Fa "unsigned char (*func)(EditLine *e, int ch)"
401 Add a user defined function,
402 .Fn func ,
403 referred to as
404 .Fa name
405 which is invoked when a key which is bound to
406 .Fa name
407 is entered.
408 .Fa help
409 is a description of
410 .Fa name .
411 At invocation time,
412 .Fa ch
413 is the key which caused the invocation.
414 The return value of
415 .Fn func
416 should be one of:
417 .Bl -tag -width "CC_REDISPLAY"
418 .It Dv CC_NORM
419 Add a normal character.
420 .It Dv CC_NEWLINE
421 End of line was entered.
422 .It Dv CC_EOF
423 EOF was entered.
424 .It Dv CC_ARGHACK
425 Expecting further command input as arguments, do nothing visually.
426 .It Dv CC_REFRESH
427 Refresh display.
428 .It Dv CC_REFRESH_BEEP
429 Refresh display, and beep.
430 .It Dv CC_CURSOR
431 Cursor moved, so update and perform
432 .Dv CC_REFRESH .
433 .It Dv CC_REDISPLAY
434 Redisplay entire input line.
435 This is useful if a key binding outputs extra information.
436 .It Dv CC_ERROR
437 An error occurred.
438 Beep, and flush tty.
439 .It Dv CC_FATAL
440 Fatal error, reset tty to known state.
441 .El
442 .It Dv EL_HIST , Fa "History *(*func)(History *, int op, ...)" , \
443 Fa "const char *ptr"
444 Defines which history function to use, which is usually
445 .Fn history .
446 .Fa ptr
447 should be the value returned by
448 .Fn history_init .
449 .It Dv EL_EDITMODE , Fa "int flag"
450 If
451 .Fa flag
452 is non-zero,
453 editing is enabled (the default).
454 Note that this is only an indication, and does not
455 affect the operation of
456 .Nm .
457 At this time, it is the caller's responsibility to
458 check this
459 (using
460 .Fn el_get )
461 to determine if editing should be enabled or not.
462 .It Dv EL_UNBUFFERED , Fa "int flag"
463 If
464 .Fa flag
465 is zero,
466 unbuffered mode is disabled (the default).
467 In unbuffered mode,
468 .Fn el_gets
469 will return immediately after processing a single character.
470 .It Dv EL_GETCFN , Fa "int (*f)(EditLine *, char *c)"
471 Define the character reading function as
472 .Fa f ,
473 which is to return the number of characters read and store them in
474 .Fa c .
475 This function is called internally by
476 .Fn el_gets
477 and
478 .Fn el_getc .
479 The builtin function can be set or restored with the special function
480 name
481 .Dq Dv EL_BUILTIN_GETCFN .
482 .It Dv EL_CLIENTDATA , Fa "void *data"
483 Register
484 .Fa data
485 to be associated with this EditLine structure.
486 It can be retrieved with the corresponding
487 .Fn el_get
488 call.
489 .It Dv EL_SETFP , Fa "int fd" , Fa "FILE *fp"
490 Set the current
491 .Nm editline
492 file pointer for
493 .Dq input
494 .Fa fd
495 =
496 .Dv 0 ,
497 .Dq output
498 .Fa fd
499 =
500 .Dv 1 ,
501 or
502 .Dq error
503 .Fa fd
504 =
505 .Dv 2
506 from
507 .Fa fp .
508 .El
509 .It Fn el_get
510 Get
511 .Nm
512 parameters.
513 .Fa op
514 determines which parameter to retrieve into
515 .Fa result .
516 Returns 0 if successful, \-1 otherwise.
517 .Pp
518 The following values for
519 .Fa op
520 are supported, along with actual type of
521 .Fa result :
522 .Bl -tag -width 4n
523 .It Dv EL_PROMPT , Fa "char *(*f)(EditLine *)" , Fa "char *c"
524 Set
525 .Fa f .
526 to a pointer to the function that displays the prompt.
527 If
528 .Fa c
529 is not
530 .Dv NULL ,
531 set it to the start/stop literal prompt character.
532 .It Dv EL_RPROMPT , Fa "char *(*f)(EditLine *)" , Fa "char *c"
533 Set
534 .Fa f .
535 to a pointer to the function that displays the prompt.
536 If
537 .Fa c
538 is not
539 .Dv NULL ,
540 set it to the start/stop literal prompt character.
541 .It Dv EL_EDITOR , Fa "const char **n"
542 Set the name of the editor in
543 .Fa n ,
544 which will be one of
545 .Dq emacs
546 or
547 .Dq vi .
548 .It Dv EL_GETTC , Fa "const char *name" , Fa "void *value"
549 If
550 .Fa name
551 is a valid
552 .Xr termcap 5
553 capability set
554 .Fa value
555 to the current value of that capability.
556 .It Dv EL_SIGNAL , Fa "int *s"
557 Set
558 .Fa s
559 to non zero if
560 .Nm
561 has installed private signal handlers (see
562 .Fn el_get
563 above).
564 .It Dv EL_EDITMODE , Fa "int *c"
565 Set
566 .Fa c
567 to non-zero if editing is enabled.
568 .It Dv EL_GETCFN , Fa "int (**f)(EditLine *, char *)"
569 Return a pointer to the function that read characters, which is equal to
570 .Dq Dv EL_BUILTIN_GETCFN
571 in the case of the default builtin function.
572 .It Dv EL_CLIENTDATA , Fa "void **data"
573 Set
574 .Fa data
575 to the previously registered client data set by an
576 .Fn el_set
577 call.
578 .It Dv EL_UNBUFFERED , Fa "int *c"
579 Set
580 .Fa c
581 to non-zero if unbuffered mode is enabled.
582 .It Dv EL_GETFP , Fa "int fd", Fa "FILE **fp"
583 Set
584 .Fa fp
585 to the current
586 .Nm editline
587 file pointer for
588 .Dq input
589 .Fa fd
590 =
591 .Dv 0 ,
592 .Dq output
593 .Fa fd
594 =
595 .Dv 1 ,
596 or
597 .Dq error
598 .Fa fd
599 =
600 .Dv 2 .
601 .El
602 .It Fn el_source
603 Initialize
604 .Nm
605 by reading the contents of
606 .Fa file .
607 .Fn el_parse
608 is called for each line in
609 .Fa file .
610 If
611 .Fa file
612 is
613 .Dv NULL ,
614 try
615 .Pa $HOME/.editrc .
616 Refer to
617 .Xr editrc 5
618 for details on the format of
619 .Fa file .
620 .Fn el_source
621 returns 0 on success and \-1 on error.
622 .It Fn el_resize
623 Must be called if the terminal size changes.
624 If
625 .Dv EL_SIGNAL
626 has been set with
627 .Fn el_set ,
628 then this is done automatically.
629 Otherwise, it's the responsibility of the application to call
630 .Fn el_resize
631 on the appropriate occasions.
632 .It Fn el_cursor
633 Move the cursor to the right (if positive) or to the left (if negative)
634 .Fa count
635 characters.
636 Returns the resulting offset of the cursor from the beginning of the line.
637 .It Fn el_line
638 Return the editing information for the current line in a
639 .Fa LineInfo
640 structure, which is defined as follows:
641 .Bd -literal
642 typedef struct lineinfo {
643     const char *buffer;    /* address of buffer */
644     const char *cursor;    /* address of cursor */
645     const char *lastchar;  /* address of last character */
646 } LineInfo;
647 .Ed
648 .Pp
649 .Fa buffer
650 is not NUL terminated.
651 This function may be called after
652 .Fn el_gets
653 to obtain the
654 .Fa LineInfo
655 structure pertaining to line returned by that function,
656 and from within user defined functions added with
657 .Dv EL_ADDFN .
658 .It Fn el_insertstr
659 Insert
660 .Fa str
661 into the line at the cursor.
662 Returns \-1 if
663 .Fa str
664 is empty or won't fit, and 0 otherwise.
665 .It Fn el_deletestr
666 Delete
667 .Fa count
668 characters before the cursor.
669 .El
670 .Sh HISTORY LIST FUNCTIONS
671 The history functions use a common data structure,
672 .Fa History ,
673 which is created by
674 .Fn history_init
675 and freed by
676 .Fn history_end .
677 .Pp
678 The following functions are available:
679 .Bl -tag -width 4n
680 .It Fn history_init
681 Initialize the history list, and return a data structure
682 to be used by all other history list functions, or
683 .Dv NULL
684 on failure.
685 .It Fn history_end
686 Clean up and finish with
687 .Fa h ,
688 assumed to have been created with
689 .Fn history_init .
690 .It Fn history
691 Perform operation
692 .Fa op
693 on the history list, with optional arguments as needed by the
694 operation.
695 .Fa ev
696 is changed accordingly to operation.
697 The following values for
698 .Fa op
699 are supported, along with the required argument list:
700 .Bl -tag -width 4n
701 .It Dv H_SETSIZE , Fa "int size"
702 Set size of history to
703 .Fa size
704 elements.
705 .It Dv H_GETSIZE
706 Get number of events currently in history.
707 .It Dv H_END
708 Cleans up and finishes with
709 .Fa h ,
710 assumed to be created with
711 .Fn history_init .
712 .It Dv H_CLEAR
713 Clear the history.
714 .It Dv H_FUNC , Fa "void *ptr" , Fa "history_gfun_t first" , \
715 Fa "history_gfun_t next" , Fa "history_gfun_t last" , \
716 Fa "history_gfun_t prev" , Fa "history_gfun_t curr" , \
717 Fa "history_sfun_t set" , Fa "history_vfun_t clear" , \
718 Fa "history_efun_t enter" , Fa "history_efun_t add"
719 Define functions to perform various history operations.
720 .Fa ptr
721 is the argument given to a function when it's invoked.
722 .It Dv H_FIRST
723 Return the first element in the history.
724 .It Dv H_LAST
725 Return the last element in the history.
726 .It Dv H_PREV
727 Return the previous element in the history.
728 .It Dv H_NEXT
729 Return the next element in the history.
730 .It Dv H_CURR
731 Return the current element in the history.
732 .It Dv H_SET
733 Set the cursor to point to the requested element.
734 .It Dv H_ADD , Fa "const char *str"
735 Append
736 .Fa str
737 to the current element of the history, or perform the
738 .Dv H_ENTER
739 operation with argument
740 .Fa str
741 if there is no current element.
742 .It Dv H_APPEND , Fa "const char *str"
743 Append
744 .Fa str
745 to the last new element of the history.
746 .It Dv H_ENTER , Fa "const char *str"
747 Add
748 .Fa str
749 as a new element to the history, and, if necessary,
750 removing the oldest entry to keep the list to the created size.
751 If
752 .Dv H_SETUNIQUE
753 has been called with a non-zero argument, the element
754 will not be entered into the history if its contents match
755 the ones of the current history element.
756 If the element is entered
757 .Fn history
758 returns 1; if it is ignored as a duplicate returns 0.
759 Finally
760 .Fn history
761 returns \-1 if an error occurred.
762 .It Dv H_PREV_STR , Fa "const char *str"
763 Return the closest previous event that starts with
764 .Fa str .
765 .It Dv H_NEXT_STR , Fa "const char *str"
766 Return the closest next event that starts with
767 .Fa str .
768 .It Dv H_PREV_EVENT , Fa "int e"
769 Return the previous event numbered
770 .Fa e .
771 .It Dv H_NEXT_EVENT , Fa "int e"
772 Return the next event numbered
773 .Fa e .
774 .It Dv H_LOAD , Fa "const char *file"
775 Load the history list stored in
776 .Fa file .
777 .It Dv H_SAVE , Fa "const char *file"
778 Save the history list to
779 .Fa file .
780 .It Dv H_SAVE_FP , Fa "FILE *fp"
781 Save the history list to the opened
782 .Ft FILE
783 pointer
784 .Fa fp .
785 .It Dv H_SETUNIQUE , Fa "int unique"
786 Set flag that adjacent identical event strings should not be entered
787 into the history.
788 .It Dv H_GETUNIQUE
789 Retrieve the current setting if adjacent identical elements should
790 be entered into the history.
791 .It Dv H_DEL , Fa "int e"
792 Delete the event numbered
793 .Fa e .
794 This function is only provided for
795 .Xr readline 3
796 compatibility.
797 The caller is responsible for free'ing the string in the returned
798 .Fa HistEvent .
799 .El
800 .Pp
801 .Fn history
802 returns \*[Gt]= 0 if the operation
803 .Fa op
804 succeeds.
805 Otherwise, \-1 is returned and
806 .Fa ev
807 is updated to contain more details about the error.
808 .El
809 .Sh TOKENIZATION FUNCTIONS
810 The tokenization functions use a common data structure,
811 .Fa Tokenizer ,
812 which is created by
813 .Fn tok_init
814 and freed by
815 .Fn tok_end .
816 .Pp
817 The following functions are available:
818 .Bl -tag -width 4n
819 .It Fn tok_init
820 Initialize the tokenizer, and return a data structure
821 to be used by all other tokenizer functions.
822 .Fa IFS
823 contains the Input Field Separators, which defaults to
824 .Aq space ,
825 .Aq tab ,
826 and
827 .Aq newline
828 if
829 .Dv NULL .
830 .It Fn tok_end
831 Clean up and finish with
832 .Fa t ,
833 assumed to have been created with
834 .Fn tok_init .
835 .It Fn tok_reset
836 Reset the tokenizer state.
837 Use after a line has been successfully tokenized
838 by
839 .Fn tok_line
840 or
841 .Fn tok_str
842 and before a new line is to be tokenized.
843 .It Fn tok_line
844 Tokenize
845 .Fa li ,
846 If successful, modify:
847 .Fa argv
848 to contain the words,
849 .Fa argc
850 to contain the number of words,
851 .Fa cursorc
852 (if not
853 .Dv NULL )
854 to contain the index of the word containing the cursor,
855 and
856 .Fa cursoro
857 (if not
858 .Dv NULL )
859 to contain the offset within
860 .Fa argv[cursorc]
861 of the cursor.
862 .Pp
863 Returns
864 0 if successful,
865 \-1 for an internal error,
866 1 for an unmatched single quote,
867 2 for an unmatched double quote,
868 and
869 3 for a backslash quoted
870 .Aq newline .
871 A positive exit code indicates that another line should be read
872 and tokenization attempted again.
873 .
874 .It Fn tok_str
875 A simpler form of
876 .Fn tok_line ;
877 .Fa str
878 is a NUL terminated string to tokenize.
879 .El
880 .
881 .\"XXX.Sh EXAMPLES
882 .\"XXX: provide some examples
883 .Sh SEE ALSO
884 .Xr sh 1 ,
885 .Xr signal 3 ,
886 .Xr termcap 3 ,
887 .Xr editrc 5 ,
888 .Xr termcap 5
889 .Sh HISTORY
890 The
891 .Nm
892 library first appeared in
893 .Bx 4.4 .
894 .Dv CC_REDISPLAY
895 appeared in
896 .Nx 1.3 .
897 .Dv CC_REFRESH_BEEP ,
898 .Dv EL_EDITMODE
899 and the readline emulation appeared in
900 .Nx 1.4 .
901 .Dv EL_RPROMPT
902 appeared in
903 .Nx 1.5 .
904 .Sh AUTHORS
905 .An -nosplit
906 The
907 .Nm
908 library was written by
909 .An Christos Zoulas .
910 .An Luke Mewburn
911 wrote this manual and implemented
912 .Dv CC_REDISPLAY ,
913 .Dv CC_REFRESH_BEEP ,
914 .Dv EL_EDITMODE ,
915 and
916 .Dv EL_RPROMPT .
917 .An Jaromir Dolecek
918 implemented the readline emulation.
919 .An Johny Mattsson
920 implemented wide-character support.
921 .Sh BUGS
922 At this time, it is the responsibility of the caller to
923 check the result of the
924 .Dv EL_EDITMODE
925 operation of
926 .Fn el_get
927 (after an
928 .Fn el_source
929 or
930 .Fn el_parse )
931 to determine if
932 .Nm
933 should be used for further input.
934 I.e.,
935 .Dv EL_EDITMODE
936 is purely an indication of the result of the most recent
937 .Xr editrc 5
938 .Ic edit
939 command.