1January 12, 2007()                                          January 12, 2007()
2
3
4

NAME

6       editline,   el_init,   el_end,  el_reset,  el_gets,  el_getc,  el_push,
7       el_parse, el_set, el_get, el_source, el_resize, el_line,  el_insertstr,
8       el_deletestr,  history_init,  history_end,  history, tok_init, tok_end,
9       tok_reset, tok_line, tok_str - line editor,  history  and  tokenization
10       functions
11

LIBRARY

13       Command Line Editor Library (libedit, -ledit)
14

SYNOPSIS

16       #include <histedit.h>
17
18       EditLine *
19       el_init(const char *prog, FILE *fin, FILE *fout, FILE *ferr);
20
21       void
22       el_end(EditLine *e);
23
24       void
25       el_reset(EditLine *e);
26
27       const char *
28       el_gets(EditLine *e, int *count);
29
30       int
31       el_getc(EditLine *e, char *ch);
32
33       void
34       el_push(EditLine *e, const char *str);
35
36       int
37       el_parse(EditLine *e, int argc, const char *argv[]);
38
39       int
40       el_set(EditLine *e, int op, ...);
41
42       int
43       el_get(EditLine *e, int op, ...);
44
45       int
46       el_source(EditLine *e, const char *file);
47
48       void
49       el_resize(EditLine *e);
50
51       const LineInfo *
52       el_line(EditLine *e);
53
54       int
55       el_insertstr(EditLine *e, const char *str);
56
57       void
58       el_deletestr(EditLine *e, int count);
59
60       History *
61       history_init();
62
63       void
64       history_end(History *h);
65
66       int
67       history(History *h, HistEvent *ev, int op, ...);
68
69       Tokenizer *
70       tok_init(const char *IFS);
71
72       void
73       tok_end(Tokenizer *t);
74
75       void
76       tok_reset(Tokenizer *t);
77
78       int
79       tok_line(Tokenizer  *t,  const  LineInfo  *li,  int  *argc,  const char
80       **argv[], int *cursorc, int *cursoro);
81
82       int
83       tok_str(Tokenizer *t, const char *str, int *argc, const char **argv[]);
84

DESCRIPTION

86       The editline library provides generic line editing,  history  and  tok‐
87       enization functions, similar to those found in sh(1).
88
89       These  functions  are available in the libedit library (which needs the
90       libcurses library).  Programs should be linked with -ledit -lcurses.
91

LINE EDITING FUNCTIONS

