summaryrefslogtreecommitdiff
path: root/sed/debug.c
diff options
context:
space:
mode:
authorAssaf Gordon <assafgordon@gmail.com>2021-08-11 11:33:48 -0600
committerAssaf Gordon <assafgordon@gmail.com>2021-08-16 12:34:20 -0600
commit07c9c74c6bffe92e856ba77789736b2a1d7f478e (patch)
tree897aeb2b6d721ec2f7d0014739f8069c84aac5be /sed/debug.c
parentaa15df834a0e8dce0d59d40a2fb6da9ea3028987 (diff)
downloadsed-07c9c74c6bffe92e856ba77789736b2a1d7f478e.tar.gz
sed: allow '0rFILE' (insert FILE before the first line)
The 'r' command can be used with address zero, effectively prepending a file to the beginning of the input file, e.g.: sed '0rA.TXT' B.TXT > C.TXT is equivalent to: cat A.TXT B.TXT > C.TXT With "sed -i", this allows safe in-place prepending of files. A typical example would be adding a license header to multiple source files: sed -i '0rLICENSE' *.c *.h find -iname '*.cpp' | xargs sed -i '0rLICENSE' A current cumbersome alternative is: sed -i -e 'x;${p;x};1rA.TXT' -e '1d' B.TXT * NEWS: Mention new feature. * sed/sed.h (struct readcmd): New struct. (struct sed_cmd): Use new struct instead of a char* for the filename. * sed/compile.c (compile_program): Expand conditional detecting invalid usage of "0" address to allow "0r"; Adjust '0r' to '1r' with prepending (instead of appending). * sed/execute.c (execute_program): 'r' command: support prepending. * sed/debug.c (debug_print_function): Use the new 'struct readcmd'. * testsuite/cmd-0r.sh: New test. * testsuite/local.mk (TESTS): Add new test. * doc/sed.texi (Zero Address): New section. (Adding a header to multiple files): New example section.
Diffstat (limited to 'sed/debug.c')
-rw-r--r--sed/debug.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/sed/debug.c b/sed/debug.c
index 0530496..99f8b87 100644
--- a/sed/debug.c
+++ b/sed/debug.c
@@ -363,7 +363,7 @@ debug_print_function (const struct vector *program, const struct sed_cmd *sc)
case 'r':
putchar (' ');
- fputs (sc->x.fname, stdout);
+ fputs (sc->x.readcmd.fname, stdout);
break;
case 'R':