64 errorT err = dbase->
Open(codec, fMode, filename, progress);
102 const char* usage =
"Usage: sc_base compact baseId [stats]";
107 }
else if (argc == 4 && std::strcmp(
"stats", argv[3]) == 0) {
108 unsigned long long n_deleted, n_unused, n_sparse, n_badNameId;
112 val.push_back(n_deleted);
113 val.push_back(n_unused);
114 val.push_back(n_sparse);
115 val.push_back(n_badNameId);
128 const char* usage =
"Usage: sc_base copygames baseId <gameNum|filterName> targetBaseId";
162 const char* usage =
"Usage: sc_base create <MEMORY|SCID4|PGN> filename";
168 if (std::strcmp(
"MEMORY", argv[2]) == 0)
170 else if (std::strcmp(
"SCID4", argv[2]) == 0)
172 else if (std::strcmp(
"PGN", argv[2]) == 0)
179 ti, argc == 4 ? argv[3] : argv[2],
189 const char* usage =
"Usage: sc_base extra baseId [tagname new_value]";
194 for (
const auto& e : list) {
196 res.push_back(e.second.c_str());
218 const char* usage =
"Usage: sc_base filename baseId";
232 const char* usage =
"Usage: sc_base gameflag baseId <gameNum|filterName|all> <get|set|unset|invert> flagType";
236 if (std::strcmp(
"get", argv[4]) == 0)
238 else if (std::strcmp(
"set", argv[4]) == 0)
240 else if (std::strcmp(
"unset", argv[4]) == 0)
242 else if (std::strcmp(
"invert", argv[4]) == 0)
245 if (flagType != 0 && cmd != 0) {
246 bool value = (cmd == 2);
249 if (filter != 0 || (std::strcmp(
"all", argv[3]) == 0)) {
257 if (gNum > 0 && gNum <= dbase->numGames()) {
288 const char* usage =
"Usage: sc_base gamelocation baseId filterName sortCrit <gnumber | 0 text start_pos forward_dir>";
294 const char*
sort = argv[4];
300 const char* text = argv[6];
303 auto contains = [dbase, nb, text](
gamenumT g) {
311 std::vector<gamenumT> buf(filter->
size() -
start);
313 dbase->
listGames(sort, start, buf.size(), filter, buf.data()));
314 auto it = std::find_if(buf.begin(), buf.end(), contains);
316 location = start + std::distance(buf.begin(), it);
318 std::vector<gamenumT> buf(start);
319 buf.resize(dbase->
listGames(sort, 0, start, filter, buf.data()));
320 auto it = std::find_if(buf.rbegin(), buf.rend(), contains);
321 if (it != buf.rend())
322 location = std::distance(it, buf.rend()) - 1;
339 const char* usage =
"Usage: sc_base gameslist baseId start count filterName sortCrit";
348 count = dbase->
listGames(argv[6], start, count, filter, idxList);
353 for (
uint i = 0; i < count; ++i) {
354 uint idx = idxList[i];
357 uint ply = filter->
get(idx) -1;
362 ginfo.push_back(idx +1);
369 eloStr = std::to_string(welo);
372 eloStr = std::to_string(welo);
374 eloStr.insert(eloStr.begin(),
'(');
375 eloStr.insert(eloStr.end(),
')');
378 ginfo.push_back(eloStr);
382 eloStr = std::to_string(belo);
385 eloStr = std::to_string(belo);
387 eloStr.insert(eloStr.begin(),
'(');
388 eloStr.insert(eloStr.end(),
')');
391 ginfo.push_back(eloStr);
394 ginfo.push_back(buf_date);
401 char deleted[2] = {0};
403 ginfo.push_back(deleted);
406 ginfo.push_back(flags);
409 ginfo.push_back(ecoStr);
411 ginfo.push_back(endMaterial);
412 char startpos[2] = {0};
414 ginfo.push_back(startpos);
415 char buf_eventdate[16];
417 ginfo.push_back(buf_eventdate);
418 ginfo.push_back(ie->
GetYear());
419 ginfo.push_back((welo + belo)/2);
424 res.push_back(std::to_string(idx+1) +
"_" + std::to_string(ply));
425 res.push_back(ginfo);
426 res.push_back(deleted);
437 for (
const auto& pos : positions) {
439 posInfo.push_back(pos.RAVdepth);
440 posInfo.push_back(pos.RAVnum);
441 posInfo.push_back(pos.FEN);
443 for (
const auto&
nag : pos.NAGs) {
450 posInfo.push_back(nags);
451 posInfo.push_back(pos.comment);
452 posInfo.push_back(pos.lastMoveSAN);
453 res.push_back(posInfo);
480 const char* usage =
"Usage: sc_base getGame baseId gameNum [live]";
481 bool live = (argc == 5 && std::strcmp(
"live", argv[4]) == 0);
482 if (!live && argc != 4)
486 if (live && dbase->
gameNumber == (static_cast<long long>(gNum) - 1)) {
488 auto res = sc_base_getGameHelper(ti, *(dbase->
game));
501 return sc_base_getGameHelper(ti, game);
514 const char* usage =
"Usage: sc_base import baseId filename";
521 std::string errorMsg;
528 res.push_back(dbase->
numGames() - nImported);
529 res.push_back(errorMsg);
538 const char* usage =
"Usage: sc_base list";
543 for (
size_t i=0, n=l.size(); i < n; i++) res.
push_back(l[i]);
553 const char* usage =
"Usage: sc_base numGames baseId";
571 const char* usage =
"Usage: sc_base open <SCID4|PGN> filename";
577 if (std::strcmp(
"SCID4", argv[2]) == 0)
579 else if (std::strcmp(
"PGN", argv[2]) == 0)
585 return doOpenBase(ti, argc == 4 ? argv[3] : argv[2],
FMODE_Both, codec);
601 const char* usage =
"Usage: sc_base slot filename";
616 const char* usage =
"Usage: sc_base sortcache baseId <create|release> sortCrit";
619 if (std::strcmp(
"create", argv[3]) == 0) {
650 const char* usage =
"Usage: sc_base stats baseId <dates|eco ?|flag ?|flags|ratings|results>";
653 const char* subcmd = argv[3];
657 enum { OPT_DATE, OPT_ECO, OPT_FLAG, OPT_FLAGS, OPT_RATINGS, OPT_RESULTS };
658 const char * options[] = {
"dates",
"eco",
"flag",
"flags",
"ratings",
"results", NULL };
668 res.push_back(eco->
count);
678 res.push_back(count == 0 ? 0.0 : score / count / 10.0);
752 const char* usage =
"Usage: sc_base tournaments baseId filterName n_maxResults [-avgelo range] [-n_games range] [-n_players range] [-sort criteria] ";
760 const char* sortCriteria = 0;
763 static const char* options[] = {
764 "-avgelo",
"-n_games",
"-n_players",
"-player",
"-sort", NULL
766 enum { AVGELO, N_GAMES, N_PLAYERS, PLAYER, SORT };
768 for (
int i = 5; (i + 1) < argc; i += 2) {
770 const char* value = argv[i + 1];
771 if (*value == 0)
continue;
783 search.filterByPlayer(value);
786 sortCriteria = value;
793 if (sortCriteria != 0) {
794 if (!
search.sort(sortCriteria, nResults))
800 if (std::distance(it, it_end) > nResults) {
801 it_end = it + nResults;
806 UI_List res(std::distance(it, it_end));
808 for (; it != it_end; it++) {
815 tourney.push_back(it->nPlayers());
816 tourney.push_back(it->nGames());
817 tourney.push_back(it->getAvgElo());
818 tourney.push_back(it->getStartGameNum() + 1);
819 const char* name1st =
"";
821 double score1st = 0.0;
822 const char* name2nd =
"";
824 double score2nd = 0.0;
825 if (it->nPlayers() > 0) {
829 score1st = p.
score / 2.0;
831 if (it->nPlayers() > 1) {
835 score2nd = p.
score / 2.0;
858 const char* usage =
"Usage: sc_base player_elo baseId filterName playerName";
863 if (filter ==
nullptr)
870 std::map<unsigned, eloT> eloByMonth;
871 auto getPlayerElo = [](
auto idx_entry,
auto player_id) ->
eloT {
873 if (idx_entry->GetWhite() == player_id)
874 return idx_entry->GetWhiteElo();
875 if (idx_entry->GetBlack() == player_id)
876 return idx_entry->GetBlackElo();
879 for (
auto gnum : filter) {
881 if (
auto elo = getPlayerElo(ie,
id)) {
891 eloByMonth[year * 12 + month] = elo;
895 UI_List res(eloByMonth.size() * 2);
896 for (
auto& e : eloByMonth) {
898 res.push_back(e.second);
915 static const char * options [] = {
916 "close",
"compact",
"copygames",
917 "create",
"current",
"duplicates",
918 "export",
"extra",
"filename",
"gameflag",
919 "gamelocation",
"gameslist",
"getGame",
"import",
920 "inUse",
"isReadOnly",
"list",
"numGames",
"open",
921 "piecetrack",
"player_elo",
"slot",
"sortcache",
"stats",
922 "switch",
"tag",
"tournaments",
"type",
926 BASE_CLOSE, BASE_COMPACT, BASE_COPYGAMES,
927 BASE_CREATE, BASE_CURRENT, BASE_DUPLICATES,
928 BASE_EXPORT, BASE_EXTRA, BASE_FILENAME, BASE_GAMEFLAG,
929 BASE_GAMELOCATION, BASE_GAMESLIST, BASE_GETGAME, BASE_IMPORT,
930 BASE_INUSE, BASE_ISREADONLY, BASE_LIST, BASE_NUMGAMES, BASE_OPEN,
931 BASE_PTRACK, BASE_PLAYER_ELO, BASE_SLOT, BASE_SORTCACHE, BASE_STATS,
932 BASE_SWITCH, BASE_TAG, BASE_TOURNAMENTS, BASE_TYPE
940 return sc_base_create(ti, argc, argv);
943 return sc_base_switch(0, ti);
952 return sc_base_list(ti, argc, argv);
955 return sc_base_open(ti, argc, argv);
961 return sc_base_slot (ti, argc, argv);
974 return sc_base_close(dbase, ti, argc, argv);
977 return sc_base_compact(dbase, ti, argc, argv);
980 return sc_base_copygames(dbase, ti, argc, argv);
982 case BASE_DUPLICATES:
987 return sc_base_extra(dbase, ti, argc, argv);
990 return sc_base_filename(dbase, ti, argc, argv);
993 return sc_base_gameflag(dbase, ti, argc, argv);
995 case BASE_GAMELOCATION:
996 return sc_base_gamelocation(dbase, ti, argc, argv);
999 return sc_base_gameslist(dbase, ti, argc, argv);
1002 return sc_base_getGame(dbase, ti, argc, argv);
1005 return sc_base_import (dbase, ti, argc, argv);
1007 case BASE_ISREADONLY:
1011 return sc_base_numGames (dbase, ti, argc, argv);
1013 case BASE_PLAYER_ELO:
1014 return sc_base_player_elo(*dbase, ti, argc, argv);
1016 case BASE_SORTCACHE:
1017 return sc_base_sortcache(dbase, ti, argc, argv);
1020 return sc_base_stats(dbase, ti, argc, argv);
1023 return sc_base_switch (dbase, ti);
1025 case BASE_TOURNAMENTS:
1026 return sc_base_tournaments (dbase, ti, argc, argv);
1029 std::string res =
"sc_base\nInvalid minor command: ";
1030 res.append(argv[1]);
const IndexEntry * getIndexEntry(gamenumT g) const
uint date_GetYear(dateT date)
errorT setExtraInfo(const char *tagname, const char *new_value)
Store an extra information about the database (type, description, etc..)
bool GetStartFlag() const
int strExactMatch(const char *keyStr, const char **strTable)
const char * GetBlackName(const NameBase *nb) const
errorT FindExactName(nameT nt, const char *str, idNumberT *idPtr) const
Finds an exact full, case-sensitive name.
std::string matsig_makeString(matSigT m)
int switchCurrent(scidBaseT *dbase=0)
switchCurrent() - DEPRECATED.
FastGame getGame(const IndexEntry *ie) const
std::vector< Tourney >::const_iterator Iter
const errorT ERROR_FileInUse
void restoreLocation(const GameSavedPos &savedPos)
resultT GetResult() const
SortCache * createSortCache(const char *criteria)
Increment the reference count of a SortCache object matching criteria.
const Stats & getStats() const
Statistics.
class SearchTournamens - Search tournaments in a database
const char * GetWhiteName(const NameBase *nb) const
const errorT ERROR_BadArg
const char * GetEventName(const NameBase *nb) const
UI_res_t sc_base_piecetrack(UI_extra_t, UI_handle_t, int argc, const char **argv)
const resultT RESULT_Black
int strUniqueMatch(const char *keyStr, const char **strTable)
class StrRange - parse a string interpreting its content as 1 or 2 integers separated by whitespace...
byte get(gamenumT gnum) const
void collectPositions(Game &game, TCont &dest)
Iterate all the positions of a game and store the corresponding GamePos objects into a container...
const gamenumT INVALID_GAMEID
static uint CharToFlag(char ch)
scidBaseT * getBase(int baseHandle)
getBase() - get a database from the pool.
matSigT GetFinalMatSig() const
uint16_t GetNumHalfMoves() const
const char * GetName(nameT nt, idNumberT id) const
Retrieve a name.
uint results[NUM_RESULT_TYPES]
void date_DecodeToString(dateT date, char *str)
const resultT RESULT_Draw
errorT importGame(const scidBaseT *srcBase, uint gNum)
int find(const char *filename)
find() - search for a database.
static uint32_t CharToFlagMask(char flag)
const char RESULT_STR[4][4]
This class stores the database's names (players, events, sites and rounds).
UI_res_t sc_base(UI_extra_t cd, UI_handle_t ti, int argc, const char **argv)
uint GetFlagStr(char *dest, const char *flags) const
errorT invertFlag(uint flag, uint gNum)
const std::string & getFileName() const
size_t sortedPosition(const char *criteria, const HFilter &filter, gamenumT gameId)
Get the sorted position of a game.
const resultT RESULT_White
uint sc_base_duplicates(scidBaseT *dbase, UI_handle_t, int argc, const char **argv)
bool GetDeleteFlag() const
const Eco * getEcoStats(const char *ecoStr) const
std::string getMoveSAN(int ply_to_skip, int count)
bool strAlphaContains(const char *longStr, const char *keyStr)
uint GetCommentCount() const
errorT getCompactStat(unsigned long long *n_deleted, unsigned long long *n_unused, unsigned long long *n_sparse, unsigned long long *n_badNameId)
byte GetRating(const NameBase *nb) const
void releaseSortCache(const char *criteria)
Decrement the reference count of the SortCache object matching criteria.
UI_res_t sc_base_tag(UI_extra_t, UI_handle_t, int argc, const char **argv)
void eco_ToExtendedString(ecoT ecoCode, char *ecoStr)
uint32_t strGetUnsigned(const char *str)
uint nResults[NUM_RESULT_TYPES]
scidBaseT * getFreeSlot()
getFreeSlot() - search for a free database slot.
uint flagCount[IndexEntry::IDX_NUM_FLAGS]
errorT importGames(const scidBaseT *srcBase, const HFilter &filter, const Progress &progress)
const errorT ERROR_FileReadOnly
UI_res_t UI_Result(UI_handle_t ti, errorT res)
UI_Result() - pass the result of an operation from c++ to UI.
GameSavedPos currentLocation() const
std::vector< int > getHandles()
getHandles() - get the handles of opened databases.
errorT compact(const Progress &progress)
void push_back(Tcl_Obj *value)
bool report(size_t done, size_t total) const
const errorT ERROR_FileNotOpen
gamenumT numGames() const
An heterogeneous container used to pass a list of values from c++ to UI.
const char * GetSiteName(const NameBase *nb) const
HFilter getFilter(const std::string &filterId) const
Progress UI_CreateProgress(UI_handle_t ti)
UI_CreateProgress() - create a Progress object.
const IndexEntry * getIndexEntry_bounds(gamenumT g) const
errorT Open(ICodecDatabase::Codec dbtype, fileModeT mode, const char *filename=0, const Progress &progress=Progress())
bool strGetBoolean(const char *str)
void game_printNag(byte nag, char *str, bool asSymbol, gameFormatT format)
UI_res_t sc_base_inUse(UI_extra_t, UI_handle_t, int argc, const char **argv)
const errorT ERROR_FileMode
const resultT RESULT_None
const NameBase * getNameBase() const
const errorT ERROR_NameDataLoss
std::vector< std::pair< const char *, std::string > > getExtraInfo() const
Returns a vector of tag pairs containing extra information about the database (type, description, autoload, etc..)
const char * GetRoundName(const NameBase *nb) const
uint date_GetMonth(dateT date)
const errorT ERROR_FileOpen
void strTrimDate(char *str)
UI_res_t sc_base_export(UI_extra_t, UI_handle_t, int argc, const char **argv)
size_t listGames(const char *criteria, size_t start, size_t count, const HFilter &filter, gamenumT *destCont)
Retrieve a list of ordered game indexes sorted by criteria.
bool getFlag(uint flag, uint gNum) const
uint GetVariationCount() const
dateT GetEventDate() const
errorT setFlag(bool value, uint flag, uint gNum)