93       The line editing functions use a common data structure, EditLine, which
94       is created by el_init() and freed by el_end().
95
96       The following functions are available:
97
98       el_init()
99              Initialise  the  line  editor, and return a data structure to be
100              used by all other line editing functions.  prog is the  name  of
101              the  invoking  program,  used when reading the editrc(5) file to
102              determine which settings to use.  fin, fout  and  ferr  are  the
103              input, output, and error streams (respectively) to use.  In this
104              documentation, references to ``the tty'' are  actually  to  this
105              input/output stream combination.
106
107       el_end()
108              Clean  up  and  finish with e, assumed to have been created with
109              el_init().
110
111       el_reset()
112              Reset the tty and the parser.  This should be  called  after  an
113              error which may have upset the tty's state.
114
115       el_gets()
116              Read a line from the tty.  count is modified to contain the num‐
117              ber of characters read.  Returns the line read if successful, or
118              NULL if no characters were read or if an error occurred.
119
120       el_getc()
121              Read  a  character  from the tty.  ch is modified to contain the
122              character read.  Returns the number of characters read  if  suc‐
123              cessful, -1 otherwise.
124
125       el_push()
126              Pushes  str  back  onto  the  input stream.  This is used by the
127              macro expansion mechanism.  Refer to the description of bind  -s
128              in editrc(5) for more information.
129
130       el_parse()
131              Parses  the  argv array (which is argc elements in size) to exe‐
132              cute builtin editline commands.  If the command is prefixed with
133              ``prog  :''  then  el_parse()  will  only execute the command if
134              ``prog'' matches the prog argument supplied to  el_init().   The
135              return  value is -1 if the command is unknown, 0 if there was no
136              error or ``prog'' didn't match, or 1 if the command returned  an
137              error.  Refer to editrc(5) for more information.
138
139       el_set()
140              Set  editline parameters.  op determines which parameter to set,
141              and each operation has its own parameter list.
142
143              The following values  for  op  are  supported,  along  with  the
144              required argument list:
145
146              EL_PROMPT , char *(*f)(EditLine *)
147                     Define  prompt printing function as f, which is to return
148                     a string that contains the prompt.
149
150              EL_RPROMPT , char *(*f)(EditLine *)
151                     Define right side prompt printing function as f, which is
152                     to return a string that contains the prompt.
153
154              EL_TERMINAL , const char *type
155                     Define terminal type of the tty to be type, or to TERM if
156                     type is NULL .
157
158              EL_EDITOR , const char *mode
159                     Set editing mode to mode, which must be one of  ``emacs''
160                     or ``vi''.
161
162              EL_SIGNAL , int flag
163                     If flag is non-zero, editline will install its own signal
164                     handler for the following signals  when  reading  command
165                     input:  SIGCONT  ,  SIGHUP , SIGINT , SIGQUIT , SIGSTOP ,
166                     SIGTERM , SIGTSTP , and SIGWINCH .  Otherwise,  the  cur‐
167                     rent signal handlers will be used.
168
169              EL_BIND , const char *, ..., NULL
170                     Perform the bind builtin command.  Refer to editrc(5) for
171                     more information.
172
173              EL_ECHOTC , const char *, ..., NULL
174                     Perform the echotc builtin command.  Refer  to  editrc(5)
175                     for more information.
176
177              EL_SETTC , const char *, ..., NULL
178                     Perform  the  settc  builtin command.  Refer to editrc(5)
179                     for more information.
180
181              EL_SETTY , const char *, ..., NULL
182                     Perform the setty builtin command.   Refer  to  editrc(5)
183                     for more information.
184
185              EL_TELLTC , const char *, ..., NULL
186                     Perform  the  telltc builtin command.  Refer to editrc(5)
187                     for more information.
188
189              EL_ADDFN , const char *name, const  char  *help,  unsigned  char
190              (*func)(EditLine *e, int ch)
191                     Add  a user defined function, func(), referred to as name
192                     which is invoked when a key which is  bound  to  name  is
193                     entered.   help  is a description of name.  At invocation
194                     time, ch is the key which  caused  the  invocation.   The
195                     return value of func() should be one of:
196
197                     CC_NORM
198                            Add a normal character.
199
200                     CC_NEWLINE
201                            End of line was entered.
202
203                     CC_EOF EOF was entered.
204
205                     CC_ARGHACK
206                            Expecting  further  command input as arguments, do
207                            nothing visually.
208
209                     CC_REFRESH
210                            Refresh display.
211
212                     CC_REFRESH_BEEP
213                            Refresh display, and beep.
214
215                     CC_CURSOR
216                            Cursor moved, so update and perform CC_REFRESH .
217
218                     CC_REDISPLAY
219                            Redisplay entire input line.  This is useful if  a
220                            key binding outputs extra information.
221
222                     CC_ERROR
223                            An error occurred.  Beep, and flush tty.
224
225                     CC_FATAL
226                            Fatal error, reset tty to known state.
227
228              EL_HIST  ,  History *(*func)(History *, int op, ...), const char
229              *ptr
230                     Defines which history function to use, which  is  usually
231                     history().   ptr  should  be  the  value returned by his‐
232                     tory_init().
233
234              EL_EDITMODE , int flag
235                     If flag is non-zero, editing is  enabled  (the  default).
236                     Note that this is only an indication, and does not affect
237                     the operation of .  At this  time,  it  is  the  caller's
238                     responsibility  to check this (using el_get() ) to deter‐
239                     mine if editing should be enabled or not.
240
241              EL_GETCFN , int (*f)(EditLine *, char *c)
242                     Define the character reading function as f, which  is  to
243                     return the number of characters read and store them in c.
244                     This function  is  called  internally  by  el_gets()  and
245                     el_getc().   The  builtin function can be set or restored
246                     with the special function name ``EL_BUILTIN_GETCFN''.
247
248              EL_CLIENTDATA , void *data
249                     Register data to be associated with this EditLine  struc‐
250                     ture.    It  can  be  retrieved  with  the  corresponding
251                     el_get() call.
252
253              EL_SETFP , int fd, Fa FILE *fp
254                     Set the current editline file pointer for ``input'' fd  =
255                     0 , ``output'' fd = 1 , or ``error'' fd = 2 from fp.
256
257       el_get()
258              Get  editline  parameters.   op  determines  which  parameter to
259              retrieve into result.  Returns 0 if successful, -1 otherwise.
260
261              The following values for op are  supported,  along  with  actual
262              type of result :
263
264              EL_PROMPT , char *(*f)(EditLine *)
265                     Return  a  pointer  to  the  function  that  displays the
266                     prompt.
267
268              EL_RPROMPT , char *(*f)(EditLine *)
269                     Return a pointer to the function that displays the right‐
270                     side prompt.
271
272              EL_EDITOR , const char *
273                     Return  the  name  of  the  editor,  which will be one of
274                     ``emacs'' or ``vi''.
275
276              EL_GETTC , const char *name, Fa void *value
277                     Return non-zero if name is a valid termcap(5)  capability
278                     and set value to the current value of that capability.
279
280              EL_SIGNAL , int *
281                     Return  non-zero if editline has installed private signal
282                     handlers (see el_get() above).
283
284              EL_EDITMODE , int *
285                     Return non-zero if editing is enabled.
286
287              EL_GETCFN , int (**f)(EditLine *, char *)
288                     Return a pointer to the function  that  read  characters,
289                     which  is  equal  to ``EL_BUILTIN_GETCFN'' in the case of
290                     the default builtin function.
291
292              EL_CLIENTDATA , void **data
293                     Retrieve data previously registered with the  correspond‐
294                     ing el_set() call.
295
296              EL_UNBUFFERED , int
297                     Sets  or clears unbuffered mode.  In this mode, el_gets()
298                     will return immediately after processing a single charac‐
299                     ter.
300
301              EL_PREP_TERM , int
302                     Sets or clears terminal editing mode.
303
304              EL_GETFP , int fd", Fa FILE **fp
305                     Return  in  fp  the  current  editline  file  pointer for
306                     ``input'' fd = 0 , ``output'' fd = 1 , or ``error'' fd  =
307                     2 .
308
309       el_source()
310              Initialise editline by reading the contents of file.  el_parse()
311              is called for each  line  in  file.   If  file  is  NULL  ,  try
312              $PWD/.editrc then $HOME/.editrc.  Refer to editrc(5) for details
313              on the format of file.
314
315       el_resize()
316              Must be called if the terminal size changes.  If  EL_SIGNAL  has
317              been set with el_set(), then this is done automatically.  Other‐
318              wise,  it's  the  responsibility  of  the  application  to  call
319              el_resize() on the appropriate occasions.
320
321       el_line()
322              Return  the  editing information for the current line in a Line‐
323              Info structure, which is defined as follows:
324
325              typedef struct lineinfo {
326                  const char *buffer;    /* address of buffer */
327                  const char *cursor;    /* address of cursor */
328                  const char *lastchar;  /* address of last character */
329              } LineInfo;
330
331              buffer is not NUL terminated.  This function may be called after
332              el_gets()  to  obtain  the LineInfo structure pertaining to line
333              returned by that function, and from within  user  defined  func‐
334              tions added with EL_ADDFN .
335
336       el_insertstr()
337              Insert  str  into  the line at the cursor.  Returns -1 if str is
338              empty or won't fit, and 0 otherwise.
339
340       el_deletestr()
341              Delete count characters before the cursor.
342

