master
/ miniconda3 / pkgs / libedit-3.1.20221030-h5eee18b_0 / share / man / man3 / editline.3

editline.3 @a663dc1 raw · history · blame

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
.TH EDITLINE 3 "August 15, 2021" ""
.SH NAME
\fBeditline\fP,
\fBel_init\fP,
\fBel_init_fd\fP,
\fBel_end\fP,
\fBel_reset\fP,
\fBel_gets\fP,
\fBel_wgets\fP,
\fBel_getc\fP,
\fBel_wgetc\fP,
\fBel_push\fP,
\fBel_wpush\fP,
\fBel_parse\fP,
\fBel_wparse\fP,
\fBel_set\fP,
\fBel_wset\fP,
\fBel_get\fP,
\fBel_wget\fP,
\fBel_source\fP,
\fBel_resize\fP,
\fBel_cursor\fP,
\fBel_line\fP,
\fBel_wline\fP,
\fBel_insertstr\fP,
\fBel_winsertstr\fP,
\fBel_deletestr\fP,
\fBel_wdeletestr\fP,
\fBhistory_init\fP,
\fBhistory_winit\fP,
\fBhistory_end\fP,
\fBhistory_wend\fP,
\fBhistory\fP,
\fBhistory_w\fP,
\fBtok_init\fP,
\fBtok_winit\fP,
\fBtok_end\fP,
\fBtok_wend\fP,
\fBtok_reset\fP,
\fBtok_wreset\fP,
\fBtok_line\fP,
\fBtok_wline\fP,
\fBtok_str\fP,
\fBtok_wstr\fP
\- line editor, history and tokenization functions
.SH LIBRARY
Command Line Editor Library (libedit, -ledit)
.SH SYNOPSIS
.PP
\fB#include <histedit.h>\fP
.PP
\fIEditLine *\fP
.br
\fBel_init\fP(\fIconst char *prog\fP, \fIFILE *fin\fP, \fIFILE *fout\fP, \fIFILE *ferr\fP);
.PP
\fIEditLine *\fP
.br
\fBel_init_fd\fP(\fIconst char *prog\fP, \fIFILE *fin\fP, \fIFILE *fout\fP, \fIFILE *ferr\fP, \fIint fdin\fP, \fIint fdout\fP, \fIint fderr\fP);
.PP
\fIvoid\fP
.br
\fBel_end\fP(\fIEditLine *e\fP);
.PP
\fIvoid\fP
.br
\fBel_reset\fP(\fIEditLine *e\fP);
.PP
\fIconst char *\fP
.br
\fBel_gets\fP(\fIEditLine *e\fP, \fIint *count\fP);
.PP
\fIconst wchar_t *\fP
.br
\fBel_wgets\fP(\fIEditLine *e\fP, \fIint *count\fP);
.PP
\fIint\fP
.br
\fBel_getc\fP(\fIEditLine *e\fP, \fIchar *ch\fP);
.PP
\fIint\fP
.br
\fBel_wgetc\fP(\fIEditLine *e\fP, \fIwchar_t *wc\fP);
.PP
\fIvoid\fP
.br
\fBel_push\fP(\fIEditLine *e\fP, \fIconst char *mbs\fP);
.PP
\fIvoid\fP
.br
\fBel_wpush\fP(\fIEditLine *e\fP, \fIconst wchar_t *wcs\fP);
.PP
\fIint\fP
.br
\fBel_parse\fP(\fIEditLine *e\fP, \fIint argc\fP, \fIconst char *argv[]\fP);
.PP
\fIint\fP
.br
\fBel_wparse\fP(\fIEditLine *e\fP, \fIint argc\fP, \fIconst wchar_t *argv[]\fP);
.PP
\fIint\fP
.br
\fBel_set\fP(\fIEditLine *e\fP, \fIint op\fP, \fI...\fP);
.PP
\fIint\fP
.br
\fBel_wset\fP(\fIEditLine *e\fP, \fIint op\fP, \fI...\fP);
.PP
\fIint\fP
.br
\fBel_get\fP(\fIEditLine *e\fP, \fIint op\fP, \fI...\fP);
.PP
\fIint\fP
.br
\fBel_wget\fP(\fIEditLine *e\fP, \fIint op\fP, \fI...\fP);
.PP
\fIint\fP
.br
\fBel_source\fP(\fIEditLine *e\fP, \fIconst char *file\fP);
.PP
\fIvoid\fP
.br
\fBel_resize\fP(\fIEditLine *e\fP);
.PP
\fIint\fP
.br
\fBel_cursor\fP(\fIEditLine *e\fP, \fIint count\fP);
.PP
\fIconst LineInfo *\fP
.br
\fBel_line\fP(\fIEditLine *e\fP);
.PP
\fIconst LineInfoW *\fP
.br
\fBel_wline\fP(\fIEditLine *e\fP);
.PP
\fIint\fP
.br
\fBel_insertstr\fP(\fIEditLine *e\fP, \fIconst char *str\fP);
.PP
\fIint\fP
.br
\fBel_winsertstr\fP(\fIEditLine *e\fP, \fIconst wchar_t *str\fP);
.PP
\fIvoid\fP
.br
\fBel_deletestr\fP(\fIEditLine *e\fP, \fIint count\fP);
.PP
\fIvoid\fP
.br
\fBel_wdeletestr\fP(\fIEditLine *e\fP, \fIint count\fP);
.PP
\fIHistory *\fP
.br
\fBhistory_init\fP(void );
.PP
\fIHistoryW *\fP
.br
\fBhistory_winit\fP(void );
.PP
\fIvoid\fP
.br
\fBhistory_end\fP(\fIHistory *h\fP);
.PP
\fIvoid\fP
.br
\fBhistory_wend\fP(\fIHistoryW *h\fP);
.PP
\fIint\fP
.br
\fBhistory\fP(\fIHistory *h\fP, \fIHistEvent *ev\fP, \fIint op\fP, \fI...\fP);
.PP
\fIint\fP
.br
\fBhistory_w\fP(\fIHistoryW *h\fP, \fIHistEventW *ev\fP, \fIint op\fP, \fI...\fP);
.PP
\fITokenizer *\fP
.br
\fBtok_init\fP(\fIconst char *IFS\fP);
.PP
\fITokenizerW *\fP
.br
\fBtok_winit\fP(\fIconst wchar_t *IFS\fP);
.PP
\fIvoid\fP
.br
\fBtok_end\fP(\fITokenizer *t\fP);
.PP
\fIvoid\fP
.br
\fBtok_wend\fP(\fITokenizerW *t\fP);
.PP
\fIvoid\fP
.br
\fBtok_reset\fP(\fITokenizer *t\fP);
.PP
\fIvoid\fP
.br
\fBtok_wreset\fP(\fITokenizerW *t\fP);
.PP
\fIint\fP
.br
\fBtok_line\fP(\fITokenizer *t\fP, \fIconst LineInfo *li\fP, \fIint *argc\fP, \fIconst char **argv[]\fP, \fIint *cursorc\fP, \fIint *cursoro\fP);
.PP
\fIint\fP
.br
\fBtok_wline\fP(\fITokenizerW *t\fP, \fIconst LineInfoW *li\fP, \fIint *argc\fP, \fIconst wchar_t **argv[]\fP, \fIint *cursorc\fP, \fIint *cursoro\fP);
.PP
\fIint\fP
.br
\fBtok_str\fP(\fITokenizer *t\fP, \fIconst char *str\fP, \fIint *argc\fP, \fIconst char **argv[]\fP);
.PP
\fIint\fP
.br
\fBtok_wstr\fP(\fITokenizerW *t\fP, \fIconst wchar_t *str\fP, \fIint *argc\fP, \fIconst wchar_t **argv[]\fP);
.SH DESCRIPTION
The
\fBeditline\fP
library provides generic line editing, history and tokenization functions,
similar to those found in
\fBsh\fP(1).

