Skip to content

Commit b2c0634

Browse files
committed
Move args parsing to UCI::loop
This leaves a very clean main.cpp No functional change.
1 parent ada55c5 commit b2c0634

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

src/main.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919

2020
#include <iostream>
21-
#include <string>
2221

2322
#include "bitboard.h"
2423
#include "evaluate.h"
@@ -42,12 +41,7 @@ int main(int argc, char* argv[]) {
4241
Threads.init();
4342
TT.resize(Options["Hash"]);
4443

45-
std::string args;
46-
47-
for (int i = 1; i < argc; ++i)
48-
args += std::string(argv[i]) + " ";
49-
50-
UCI::loop(args);
44+
UCI::loop(argc, argv);
5145

5246
Threads.exit();
5347
}

src/uci.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,16 @@ namespace {
143143
/// that we exit gracefully if the GUI dies unexpectedly. In addition to the UCI
144144
/// commands, the function also supports a few debug commands.
145145

146-
void UCI::loop(const string& args) {
146+
void UCI::loop(int argc, char* argv[]) {
147147

148148
Position pos(StartFEN, false, Threads.main()); // The root position
149-
string token, cmd = args;
149+
string token, cmd;
150+
151+
for (int i = 1; i < argc; ++i)
152+
cmd += std::string(argv[i]) + " ";
150153

151154
do {
152-
if (args.empty() && !getline(cin, cmd)) // Block here waiting for input
155+
if (argc == 1 && !getline(cin, cmd)) // Block here waiting for input
153156
cmd = "quit";
154157

155158
istringstream is(cmd);
@@ -208,7 +211,7 @@ void UCI::loop(const string& args) {
208211
else
209212
sync_cout << "Unknown command: " << cmd << sync_endl;
210213

211-
} while (token != "quit" && args.empty()); // Args have one-shot behaviour
214+
} while (token != "quit" && argc == 1); // Passed args have one-shot behaviour
212215

213216
Threads.wait_for_think_finished(); // Cannot quit whilst the search is running
214217
}

src/ucioption.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Option {
6161
};
6262

6363
void init(OptionsMap&);
64-
void loop(const std::string&);
64+
void loop(int argc, char* argv[]);
6565

6666
} // namespace UCI
6767

0 commit comments

Comments
 (0)