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