These functions are available in the
\fBlibedit\fP
library (which needs the
\fBlibtermcap\fP
library).
Programs should be linked with
\fB\-ledit\fP ltermcap .

The
\fBeditline\fP
library respects the
.IR LC_CTYPE
locale set by the application program and never uses
\fBsetlocale\fP(3)
to change the locale.
.SH LINE EDITING FUNCTIONS
The line editing functions use a common data structure,
\fIEditLine\fP,
which is created by
\fBel_init\fP()
or
\fBel_init_fd\fP()
and freed by
\fBel_end\fP().

The wide-character functions behave the same way as their narrow
counterparts.

The following functions are available:
.TP
\fBel_init\fP()
Initialize the line editor, and return a data structure
to be used by all other line editing functions, or
NULL
on failure.
\fIprog \fP
is the name of the invoking program, used when reading the
\fBeditrc\fP(5)
file to determine which settings to use.
\fIfin\fP,
\fIfout \fP
and
\fIferr \fP
are the input, output, and error streams (respectively) to use.
In this documentation, references to
``the tty''
are actually to this input/output stream combination.
.TP
\fBel_init_fd\fP()
Like
\fBel_init\fP()
but allows specifying file descriptors for the
\fBstdio\fP(3)
corresponding streams, in case those were created with
\fBfunopen\fP(3).
.TP
\fBel_end\fP()
Clean up and finish with
\fIe\fP,
assumed to have been created with
\fBel_init\fP()
or
\fBel_init_fd\fP().
.TP
\fBel_reset\fP()
Reset the tty and the parser.
This should be called after an error which may have upset the tty's
state.
.TP
\fBel_gets\fP()
Read a line from the tty.
\fIcount \fP
is modified to contain the number of characters read.
Returns the line read if successful, or
NULL
if no characters were read or if an error occurred.
If an error occurred,
\fIcount \fP
is set to \-1 and
errno
contains the error code that caused it.
The return value may not remain valid across calls to
\fBel_gets\fP()
and must be copied if the data is to be retained.
.TP
\fBel_wgetc\fP()
Read a wide character from the tty, respecting the current locale,
or from the input queue described in
\fBeditline\fP(7)
if that is not empty, and store it in
\fIwc\fP.
If an invalid or incomplete character is found, it is discarded,
\fIerrno\fP
is set to
Er EILSEQ ,
and the next character is read and stored in
\fIwc\fP.
Returns 1 if a valid character was read, 0 on end of file, or \-1 on
\fBread\fP(2)
failure.
In the latter case,
\fIerrno\fP
is set to indicate the error.
.TP
\fBel_getc\fP()
Read a wide character as described for
\fBel_wgetc\fP()
and return 0 on end of file or \-1 on failure.
If the wide character can be represented as a single-byte character,
convert it with
\fBwctob\fP(3),
store the result in
\fIch\fP,
and return 1; otherwise, set
\fIerrno\fP
to
Er ERANGE
and return \-1.
In the C or POSIX locale, this simply reads a byte, but for any other
locale, including UTF-8, this is rarely useful.
.TP
\fBel_wpush\fP()
Push the wide character string
\fIwcs \fP
back onto the input queue described in
\fBeditline\fP(7).
If the queue overflows, for example due to a recursive macro,
or if an error occurs, for example because
\fIwcs \fP
is
NULL
or memory allocation fails, the function beeps at the user,
but does not report the problem to the caller.
.TP
\fBel_push\fP()
Use the current locale to convert the multibyte string
\fImbs \fP
to a wide character string, and pass the result to
\fBel_wpush\fP().
.TP
\fBel_parse\fP()
Parses the
\fIargv \fP
array (which is
\fIargc \fP
elements in size)
to execute builtin
\fBeditline\fP
commands.
If the command is prefixed with
``prog :''
then
\fBel_parse\fP()
will only execute the command if
``prog''
matches the
\fIprog \fP
argument supplied to
\fBel_init\fP().
The return value is
\-1 if the command is unknown,
0 if there was no error or
``prog''
didn't match, or
1 if the command returned an error.
Refer to
\fBeditrc\fP(5)
for more information.
.TP
\fBel_set\fP()
Set
\fBeditline\fP
parameters.
\fIop \fP
determines which parameter to set, and each operation has its
own parameter list.
Returns 0 on success, \-1 on failure.

