mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Add readStandardInput helper
This commit is contained in:
parent
7186e142b8
commit
6f2865228c
@ -66,6 +66,20 @@ string dev::readFileAsString(string const& _file)
|
|||||||
return readFile<string>(_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)
|
void dev::writeFile(std::string const& _file, bytesConstRef _data, bool _writeDeleteRename)
|
||||||
{
|
{
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
@ -34,6 +34,9 @@ namespace dev
|
|||||||
/// If the file doesn't exist or isn't readable, returns an empty container / bytes.
|
/// If the file doesn't exist or isn't readable, returns an empty container / bytes.
|
||||||
std::string readFileAsString(std::string const& _file);
|
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.
|
/// Write the given binary data into the given file, replacing the file if it pre-exists.
|
||||||
/// Throws exception on error.
|
/// Throws exception on error.
|
||||||
/// @param _writeDeleteRename useful not to lose any data: If set, first writes to another file in
|
/// @param _writeDeleteRename useful not to lose any data: If set, first writes to another file in
|
||||||
|
@ -118,14 +118,7 @@ int main(int argc, char** argv)
|
|||||||
|
|
||||||
string src;
|
string src;
|
||||||
if (infile.empty())
|
if (infile.empty())
|
||||||
{
|
src = readStandardInput();
|
||||||
string s;
|
|
||||||
while (!cin.eof())
|
|
||||||
{
|
|
||||||
getline(cin, s);
|
|
||||||
src.append(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
src = readFileAsString(infile);
|
src = readFileAsString(infile);
|
||||||
|
|
||||||
|
@ -430,14 +430,7 @@ void CommandLineInterface::readInputFilesAndConfigureRemappings()
|
|||||||
m_allowedDirectories.push_back(boost::filesystem::path(path).remove_filename());
|
m_allowedDirectories.push_back(boost::filesystem::path(path).remove_filename());
|
||||||
}
|
}
|
||||||
if (addStdin)
|
if (addStdin)
|
||||||
{
|
m_sourceCodes[g_stdinFileName] = dev::readStandardInput();
|
||||||
string s;
|
|
||||||
while (!cin.eof())
|
|
||||||
{
|
|
||||||
getline(cin, s);
|
|
||||||
m_sourceCodes[g_stdinFileName].append(s + '\n');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CommandLineInterface::parseLibraryOption(string const& _input)
|
bool CommandLineInterface::parseLibraryOption(string const& _input)
|
||||||
@ -731,13 +724,7 @@ bool CommandLineInterface::processInput()
|
|||||||
|
|
||||||
if (m_args.count(g_argStandardJSON))
|
if (m_args.count(g_argStandardJSON))
|
||||||
{
|
{
|
||||||
string input;
|
string input = dev::readStandardInput();
|
||||||
while (!cin.eof())
|
|
||||||
{
|
|
||||||
string tmp;
|
|
||||||
getline(cin, tmp);
|
|
||||||
input.append(tmp + "\n");
|
|
||||||
}
|
|
||||||
StandardCompiler compiler(fileReader);
|
StandardCompiler compiler(fileReader);
|
||||||
cout << compiler.compile(input) << endl;
|
cout << compiler.compile(input) << endl;
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user