editline.3 23 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  1. .TH EDITLINE 3 "August 15, 2021" ""
  2. .SH NAME
  3. \fBeditline\fP,
  4. \fBel_init\fP,
  5. \fBel_init_fd\fP,
  6. \fBel_end\fP,
  7. \fBel_reset\fP,
  8. \fBel_gets\fP,
  9. \fBel_wgets\fP,
  10. \fBel_getc\fP,
  11. \fBel_wgetc\fP,
  12. \fBel_push\fP,
  13. \fBel_wpush\fP,
  14. \fBel_parse\fP,
  15. \fBel_wparse\fP,
  16. \fBel_set\fP,
  17. \fBel_wset\fP,
  18. \fBel_get\fP,
  19. \fBel_wget\fP,
  20. \fBel_source\fP,
  21. \fBel_resize\fP,
  22. \fBel_cursor\fP,
  23. \fBel_line\fP,
  24. \fBel_wline\fP,
  25. \fBel_insertstr\fP,
  26. \fBel_winsertstr\fP,
  27. \fBel_deletestr\fP,
  28. \fBel_wdeletestr\fP,
  29. \fBhistory_init\fP,
  30. \fBhistory_winit\fP,
  31. \fBhistory_end\fP,
  32. \fBhistory_wend\fP,
  33. \fBhistory\fP,
  34. \fBhistory_w\fP,
  35. \fBtok_init\fP,
  36. \fBtok_winit\fP,
  37. \fBtok_end\fP,
  38. \fBtok_wend\fP,
  39. \fBtok_reset\fP,
  40. \fBtok_wreset\fP,
  41. \fBtok_line\fP,
  42. \fBtok_wline\fP,
  43. \fBtok_str\fP,
  44. \fBtok_wstr\fP
  45. \- line editor, history and tokenization functions
  46. .SH LIBRARY
  47. Command Line Editor Library (libedit, -ledit)
  48. .SH SYNOPSIS
  49. .PP
  50. \fB#include <histedit.h>\fP
  51. .PP
  52. \fIEditLine *\fP
  53. .br
  54. \fBel_init\fP(\fIconst char *prog\fP, \fIFILE *fin\fP, \fIFILE *fout\fP, \fIFILE *ferr\fP);
  55. .PP
  56. \fIEditLine *\fP
  57. .br
  58. \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);
  59. .PP
  60. \fIvoid\fP
  61. .br
  62. \fBel_end\fP(\fIEditLine *e\fP);
  63. .PP
  64. \fIvoid\fP
  65. .br
  66. \fBel_reset\fP(\fIEditLine *e\fP);
  67. .PP
  68. \fIconst char *\fP
  69. .br
  70. \fBel_gets\fP(\fIEditLine *e\fP, \fIint *count\fP);
  71. .PP
  72. \fIconst wchar_t *\fP
  73. .br
  74. \fBel_wgets\fP(\fIEditLine *e\fP, \fIint *count\fP);
  75. .PP
  76. \fIint\fP
  77. .br
  78. \fBel_getc\fP(\fIEditLine *e\fP, \fIchar *ch\fP);
  79. .PP
  80. \fIint\fP
  81. .br
  82. \fBel_wgetc\fP(\fIEditLine *e\fP, \fIwchar_t *wc\fP);
  83. .PP
  84. \fIvoid\fP
  85. .br
  86. \fBel_push\fP(\fIEditLine *e\fP, \fIconst char *mbs\fP);
  87. .PP
  88. \fIvoid\fP
  89. .br
  90. \fBel_wpush\fP(\fIEditLine *e\fP, \fIconst wchar_t *wcs\fP);
  91. .PP
  92. \fIint\fP
  93. .br
  94. \fBel_parse\fP(\fIEditLine *e\fP, \fIint argc\fP, \fIconst char *argv[]\fP);
  95. .PP
  96. \fIint\fP
  97. .br
  98. \fBel_wparse\fP(\fIEditLine *e\fP, \fIint argc\fP, \fIconst wchar_t *argv[]\fP);
  99. .PP
  100. \fIint\fP
  101. .br
  102. \fBel_set\fP(\fIEditLine *e\fP, \fIint op\fP, \fI...\fP);
  103. .PP
  104. \fIint\fP
  105. .br
  106. \fBel_wset\fP(\fIEditLine *e\fP, \fIint op\fP, \fI...\fP);
  107. .PP
  108. \fIint\fP
  109. .br
  110. \fBel_get\fP(\fIEditLine *e\fP, \fIint op\fP, \fI...\fP);
  111. .PP
  112. \fIint\fP
  113. .br
  114. \fBel_wget\fP(\fIEditLine *e\fP, \fIint op\fP, \fI...\fP);
  115. .PP
  116. \fIint\fP
  117. .br
  118. \fBel_source\fP(\fIEditLine *e\fP, \fIconst char *file\fP);
  119. .PP
  120. \fIvoid\fP
  121. .br
  122. \fBel_resize\fP(\fIEditLine *e\fP);
  123. .PP
  124. \fIint\fP
  125. .br
  126. \fBel_cursor\fP(\fIEditLine *e\fP, \fIint count\fP);
  127. .PP
  128. \fIconst LineInfo *\fP
  129. .br
  130. \fBel_line\fP(\fIEditLine *e\fP);
  131. .PP
  132. \fIconst LineInfoW *\fP
  133. .br
  134. \fBel_wline\fP(\fIEditLine *e\fP);
  135. .PP
  136. \fIint\fP
  137. .br
  138. \fBel_insertstr\fP(\fIEditLine *e\fP, \fIconst char *str\fP);
  139. .PP
  140. \fIint\fP
  141. .br
  142. \fBel_winsertstr\fP(\fIEditLine *e\fP, \fIconst wchar_t *str\fP);
  143. .PP
  144. \fIvoid\fP
  145. .br
  146. \fBel_deletestr\fP(\fIEditLine *e\fP, \fIint count\fP);
  147. .PP
  148. \fIvoid\fP
  149. .br
  150. \fBel_wdeletestr\fP(\fIEditLine *e\fP, \fIint count\fP);
  151. .PP
  152. \fIHistory *\fP
  153. .br
  154. \fBhistory_init\fP(void );
  155. .PP
  156. \fIHistoryW *\fP
  157. .br
  158. \fBhistory_winit\fP(void );
  159. .PP
  160. \fIvoid\fP
  161. .br
  162. \fBhistory_end\fP(\fIHistory *h\fP);
  163. .PP
  164. \fIvoid\fP
  165. .br
  166. \fBhistory_wend\fP(\fIHistoryW *h\fP);
  167. .PP
  168. \fIint\fP
  169. .br
  170. \fBhistory\fP(\fIHistory *h\fP, \fIHistEvent *ev\fP, \fIint op\fP, \fI...\fP);
  171. .PP
  172. \fIint\fP
  173. .br
  174. \fBhistory_w\fP(\fIHistoryW *h\fP, \fIHistEventW *ev\fP, \fIint op\fP, \fI...\fP);
  175. .PP
  176. \fITokenizer *\fP
  177. .br
  178. \fBtok_init\fP(\fIconst char *IFS\fP);
  179. .PP
  180. \fITokenizerW *\fP
  181. .br
  182. \fBtok_winit\fP(\fIconst wchar_t *IFS\fP);
  183. .PP
  184. \fIvoid\fP
  185. .br
  186. \fBtok_end\fP(\fITokenizer *t\fP);
  187. .PP
  188. \fIvoid\fP
  189. .br
  190. \fBtok_wend\fP(\fITokenizerW *t\fP);
  191. .PP
  192. \fIvoid\fP
  193. .br
  194. \fBtok_reset\fP(\fITokenizer *t\fP);
  195. .PP
  196. \fIvoid\fP
  197. .br
  198. \fBtok_wreset\fP(\fITokenizerW *t\fP);
  199. .PP
  200. \fIint\fP
  201. .br
  202. \fBtok_line\fP(\fITokenizer *t\fP, \fIconst LineInfo *li\fP, \fIint *argc\fP, \fIconst char **argv[]\fP, \fIint *cursorc\fP, \fIint *cursoro\fP);
  203. .PP
  204. \fIint\fP
  205. .br
  206. \fBtok_wline\fP(\fITokenizerW *t\fP, \fIconst LineInfoW *li\fP, \fIint *argc\fP, \fIconst wchar_t **argv[]\fP, \fIint *cursorc\fP, \fIint *cursoro\fP);
  207. .PP
  208. \fIint\fP
  209. .br
  210. \fBtok_str\fP(\fITokenizer *t\fP, \fIconst char *str\fP, \fIint *argc\fP, \fIconst char **argv[]\fP);
  211. .PP
  212. \fIint\fP
  213. .br
  214. \fBtok_wstr\fP(\fITokenizerW *t\fP, \fIconst wchar_t *str\fP, \fIint *argc\fP, \fIconst wchar_t **argv[]\fP);
  215. .SH DESCRIPTION
  216. The
  217. \fBeditline\fP
  218. library provides generic line editing, history and tokenization functions,
  219. similar to those found in
  220. \fBsh\fP(1).
  221. These functions are available in the
  222. \fBlibedit\fP
  223. library (which needs the
  224. \fBlibtermcap\fP
  225. library).
  226. Programs should be linked with
  227. \fB\-ledit\fP ltermcap .
  228. The
  229. \fBeditline\fP
  230. library respects the
  231. .IR LC_CTYPE
  232. locale set by the application program and never uses
  233. \fBsetlocale\fP(3)
  234. to change the locale.
  235. .SH LINE EDITING FUNCTIONS
  236. The line editing functions use a common data structure,
  237. \fIEditLine\fP,
  238. which is created by
  239. \fBel_init\fP()
  240. or
  241. \fBel_init_fd\fP()
  242. and freed by
  243. \fBel_end\fP().
  244. The wide-character functions behave the same way as their narrow
  245. counterparts.
  246. The following functions are available:
  247. .TP
  248. \fBel_init\fP()
  249. Initialize the line editor, and return a data structure
  250. to be used by all other line editing functions, or
  251. NULL
  252. on failure.
  253. \fIprog \fP
  254. is the name of the invoking program, used when reading the
  255. \fBeditrc\fP(5)
  256. file to determine which settings to use.
  257. \fIfin\fP,
  258. \fIfout \fP
  259. and
  260. \fIferr \fP
  261. are the input, output, and error streams (respectively) to use.
  262. In this documentation, references to
  263. ``the tty''
  264. are actually to this input/output stream combination.
  265. .TP
  266. \fBel_init_fd\fP()
  267. Like
  268. \fBel_init\fP()
  269. but allows specifying file descriptors for the
  270. \fBstdio\fP(3)
  271. corresponding streams, in case those were created with
  272. \fBfunopen\fP(3).
  273. .TP
  274. \fBel_end\fP()
  275. Clean up and finish with
  276. \fIe\fP,
  277. assumed to have been created with
  278. \fBel_init\fP()
  279. or
  280. \fBel_init_fd\fP().
  281. .TP
  282. \fBel_reset\fP()
  283. Reset the tty and the parser.
  284. This should be called after an error which may have upset the tty's
  285. state.
  286. .TP
  287. \fBel_gets\fP()
  288. Read a line from the tty.
  289. \fIcount \fP
  290. is modified to contain the number of characters read.
  291. Returns the line read if successful, or
  292. NULL
  293. if no characters were read or if an error occurred.
  294. If an error occurred,
  295. \fIcount \fP
  296. is set to \-1 and
  297. errno
  298. contains the error code that caused it.
  299. The return value may not remain valid across calls to
  300. \fBel_gets\fP()
  301. and must be copied if the data is to be retained.
  302. .TP
  303. \fBel_wgetc\fP()
  304. Read a wide character from the tty, respecting the current locale,
  305. or from the input queue described in
  306. \fBeditline\fP(7)
  307. if that is not empty, and store it in
  308. \fIwc\fP.
  309. If an invalid or incomplete character is found, it is discarded,
  310. \fIerrno\fP
  311. is set to
  312. Er EILSEQ ,
  313. and the next character is read and stored in
  314. \fIwc\fP.
  315. Returns 1 if a valid character was read, 0 on end of file, or \-1 on
  316. \fBread\fP(2)
  317. failure.
  318. In the latter case,
  319. \fIerrno\fP
  320. is set to indicate the error.
  321. .TP
  322. \fBel_getc\fP()
  323. Read a wide character as described for
  324. \fBel_wgetc\fP()
  325. and return 0 on end of file or \-1 on failure.
  326. If the wide character can be represented as a single-byte character,
  327. convert it with
  328. \fBwctob\fP(3),
  329. store the result in
  330. \fIch\fP,
  331. and return 1; otherwise, set
  332. \fIerrno\fP
  333. to
  334. Er ERANGE
  335. and return \-1.
  336. In the C or POSIX locale, this simply reads a byte, but for any other
  337. locale, including UTF-8, this is rarely useful.
  338. .TP
  339. \fBel_wpush\fP()
  340. Push the wide character string
  341. \fIwcs \fP
  342. back onto the input queue described in
  343. \fBeditline\fP(7).
  344. If the queue overflows, for example due to a recursive macro,
  345. or if an error occurs, for example because
  346. \fIwcs \fP
  347. is
  348. NULL
  349. or memory allocation fails, the function beeps at the user,
  350. but does not report the problem to the caller.
  351. .TP
  352. \fBel_push\fP()
  353. Use the current locale to convert the multibyte string
  354. \fImbs \fP
  355. to a wide character string, and pass the result to
  356. \fBel_wpush\fP().
  357. .TP
  358. \fBel_parse\fP()
  359. Parses the
  360. \fIargv \fP
  361. array (which is
  362. \fIargc \fP
  363. elements in size)
  364. to execute builtin
  365. \fBeditline\fP
  366. commands.
  367. If the command is prefixed with
  368. ``prog :''
  369. then
  370. \fBel_parse\fP()
  371. will only execute the command if
  372. ``prog''
  373. matches the
  374. \fIprog \fP
  375. argument supplied to
  376. \fBel_init\fP().
  377. The return value is
  378. \-1 if the command is unknown,
  379. 0 if there was no error or
  380. ``prog''
  381. didn't match, or
  382. 1 if the command returned an error.
  383. Refer to
  384. \fBeditrc\fP(5)
  385. for more information.
  386. .TP
  387. \fBel_set\fP()
  388. Set
  389. \fBeditline\fP
  390. parameters.
  391. \fIop \fP
  392. determines which parameter to set, and each operation has its
  393. own parameter list.
  394. Returns 0 on success, \-1 on failure.
  395. The following values for
  396. \fIop \fP
  397. are supported, along with the required argument list:
  398. .RS
  399. .TP
  400. EL_PROMPT , \fIchar *(*f)(EditLine *)\fP
  401. Define prompt printing function as
  402. \fIf\fP,
  403. which is to return a string that contains the prompt.
  404. .TP
  405. EL_PROMPT_ESC , \fIchar *(*f)(EditLine *), Fa char c\fP
  406. Same as
  407. EL_PROMPT ,
  408. but the
  409. \fIc \fP
  410. argument indicates the start/stop literal prompt character.
  411. If a start/stop literal character is found in the prompt, the
  412. character itself
  413. is not printed, but characters after it are printed directly to the
  414. terminal without affecting the state of the current line.
  415. A subsequent second start/stop literal character ends this behavior.
  416. This is typically used to embed literal escape sequences that change the
  417. color/style of the terminal in the prompt.
  418. Note that the literal escape character cannot be the last character in the
  419. prompt, as the escape sequence is attached to the next character in the prompt.
  420. 0
  421. unsets it.
  422. .TP
  423. EL_REFRESH
  424. Re-display the current line on the next terminal line.
  425. .TP
  426. EL_RPROMPT , \fIchar *(*f)(EditLine *)\fP
  427. Define right side prompt printing function as
  428. \fIf\fP,
  429. which is to return a string that contains the prompt.
  430. .TP
  431. EL_RPROMPT_ESC , \fIchar *(*f)(EditLine *), Fa char c\fP
  432. Define the right prompt printing function but with a literal escape character.
  433. .TP
  434. EL_TERMINAL , \fIconst char *type\fP
  435. Define terminal type of the tty to be
  436. \fItype\fP,
  437. or to
  438. .IR TERM
  439. if
  440. \fItype \fP
  441. is
  442. NULL .
  443. .TP
  444. EL_EDITOR , \fIconst char *mode\fP
  445. Set editing mode to
  446. \fImode\fP,
  447. which must be one of
  448. ``emacs''
  449. or
  450. ``vi''.
  451. .TP
  452. EL_SIGNAL , \fIint flag\fP
  453. If
  454. \fIflag \fP
  455. is non-zero,
  456. \fBeditline\fP
  457. will install its own signal handler for the following signals when
  458. reading command input:
  459. SIGCONT ,
  460. SIGHUP ,
  461. SIGINT ,
  462. SIGQUIT ,
  463. SIGSTOP ,
  464. SIGTERM ,
  465. SIGTSTP ,
  466. and
  467. SIGWINCH .
  468. Otherwise, the current signal handlers will be used.
  469. .TP
  470. EL_BIND , \fIconst char *, Fa ..., Dv NULL \fP
  471. Perform the
  472. \fBbind\fP
  473. builtin command.
  474. Refer to
  475. \fBeditrc\fP(5)
  476. for more information.
  477. .TP
  478. EL_ECHOTC , \fIconst char *, Fa ..., Dv NULL \fP
  479. Perform the
  480. \fBechotc\fP
  481. builtin command.
  482. Refer to
  483. \fBeditrc\fP(5)
  484. for more information.
  485. .TP
  486. EL_SETTC , \fIconst char *, Fa ..., Dv NULL \fP
  487. Perform the
  488. \fBsettc\fP
  489. builtin command.
  490. Refer to
  491. \fBeditrc\fP(5)
  492. for more information.
  493. .TP
  494. EL_SETTY , \fIconst char *, Fa ..., Dv NULL \fP
  495. Perform the
  496. \fBsetty\fP
  497. builtin command.
  498. Refer to
  499. \fBeditrc\fP(5)
  500. for more information.
  501. .TP
  502. EL_TELLTC , \fIconst char *, Fa ..., Dv NULL \fP
  503. Perform the
  504. \fBtelltc\fP
  505. builtin command.
  506. Refer to
  507. \fBeditrc\fP(5)
  508. for more information.
  509. .TP
  510. EL_ADDFN , \fIconst char *name, Fa const char *help, \ \fP
  511. Fa "unsigned char (*func)(EditLine *e, int ch)"
  512. Add a user defined function,
  513. \fBfunc\fP(),
  514. referred to as
  515. \fIname \fP
  516. which is invoked when a key which is bound to
  517. \fIname \fP
  518. is entered.
  519. \fIhelp \fP
  520. is a description of
  521. \fIname\fP.
  522. At invocation time,
  523. \fIch \fP
  524. is the key which caused the invocation.
  525. The return value of
  526. \fBfunc\fP()
  527. should be one of:
  528. .RS
  529. .TP
  530. CC_NORM
  531. Add a normal character.
  532. .TP
  533. CC_NEWLINE
  534. End of line was entered.
  535. .TP
  536. CC_EOF
  537. EOF was entered.
  538. .TP
  539. CC_ARGHACK
  540. Expecting further command input as arguments, do nothing visually.
  541. .TP
  542. CC_REFRESH
  543. Refresh display.
  544. .TP
  545. CC_REFRESH_BEEP
  546. Refresh display, and beep.
  547. .TP
  548. CC_CURSOR
  549. Cursor moved, so update and perform
  550. CC_REFRESH .
  551. .TP
  552. CC_REDISPLAY
  553. Redisplay entire input line.
  554. This is useful if a key binding outputs extra information.
  555. .TP
  556. CC_ERROR
  557. An error occurred.
  558. Beep, and flush tty.
  559. .TP
  560. CC_FATAL
  561. Fatal error, reset tty to known state.
  562. .RE
  563. .TP
  564. EL_HIST , \fIHistory *(*func)(History *, int op, ...), \ \fP
  565. Fa "const char *ptr"
  566. Defines which history function to use, which is usually
  567. \fBhistory\fP().
  568. \fIptr \fP
  569. should be the value returned by
  570. \fBhistory_init\fP().
  571. .TP
  572. EL_EDITMODE , \fIint flag\fP
  573. If
  574. \fIflag \fP
  575. is non-zero,
  576. editing is enabled (the default).
  577. Note that this is only an indication, and does not
  578. affect the operation of
  579. \fB.\fP
  580. At this time, it is the caller's responsibility to
  581. check this
  582. (using
  583. \fBel_get\fP() )
  584. to determine if editing should be enabled or not.
  585. .TP
  586. EL_UNBUFFERED , \fIint flag\fP
  587. If
  588. \fIflag \fP
  589. is zero,
  590. unbuffered mode is disabled (the default).
  591. In unbuffered mode,
  592. \fBel_gets\fP()
  593. will return immediately after processing a single character.
  594. .TP
  595. EL_SAFEREAD , \fIint flag\fP
  596. If the
  597. \fIflag \fP
  598. argument is non-zero, then
  599. \fBeditline\fP
  600. attempts to recover from read errors, ignoring the first interrrupted
  601. error, and trying to reset the input file descriptor to reset non-blocking I/O.
  602. This is disabled by default, and desirable only when
  603. \fBeditline\fP
  604. is used in shell-like applications.
  605. .TP
  606. EL_GETCFN , \fIel_rfunc_t f\fP
  607. Whenever reading a character, use the function
  608. -ragged -offset indent -compact
  609. .PP
  610. \fIint\fP
  611. .br
  612. Fo f
  613. \fIEditLine *e\fP
  614. \fIwchar_t *wc\fP
  615. Fc
  616. which stores the character in
  617. \fIwc \fP
  618. and returns 1 on success, 0 on end of file, or \-1 on I/O or encoding
  619. errors.
  620. Functions internally using it include
  621. \fBel_wgets\fP(),
  622. \fBel_wgetc\fP(),
  623. \fBel_gets\fP(),
  624. and
  625. \fBel_getc\fP().
  626. Initially, a builtin function is installed, and replacing it
  627. is discouraged because writing such a function is very error prone.
  628. The builtin function can be restored at any time by passing the
  629. special value
  630. EL_BUILTIN_GETCFN
  631. instead of a function pointer.
  632. .TP
  633. EL_CLIENTDATA , \fIvoid *data\fP
  634. Register
  635. \fIdata \fP
  636. to be associated with this EditLine structure.
  637. It can be retrieved with the corresponding
  638. \fBel_get\fP();
  639. call.
  640. .TP
  641. EL_SETFP , \fIint fd, Fa FILE *fp\fP
  642. Set the current
  643. \fBeditline\fP
  644. file pointer for
  645. ``input''
  646. \fIfd \fP
  647. =
  648. 0 ,
  649. ``output''
  650. \fIfd \fP
  651. =
  652. 1 ,
  653. or
  654. ``error''
  655. \fIfd \fP
  656. =
  657. 2
  658. from
  659. \fIfp\fP.
  660. .RE
  661. .TP
  662. \fBel_get\fP()
  663. Get
  664. \fBeditline\fP
  665. parameters.
  666. \fIop \fP
  667. determines which parameter to retrieve into
  668. \fIresult\fP.
  669. Returns 0 if successful, \-1 otherwise.
  670. The following values for
  671. \fIop \fP
  672. are supported, along with actual type of
  673. \fIresult : \fP
  674. .RS
  675. .TP
  676. EL_PROMPT , \fIchar *(*f)(EditLine *), Fa char *c\fP
  677. Set
  678. \fIf \fP
  679. to a pointer to the function that displays the prompt.
  680. If
  681. \fIc \fP
  682. is not
  683. NULL ,
  684. set it to the start/stop literal prompt character.
  685. .TP
  686. EL_RPROMPT , \fIchar *(*f)(EditLine *), Fa char *c\fP
  687. Set
  688. \fIf \fP
  689. to a pointer to the function that displays the prompt.
  690. If
  691. \fIc \fP
  692. is not
  693. NULL ,
  694. set it to the start/stop literal prompt character.
  695. .TP
  696. EL_EDITOR , \fIconst char **n\fP
  697. Set the name of the editor in
  698. \fIn\fP,
  699. which will be one of
  700. ``emacs''
  701. or
  702. ``vi''.
  703. .TP
  704. EL_GETTC , \fIconst char *name, Fa void *value\fP
  705. If
  706. \fIname \fP
  707. is a valid
  708. \fBtermcap\fP(5)
  709. capability set
  710. \fIvalue \fP
  711. to the current value of that capability.
  712. .TP
  713. EL_SIGNAL , \fIint *s\fP
  714. Set
  715. \fIs \fP
  716. to non-zero if
  717. \fBeditline\fP
  718. has installed private signal handlers (see
  719. \fBel_get\fP()
  720. above).
  721. .TP
  722. EL_EDITMODE , \fIint *c\fP
  723. Set
  724. \fIc \fP
  725. to non-zero if editing is enabled.
  726. .TP
  727. EL_GETCFN , \fIel_rfunc_t *f\fP
  728. Set
  729. \fIf \fP
  730. to a pointer to the function that reads characters, or to
  731. EL_BUILTIN_GETCFN
  732. if the builtin function is in use.
  733. .TP
  734. EL_CLIENTDATA , \fIvoid **data\fP
  735. Set
  736. \fIdata \fP
  737. to the previously registered client data set by an
  738. \fBel_set\fP()
  739. call.
  740. .TP
  741. EL_UNBUFFERED , \fIint *c\fP
  742. Set
  743. \fIc \fP
  744. to non-zero if unbuffered mode is enabled.
  745. .TP
  746. EL_SAFEREAD , \fIint *c\fP
  747. Set
  748. \fIc \fP
  749. to non-zero if safe read is set.
  750. .TP
  751. EL_GETFP , \fIint fd", Fa FILE **fp\fP
  752. Set
  753. \fIfp \fP
  754. to the current
  755. \fBeditline\fP
  756. file pointer for
  757. ``input''
  758. \fIfd \fP
  759. =
  760. 0 ,
  761. ``output''
  762. \fIfd \fP
  763. =
  764. 1 ,
  765. or
  766. ``error''
  767. \fIfd \fP
  768. =
  769. 2 .
  770. .RE
  771. .TP
  772. \fBel_source\fP()
  773. Initialize
  774. \fBeditline\fP
  775. by reading the contents of
  776. \fIfile\fP.
  777. \fBel_parse\fP()
  778. is called for each line in
  779. \fIfile\fP.
  780. If
  781. \fIfile \fP
  782. is
  783. NULL ,
  784. try
  785. \fI$EDITRC\fP
  786. and if that is not set
  787. \fI$HOME/.editrc\fP.
  788. Refer to
  789. \fBeditrc\fP(5)
  790. for details on the format of
  791. \fIfile\fP.
  792. \fBel_source\fP()
  793. returns 0 on success and \-1 on error.
  794. .TP
  795. \fBel_resize\fP()
  796. Must be called if the terminal size changes.
  797. If
  798. EL_SIGNAL
  799. has been set with
  800. \fBel_set\fP(),
  801. then this is done automatically.
  802. Otherwise, it's the responsibility of the application to call
  803. \fBel_resize\fP()
  804. on the appropriate occasions.
  805. .TP
  806. \fBel_cursor\fP()
  807. Move the cursor to the right (if positive) or to the left (if negative)
  808. \fIcount \fP
  809. characters.
  810. Returns the resulting offset of the cursor from the beginning of the line.
  811. .TP
  812. \fBel_line\fP()
  813. Return the editing information for the current line in a
  814. \fILineInfo \fP
  815. structure, which is defined as follows:
  816. typedef struct lineinfo {
  817. .br
  818. const char *buffer; /* address of buffer */
  819. .br
  820. const char *cursor; /* address of cursor */
  821. .br
  822. const char *lastchar; /* address of last character */
  823. .br
  824. } LineInfo;
  825. .br
  826. \fIbuffer \fP
  827. is not NUL terminated.
  828. This function may be called after
  829. \fBel_gets\fP()
  830. to obtain the
  831. \fILineInfo \fP
  832. structure pertaining to line returned by that function,
  833. and from within user defined functions added with
  834. EL_ADDFN .
  835. .TP
  836. \fBel_insertstr\fP()
  837. Insert
  838. \fIstr \fP
  839. into the line at the cursor.
  840. Returns \-1 if
  841. \fIstr \fP
  842. is empty or won't fit, and 0 otherwise.
  843. .TP
  844. \fBel_deletestr\fP()
  845. Delete
  846. \fIcount \fP
  847. characters before the cursor.
  848. .SH HISTORY LIST FUNCTIONS
  849. The history functions use a common data structure,
  850. \fIHistory\fP,
  851. which is created by
  852. \fBhistory_init\fP()
  853. and freed by
  854. \fBhistory_end\fP().
  855. The following functions are available:
  856. .TP
  857. \fBhistory_init\fP()
  858. Initialize the history list, and return a data structure
  859. to be used by all other history list functions, or
  860. NULL
  861. on failure.
  862. .TP
  863. \fBhistory_end\fP()
  864. Clean up and finish with
  865. \fIh\fP,
  866. assumed to have been created with
  867. \fBhistory_init\fP().
  868. .TP
  869. \fBhistory\fP()
  870. Perform operation
  871. \fIop \fP
  872. on the history list, with optional arguments as needed by the
  873. operation.
  874. \fIev \fP
  875. is changed accordingly to operation.
  876. The following values for
  877. \fIop \fP
  878. are supported, along with the required argument list:
  879. .RS
  880. .TP
  881. H_SETSIZE , \fIint size\fP
  882. Set size of history to
  883. \fIsize \fP
  884. elements.
  885. .TP
  886. H_GETSIZE
  887. Get number of events currently in history.
  888. .TP
  889. H_END
  890. Cleans up and finishes with
  891. \fIh\fP,
  892. assumed to be created with
  893. \fBhistory_init\fP().
  894. .TP
  895. H_CLEAR
  896. Clear the history.
  897. .TP
  898. H_FUNC , \fIvoid *ptr, Fa history_gfun_t first, \ \fP
  899. Fa "history_gfun_t next" , Fa "history_gfun_t last" , \
  900. Fa "history_gfun_t prev" , Fa "history_gfun_t curr" , \
  901. Fa "history_sfun_t set" , Fa "history_vfun_t clear" , \
  902. Fa "history_efun_t enter" , Fa "history_efun_t add"
  903. Define functions to perform various history operations.
  904. \fIptr \fP
  905. is the argument given to a function when it's invoked.
  906. .TP
  907. H_FIRST
  908. Return the first element in the history.
  909. .TP
  910. H_LAST
  911. Return the last element in the history.
  912. .TP
  913. H_PREV
  914. Return the previous element in the history.
  915. It is newer than the current one.
  916. .TP
  917. H_NEXT
  918. Return the next element in the history.
  919. It is older than the current one.
  920. .TP
  921. H_CURR
  922. Return the current element in the history.
  923. .TP
  924. H_SET , \fIint position\fP
  925. Set the cursor to point to the requested element.
  926. .TP
  927. H_ADD , \fIconst char *str\fP
  928. Append
  929. \fIstr \fP
  930. to the current element of the history, or perform the
  931. H_ENTER
  932. operation with argument
  933. \fIstr \fP
  934. if there is no current element.
  935. .TP
  936. H_APPEND , \fIconst char *str\fP
  937. Append
  938. \fIstr \fP
  939. to the last new element of the history.
  940. .TP
  941. H_ENTER , \fIconst char *str\fP
  942. Add
  943. \fIstr \fP
  944. as a new element to the history and, if necessary,
  945. removing the oldest entry to keep the list to the created size.
  946. If
  947. H_SETUNIQUE
  948. has been called with a non-zero argument, the element
  949. will not be entered into the history if its contents match
  950. the ones of the current history element.
  951. If the element is entered
  952. \fBhistory\fP()
  953. returns 1; if it is ignored as a duplicate returns 0.
  954. Finally
  955. \fBhistory\fP()
  956. returns \-1 if an error occurred.
  957. .TP
  958. H_PREV_STR , \fIconst char *str\fP
  959. Return the closest previous event that starts with
  960. \fIstr\fP.
  961. .TP
  962. H_NEXT_STR , \fIconst char *str\fP
  963. Return the closest next event that starts with
  964. \fIstr\fP.
  965. .TP
  966. H_PREV_EVENT , \fIint e\fP
  967. Return the previous event numbered
  968. \fIe\fP.
  969. .TP
  970. H_NEXT_EVENT , \fIint e\fP
  971. Return the next event numbered
  972. \fIe\fP.
  973. .TP
  974. H_LOAD , \fIconst char *file\fP
  975. Load the history list stored in
  976. \fIfile\fP.
  977. .TP
  978. H_SAVE , \fIconst char *file\fP
  979. Save the history list to
  980. \fIfile\fP.
  981. .TP
  982. H_SAVE_FP , \fIFILE *fp\fP
  983. Save the history list to the opened
  984. .PP
  985. \fIFILE\fP
  986. .br
  987. pointer
  988. \fIfp\fP.
  989. .TP
  990. H_NSAVE_FP , \fIsize_t n, Fa FILE *fp\fP
  991. Save the last
  992. .PP
  993. \fIn\fP
  994. .br
  995. history entries to the opened
  996. .PP
  997. \fIFILE\fP
  998. .br
  999. pointer
  1000. \fIfp\fP.
  1001. .TP
  1002. H_SETUNIQUE , \fIint unique\fP
  1003. Set flag that adjacent identical event strings should not be entered
  1004. into the history.
  1005. .TP
  1006. H_GETUNIQUE
  1007. Retrieve the current setting if adjacent identical elements should
  1008. be entered into the history.
  1009. .TP
  1010. H_DEL , \fIint e\fP
  1011. Delete the event numbered
  1012. \fIe\fP.
  1013. This function is only provided for
  1014. \fBreadline\fP
  1015. compatibility.
  1016. The caller is responsible for free'ing the string in the returned
  1017. \fIHistEvent\fP.
  1018. .RE
  1019. \fBhistory\fP();
  1020. returns >= 0 if the operation
  1021. \fIop \fP
  1022. succeeds.
  1023. Otherwise, \-1 is returned and
  1024. \fIev \fP
  1025. is updated to contain more details about the error.
  1026. .SH TOKENIZATION FUNCTIONS
  1027. The tokenization functions use a common data structure,
  1028. \fITokenizer\fP,
  1029. which is created by
  1030. \fBtok_init\fP()
  1031. and freed by
  1032. \fBtok_end\fP().
  1033. The following functions are available:
  1034. .TP
  1035. \fBtok_init\fP()
  1036. Initialize the tokenizer, and return a data structure
  1037. to be used by all other tokenizer functions.
  1038. \fIIFS \fP
  1039. contains the Input Field Separators, which defaults to
  1040. <space ,>
  1041. <tab ,>
  1042. and
  1043. <newline>
  1044. if
  1045. NULL .
  1046. .TP
  1047. \fBtok_end\fP()
  1048. Clean up and finish with
  1049. \fIt\fP,
  1050. assumed to have been created with
  1051. \fBtok_init\fP().
  1052. .TP
  1053. \fBtok_reset\fP()
  1054. Reset the tokenizer state.
  1055. Use after a line has been successfully tokenized
  1056. by
  1057. \fBtok_line\fP()
  1058. or
  1059. \fBtok_str\fP()
  1060. and before a new line is to be tokenized.
  1061. .TP
  1062. \fBtok_line\fP()
  1063. Tokenize
  1064. \fIli\fP,
  1065. If successful, modify:
  1066. \fIargv \fP
  1067. to contain the words,
  1068. \fIargc \fP
  1069. to contain the number of words,
  1070. \fIcursorc \fP
  1071. (if not
  1072. NULL )
  1073. to contain the index of the word containing the cursor,
  1074. and
  1075. \fIcursoro \fP
  1076. (if not
  1077. NULL )
  1078. to contain the offset within
  1079. \fIargv[cursorc] \fP
  1080. of the cursor.
  1081. Returns
  1082. 0 if successful,
  1083. \-1 for an internal error,
  1084. 1 for an unmatched single quote,
  1085. 2 for an unmatched double quote,
  1086. and
  1087. 3 for a backslash quoted
  1088. <newline .>
  1089. A positive exit code indicates that another line should be read
  1090. and tokenization attempted again.
  1091. .TP
  1092. \fBtok_str\fP()
  1093. A simpler form of
  1094. \fBtok_line\fP(; )
  1095. \fIstr \fP
  1096. is a NUL terminated string to tokenize.
  1097. .SH SEE ALSO
  1098. \fBsh\fP(1),
  1099. \fBsignal\fP(3),
  1100. \fBtermcap\fP(3),
  1101. \fBeditrc\fP(5),
  1102. \fBtermcap\fP(5),
  1103. \fBeditline\fP(7)
  1104. .SH HISTORY
  1105. The
  1106. \fBeditline\fP
  1107. library first appeared in
  1108. Bx 4.4 .
  1109. CC_REDISPLAY
  1110. appeared in
  1111. Nx 1.3 .
  1112. CC_REFRESH_BEEP ,
  1113. EL_EDITMODE
  1114. and the readline emulation appeared in
  1115. Nx 1.4 .
  1116. EL_RPROMPT
  1117. appeared in
  1118. Nx 1.5 .
  1119. .SH AUTHORS
  1120. -nosplit
  1121. The
  1122. \fBeditline\fP
  1123. library was written by
  1124. Christos Zoulas .
  1125. Luke Mewburn
  1126. wrote this manual and implemented
  1127. CC_REDISPLAY ,
  1128. CC_REFRESH_BEEP ,
  1129. EL_EDITMODE ,
  1130. and
  1131. EL_RPROMPT .
  1132. Jaromir Dolecek
  1133. implemented the readline emulation.
  1134. Johny Mattsson
  1135. implemented wide-character support.
  1136. .SH BUGS
  1137. At this time, it is the responsibility of the caller to
  1138. check the result of the
  1139. EL_EDITMODE
  1140. operation of
  1141. \fBel_get\fP()
  1142. (after an
  1143. \fBel_source\fP()
  1144. or
  1145. \fBel_parse\fP() )
  1146. to determine if
  1147. \fBeditline\fP
  1148. should be used for further input.
  1149. I.e.,
  1150. EL_EDITMODE
  1151. is purely an indication of the result of the most recent
  1152. \fBeditrc\fP(5)
  1153. \fBedit\fP
  1154. command.