Commit Graph

159 Commits

Author SHA1 Message Date
christos
a47ebb18b3 add +1 to strlcpy's (Patrick Welche) 2019-10-09 14:31:07 +00:00
christos
991f62167b Change strncpy to either memcpy (when we know the len), or strlcpy (when
we used to NUL terminate explicitly.
2019-10-08 19:17:57 +00:00
christos
a909d35bd1 Increment offset when adding an element to history to keep it aligned with
the last element entered (Sandy Li Changqing)
2019-08-21 11:11:48 +00:00
christos
113f06a345 PR/54399: Sören Tempel: Uninitialized memory access in libedit history.
Initialize the buffer using calloc. While here change all malloc(a * sizeof(b))
to calloc(a, sizeof(b)). XXX: should fix realloc similarly.
2019-07-23 10:18:52 +00:00
christos
037284caf7 PR/54281: Jonathan Perkins: NUL terminate rl_line_buffer on modification
to avoid completion leak.
2019-06-07 15:21:48 +00:00
christos
72dd3db662 PR/54280: rl_completer_quote_characters should be const for readline compat 2019-06-07 15:19:29 +00:00
christos
b8c4664f83 PR/54279: Jonathan Perkins: Ignore adjacent start/end prompt ignore. 2019-06-07 15:18:20 +00:00
christos
ef72f68d26 Follow the man page for EL_GETTC and not require a NULL terminated argument
list: https://reviews.llvm.org/D61191
2019-04-26 16:56:57 +00:00
christos
52b10dfde0 PR/53983: Jonathan Perkins: Fix types for readline compatibility 2019-02-15 23:20:35 +00:00
christos
ccbb6255be PR/53981: Jonathan Perkins: history_list should null-terminate 2019-02-14 20:09:12 +00:00
christos
11e9eb638e PR/53856: F. Aragon: editline/libedit not prompting colors in readline mode 2019-01-10 18:41:56 +00:00
christos
85390d7315 Add a couple more readline compat functions. 2018-12-02 16:58:13 +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
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
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
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
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
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
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
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
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
christos
78abb1b97e more compatible with readline history functions. 2016-08-24 13:10:59 +00:00
christos
d764cbd394 Fix previous to better match readline behavior (Ingo Schwarze) 2016-06-02 21:40:51 +00:00
christos
956883ecd7 From Ingo Schwarze:
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-06-02 15:11:18 +00:00
christos
94b4dd721e remove the right history entry (Ingo Schwarze) 2016-05-31 19:25:17 +00:00
christos
4b3392da81 From Bastian Maerkisch, via Igno Schwarze:
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-13 15:55:59 +00:00
christos
f9ed317e87 GNU readline(3) regards history chronologically, that is, from the
perspective of the dawn of time, so "next" means "newer" and "previous"
means "older".  Libedit, by contrast, uses reverse chronology and
regards history from the perspective of the present, such that "next"
means "longer ago" and "previous" means "not so long ago".

The following patch fixes previous_history() and next_history()
as proposed by Bastian Maerkisch.

But there is a related problem demonstrated by Bastian's regression
tests that his patch did not fix:  next_history() can advance not
only to the newest entry, but beyond it, which core libedit cannot
do.  So that feature must be implemented locally in readline.c.

With that, the last of Bastians tests is fixed, test_movement_direction().

This patch also improves libedit documentation to more clearly state
what "previous" and "next" mean.  GNU readline documentation is
just as unclear, but we can't easily fix that since libedit doesn't
include its own readline.3 manual.

(Ingo Schwarze)
2016-05-09 21:27:55 +00:00
christos
05b61ce72a The libedit implementation of history_get() also differs from the GNU
implementation:  libedit goes to the entry with the given number
stored in the HistEvent structure, while GNU subtracts history_base,
then advances that many entries from the oldest one.  If entries were
removed in between, GNU advances further than libedit.

The call sequence H_CURR, H_DELDATA, H_CURR, H_NEXT_EVDATA looks
weird, as if part of that must somehow be redundant.  But actually,
the user interface is so counter-intuitive that every single step
is really required.

 - The first H_CURR is needed to be able to go back after an error.
 - The H_DELDATA is needed to move the cursor.  Even though it takes
   a pointer to ev, that structure is not filled in when the call
   succeeds.  H_DELDATA only moves the cursor, it doesn't tell us
   the new event number.
 - Consequently, the second H_CURR is required to get ev.num filled
   in.  But it doesn't return the data because ev has no field for
   that.
 - So even though the cursor is already positioned correctly,
   H_NEXT_EVDATA is needed as the final step merely to get the data.

(Ingo Schwarze)
2016-05-09 21:25:11 +00:00
christos
c3337d4460 In stiffle_history(), trim excessive entries from the history and advance
history_base like the GNU implementation does. (from Bastian Maerkisch)
2016-05-08 20:15:00 +00:00
christos
7033ecf0e8 fix logic (Ingo Schwarze) 2016-05-06 21:01:19 +00:00
christos
4fc1f47d56 From Ingo Schwarze:
* Replace fcns.c by a shorter and simpler func.h
   and include it only in the one file needing it, map.c.
 * Combine help.h and help.c into a simplified help.h
   and include it only in the one file needing it, map.c.
 * Check the very simple, static files editline.c, historyn.c, and
   tokenizern.c into CVS rather than needlessly generating them.
 * So we no longer autogenerate any C files.  :-)
 * Shorten and simplify makelist by deleting the options -n, -e, -bc,
   and -m; the latter was unused and useless in the first place.
 * Move the declaration of el_func_t from fcns.h to the header
   actually needing it, map.h.  Since that header is already
   included by el.h for unrelated reasons, that makes el_func_t
   just as globally available as before.
 * No longer include the simplified fcns.h into el.h,
   include it directly into the *.c files needing it.
