From 163db7367fb45955069b46014e60224b1bc037b6 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 15 Aug 2003 09:21:19 +0000 Subject: [PATCH] * Fix can now read expressions from stdin (by saying `fix -'). --- src/fix.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/fix.cc b/src/fix.cc index e50d77620..2a1c09c2a 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++)