Commit Graph

768 Commits

Author SHA1 Message Date
christos e9933f923a From Yuichiro Naito (FreeBSD):
hrs@ says that
(cbp >= MB_LEN_MAX) condition is necessary for checking invalid
byte sequences.  If malicious input was given, libedit would read
byte sequences forever.
2018-11-25 16:21:04 +00:00
christos 2cb4fa4296 From Yuichiro Naito (FreeBSD):
hrs@ says that wctomb(3) has an internal shift state,
if wctomb(3) is called outside of libedit,
the internal state can be changed and causes miscalculate multibyte size.

So in this part, wcrtomb(3) should be used.
wcrtomb(3) requires that shift state is given in the argument.
We always initialize the shift state in ct_enc_width() to keep independent
from outside of libedit.
2018-11-25 16:20:28 +00:00
christos e06500e20d PR/53682: Jordan Lewis: use newlines instead of padded spaces when restoring
multi-line histories.
2018-11-24 12:17:35 +00:00
christos e91c30539f fix compilation 2018-11-18 17:15:41 +00:00
christos 18bb6ea433 Remove utf-8 requirement (Yuichiro NAITO) 2018-11-18 17:09:39 +00:00
christos b15150dc5e Apply revisions 1.21, 1.22 from OpenBSD:
In re_fastputc(), set lastline to the new line, not the previous
line so it gets initialized properly.  Fixes a crash in bc with
MALLOC_OPTIONS=UJ.  OK deraadt@, committing on behalf of yasuoka@

Initialize "old" screen buffer lines before use; otherwise, they would
never get NUL-terminated and cause read buffer overruns.
This fixes for example segfaults in sftp(1) that could be triggered
by typing in an extremely long string (more than one line - the longer,
the likelier to crash), then hitting backspace once.
Problem reported and patch OK'ed by sthen@.

XXX: pullup-8
2018-10-23 16:49:13 +00:00
kre b8b0289d66 Fix editing mistake, remove ) from func call that is now gone. 2018-09-13 09:03:40 +00:00
christos 26f83385d3 more efficient to use decode_result :-) Pointed out by kre@ 2018-09-13 01:26:33 +00:00
christos 6da79ee096 PR/53597: Yasuhiro Horimoto: Avoid segmentation fault in bad history file. 2018-09-12 22:10:35 +00:00
christos a3c16b5549 Provide more compatibility with readline headers; now python-3.6.5 works
when changing 'readline' -> 'edit' in setup.py.
Revert previous conditional setting of unbuffered.
2018-06-09 17:41:55 +00:00
christos 01f10711d4 fix uninitialized 2018-05-04 20:38:26 +00:00
abhinav 2afc179c8f Handle filename autocompletion when the cursor is at a backslash or quote character
For example, handle following case:
	$ touch 'foo bar'
	$ ls foo\<TAB> --> $ ls foo\ bar

Also add test cases for this.

Thanks to Christos for review
2018-05-04 16:39:14 +00:00
abhinav b36e4c8fbf Add '*' and '[' to the list of characters which need escaping during autocompletion 2018-05-02 08:45:03 +00:00
christos 7767204c93 PR/53058: Nikhil Benesch: use correctly typed variables (wchar_t vs wint_t)
as parameters.
2018-02-26 17:36:14 +00:00
christos ff1a7c8cc8 Only FLUSH if we are ending libedit; DRAIN if we suspend for readline.
This allows pasting multiline buffers (Gerry Swislow)
2018-01-01 22:32:46 +00:00
uwe ec59efb2b5 The order in which the arguments to a function are evaluated is
undefined, so don't use va_arg() twice.