2016-04-18 17:01:19 +00:00
christos
4e541d85ca Start removing the WIDECHAR ifdefs; building without it has stopped working
anyway. (Ingo Schwarze)
2016-03-23 22:27:48 +00:00
christos
94623721e8 Make the read_char function always take a wchar_t * argument (Ingo Schwarze) 2016-02-24 17:13:22 +00:00
christos
22383670cc whitespace and header sorting changes (Ingo Schwarze). No functional changes. 2016-02-17 19:47:49 +00:00
christos
747f681109 more include file cleanup (Ingo Schwarze) 2016-02-16 19:08:41 +00:00
christos
aefc1e4460 From Ingo Scharze:
Let "el.h" include everything needed for struct editline,
and don't include that stuff multiple times.  That also improves
consistency, also avoids circular inclusions, and also makes it
easier to follow what is going on, even though not quite as nice.
But it seems like the best we can do...
2016-02-16 15:53:48 +00:00
christos
f09cb8c626 cleanup chartype.h includes (Ingo Schwarze) 2016-02-16 14:08:25 +00:00
christos
40850369f8 cleanup inclusion of histedit.h (Ingo Schwarze) 2016-02-16 14:06:05 +00:00
christos
d8252c8b23 attribute unused 2016-02-15 23:36:30 +00:00
christos
f91f480498 OpenBSD readline.c rev. 1.14 2015/02/06 23:21:58 millert
use SIZE_MAX
2016-02-15 22:48:59 +00:00
christos
92b1772005 OpenBSD readline.c rev. 1.13 2015/01/13 08:33:12 reyk
rl_set_keyboard_input_timeout() for readline 4.2 compat
2016-02-15 21:58:37 +00:00
christos
0804279dff Adjust API to a more modern readline (Ryo Onodera) 2015-06-02 15:35:31 +00:00
christos
0b61093115 - fix types of rl_completion_entry_function and rl_add_defun
- call update pos before completion to refresh the screen
From Thomas Eriksson
2015-05-26 19:59:21 +00:00
christos
2a7851d30c Fix overlapping strcpy (Gerry Swislow) 2015-04-01 15:23:15 +00:00
christos
b52bce6ba8 set some readline compatibility default key settings.
https://bugzilla.redhat.com/attachment.cgi?id=1001895
2015-03-24 21:29:52 +00:00
snj
f0a7346d21 src is too big these days to tolerate superfluous apostrophes. It's
"its", people!
2014-10-18 08:33:23 +00:00
christos
3ea928643b Fix typo in comment (Tobias Stoeckmann) 2014-08-15 13:32:53 +00:00
christos
0fb55ca669 PR/48957: Federico G. Schwindt: Restore commented out code that broke
rl_callback_handler.
2014-07-06 18:09:04 +00:00
christos
7683f26e31 ... if called prior to using_history(). This needed to be worked around
in PHP: http://git.php.net/?p=php-src.git;a=commitdiff;h=31d67bd3

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1055409
2014-01-21 13:51:44 +00:00