HISTORY LIST FUNCTIONS

344       The history functions use a common data structure,  History,  which  is
345       created by history_init() and freed by history_end().
346
347       The following functions are available:
348
349       history_init()
350              Initialise  the  history list, and return a data structure to be
351              used by all other history list functions.
352
353       history_end()
354              Clean up and finish with h, assumed to have  been  created  with
355              history_init().
356
357       history()
358              Perform  operation  op  on the history list, with optional argu‐
359              ments as needed by the operation.  ev is changed accordingly  to
360              operation.   The  following  values  for op are supported, along
361              with the required argument list:
362
363              H_SETSIZE , int size
364                     Set size of history to size elements.
365
366              H_GETSIZE
367                     Get number of events currently in history.
368
369              H_END  Cleans up and finishes with h, assumed to be created with
370                     history_init().
371
372              H_CLEAR
373                     Clear the history.
374
375              H_FUNC  ,  void *ptr, history_gfun_t first, history_gfun_t next,
376              history_gfun_t last, history_gfun_t prev,  history_gfun_t  curr,
377              history_sfun_t  set, history_vfun_t clear, history_efun_t enter,
378              history_efun_t add
379                     Define functions to perform various  history  operations.
380                     ptr  is  the  argument  given  to  a  function  when it's
381                     invoked.
382
383              H_FIRST
384                     Return the first element in the history.
385
386              H_LAST Return the last element in the history.
387
388              H_PREV Return the previous element in the history.
389
390              H_NEXT Return the next element in the history.
391
392              H_CURR Return the current element in the history.
393
394              H_SET  Set the cursor to point to the requested element.
395
396              H_ADD , const char *str
397                     Append str to the current element of the history, or per‐
398                     form  the H_ENTER operation with argument str if there is
399                     no current element.
400
401              H_APPEND , const char *str
402                     Append str to the last new element of the history.
403
404              H_ENTER , const char *str
405                     Add str as a new element to the history, and,  if  neces‐
406                     sary,  removing  the oldest entry to keep the list to the
407                     created size.  If H_SETUNIQUE was has been called with  a
408                     non-zero  arguments, the element will not be entered into
409                     the history if its contents match the ones of the current
410                     history  element.   If  the  element is entered history()
411                     returns 1, if it is ignored as  a  duplicate  returns  0.
412                     Finally history() returns -1 if an error occurred.
413
414              H_PREV_STR , const char *str
415                     Return the closest previous event that starts with str.
416
417              H_NEXT_STR , const char *str
418                     Return the closest next event that starts with str.
419
420              H_PREV_EVENT , int e
421                     Return the previous event numbered e.
422
423              H_NEXT_EVENT , int e
424                     Return the next event numbered e.
425
426              H_LOAD , const char *file
427                     Load the history list stored in file.
428
429              H_SAVE , const char *file
430                     Save the history list to file.
431
432              H_SETUNIQUE , int unique
433                     Set flag that adjacent identical event strings should not
434                     be entered into the history.
435
436              H_GETUNIQUE
437                     Retrieve the current setting if adjacent  identical  ele‐
438                     ments should be entered into the history.
439
440              H_DEL , int e
441                     Delete  the event numbered e.  This function is only pro‐
442                     vided  for  readline(3)  compatibility.   The  caller  is
443                     responsible  for free'ing the string in the returned His‐
444                     tEvent.
445
446       history() returns = 0 if the operation op succeeds.  Otherwise,  -1  is
447       returned and ev is updated to contain more details about the error.
448

