about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-08-15T09·21+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-08-15T09·21+0000
commit163db7367fb45955069b46014e60224b1bc037b6 (patch)
tree7fa36ec65ee0131620b94a2673ac7b31796e1eda
parent161aab582bb3d794414c0275ff8216292f85ab5c (diff)
* Fix can now read expressions from stdin (by saying `fix -').
-rw-r--r--src/fix.cc18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/fix.cc b/src/fix.cc
index e50d77620cd7..2a1c09c2a2cd 100644
--- a/src/fix.cc
+++ b/src/fix.cc
@@ -375,6 +375,16 @@ static Expr evalFile(EvalState & state, string relPath)
 }
 
 
+static Expr evalStdin(EvalState & state)
+{
+    Nest nest(lvlTalkative, format("evaluating standard input"));
+    Expr e = ATreadFromFile(stdin);
+    if (!e) 
+        throw Error(format("unable to read a term from stdin"));
+    return evalExpr(state, e);
+}
+
+
 static void printFSId(EvalState & state, Expr e)
 {
     ATermList es;
@@ -398,6 +408,7 @@ void run(Strings args)
 
     EvalState state;
     Strings files;
+    bool readStdin = false;
 
     state.searchDirs.push_back(".");
     state.searchDirs.push_back(nixDataDir + "/fix");
@@ -414,13 +425,18 @@ void run(Strings args)
         }
         else if (arg == "--verbose" || arg == "-v")
             verbosity = (Verbosity) ((int) verbosity + 1);
+        else if (arg == "-")
+            readStdin = true;
         else if (arg[0] == '-')
             throw UsageError(format("unknown flag `%1%`") % arg);
         else
             files.push_back(arg);
     }
 
-    if (files.empty()) throw UsageError("no files specified");
+    if (readStdin) {
+        Expr e = evalStdin(state);
+        printFSId(state, e);
+    }
 
     for (Strings::iterator it = files.begin();
          it != files.end(); it++)