The following values for
\fIop \fP
are supported, along with the required argument list:
.RS
.TP
EL_PROMPT , \fIchar *(*f)(EditLine *)\fP
Define prompt printing function as
\fIf\fP,
which is to return a string that contains the prompt.
.TP
EL_PROMPT_ESC , \fIchar *(*f)(EditLine *), Fa char c\fP
Same as
EL_PROMPT ,
but the
\fIc \fP
argument indicates the start/stop literal prompt character.

If a start/stop literal character is found in the prompt, the
character itself
is not printed, but characters after it are printed directly to the
terminal without affecting the state of the current line.
A subsequent second start/stop literal character ends this behavior.
This is typically used to embed literal escape sequences that change the
color/style of the terminal in the prompt.
Note that the literal escape character cannot be the last character in the
prompt, as the escape sequence is attached to the next character in the prompt.
0
unsets it.
.TP
EL_REFRESH
Re-display the current line on the next terminal line.
.TP
EL_RPROMPT , \fIchar *(*f)(EditLine *)\fP
Define right side prompt printing function as
\fIf\fP,
which is to return a string that contains the prompt.
.TP
EL_RPROMPT_ESC , \fIchar *(*f)(EditLine *), Fa char c\fP
Define the right prompt printing function but with a literal escape character.
.TP
EL_TERMINAL , \fIconst char *type\fP
Define terminal type of the tty to be
\fItype\fP,
or to
.IR TERM
if
\fItype \fP
is
NULL .
.TP
EL_EDITOR , \fIconst char *mode\fP
Set editing mode to
\fImode\fP,
which must be one of
``emacs''
or
``vi''.
.TP
EL_SIGNAL , \fIint flag\fP
If
\fIflag \fP
is non-zero,
\fBeditline\fP
will install its own signal handler for the following signals when
reading command input:
SIGCONT ,
SIGHUP ,
SIGINT ,
SIGQUIT ,
SIGSTOP ,
SIGTERM ,
SIGTSTP ,
and
SIGWINCH .
Otherwise, the current signal handlers will be used.
.TP
EL_BIND , \fIconst char *, Fa ..., Dv NULL \fP
Perform the
\fBbind\fP
builtin command.
Refer to
\fBeditrc\fP(5)
for more information.
.TP
EL_ECHOTC , \fIconst char *, Fa ..., Dv NULL \fP
Perform the
\fBechotc\fP
builtin command.
Refer to
\fBeditrc\fP(5)
for more information.
.TP
EL_SETTC , \fIconst char *, Fa ..., Dv NULL \fP
Perform the
\fBsettc\fP
builtin command.
Refer to
\fBeditrc\fP(5)
for more information.
.TP
EL_SETTY , \fIconst char *, Fa ..., Dv NULL \fP
Perform the
\fBsetty\fP
builtin command.
Refer to
\fBeditrc\fP(5)
for more information.
.TP
EL_TELLTC , \fIconst char *, Fa ..., Dv NULL \fP
Perform the
\fBtelltc\fP
builtin command.
Refer to
\fBeditrc\fP(5)
for more information.
.TP
EL_ADDFN , \fIconst char *name, Fa const char *help, \ \fP
Fa "unsigned char (*func)(EditLine *e, int ch)"
Add a user defined function,
\fBfunc\fP(),
referred to as
\fIname \fP
which is invoked when a key which is bound to
\fIname \fP
is entered.
\fIhelp \fP
is a description of
\fIname\fP.
At invocation time,
\fIch \fP
is the key which caused the invocation.
The return value of
\fBfunc\fP()
should be one of:
.RS
.TP
CC_NORM
Add a normal character.
.TP
CC_NEWLINE
End of line was entered.
.TP
CC_EOF
EOF was entered.
.TP
CC_ARGHACK
Expecting further command input as arguments, do nothing visually.
.TP
CC_REFRESH
Refresh display.
.TP
CC_REFRESH_BEEP
Refresh display, and beep.
.TP
CC_CURSOR
Cursor moved, so update and perform
CC_REFRESH .
.TP
CC_REDISPLAY
Redisplay entire input line.
This is useful if a key binding outputs extra information.
.TP
CC_ERROR
An error occurred.
Beep, and flush tty.
.TP
CC_FATAL
Fatal error, reset tty to known state.
.RE
.TP
EL_HIST , \fIHistory *(*func)(History *, int op, ...), \ \fP
Fa "const char *ptr"
Defines which history function to use, which is usually
\fBhistory\fP().
\fIptr \fP
should be the value returned by
\fBhistory_init\fP().
.TP
EL_EDITMODE , \fIint flag\fP
If
\fIflag \fP
is non-zero,
editing is enabled (the default).
Note that this is only an indication, and does not
affect the operation of
\fB.\fP
At this time, it is the caller's responsibility to
check this
(using
\fBel_get\fP() )
to determine if editing should be enabled or not.
.TP
EL_UNBUFFERED , \fIint flag\fP
If
\fIflag \fP
is zero,
unbuffered mode is disabled (the default).
In unbuffered mode,
\fBel_gets\fP()
will return immediately after processing a single character.
.TP
EL_SAFEREAD , \fIint flag\fP
If the
\fIflag \fP
argument is non-zero, then
\fBeditline\fP
attempts to recover from read errors, ignoring the first interrrupted
error, and trying to reset the input file descriptor to reset non-blocking I/O.
This is disabled by default, and desirable only when
\fBeditline\fP
is used in shell-like applications.
.TP
EL_GETCFN , \fIel_rfunc_t f\fP
Whenever reading a character, use the function
-ragged -offset indent -compact
.PP
\fIint\fP
.br
Fo f
\fIEditLine *e\fP
\fIwchar_t *wc\fP
Fc
which stores the character in
\fIwc \fP
and returns 1 on success, 0 on end of file, or \-1 on I/O or encoding
errors.
Functions internally using it include
\fBel_wgets\fP(),
\fBel_wgetc\fP(),
\fBel_gets\fP(),
and
\fBel_getc\fP().
Initially, a builtin function is installed, and replacing it
is discouraged because writing such a function is very error prone.
The builtin function can be restored at any time by passing the
special value
EL_BUILTIN_GETCFN
instead of a function pointer.
.TP
EL_CLIENTDATA , \fIvoid *data\fP
Register
\fIdata \fP
to be associated with this EditLine structure.
It can be retrieved with the corresponding
\fBel_get\fP();
call.
.TP
EL_SETFP , \fIint fd, Fa FILE *fp\fP
Set the current
\fBeditline\fP
file pointer for
``input''
\fIfd \fP
=
0 ,
``output''
\fIfd \fP
=
1 ,
or
``error''
\fIfd \fP
=
2
from
\fIfp\fP.
.RE
.TP
\fBel_get\fP()
Get
\fBeditline\fP
parameters.
\fIop \fP
determines which parameter to retrieve into
\fIresult\fP.
Returns 0 if successful, \-1 otherwise.