TOKENIZATION FUNCTIONS

450       The  tokenization  functions  use  a  common data structure, Tokenizer,
451       which is created by tok_init() and freed by tok_end().
452
453       The following functions are available:
454
455       tok_init()
456              Initialise the tokenizer, and return a data structure to be used
457              by  all other tokenizer functions.  IFS contains the Input Field
458              Separators, which defaults to <space> , <tab> , and <newline> if
459              NULL .
460
461       tok_end()
462              Clean  up  and  finish with t, assumed to have been created with
463              tok_init().
464
465       tok_reset()
466              Reset the tokenizer state.  Use after a line has  been  success‐
467              fully tokenized by tok_line() or tok_str() and before a new line
468              is to be tokenized.
469
470       tok_line()
471              Tokenize li, If successful, modify: argv to contain  the  words,
472              argc  to  contain the number of words, cursorc (if not NULL ) to
473              contain the index of the word containing the cursor, and cursoro
474              (if not NULL ) to contain the offset within argv[cursorc] of the
475              cursor.
476
477              Returns 0 if successful, -1 for an  internal  error,  1  for  an
478              unmatched  single  quote, 2 for an unmatched double quote, and 3
479              for a backslash quoted <newline .> A positive  exit  code  indi‐
480              cates   that  another  line  should  be  read  and  tokenization
481              attempted again.
482
483       tok_str()
484              A simpler form of tok_line(; ) str is a NUL terminated string to
485              tokenize.
486

SEE ALSO

488       sh(1), signal(3), termcap(3), editrc(5), termcap(5)
489

HISTORY

491       The  editline library first appeared in Bx 4.4 .  CC_REDISPLAY appeared
492       in Nx 1.3 .  CC_REFRESH_BEEP , EL_EDITMODE and the  readline  emulation
493       appeared in Nx 1.4 .  EL_RPROMPT appeared in Nx 1.5 .
494

AUTHORS

496       The  editline  library  was  written  by Christos Zoulas.  Luke Mewburn
497       wrote this manual and  implemented  CC_REDISPLAY  ,  CC_REFRESH_BEEP  ,
498       EL_EDITMODE  ,  and EL_RPROMPT .  Jaromir Dolecek implemented the read‐
499       line emulation.
500

BUGS

502       At this time, it is the responsibility  of  the  caller  to  check  the
503       result  of  the EL_EDITMODE operation of el_get() (after an el_source()
504       or el_parse() ) to determine if editline should  be  used  for  further
505       input.   I.e., EL_EDITMODE is purely an indication of the result of the
506       most recent editrc(5) edit command.
507
508
509
510                                                            January 12, 2007()
Impressum