summaryrefslogtreecommitdiff
path: root/lib/libedit
AgeCommit message (Collapse)Author
2018-02-26PR/53058: Nikhil Benesch: use correctly typed variables (wchar_t vs wint_t)christos
as parameters.
2018-01-01Only FLUSH if we are ending libedit; DRAIN if we suspend for readline.christos
This allows pasting multiline buffers (Gerry Swislow)
2017-12-23The order in which the arguments to a function are evaluated isuwe
undefined, so don't use va_arg() twice. PR lib/52849
2017-12-08For applications that don't issue their own prompt (like python)christos
don't set unbuffered unless they've already printed the prompt. This avoids printing the prompt before the application has a chance to process the input line. From sjg@
2017-10-27Add NULL check after doing memory allocation at a couple of placesabhinav
ok christos@
2017-10-15Add copyright and rcs header to the test program.abhinav
Also, remove a test case which was not supposed to be there. (While that test case works with the changes I committed, testing that test case with the test program is not possible in its current form. I'm working on that.)
2017-10-15Add support for escaping special characters when doing filename completion.abhinav
For instance if the file name is "foo bar": $ ls foo<TAB> should get autocompleted to: $ ls foo\ bar Works for similar other characters too, which need escaping. Also, add an accompanying test program to ensure the escaping is correct in various scenarios (within quotes, without quotes, with other special characeters) Thanks to Christos for reviews, help and feedback.
2017-10-11Fix typo in commentabhinav
2017-09-17PR lib/52547 - read_history (readline.c) should now sets history_length.kre
Patch from Yen Chi Hsuan in the PR, extracted from Apple's version of readline.c, then modified by me to be consistent about what the return value really is.
2017-09-16Fix indentation (convert spaces to tab)abhinav
2017-09-05For readline emulation, don't reset the tty to "sane" (cooked) mode if wechristos
did not start this way. Also set and reset the tty on entry and exit from readline() since this is what readline does.
2017-09-02Remove trailing whitespace; convert Xr readline to Nm readline, sincewiz
we won't get a readline man page in base.
2017-09-01PR/51517: Jay West: Tty settings not restored on exitchristos
PR/51518: Jay West: prompt is interleaved with client output Both these issues are caused by rl_restore_handler not DTRT; fix it so that it kills the internal libedit state completely. This is inefficient, but it works. Also fix: 1. add append_history()/H_NSAVE_FP 2. call the rl_startup_hook before printing the first prompt as documented. callint it from rl_initialize breaks python, because the callback ends up being invoked before the readline module is installed, and we end up dereferencing a NULL pointer. 3. add el_resize_terminal. With those changes, s/lreadline/ledit/g in python works.
2017-07-03Remove workaround for ancient HTML generation code.wiz
2017-06-30Allow wide characters (properly encoded as byte strings according to LC_CTYPE)kre
to be (perhaps part of) the "invisible" characters in a prompt, or the required prompt character which follows the literal sequence (this character must be one with a printing column width >= 1). The literal indicator character (which is just a marker, and not printed anywhere) (the PSlit parameter in sh(1)) can also be a wide char (passed to libedit as a wchar_t, encoded as that by sh(1) or other applications that support this.) Note: this has currently only been tested with everything ascii (C locale).
2017-06-29Fix an obvious, but almost invisible typo (avoid some core dumps).kre
2017-06-27fix commentchristos
2017-06-27add literal escape sequence support, patterned after the tcsh ones.christos
2017-06-27remove unused variablechristos
2017-06-27- add literal sequence handling.christos
2017-06-27- handle literal escape sequence printing.christos
- factor out common code in allocation and freeing of the display.
2017-06-27mention the limitation of the literal sequence delimiter.christos
2017-06-27Include EDITRC in doc.kre
2017-06-27Make the default editrc file be $EDITRC (from env) if set, falling backkre
to $HOME/.editrc otherwise. Better support for this in sh coming.
2017-05-22Add DragonFly.christos
2017-04-21When doing filename autocompletion, append a trailing slash at the end of ↵abhinav
directory names. We already do this when there is only one completion option but in case of of multiple completion options, it wasn't being done. ok christos@
2017-04-10Add missing argument for H_SET.abhinav
ok christos@
2017-03-05one extra char for NUL.christos
2017-03-05Grow the buffer for event search if there was not enough space.christos
From Gerry Swislow
2017-01-09Make sure we take into account history_base when computing negative historychristos
offsets. (Gerry Swinslow)
2017-01-09Make sure that argv is NULL terminated since functions like tty_stty relychristos
on it to be so (Gerry Swinslow)
2016-12-11PR/51706: Amir Plivatsky: Fix memory leakchristos
2016-11-07Change the way the built-in history works; some programs enter historychristos
with the trailing newline, others don't so don't make any assumptions about it when printing. Also print the correct event number (generated), separate the event number from the event with a tab, and visually encode the string (don't encode tabs and spaces though).
2016-10-31Fix file name auto completion in one specific case.abhinav
For example if you do $mkdir -p /tmp/dir1/dir2 Then: $ls /tmp/di <TAB> auto completes to $ls /tmp/dir1/ Hitting <TAB> again auto completes to $ls /tmp/dir1/dir2 Whereas it should auto complete to $ls /tmp/dir1/dir2/ Essentially, in cases like above where you have to hit <TAB> twice to get to the match and there is only one match (because only one file/sub-directory) then auto complete doesn't work correctly. It doesn't append a trailing slash (in case of directory) or a space (in case of a file) to the match name. I have tested file name completion in sh(1) and symbol completion in gdb after this change.
2016-10-28export rl_donechristos
2016-10-28pass the stream to the getc functionchristos
2016-09-01fix typombalmer
2016-08-24more compatible with readline history functions.christos
2016-06-02Fix previous to better match readline behavior (Ingo Schwarze)christos
2016-06-02From Ingo Schwarze:christos
In libedit, the only way how H_ENTER can fail is memory exhaustion, too, and of course it is handled gracefully, returning -1 from history(). So of course, we will continue to handle it gracefully in add_history() as well, but we are free to decide what to do with the library state in this case because GNU just dies... I think the most reasonable course of action is to simply not change the library state in any way when add_history() fails due to memory exhaustion, but just return. If H_ENTER does not fail, we know that the history now contains at least one entry, so there is no need any longer to check the H_GETSIZE return value. And we can of course always set current_history_valid. While testing these changes, i noticed three problems so closely related that i'd like to fix them in the same diff. 1. libedit has the wrong prototype for add_history(). GNU readline-6.3 defines it as void add_history(const char *). Of course, that is very stupid - no way to report problems to the caller! But the whole point of a compatibility mode is being compatible, so we should ultimately change this. Of course, changing the prototype of a public symbol requires a libedit major bump. I don't want to do that casually. Rather, i will take a note and change the prototype the next time we need a libedit major bump for more important reasons. For now, let's just always return 0. 2. While *implicitely* pushing an old entry off the history increments history_base in GNU readline, testing reveals that *explicitly* deleting one does not. Again, this is not documented, but it applies to both remove_history() and stifle_history(). So delete history_base manipulation from stifle_history(), which also allows to simplify the code and delete two automatic variables. 3. GNU readline add_history(NULL) crashes with a segfault. There is nothing wrong with having a public interface behave that way. Many standard interfaces do, including strlen(3). Such crashes can even be useful to catch buggy application programs. In libedit/readline.c rev. 1.104, Christos made add_history() silently ignore this coding error, according to the commit message to hide a bug in nslookup(1). That change was never merged to OpenBSD. I strongly disagree with this change. If nslookup(1) is still broken, that program needs to be fixed instead. In any case, delete the bogus check; hiding bugs is dangerous.
2016-05-31remove the right history entry (Ingo Schwarze)christos
2016-05-25abstract read code to a single function (Ingo Schwarze)christos
2016-05-24el_map.alt can't be NULL here (Ingo Schwarze)christos
2016-05-24remove debug read (Ingo Schwarze)christos
2016-05-24From Ingo Schwarze:christos
Reduce obfuscation of errno handling. There is only one purpose non-local errno handling is needed for: Inside el_wgets(), several functions call down indirectly to el_wgetc(), many of them via the dispatch table. When el_wgetc() fails, it does properly report failure, but then various cleanup is done which may clobber errno. But when returning due to failure, el_wgets() wants to have errno set to the reason of the original read failure, not to the reason of some subsequent failure of some cleanup operation. So el_wgetc() needs to save errno, and if it's non-zero, el_wgets() needs to restore it on failure. This core logic is currently obscured by the fact that el_errno is set and inspected at some additional places where it isn't needed. Besides, since el_wgetc() and and el_wgets() are both in read.c, el_errno does not need to be in struct editline, it can and should be local to read.c in struct el_read_t. Let's look at what can be simplified. 1. keymacro_get() abuses el_errno instead of having a proper error return code. Adding that error return code is easy because node_trav() already detects the condition and an adequate code is already defined. Returning it, testing for it in read_getcmd(), and returning with error from there removes the need to inspect el_errno from el_wgets() after calling read_getcmd(). Note that resetting lastchar and cursor and clearing buffer[0] is irrelevant. The code returns from el_wgets() right afterwards. Outside el_wgets(), these variables are no longer relevant. When el_wgets() is called the next time, it will call ch_reset() anyway, resetting the two pointers. And as long as lastchar points to the beginning of the buffer, the contents of the buffer won't be used for anything. 2. read_getcmd() doesn't need to set el_errno again after el_wgetc() failure since el_wgetc() already did so. While here, remove the silly "if EOF or error" comments from the el_wgetc() return value tests. It's a public interface documented in a manual, so people working on the implementation can obviously be expected to know how it works. It's a case of count++; /* Increment count. */ 3. In the two code paths of el_wgets() that lead up to "goto noedit", there is no need to save the errno because nothing that might change it happens before returning. For clarity, since el_wgets() is the function restoring the errno, also move initializing it to the same function. Finally, note that restoring errno when the saved value is zero is wrong. No library code is ever allowed to clear a previously set value of errno. Only application programs are allowed to do that, and even they usually don't need to do so, except when using certain ill-designed interfaces like strtol(3). I tested that the behaviour remains sane in the following cases, all during execution of el_wgets(3) and with a signal handler for USR1 installed without SA_RESTART. * Enter some text and maybe move around a bit. Then send a USR1 signal. The signal gets processed, then read_char() resumes reading. Send another USR1 signal. Now el_wgets() sets errno=EINTR and returns -1. * Press Ctrl-V to activate ed-quoted-insert. Then send a USR1 signal. The signal gets processed, then read_char() resumes reading. Send another USR1 signal. ed_quoted_insert() returns ed_end_of_file(), i.e. CC_EOF, and el_wgets() returns 0. * Press a key starting a keyboard macro. Then send a USR1 signal. The signal gets processed, then read_char() resumes reading. Send another USR1 signal. Now el_wgets() sets errno=EINTR and returns -1. * Press : to enter builtin command mode. Start typing a command. Then send a USR1 signal. The signal gets processed, then read_char() resumes reading. Send another USR1 signal. Now c_gets() returns -1, ed_command() beeps and returns CC_REFRESH, and el_wgets() resumes operation as it should. I also tested with "el_set(el, EL_EDITMODE, 0)", and it returns the right value and sets errno correctly.
2016-05-22documentation improvements (Ingo Schwarze)christos
2016-05-22Stop the read module from poking the el_chared.c_macro data structurechristos
currently belonging to the chared module. The read module does so from three of its functions, while no other module uses the macro data, not even the chared module itself. That's quite logical because macros are a feature of input handling, all of which is done by the read module, and none by the chared module. So move the data into the read modules's own opaque data structure, struct el_read_t. That simplifies internal interfaces in several respects: The semi-public chared.h has one fewer struct, one fewer #define, and one fewer member in struct el_chared_t; all three move to one single C file, read.c, and are now module-local. And the internal interface function ch_reset() needs one fewer argument, making the code of many functions in various modules more readable. The price is one additional internal interface function, read_end(), 10 lines long including comments, called publicly from exactly one place: el_end() in el.c. That's hardly an increase in complexity since most other modules already have their *_end() function, read.c was the odd one out not having one. From Ingo Schwarze
2016-05-21Fix the prototype used by EL_GETCFN, mention the associated typedefchristos
name, document the return values, expand the list of affected functions, warn against using EL_GETCFN, and clarify some wording and notation. (Ingo Schwarze)
2016-05-13From Bastian Maerkisch, via Igno Schwarze:christos
Even though section "2.3.3 Information About the History List" of the history(3) info(1) manual only says -- Function: int where_history (void) Returns the offset of the current history element. which maybe isn't completely clear, a plausible implementation is that the offset returned is the same offset that can be used for history_set_pos(), i.e. that it is 0 for the oldest entry and increases with time, and that's how the GNU implementation behaves indeed. The libedit implementation, on the other hand, returns 1 for the newest entry and increases going back in time.
2016-05-09s/protected/libedit_private/gchristos