The following values for
\fIop \fP
are supported, along with actual type of
\fIresult : \fP
.RS
.TP
EL_PROMPT , \fIchar *(*f)(EditLine *), Fa char *c\fP
Set
\fIf \fP
to a pointer to the function that displays the prompt.
If
\fIc \fP
is not
NULL ,
set it to the start/stop literal prompt character.
.TP
EL_RPROMPT , \fIchar *(*f)(EditLine *), Fa char *c\fP
Set
\fIf \fP
to a pointer to the function that displays the prompt.
If
\fIc \fP
is not
NULL ,
set it to the start/stop literal prompt character.
.TP
EL_EDITOR , \fIconst char **n\fP
Set the name of the editor in
\fIn\fP,
which will be one of
``emacs''
or
``vi''.
.TP
EL_GETTC , \fIconst char *name, Fa void *value\fP
If
\fIname \fP
is a valid
\fBtermcap\fP(5)
capability set
\fIvalue \fP
to the current value of that capability.
.TP
EL_SIGNAL , \fIint *s\fP
Set
\fIs \fP
to non-zero if
\fBeditline\fP
has installed private signal handlers (see
\fBel_get\fP()
above).
.TP
EL_EDITMODE , \fIint *c\fP
Set
\fIc \fP
to non-zero if editing is enabled.
.TP
EL_GETCFN , \fIel_rfunc_t *f\fP
Set
\fIf \fP
to a pointer to the function that reads characters, or to
EL_BUILTIN_GETCFN
if the builtin function is in use.
.TP
EL_CLIENTDATA , \fIvoid **data\fP
Set
\fIdata \fP
to the previously registered client data set by an
\fBel_set\fP()
call.
.TP
EL_UNBUFFERED , \fIint *c\fP
Set
\fIc \fP
to non-zero if unbuffered mode is enabled.
.TP
EL_SAFEREAD , \fIint *c\fP
Set
\fIc \fP
to non-zero if safe read is set.
.TP
EL_GETFP , \fIint fd", Fa FILE **fp\fP
Set
\fIfp \fP
to the current
\fBeditline\fP
file pointer for
``input''
\fIfd \fP
=
0 ,
``output''
\fIfd \fP
=
1 ,
or
``error''
\fIfd \fP
=
2 .
.RE
.TP
\fBel_source\fP()
Initialize
\fBeditline\fP
by reading the contents of
\fIfile\fP.
\fBel_parse\fP()
is called for each line in
\fIfile\fP.
If
\fIfile \fP
is
NULL ,
try
\fI$EDITRC\fP
and if that is not set
\fI$HOME/.editrc\fP.
Refer to
\fBeditrc\fP(5)
for details on the format of
\fIfile\fP.
\fBel_source\fP()
returns 0 on success and \-1 on error.
.TP
\fBel_resize\fP()
Must be called if the terminal size changes.
If
EL_SIGNAL
has been set with
\fBel_set\fP(),
then this is done automatically.
Otherwise, it's the responsibility of the application to call
\fBel_resize\fP()
on the appropriate occasions.
.TP
\fBel_cursor\fP()
Move the cursor to the right (if positive) or to the left (if negative)
\fIcount \fP
characters.
Returns the resulting offset of the cursor from the beginning of the line.
.TP
\fBel_line\fP()
Return the editing information for the current line in a
\fILineInfo \fP
structure, which is defined as follows:

