Commit Graph

2005 Commits

Author SHA1 Message Date
Roberto E. Vargas Caballero b30fb56804 ed: Add other pending bug
At this stage is clear that the match() function of ed has
serious problems that have to be solved.
2024-03-22 04:39:25 +01:00
Roberto E. Vargas Caballero ac6d382515 build: Fix sbase-box-install target
The target tried to execute a non valid shell script
and there was a possibility to fatorize the creation
of the proto file instead of repeating it in all
the actions that required.
2024-03-12 17:11:35 +01:00
Elie Le Vaillant 13898fa7a9 tar: chktar: fix conditional typo 2024-03-06 16:00:10 +01:00
Elie Le Vaillant bca3fcca91 tar: sanitize, chktar: leading spaces should be skipped over
Some tar archives (eg. ftp://ftp.gnu.org/gnu/shtool/shtool-2.0.8.tar.gz)
use leading spaces instead of leading zeroes for numeric fields.
Although it is not allowed by the ustar specification, most tar
implementations recognize it as correct.  But since 3ef6d4e4, we
replace all spaces by NULs here, not just trailing ones, which leads to
recognizing such archives as malformed.  This fixes it: we now skip
over leading spaces, allowing strtol(3) to read those numeric fields.
2024-03-05 13:25:44 +01:00
Randy Palamar d335c366f7 expr: tonum: handle case where result was previously calculated
As pointed out in a mail to dev expr was segfaulting when multiple
math operations were specified on the command line: eg. 'expr 3 \*
2 + 1'. This happens because the tonum(), introduced in e50d533,
assumed that v->str was always non null. parse() guarantees this
for user input but this is not the case when doop() is called with
the result of a previous calculation. However in that case we know
that v->num is already valid so we can simply return.
2024-01-31 05:00:51 +01:00
Roberto E. Vargas Caballero 6b9da17eb4 build: Fix OBJ definition and remove MAN
The MAN macro was not used, and it and OBJ had the same problem
because they were defined using an empty string in the replace
pattern of the macro expansion, but as it is said by POSIX:

	The subst1 to be replaced shall be recognized when it is a suffix
	at the end of a word in string1

so, an empty string should not be used.

Also, a new inference rule is added to generate the binary
directly from the .c without generating the intermediate
object, removing the need of chaining different inference
rules which is not guaranteed to work in all the make
implementations.
2024-01-19 22:01:25 +01:00
Randy Palamar 270ca025ce expr: don't evaluate matched substr as a number
POSIX specifies that if the pattern contains a subexpression then
the first matched subexpression should be returned if it exists.

This fixes things like the following:

./expr 00003 : '\(.*\)'
Before: 3
After: 00003
2024-01-16 09:11:46 +01:00
Randy Palamar e50d533d59 expr: treat expressions as strs until evaluation
Comparison operations (>, <, =, etc.) and matching operations must
operate originally provided string not one that has gone back and
forth through string formatting. This caused operations such as
the following to give incorrect results:

./expr 00003 : '.*'
Before: 1
After: 5

This commit fixes that issue.
2024-01-16 09:11:40 +01:00
Roberto E. Vargas Caballero 7d5b113423 ed: Add new TODO 2024-01-12 20:48:42 +01:00
Roberto E. Vargas Caballero 2732217a40 ed: Handle correctly lines in substitutions
The s command can apply a replace pattern with embedded newlines
which modifies the line/index assignament. Using a range in  the
address fail because afther the call to subline() the next  line
has to be searched based in the index because the replace  could
insert newlines.
2023-12-29 20:27:23 +01:00
Jules Maselbas e24228e062 sbase-box: Fix segmentation fault when exe without args
when sbase-box is executed without argument, the check sbase-box
options doesn't verify the argument count leading to a segfault.

Add a check on the argc before parsing sbase-box options (currently
only `-i`)
2023-12-28 20:16:54 +01:00
Roberto E. Vargas Caballero 6a557314b9 ed: Don't undo commands in sigint
If newcmd is 0 then error() undo all the modifications
that happened since the last command, but this is  not
what POSIX mandates:

SIGINT	The ed utility shall interrupt its current activity, write the
	string "?\n" to standard output, and return to command mode
	(see the EXTENDED DESCRIPTION section).
2023-12-28 17:26:50 +01:00
Roberto E. Vargas Caballero bbdd7bedc4 ed: Simplify sighup dealing
As we already have the dump() function we can move the
modification check inside the new dump() function.
2023-12-28 17:19:47 +01:00
Roberto E. Vargas Caballero 137f0917e4 ed: Print only last line in empty command 2023-12-28 17:19:17 +01:00
Roberto E. Vargas Caballero 2d4d7dc6d4 ed: Fix G and V commands 2023-12-28 17:16:34 +01:00
Roberto E. Vargas Caballero 516e7fec92 ed: Remove nothing comments
Several bugs happened in the past due to this kind of comments
and it is better to get rid of them.
2023-12-28 17:16:24 +01:00
Roberto E. Vargas Caballero 54a0fc3ecc ed: Fix makeline
Strings without newlines created problems in the function
and the global field was not updated, making that new lines
added were marked as global being processed in the current
global command.
2023-12-28 17:14:04 +01:00
Roberto E. Vargas Caballero 09dc00f995 ed: Update TODO
Remove the cases are tested to work correctly now.
2023-12-28 17:04:13 +01:00
Roberto E. Vargas Caballero 890f6c2c05 ed: Improve execsh 2023-12-28 17:02:44 +01:00
Roberto E. Vargas Caballero aacfa18b79 ed: Avoid dangling pointer in getrhs()
If the string r.str is freed but error() is called then
next call will see a pointer that maybe it will try to free
because the call to error unwind the frame stack.
2023-12-28 17:02:19 +01:00
Roberto E. Vargas Caballero b089261c3a ed: Read from input in append()
This enables using a and i commands in a global command
because the input is not anymore taken from stdin.
2023-12-28 17:01:58 +01:00
Roberto E. Vargas Caballero 1e10bf6069 ed: Add getinput() and setinput()
These functions allow to read from stdin the full next
line or seting as input a character array. These functions
avoid all the complexity about repeat commands that is very
fragile and depends on having multiple global variables with
weak relation between them.
2023-12-28 16:49:34 +01:00
Roberto E. Vargas Caballero b710ee81fc ed: Add copystring()
This makes possible to use the function to initialize the string from
an existing char array.
2023-12-28 14:01:30 +01:00
Quentin Rameau 4cf7643094 find: Make parameter error messages more specific
Differenciate option operands from path operands
when an error is detected on the command line parameters.
2023-11-14 19:36:18 +01:00
Quentin Rameau 870b26af8e scripts: Fix non-portable find -perm /mode 2023-11-14 19:35:23 +01:00
Quentin Rameau f496998f4f scripts: Fix non-portable usage of find -maxdepth 2023-11-14 19:35:03 +01:00
Quentin Rameau 6fc6bbbf71 scripts: Force file copying on install
This would otherwise cause an issue using cp to copy cp to itself.
2023-11-14 19:34:27 +01:00
Quentin Rameau c31af02d22 make: fix rogue parameter in install target 2023-11-14 19:34:08 +01:00
Hiltjo Posthuma 0a82a7d91a TODO: add replacement bug reported for ed
Also reported on IRC:

"escaping the delimiter in replacement fails also: s/./\//"
2023-10-29 17:48:13 +01:00
Roberto E. Vargas Caballero 090490b81d build: Posixfy the Makefile 2023-09-27 09:46:39 +02:00
Roberto E. Vargas Caballero ddde8021b3 Simplify install/uninstall 2023-09-27 07:59:27 +02:00
Roberto E. Vargas Caballero 6285c22a07 build: Remove unneeded dependency
Make will search in the catalogue of rules for a way to
update the target, and in case of finding the dependency
it will apply the rule without a need of specifying that
dependency.
2023-09-27 07:59:27 +02:00
Roberto E. Vargas Caballero 986bbb9253 sbase-box: Add -i flag 2023-09-27 07:59:27 +02:00
Roberto E. Vargas Caballero 58ec1f6285 build: Move getconf.sh to scripts
The scripts directory is meant to contain all the scripts needed
in the build.
2023-09-27 07:59:27 +02:00
Roberto E. Vargas Caballero ba2fc773f3 build: Simplify dist target
We can get rid of the SRC variable if we use shell wildcards.
2023-09-27 07:59:27 +02:00
Roberto E. Vargas Caballero 8933987544 build: Use ARFLAGS when creating libraries
ARFLAGS has the expected value for the toolchain used.
2023-09-27 07:59:02 +02:00
Roberto E. Vargas Caballero bb4a01e837 build: Remove LIBUTIL and LIBUTF
They were just hidding the actual names of te libraries and as
they were added to OBJ they were listed twice in the clean
command.
2023-09-27 07:58:59 +02:00
Roberto E. Vargas Caballero 0f542cab58 build: Remove LIBUTFSRC and LIBUTILSRC
These variables were used only to generate the variables
LIBUTFOBJ and LIBUTILOBJ.
2023-09-27 07:10:10 +02:00
Roberto E. Vargas Caballero 3c36fb4177 sbase-box: Simplify Makefile rule
The Makefile rule was too complex and these cases is better to just
move it to a script where will be eassier to use sed properly
and not looping over all the files 4 times.
2023-09-27 07:10:05 +02:00
Roberto E. Vargas Caballero 8ca12835a5 build: Remove .gitignore rule
It is not needed because it is just easier to maintain
the gitignore file.
2023-09-27 06:37:38 +02:00
Roberto E. Vargas Caballero d3780956a9 ed: Deal signals in a reliable way
The signal handlers were calling longjmp() but as the code was calling
non signal safe functions the behaviour was very unpredictable generating
segmentation faults and dead lock. This commit changes the signal handlers
to only set a variable that is checked in safe places where long loops
happen.
2023-09-26 11:33:45 +02:00
Rene Kita 95b9603975 Ensure commands are followed by a blank
POSIX.1-2017 demands in Shell & Utilities under 'Commands in ed':
The e, E, f, r, and w commands shall take an optional file parameter,
separated from the command letter by one or more <blank> characters.

Ensure at least one <blank> character (as defined for the POSIX locale)
is present or error out.

Signed-off-by: Rene Kita <mail@rkta.de>
2023-09-26 10:50:15 +02:00
Roberto E. Vargas Caballero 67a00c86f9 ed: Open output file for writing
Fopen() and Popen() were open as read streams, but we were writing
in both cases. In the same way, the FILE pointer returned by popen()
was close with fclose() that can lead to file descriptor leaks and
zombie processes.
2023-09-22 20:45:38 +02:00
Roberto E. Vargas Caballero feeb6e3279 ed: Don't discard full lines
Discard() was reading stdin until a new line was found, but in
case of having an empty line in the input buffer then it didn't
make sense because we were just discarding the full next line.
2023-09-22 20:44:17 +02:00
Roberto E. Vargas Caballero 2cbf61dff9 xargs: Read full lines is -I
POSIX specifies that when -I is used then arguments are delimited
only by newlines.
2023-09-22 14:19:36 +02:00
Roberto E. Vargas Caballero fc85dc819d xargs: Free argument before substitution
strnsubst() allocates a new array always, indepently of
the number of occurences of the replace string.
2023-09-22 14:18:14 +02:00
Roberto E. Vargas Caballero a1f0426699 xargs: Apply -I substitution to all the parameters
The substitution must happen in all the parameters that contain
the replacement string, but the code was soing the substitution
only once and in the parameter with an exact match.
Also, the argument length was not updated correctly, assuming
that the final argument had the size read from stdin.
2023-09-22 11:45:46 +02:00
Roberto E. Vargas Caballero 22f110db28 libutil: Remove free() from strnsub()
The free() was added in the wrong assumption that xargs was not
freeing the argument in the position replaced, but it actually
does it.

Also, removing the call to free() makes more general the function.
2023-09-22 11:44:58 +02:00
Roberto E. Vargas Caballero 4e8a096b1c xargs: Update the man page about -I 2023-09-22 10:54:08 +02:00
Roberto E. Vargas Caballero b3a8052634 xargs: Add -x when -I is used
POSIX mandates to use -x when -I is used.
2023-09-22 10:37:18 +02:00