X-Git-Url: https://git.sesse.net/?p=stockfish;a=blobdiff_plain;f=src%2Fmisc.cpp;h=07d58d637fb9fbc33b33509ed3212ca3b6246011;hp=ecd6a499fc5e75eb24cc2cd9989c13310ab773de;hb=ea7bebb604ef1fc8b1de45f38a604fad590b52f5;hpb=c2c0ba875f429e497c936b61be9f75dcc88385a9 diff --git a/src/misc.cpp b/src/misc.cpp index ecd6a499..07d58d63 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -69,26 +69,23 @@ void dbg_print_hit_rate() { /// the constant EngineVersion (defined in misc.h) is empty. const std::string engine_name() { - if(EngineVersion == "") { - static const char monthNames[12][4] = { - "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" - }; - const char *dateString = __DATE__; - std::stringstream s; - int month = 0, day = 0; - - for(int i = 0; i < 12; i++) - if(strncmp(dateString, monthNames[i], 3) == 0) - month = i + 1; - day = atoi(dateString+4); - - s << "Glaurung " << (dateString+9) << std::setfill('0') << std::setw(2) - << month << std::setfill('0') << std::setw(2) << day; - - return s.str(); - } - else - return "Glaurung " + EngineVersion; + + if (EngineVersion.empty()) + { + std::string date(__DATE__); // From compiler, format is "Sep 21 2008" + std::string months("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"); + + size_t mon = 1 + months.find(date.substr(0, 3)) / 4; + + std::stringstream s; + std::string day = (date[4] == ' ' ? date.substr(5, 1) : date.substr(4, 2)); + + s << "Glaurung clone " << date.substr(date.length() - 2) << std::setfill('0') + << std::setw(2) << mon << std::setw(2) << day; + + return s.str(); + } else + return "Glaurung clone " + EngineVersion; } @@ -178,8 +175,24 @@ int Bioskey() return 1; return dw; } else { + // Count the number of unread input records, including keyboard, + // mouse, and window-resizing input records. GetNumberOfConsoleInputEvents(inh, &dw); - return dw <= 1 ? 0 : dw; + if (dw <= 0) + return 0; + + // Read data from console without removing it from the buffer + INPUT_RECORD rec[256]; + DWORD recCnt; + if (!PeekConsoleInput(inh, rec, Min(dw, 256), &recCnt)) + return 0; + + // Search for at least one keyboard event + for (DWORD i = 0; i < recCnt; i++) + if (rec[i].EventType == KEY_EVENT) + return 1; + + return 0; } } #endif