typedef struct lineinfo {
.br
    const char *buffer;    /* address of buffer */
.br
    const char *cursor;    /* address of cursor */
.br
    const char *lastchar;  /* address of last character */
.br
} LineInfo;
.br

\fIbuffer \fP
is not NUL terminated.
This function may be called after
\fBel_gets\fP()
to obtain the
\fILineInfo \fP
structure pertaining to line returned by that function,
and from within user defined functions added with
EL_ADDFN .
.TP
\fBel_insertstr\fP()
Insert
\fIstr \fP
into the line at the cursor.
Returns \-1 if
\fIstr \fP
is empty or won't fit, and 0 otherwise.
.TP
\fBel_deletestr\fP()
Delete
\fIcount \fP
characters before the cursor.
.SH HISTORY LIST FUNCTIONS
The history functions use a common data structure,
\fIHistory\fP,
which is created by
\fBhistory_init\fP()
and freed by
\fBhistory_end\fP().

The following functions are available:
.TP
\fBhistory_init\fP()
Initialize the history list, and return a data structure
to be used by all other history list functions, or
NULL
on failure.
.TP
\fBhistory_end\fP()
Clean up and finish with
\fIh\fP,
assumed to have been created with
\fBhistory_init\fP().
.TP
\fBhistory\fP()
Perform operation
\fIop \fP
on the history list, with optional arguments as needed by the
operation.
\fIev \fP
is changed accordingly to operation.
The following values for
\fIop \fP
are supported, along with the required argument list:
.RS
.TP
H_SETSIZE , \fIint size\fP
Set size of history to
\fIsize \fP
elements.
.TP
H_GETSIZE
Get number of events currently in history.
.TP
H_END
Cleans up and finishes with
\fIh\fP,
assumed to be created with
\fBhistory_init\fP().
.TP
H_CLEAR
Clear the history.
.TP
H_FUNC , \fIvoid *ptr, Fa history_gfun_t first, \ \fP
Fa "history_gfun_t next" , Fa "history_gfun_t last" , \
Fa "history_gfun_t prev" , Fa "history_gfun_t curr" , \
Fa "history_sfun_t set" , Fa "history_vfun_t clear" , \
Fa "history_efun_t enter" , Fa "history_efun_t add"
Define functions to perform various history operations.
\fIptr \fP
is the argument given to a function when it's invoked.
.TP
H_FIRST
Return the first element in the history.
.TP
H_LAST
Return the last element in the history.
.TP
H_PREV
Return the previous element in the history.
It is newer than the current one.
.TP
H_NEXT
Return the next element in the history.
It is older than the current one.
.TP
H_CURR
Return the current element in the history.
.TP
H_SET , \fIint position\fP
Set the cursor to point to the requested element.
.TP
H_ADD , \fIconst char *str\fP
Append
\fIstr \fP
to the current element of the history, or perform the
H_ENTER
operation with argument
\fIstr \fP
if there is no current element.
.TP
H_APPEND , \fIconst char *str\fP
Append
\fIstr \fP
to the last new element of the history.
.TP
H_ENTER , \fIconst char *str\fP
Add
\fIstr \fP
as a new element to the history and, if necessary,
removing the oldest entry to keep the list to the created size.
If
H_SETUNIQUE
has been called with a non-zero argument, the element
will not be entered into the history if its contents match
the ones of the current history element.
If the element is entered
\fBhistory\fP()
returns 1; if it is ignored as a duplicate returns 0.
Finally
\fBhistory\fP()
returns \-1 if an error occurred.
.TP
H_PREV_STR , \fIconst char *str\fP
Return the closest previous event that starts with
\fIstr\fP.
.TP
H_NEXT_STR , \fIconst char *str\fP
Return the closest next event that starts with
\fIstr\fP.
.TP
H_PREV_EVENT , \fIint e\fP
Return the previous event numbered
\fIe\fP.
.TP
H_NEXT_EVENT , \fIint e\fP
Return the next event numbered
\fIe\fP.
.TP
H_LOAD , \fIconst char *file\fP
Load the history list stored in
\fIfile\fP.
.TP
H_SAVE , \fIconst char *file\fP
Save the history list to
\fIfile\fP.
.TP
H_SAVE_FP , \fIFILE *fp\fP
Save the history list to the opened
.PP
\fIFILE\fP
.br
pointer
\fIfp\fP.
.TP
H_NSAVE_FP , \fIsize_t n, Fa FILE *fp\fP
Save the last
.PP
\fIn\fP
.br
history entries to the opened
.PP
\fIFILE\fP
.br
pointer
\fIfp\fP.
.TP
H_SETUNIQUE , \fIint unique\fP
Set flag that adjacent identical event strings should not be entered
into the history.
.TP
H_GETUNIQUE
Retrieve the current setting if adjacent identical elements should
be entered into the history.
.TP
H_DEL , \fIint e\fP
Delete the event numbered
\fIe\fP.
This function is only provided for
\fBreadline\fP
compatibility.
The caller is responsible for free'ing the string in the returned
\fIHistEvent\fP.
.RE

