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