Commit Graph

18233 Commits

Author SHA1 Message Date
christos
94b4dd721e remove the right history entry (Ingo Schwarze) 2016-05-31 19:25:17 +00:00
pgoyette
d2c5329790 Use calloc(1, ...) instead of malloc(...) followed immediately by memset()
Addresses PR lib/46818
2016-05-31 07:49:09 +00:00
dholland
7dae429fbd PR 51003 David Binderman: bzero struct before passing it around.
This is actually unnecessary as the call in question uses only fields
that have been set explicitly, but good practice regardless and it's
not like it's on a performance-critical path.
2016-05-31 03:47:49 +00:00
dholland
39a10a6851 PR 51002 David Binderman: fix wrong printing code not enabled by default. 2016-05-31 03:43:10 +00:00
dholland
6413fb5a5d PR 51000 David Binderman: comment out unused assignment 2016-05-31 03:34:14 +00:00
dholland
6b93d6fdd7 PR 51190 David Binderman: simplify redundant conditionals.
Also add paranoia when looping on isdigit().
2016-05-30 17:48:29 +00:00
christos
d8509bf6e2 abstract read code to a single function (Ingo Schwarze) 2016-05-25 13:01:11 +00:00
christos
fa7ab2f97a el_map.alt can't be NULL here (Ingo Schwarze) 2016-05-24 19:31:27 +00:00
christos
6eacc2dbd2 remove debug read (Ingo Schwarze) 2016-05-24 17:42:54 +00:00
christos
0a374fd7e5 From Ingo Schwarze:
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-24 15:00:45 +00:00
christos
16467be6f9 documentation improvements (Ingo Schwarze) 2016-05-22 23:54:20 +00:00
christos
bb64d9f1ce Stop the read module from poking the el_chared.c_macro data structure
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-22 19:44:26 +00:00
christos
e9c2e28b8a Fix the prototype used by EL_GETCFN, mention the associated typedef
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-21 17:06:44 +00:00
christos
91e51ad49a remove stray debugging. 2016-05-15 20:37:48 +00:00
christos
6a4222698f Bail out if the string does not look like a timezone (is empty or does not
start with a letter or a number). tzparse("") or tzparse(".45") don't fail.
2016-05-15 20:36:42 +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
martin
f5d70023d1 We need the -O1 hack (for gcc 5.3) for crtbegin.c as well.
Works around PR toolchain/51121.
2016-05-10 10:23:09 +00:00
christos
a2d6b270ec s/protected/libedit_private/g 2016-05-09 21:46:56 +00:00
christos
137ae6aea4 Instead of compiling all the source files together in one big file, use
protected visibility to achieve the same effect.
2016-05-09 21:38:27 +00:00
christos
ecb8efd172 Elide gcc warning about intermediate const casts caused by visibility change. 2016-05-09 21:37:34 +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
kre
3060c9b9b9 Make relative date changes ("+ 2 months") etc, work a little more sanely.
OK christos@
2016-05-03 18:14:54 +00:00
christos
300e2ca473 eliminate static buffer with custom resizing code. 2016-05-02 16:48:34 +00:00
christos
9ff2bfe491 fix typos from Pedro Giffuni @FreeBSD 2016-05-02 16:35:17 +00:00
wiz
7c1df76045 Add missing backslash that broke build. 2016-05-02 14:12:09 +00:00
christos
2f3aa6bd06 Add more MLINKS, sort 2016-05-02 13:01:34 +00:00
wiz
986567e424 Fix Dd argument. 2016-05-02 12:51:25 +00:00
christos
ac44c4d1a4 Add more explicit xrefs 2016-05-02 12:43:35 +00:00
wiz
0ad20f8cb7 Fix Dd argument. 2016-05-02 09:39:24 +00:00
joerg
e073a944c0 Fix type name. From Abhinav. 2016-05-01 21:28:21 +00:00
martin
8e6585046e Change section flags to "MG" and put it into comdat.
Makes new binutils happy.
2016-05-01 08:33:14 +00:00
martin
92f3e401cd Revert previous (fallout is more subtle but there).
Rework the conditionon so it depends on .S existence instead of an arch
list.
2016-05-01 07:25:46 +00:00
martin
318ac55504 Gcc 5.3 seems to do fine compiling this for sparc64, so exclude it
from the -O1 hack
2016-04-30 13:12:13 +00:00
joerg
5d45063308 Go back to just using normal visibility for the locale symbols. Without
an actual specifier like dllimport, protected visibility is unusable.
2016-04-29 16:26:48 +00:00
christos
3694604d12 move section around. 2016-04-29 13:17:09 +00:00
wiz
eb86c933a1 Sort a bit more. 2016-04-29 12:25:51 +00:00
christos
8eca53f5f0 - merge the options descriptions, sort them.
- fix wrusage name.
2016-04-28 16:07:26 +00:00
christos
067b3315ea new man page from Ingo Schwarze. 2016-04-28 15:50:33 +00:00
christos
f432b935f6 Initialize patbuf (Ingo Schwarze) 2016-04-28 12:27:45 +00:00
wiz
a0a33836af Formatting, typos, whitespace fixes. 2016-04-24 09:01:45 +00:00
wiz
982b0c24c2 Fix typos, whitespace, formatting. 2016-04-24 08:59:30 +00:00
christos
3c50b65c77 commit the right file. 2016-04-24 00:05:28 +00:00
christos
ed7dbad892 bump 2016-04-23 23:23:17 +00:00
christos
d394d2a9b5 Add pthread_getcpuclockid(3) 2016-04-23 23:12:19 +00:00
christos
817b192df2 add clock_getcpuclockid{2,} 2016-04-23 23:11:31 +00:00
christos
5d9808ec41 Don't subtract base if not pie. 2016-04-20 14:00:16 +00:00
christos
1364b6032a From Ingo Schwarze:
- Put the data type el_rfunc_t into the public header <histedit.h>.
 - Make el_read in struct editline an opaque pointer rather
   than an embedded struct.
 - Do not include "read.h" everywhere, but only in the two files
   needing access to el_read, read.c and el.c.
 - To functions that don't need more, pass the struct el_read_t *
   rather than the full EditLine *.
 - Of course, that means that read_init() can now fail from
   memory exhaustion, but it's easy to clean up after that.
2016-04-19 19:50:53 +00:00