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