Commit Graph

31 Commits

Author SHA1 Message Date
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
Roberto E. Vargas Caballero
03d27b7806 ed: Reset modflag in clearbuf()
For the same reason we don't care about the state of
the buffer in clearundo() we can reset modflag in
clearbuf(), because after calling it we don't want
to know anything about the previous state.
2016-01-01 10:39:59 +00:00
Roberto E. Vargas Caballero
58c9739532 ed: Move modflag=0 to clearundo()
When we discard the content of an undo buffer
is because we don't need it anymore, and it means
that we don't care about the modify state of the buffer
so we can reset the modflag in clearundo(), and
remove this assignation each time clearundo() is called.
2016-01-01 10:39:59 +00:00
Roberto E. Vargas Caballero
b08660e1fd ed: Fix infinite recursion to undo() 2015-12-31 19:38:17 +00:00
Quentin Rameau
6e7743eb56 Cleanup usage() across sbase
Some tools didn't use argv0 for tool name, or usage() at all.
2015-12-21 18:07:25 +00:00
Roberto E. Vargas Caballero
6135cad495 Move edit logic to an individual function
It is better to separate this logic from
the parameter logic in main().
2015-12-16 20:25:50 +00:00
Roberto E. Vargas Caballero
05af2156b6 Fix small typo in comment 2015-12-16 20:25:50 +00:00
Roberto E. Vargas Caballero
694a5ef7fb call to addpre() in every iteration of subline()
It is needed to call to addpre(), because in other
case the prefix of all the occurrences before
the target will not be copied to the result
string.
2015-12-16 20:16:12 +00:00
Roberto E. Vargas Caballero
3e130cee66 Escape correctly characters in getrhs()
getrhs() must remove \ excepts in the case of & and \d
(where d is a digit), because in this case are sequences
understood by addsub(), so addsub() must be able to see
them.
2015-12-16 20:16:12 +00:00
Roberto E. Vargas Caballero
a65e180e5e Discard input at the end of global commands
If there is no any match, then the rest of the line
is not read, and it means that ed thins it is a new
command.
2015-12-16 20:16:12 +00:00
Quentin Rameau
d1bef890ea ed: use arg.h 2015-12-16 09:52:35 +00:00
Quentin Rameau
c5b36e1760 ed: fix cmd e/E
Ensure we have a filename before taking further action.
2015-12-16 09:52:35 +00:00
sin
fdf9ab9b2d Fix some useless warnings
Makes the code uglier but I cannot stand them.
2015-12-15 09:05:02 +00:00
Roberto E. Vargas Caballero
a19aad7c70 Fix getrhs()
getrhs() must not interpret escapes, because in other case
addsub() will not be able to see the escaped characters.
2015-12-14 14:52:53 +00:00
Roberto E. Vargas Caballero
0cd385d164 Restore state of buffer in errors
When a error occurs it is important to remove all the modifications
done by the offending command and restore the value of dot to the
state before of executing the command.
2015-12-14 14:52:53 +00:00
Roberto E. Vargas Caballero
13e0b6c605 Do not modify curln with w commands
POSIX declares that dot is not modified by w commands
2015-12-14 14:52:53 +00:00
sin
25f87bc360 Staticise globals in ed(1) 2015-12-14 12:14:52 +00:00
sin
912c21ab1f Remove unused variables in ed(1) 2015-12-14 12:14:52 +00:00
Roberto E. Vargas Caballero
1de650edf5 Add ed(1) - the standard text editor 2015-12-14 12:14:52 +00:00