\fBhistory\fP();
returns >= 0 if the operation
\fIop \fP
succeeds.
Otherwise, \-1 is returned and
\fIev \fP
is updated to contain more details about the error.
.SH TOKENIZATION FUNCTIONS
The tokenization functions use a common data structure,
\fITokenizer\fP,
which is created by
\fBtok_init\fP()
and freed by
\fBtok_end\fP().

The following functions are available:
.TP
\fBtok_init\fP()
Initialize the tokenizer, and return a data structure
to be used by all other tokenizer functions.
\fIIFS \fP
contains the Input Field Separators, which defaults to
<space ,>
<tab ,>
and
<newline>
if
NULL .
.TP
\fBtok_end\fP()
Clean up and finish with
\fIt\fP,
assumed to have been created with
\fBtok_init\fP().
.TP
\fBtok_reset\fP()
Reset the tokenizer state.
Use after a line has been successfully tokenized
by
\fBtok_line\fP()
or
\fBtok_str\fP()
and before a new line is to be tokenized.
.TP
\fBtok_line\fP()
Tokenize
\fIli\fP,
If successful, modify:
\fIargv \fP
to contain the words,
\fIargc \fP
to contain the number of words,
\fIcursorc \fP
(if not
NULL )
to contain the index of the word containing the cursor,
and
\fIcursoro \fP
(if not
NULL )
to contain the offset within
\fIargv[cursorc] \fP
of the cursor.