PR lib/52849
2017-12-23 18:25:03 +00:00
christos 47abce8f3f For applications that don't issue their own prompt (like python)
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-12-08 16:56:23 +00:00
abhinav 3c9fe72fbc Add NULL check after doing memory allocation at a couple of places
ok christos@
2017-10-27 18:16:09 +00:00
abhinav 92a9b5c3ba Add copyright and rcs header to the test program.
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-15 19:17:30 +00:00
abhinav fa61555626 Add support for escaping special characters when doing filename completion.
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-15 18:59:00 +00:00
abhinav cf2b6f694e Fix typo in comment 2017-10-11 06:49:03 +00:00
kre 5312bfd48d PR lib/52547 - read_history (readline.c) should now sets history_length.
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-17 08:10:08 +00:00
abhinav 7a99333ffa Fix indentation (convert spaces to tab) 2017-09-16 20:40:34 +00:00
christos b2ad969a13 For readline emulation, don't reset the tty to "sane" (cooked) mode if we
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-05 18:07:59 +00:00
wiz 3e39477b0a Remove trailing whitespace; convert Xr readline to Nm readline, since
we won't get a readline man page in base.
2017-09-02 06:48:10 +00:00
christos 27916d7c22 PR/51517: Jay West: Tty settings not restored on exit
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-09-01 10:19:10 +00:00
wiz 01869ca4d2 Remove workaround for ancient HTML generation code. 2017-07-03 21:28:48 +00:00
kre e3112e6cea Allow wide characters (properly encoded as byte strings according to LC_CTYPE)
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-30 20:26:52 +00:00
kre 2977f4314f Fix an obvious, but almost invisible typo (avoid some core dumps). 2017-06-29 02:54:40 +00:00
christos f51c99da13 fix comment 2017-06-27 23:29:12 +00:00
christos 9abf018dda add literal escape sequence support, patterned after the tcsh ones. 2017-06-27 23:25:13 +00:00
christos bec29a0714 remove unused variable 2017-06-27 23:24:19 +00:00
christos 3d09ba7b3f - add literal sequence handling. 2017-06-27 23:23:48 +00:00
christos 06d596a8e9 - handle literal escape sequence printing.
- factor out common code in allocation and freeing of the display.
2017-06-27 23:23:09 +00:00
christos 0a321818f6 mention the limitation of the literal sequence delimiter. 2017-06-27 23:22:20 +00:00
kre 00f36e26a6 Include EDITRC in doc. 2017-06-27 01:22:58 +00:00
kre 4fa1b5993a Make the default editrc file be $EDITRC (from env) if set, falling back
to $HOME/.editrc otherwise.    Better support for this in sh coming.
2017-06-27 00:47:37 +00:00
christos c74ab69c28 Add DragonFly. 2017-05-22 19:16:25 +00:00
abhinav 3a89c5769a When doing filename autocompletion, append a trailing slash at the end of 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-21 05:38:03 +00:00
abhinav c626d04131 Add missing argument for H_SET.
ok christos@
2017-04-10 15:02:40 +00:00
christos 3bea32ca4f one extra char for NUL. 2017-03-05 19:23:58 +00:00
christos bd242e1e3e Grow the buffer for event search if there was not enough space.
From Gerry Swislow
2017-03-05 17:30:38 +00:00
christos 1ec9eafabc Make sure we take into account history_base when computing negative history
offsets. (Gerry Swinslow)
2017-01-09 03:09:05 +00:00
christos 4937de3b47 Make sure that argv is NULL terminated since functions like tty_stty rely
on it to be so (Gerry Swinslow)
2017-01-09 02:54:18 +00:00
christos 3d8a0ad9b3 PR/51706: Amir Plivatsky: Fix memory leak 2016-12-11 15:47:06 +00:00
christos f09a36d8a1 Change the way the built-in history works; some programs enter history
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-11-07 15:30:18 +00:00
abhinav 0551ffcf66 Fix file name auto completion in one specific case.
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-31 17:46:32 +00:00
christos 931e76f255 export rl_done 2016-10-28 18:32:35 +00:00
christos 1a4590725b pass the stream to the getc function 2016-10-28 18:32:26 +00:00
mbalmer fc37f15ca1 fix typo 2016-09-01 13:23:44 +00:00