Commit Graph

1990 Commits

Author SHA1 Message Date
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
sewn 8d97acc135 xargs: add replace string flag (-I) 2023-09-22 10:34:36 +02:00
noneofyourbusiness f14887c765 tr: fix behavior of cflag when using character classes
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>
2023-09-21 15:27:01 +02:00
Heiko Berges 0b4c2ceb2f ed: Add support for ! in w command
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.
2023-09-21 15:14:16 +02:00
Richard Ipsum 53040766d1 cmp: Make output of error message POSIX compliant
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.
2023-04-12 21:37:04 -07:00
David Demelier 446903d688 libutf: add some const's 2023-04-12 21:22:28 -07:00
Michael Forney 7fc2f68aec libutf: Update to unicode 15.0.0 2023-04-12 21:20:56 -07:00
Greg Reagle df50727a08 refer to re_format(7) for BSDs 2023-04-12 21:16:30 -07:00
Arthur Williams 8dfcbf23b0 cp: don't abort when src and dest file are the same
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.
2023-04-12 21:09:12 -07:00
Andrea Calligaris 499c3b1227 sort.1: fix typo 2023-04-12 21:01:30 -07:00
Andrea Calligaris 93f34c1840 ed: Fix 'w' command not respecting '-s' option 2023-04-12 21:01:27 -07:00
Michael Forney fb16e7c6ad dd: Consider block count in inner read loop
When ibs is smaller than obs, checking the block count in the outer
loop is not sufficient; we need to break out of the inner read loop
once we've read the specified number of blocks.

Thanks to phoebos for reporting this issue.
2023-04-12 20:47:34 -07:00
Michael Forney 00995639fe dd: Fix backwards comparison when handling short writes
ipos is always ahead of opos, so the left side of this condition
was never true. This only mattered when we get short writes, since
on EOF we always have less than a full output block, so it takes
only one normal write.
2023-04-12 20:09:51 -07:00
Michael Forney 191f7e693b find: insert -a in before open parens as well
This fixes expressions like -type f '(' -name foo -o -name bar ')'.
2022-10-21 18:31:52 -07:00
Hiltjo Posthuma 63271b47f7 setsid: fix usage information for -f flag 2022-06-20 12:39:59 +02:00
Michael Forney c3e47c1f44 Fix LICENSE name
The license text matches (and has always matched) what is known as
the MIT license[0]. The MIT/X Consortium license, also called the
X11 license, is slightly different and has an additional clause
prohibiting various uses of the X Consortium name.

[0] https://opensource.org/licenses/MIT
2022-03-22 17:20:51 -07:00