Returns
0 if successful,
\-1 for an internal error,
1 for an unmatched single quote,
2 for an unmatched double quote,
and
3 for a backslash quoted
<newline .>
A positive exit code indicates that another line should be read
and tokenization attempted again.
.TP
\fBtok_str\fP()
A simpler form of
\fBtok_line\fP(; )
\fIstr \fP
is a NUL terminated string to tokenize.
.SH SEE ALSO
\fBsh\fP(1),
\fBsignal\fP(3),
\fBtermcap\fP(3),
\fBeditrc\fP(5),
\fBtermcap\fP(5),
\fBeditline\fP(7)
.SH HISTORY
The
\fBeditline\fP
library first appeared in
Bx 4.4 .
CC_REDISPLAY
appeared in
Nx 1.3 .
CC_REFRESH_BEEP ,
EL_EDITMODE
and the readline emulation appeared in
Nx 1.4 .
EL_RPROMPT
appeared in
Nx 1.5 .
.SH AUTHORS

-nosplit
The
\fBeditline\fP
library was written by

Christos Zoulas .

Luke Mewburn
wrote this manual and implemented
CC_REDISPLAY ,
CC_REFRESH_BEEP ,
EL_EDITMODE ,
and
EL_RPROMPT .

Jaromir Dolecek
implemented the readline emulation.

Johny Mattsson
implemented wide-character support.
.SH BUGS
At this time, it is the responsibility of the caller to
check the result of the
EL_EDITMODE
operation of
\fBel_get\fP()
(after an
\fBel_source\fP()
or
\fBel_parse\fP() )
to determine if
\fBeditline\fP
should be used for further input.
I.e.,
EL_EDITMODE
is purely an indication of the result of the most recent
\fBeditrc\fP(5)
\fBedit\fP
command.