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