Commit Graph

68 Commits

Author SHA1 Message Date
Michael Forney 6902aad435 Add a bugs section to TODO 2020-04-05 20:02:15 -07:00
Michael Forney a8dc42e6b5 ed: Use reallocarray 2019-12-31 13:41:38 -08:00
Firas Khalil Khana a1627b9419 ed: Changed delimiter to fix unterminated TODO comment 2018-09-23 11:02:31 +02:00
Roberto E. Vargas Caballero 6d3f18c821 ed: Add more bugs to TODO 2018-09-20 10:54:21 +02:00
Roberto E. Vargas Caballero f45156d5b4 Simplify expression in makeline()
This expression was wrong, but it was causing a false positive
in some compilers that couldn't see that error() cannot return.
The actual problem of the line is that it was too complex and it is better
to split it in simplex expressions.
2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero 18f6c5e014 Add TODO 2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero ece6569297 Fix undo
Avoid incorrect values in the number of undo elements and restore lastln
value after an undo operation.
2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero cd9b149c8f Use nextln() in scroll() 2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero ebf740f962 Improve doglobal()
Don't use directly the line numbers and call to getlst()
when a line is matched.
2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero 9781959581 Fix copy()
Copy was using directly the line numbers and incrementing them
without calling nextln(). It also didn't worry about how
line numbers are modified when we insert new lines.
2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero 504dde1373 Allow overlapping transfer 2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero d849e6d4aa Rename addchar_() to addchar()
All the ocurrences of addchar() were moved to addchar_(),
so we can rename addchar_() and remove the old definition.
2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero 3ce26f33c6 Move subline() to use String type 2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero 77fe371fe4 Fix type of c in getrhs()
C is compared against EOF, so it cannot be char.
2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero 0732529fef Fix type of c in execsh()
C is compared against EOF, so it cannot be char.
2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero a5d268c409 Move execsh() to use String type 2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero 8d59405ae0 Move join() to use String type 2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero 7c2eec7bd1 Move lastre to String type 2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero 35cf3c79f2 Move text to String type 2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero f5cb020f06 Move cmdline to String type 2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero 20794b570e Define new String type
Current handling of strings is a bit messy. This type is copied
from the sed implementation. Addchar_ is added to be able to live
with String and old style chars based in 3 different variables.
2018-07-03 09:31:46 +01:00
Roberto E. Vargas Caballero 651e2b0ee2 Set restore point before setting signal handlers 2018-07-03 09:31:46 +01:00
Michael Forney 1ff2a54e8f ed: Write "?\n" and explanatory messages to stdout
This is the behavior specified by POSIX.
2018-02-24 00:09:40 -08:00
Samadi van Koten 44ccadcde3 Fix line buffering issue with ed prompt
This fixes an issue whereby ed would not output the prompt (when
enabled) until after exitting due to stdout being line-buffered.
2018-02-23 23:58:29 -08:00
Roberto E. Vargas Caballero 9ab1478f1e ed: fix commit 2ccc1e8
The patch was wrong because the prototype of
strcpy is different to the prototype of strlcpy
2017-01-10 11:30:34 +01:00
Roberto E. Vargas Caballero b95c8ed79e ed: Don't use strlcpy()
All the buffers related to files have FILENAME_MAX size, so it is impossible
to have any buffer overrun.
2017-01-10 08:49:17 +01:00
Roberto E. Vargas Caballero 78bfd8978e Revert "ed: remove double free in join()"
This reverts commit 30da327fbd.
The double free is needed to avoid memory leaks when signals are caught
2017-01-10 08:41:35 +01:00
Thomas Mannay 89f5f84316 ed: Treat addresses of 0 as 1 for insert
From 6665eaa1d2c25a95b44a4f4fb3d24a3bd5c1180f Mon Sep 17 00:00:00 2001
From: Thomas Mannay <audiobarrier@openmailbox.org>
Date: Thu, 3 Nov 2016 15:16:32 +0000
Subject: [PATCH] Treat addresses of 0 as 1 for insert
2017-01-02 20:57:00 +01:00
Laslo Hunhold e2f886c7e2 ed: Use strlcpy() instead of strcpy() and other minor things
Based on contribution by Ali H. Fardan, thanks!
2016-12-27 13:07:02 +01:00
Thomas Mannay 30da327fbd ed: remove double free in join() 2016-12-27 12:50:25 +01:00
Thomas Mannay 2304df908c ed: place newly joined lines correctly 2016-12-27 12:50:20 +01:00
Thomas Mannay 696520714b ed: giving j only one address does nothing 2016-12-27 12:50:09 +01:00
Thomas Mannay 61e06396bd ed: remove infinite loops in join() and getindex() 2016-12-27 12:50:03 +01:00
Wolfgang Corcoran-Mathe b7c73e2392 ed: Fix backslash expressions in RHS
By stripping backslashes this code caused a number of bugs.
'\<digit>' expressions caused literal <digit>s to be subbed-in,
'\&' was treated identically to '&', and other escaped characters
added garbage to the string.
2016-12-27 12:29:52 +01:00
Wolfgang Corcoran-Mathe f5baf2630a ed: Don't match against line 0 in search()
regexec(3) happily matches /^$/ against the text of line
zero (the null string), causing an error.

