diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-10-18 19:54:47 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-10-18 19:56:11 +0800 |
commit | 6f2865228cb02f0ba0b58990a9d3006dbe2692c6 (patch) | |
tree | 8b243e672f2bd2f495215119fd5ee02c4d5c8430 | |
parent | 7186e142b8ea546d98dc8ddb630da47362be8b0a (diff) | |
download | dexon-solidity-6f2865228cb02f0ba0b58990a9d3006dbe2692c6.tar.gz dexon-solidity-6f2865228cb02f0ba0b58990a9d3006dbe2692c6.tar.zst dexon-solidity-6f2865228cb02f0ba0b58990a9d3006dbe2692c6.zip |
Add readStandardInput helper
-rw-r--r-- | libdevcore/CommonIO.cpp | 14 | ||||
-rw-r--r-- | libdevcore/CommonIO.h | 3 | ||||
-rw-r--r-- | lllc/main.cpp | 9 | ||||
-rw-r--r-- | solc/CommandLineInterface.cpp | 17 |
4 files changed, 20 insertions, 23 deletions
diff --git a/libdevcore/CommonIO.cpp b/libdevcore/CommonIO.cpp index eb7af83e..8c7e08f6 100644 --- a/libdevcore/CommonIO.cpp +++ b/libdevcore/CommonIO.cpp @@ -66,6 +66,20 @@ string dev::readFileAsString(string const& _file) return readFile<string>(_file); } +string dev::readStandardInput() +{ + string ret; + while (!cin.eof()) + { + string tmp; + // NOTE: this will read until EOF or NL + getline(cin, tmp); + ret.append(tmp); + ret.append("\n"); + } + return ret; +} + void dev::writeFile(std::string const& _file, bytesConstRef _data, bool _writeDeleteRename) { namespace fs = boost::filesystem; diff --git a/libdevcore/CommonIO.h b/libdevcore/CommonIO.h index 0c702818..33769ec3 100644 --- a/libdevcore/CommonIO.h +++ b/libdevcore/CommonIO.h @@ -34,6 +34,9 @@ namespace dev /// If the file doesn't exist or isn't readable, returns an empty container / bytes. std::string readFileAsString(std::string const& _file); +/// Retrieve and returns the contents of standard input (until EOF). +std::string readStandardInput(); + /// Write the given binary data into the given file, replacing the file if it pre-exists. /// Throws exception on error. /// @param _writeDeleteRename useful not to lose any data: If set, first writes to another file in diff --git a/lllc/main.cpp b/lllc/main.cpp index 4ff204ba..5679bc2b 100644 --- a/lllc/main.cpp +++ b/lllc/main.cpp @@ -118,14 +118,7 @@ int main(int argc, char** argv) string src; if (infile.empty()) - { - string s; - while (!cin.eof()) - { - getline(cin, s); - src.append(s); - } - } + src = readStandardInput(); else src = readFileAsString(infile); diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index b4c9fe82..fe1461b4 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -430,14 +430,7 @@ void CommandLineInterface::readInputFilesAndConfigureRemappings() m_allowedDirectories.push_back(boost::filesystem::path(path).remove_filename()); } if (addStdin) - { - string s; - while (!cin.eof()) - { - getline(cin, s); - m_sourceCodes[g_stdinFileName].append(s + '\n'); - } - } + m_sourceCodes[g_stdinFileName] = dev::readStandardInput(); } bool CommandLineInterface::parseLibraryOption(string const& _input) @@ -731,13 +724,7 @@ bool CommandLineInterface::processInput() if (m_args.count(g_argStandardJSON)) { - string input; - while (!cin.eof()) - { - string tmp; - getline(cin, tmp); - input.append(tmp + "\n"); - } + string input = dev::readStandardInput(); StandardCompiler compiler(fileReader); cout << compiler.compile(input) << endl; return true; |