[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[augeas-devel] [PATCH] Use readline only when stdin is a tty, use getline otherwise.



From: Raphaël Pinson <raphink raphink net>

---
 src/augtool.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/augtool.c b/src/augtool.c
index 0869960..a5fcde6 100644
--- a/src/augtool.c
+++ b/src/augtool.c
@@ -622,11 +622,16 @@ static int main_loop(void) {
     char *line;
     char *cmd, *args[maxargs];
     int ret = 0;
+    size_t len = 0;
 
     while(1) {
         char *dup_line;
 
-        line = readline("augtool> ");
+        if (isatty(fileno(stdin))) {
+            line = readline("augtool> ");
+        } else if (getline(&line, &len, stdin) == -1) {
+            return ret;
+        }
         if (line == NULL) {
             printf("\n");
             return ret;
@@ -644,7 +649,8 @@ static int main_loop(void) {
             r = run_command(cmd, maxargs, args);
             if (r < 0)
                 ret = -1;
-            add_history(line);
+            if (! isatty(fileno(stdin)))
+                add_history(line);
         }
         free(dup_line);
     }
-- 
1.5.6.3



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]