From dad5c70c494ec1e696f8209103a237e2a3a4b3ad Mon Sep 17 00:00:00 2001 From: David Wu Date: Sun, 14 Jun 2020 01:49:37 +0000 Subject: [PATCH] Also fix getline for analysis engine and genconfig --- cpp/command/analysis.cpp | 3 +-- cpp/command/benchmark.cpp | 13 ++++++++++--- cpp/command/gtp.cpp | 6 +----- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cpp/command/analysis.cpp b/cpp/command/analysis.cpp index 566db465f..2225f175b 100644 --- a/cpp/command/analysis.cpp +++ b/cpp/command/analysis.cpp @@ -342,8 +342,7 @@ int MainCmds::analysis(int argc, const char* const* argv) { string line; json input; - while(cin) { - getline(cin,line); + while(getline(cin,line)) { line = Global::trim(line); if(line.length() == 0) continue; diff --git a/cpp/command/benchmark.cpp b/cpp/command/benchmark.cpp index 2bb871843..0cc134c76 100644 --- a/cpp/command/benchmark.cpp +++ b/cpp/command/benchmark.cpp @@ -462,9 +462,13 @@ int MainCmds::genconfig(int argc, const char* const* argv, const char* firstComm try { cout << prompt << std::flush; string line; - std::getline(std::cin, line); - parse(Global::trim(line)); - break; + if(std::getline(std::cin, line)) { + parse(Global::trim(line)); + break; + } + else { + break; + } } catch(const StringError& err) { string what = err.what(); @@ -473,6 +477,9 @@ int MainCmds::genconfig(int argc, const char* const* argv, const char* firstComm cout << err.what() << endl; } } + if(!std::cin) { + throw StringError("Stdin was closed - failing and not generating a config"); + } }; auto parseYN = [](const string& line, bool& b) { diff --git a/cpp/command/gtp.cpp b/cpp/command/gtp.cpp index c7311b499..d187a2877 100644 --- a/cpp/command/gtp.cpp +++ b/cpp/command/gtp.cpp @@ -1391,11 +1391,7 @@ int MainCmds::gtp(int argc, const char* const* argv) { bool currentlyAnalyzing = false; string line; - while(cin) { - getline(cin,line); - if(!cin) - break; - + while(getline(cin,line)) { //Parse command, extracting out the command itself, the arguments, and any GTP id number for the command. string command; vector pieces;