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`)
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).
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.
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.
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.
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.
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.
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.
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>
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.
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.
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.
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.
a simple test case:
printf ab3 | tr -c '[:alpha:]' '\n'
output should be ab<newline>, previously you would find just newlines.
Signed-off-by: noneofyourbusiness <noneofyourbusiness@danwin1210.de>
When the file name begins with ! then the addressed buffer content is
piped to the name of the file that is considered a command that is
executed in a shell.
From POSIX:
in the POSIX locale the following diagnostic message shall be written:
"cmp: EOF on %s%s\n", <name of shorter file>, <additional info>
Amended by mcf: kept weprintf for consistency with other diagnostic
messages, but dropped the doubled prefix.
The POSIX spec gives many options on how to handle this case, but it
also states that cp (and mv) should continue with remaining operands
regardless. We used to exit immediately, which violates the spec.
This change makes cp/mv not exit immediately in this case and
also won't cause the return value to be non-zero.
From `man 1p cp`:
If source_file references the same file as dest_file, cp may write
a diagnostic message to standard error; it shall do nothing more
with source_file and shall go on to any remaining files.