Also update email address for Wolfgang Corcoran-Mathe
2016-12-27 12:28:36 +01:00
Evan Gates e3f497e1f6 subtract 'a' from indices for marks
Given:

static int marks['z' - 'a'];
marks[c];

In this case c is the character read and index is out of bounds. We
need marks[c - 'a']

While playing around with optimization settings gcc caught caught this.

Also fix one check for c, change from isalpha to islower.

-emg

From 2cc36818283e9068576c1042690c016a81b709a3 Mon Sep 17 00:00:00 2001
From: Evan Gates <evan.gates@gmail.com>
Date: Fri, 15 Jul 2016 09:52:39 -0700
Subject: [PATCH] fix marks indexing
2016-08-03 15:35:36 +01:00
Roberto E. Vargas Caballero cfc37be486 Do not try to rematch patterns with ^ or $
It is impossible to rematch a pattern which has one (or both)
of these operators, so the simplest solucion is detect them
while we are compiling the regular expression and break the
match loop after the first iteration.
2016-01-23 08:38:03 +00:00
Roberto E. Vargas Caballero cf868c8eeb Stop matching when lastmatch points to '\n'
This situation happens with something like s/$/test/,
where rm_so == rm_eo == 0. Without this check, ed
keeps looping forever.
2016-01-11 15:37:58 +00:00
Roberto E. Vargas Caballero 0b117ab6c0 Fix pattern substitution
Ed was falling doing substitution different of the first or all
(s//%/, s//%/\1, s//%/g), because it was not adding the matches
which were not going to be substituted.
2016-01-11 15:37:58 +00:00
Roberto E. Vargas Caballero 54ad6d512b Fix rematch()
Rematch() was incremnenting the last match always, even in the
cases when it was not matching anything. This patch detects
this situation and it updates it only when there is a match.
2016-01-11 15:37:58 +00:00
Roberto E. Vargas Caballero 78fd6ff239 Handle explicitly the case of line 0
Line 0 is a special line added to allow operations with
empty buffers, and we have to ensure that it is not going
to match any regular expression. The code was written in
a way that this case was handle implicitily, but this
solution was working only for the first file loaded in
ed, while the second file loaded in ed got a line with
a dirty seek field. This solution check explicitily
against invalid lines passed to makeline(), which
allows to simplify the common case.
2016-01-11 15:37:58 +00:00
sin 0fb1c6fd60 ed: Remove useless newlines 2016-01-11 15:37:58 +00:00
sin 16159a61ac ed: Use snprintf() for constructing the scratch filename 2016-01-02 10:33:56 +00:00
sin 3300d5d47a ed: Use strlcpy/strlcat to construct the scratch filename 2016-01-02 09:46:48 +00:00
Roberto E. Vargas Caballero 36e2bdf517 ed: Use TMPDIR to locate the temporal file
The current behaviour of storing the scratch file in
the current directory is a bit painful, because it
generates files in all the directories where you
execute ed. BSD ed uses TMPDIR for this purpouse,
so if the user wants to put the scratch file in
other place different of /tmp it only has to set
this variable.
2016-01-02 09:46:48 +00:00
Roberto E. Vargas Caballero cf0a0fc940 ed: Fix error introduced in b19d708
This patch introduced init() function, which removed the initialization
code of savfname in doread, but this is incorrect, because savfname
can be initialized with a r command if savfname is empty.
2016-01-02 09:46:48 +00:00
Roberto E. Vargas Caballero 6630bd97cf ed: Don't show '!' in exec with -s
POSIX indicates that this '!' is a diagnosis
that must not be printed when -s is supplied.
2016-01-02 09:46:48 +00:00
Roberto E. Vargas Caballero b2ef7e73e0 ed: Correct error message when open file
"input/output" error was to general and could create confusion.
All the other ed implementations give a "cannot open input file"
2016-01-02 09:46:48 +00:00
Roberto E. Vargas Caballero c5e28b5fe9 ed: Don't show size of files in no diagnosistic mode
-s flag disables such warnings.
2016-01-01 10:39:59 +00:00
Roberto E. Vargas Caballero b19d708923 ed: add init()
These funcction initializes the scratch buffer, and in case of
having a file name parameter it loads the file in the scratch.
It also fixes a problem before this version, where the saved
filename was not set when the file didn't exist.
2016-01-01 10:39:59 +00:00