summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-11-24 11:26:35 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-11-24 11:26:35 +0000
commit680b08a9d69fcb3582203ca5e1e6f0ba88fea9e0 (patch)
treee81ba779f78f75a2683f06c2ff70737bdfbf1388 /src
parent8d67429c8b37415b04ec195dab9bdbcec8ec013a (diff)
downloadexecline-680b08a9d69fcb3582203ca5e1e6f0ba88fea9e0.tar.gz
execline-680b08a9d69fcb3582203ca5e1e6f0ba88fea9e0.tar.xz
execline-680b08a9d69fcb3582203ca5e1e6f0ba88fea9e0.zip
Better forstdin
 No need for the complexity: the important distinction is between
"eof after reading something" and "eof right away". 0 is a natural
fit for eof after some data, and 1 is a natural fit for immediate eof.
Anything else can be scripted around this.
Diffstat (limited to 'src')
-rw-r--r--src/execline/forstdin.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/execline/forstdin.c b/src/execline/forstdin.c
index 323ef59..1a329f2 100644
--- a/src/execline/forstdin.c
+++ b/src/execline/forstdin.c
@@ -18,7 +18,7 @@
 #include <execline/config.h>
 #include <execline/execline.h>
 
-#define USAGE "forstdin [ -p | -o okcode,okcode,... | -x breakcode,breakcode,... ] [ -e eofcode ] [ -n ] [ -C | -c ] [ -0 | -d delim ] var command..."
+#define USAGE "forstdin [ -p | -o okcode,okcode,... | -x breakcode,breakcode,... ] [ -n ] [ -C | -c ] [ -0 | -d delim ] var command..."
 #define dieusage() strerr_dieusage(100, USAGE)
 
 static genalloc pids = GENALLOC_ZERO ; /* pid_t */
@@ -51,14 +51,13 @@ int main (int argc, char const **argv, char const *const *envp)
   size_t delimlen = 4 ;
   size_t nbc = 0 ;
   unsigned short okcodes[256] ;
-  int crunch = 0, chomp = 0, not = 1 ;
-  unsigned short eofcode = 0 ;
+  int crunch = 0, chomp = 0, not = 1, eofcode = 1 ;
   PROG = "forstdin" ;
   {
     subgetopt_t l = SUBGETOPT_ZERO ;
     for (;;)
     {
-      int opt = subgetopt_r(argc, argv, "pnCc0d:o:x:e:", &l) ;
+      int opt = subgetopt_r(argc, argv, "pnCc0d:o:x:", &l) ;
       if (opt == -1) break ;
       switch (opt)
       {
@@ -81,9 +80,6 @@ int main (int argc, char const **argv, char const *const *envp)
           not = 1 ;
           if (!ushort_scanlist(okcodes, 256, l.arg, &nbc)) dieusage() ;
           break ;
-        case 'e' :
-          if (!ushort_scan(l.arg, &eofcode)) dieusage() ;
-          break ;
         default : dieusage() ;
       }
     }
@@ -118,7 +114,6 @@ int main (int argc, char const **argv, char const *const *envp)
           if (chomp) break ;
         }
         else modif.len-- ;
-        if ((modif.len == modifstart) && crunch) continue ;
       }
       else
       {
@@ -129,6 +124,8 @@ int main (int argc, char const **argv, char const *const *envp)
           else strerr_diefu1sys(111, "netstring_get") ;
         }
       }
+      eofcode = 0 ;
+      if (crunch && modif.len == modifstart) continue ;
       if (!stralloc_0(&modif)) strerr_diefu1sys(111, "stralloc_0") ;
       if (!env_merge(newenv, envlen+2, envp, envlen, modif.s, modif.len))
         strerr_diefu1sys(111, "merge environment") ;