[hackers] [sbase] ed: Add support for ! in w command || Heiko Berges

From: <git_AT_suckless.org>
Date: Thu, 21 Sep 2023 15:14:52 +0200 (CEST)

commit 0b4c2ceb2f4594cc9d5ca09e39fb57f6e4f82bfb
Author: Heiko Berges <hbs-bierbaum_AT_t-online.de>
AuthorDate: Thu Sep 21 14:56:58 2023 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Sep 21 15:14:16 2023 +0200

    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.

diff --git a/ed.c b/ed.c
index b661ac5..e6ca22b 100644
--- a/ed.c
+++ b/ed.c
_AT_@ -626,8 +626,14 @@ dowrite(const char *fname, int trunc)
         size_t bytecount = 0;
         int i, line;
 
- if (!(fp = fopen(fname, (trunc) ? "w" : "a")))
- error("input/output error");
+ if(fname[0] == '!') {
+ fname++;
+ if((fp = popen(fname, "r")) == NULL)
+ error("Bad Exec");
+ } else {
+ if ((fp = fopen(fname, "r")) == NULL)
+ error("cannot open input file");
+ }
 
         line = curln;
         for (i = line1; i <= line2; ++i) {
Received on Thu Sep 21 2023 - 15:14:52 CEST

This archive was generated by hypermail 2.3.0 : Thu Sep 21 2023 - 15:24:37 CEST