Index   Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

FuegoMainUtil.cpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file FuegoMainUtil.cpp
00003     See FuegoMainUtil.h
00004 */
00005 //----------------------------------------------------------------------------
00006 
00007 #include "SgSystem.h"
00008 #include "FuegoMainUtil.h"
00009 
00010 #include <fstream>
00011 #include <sstream>
00012 #include "GoBook.h"
00013 #include "SgDebug.h"
00014 
00015 using namespace std;
00016 using namespace boost::filesystem;
00017 
00018 //----------------------------------------------------------------------------
00019 
00020 namespace {
00021 
00022 bool LoadBookFile(GoBook& book, const path& file)
00023 {
00024     path normalizedFile = file;
00025     normalizedFile.normalize();
00026     string nativeFile = normalizedFile.native_file_string();
00027     SgDebug() << "Loading opening book from '" << nativeFile << "'... ";
00028     ifstream in(nativeFile.c_str());
00029     if (! in)
00030     {
00031         SgDebug() << "not found\n";
00032         return false;
00033     }
00034     try
00035     {
00036         book.Read(in);
00037     }
00038     catch (const SgException& e)
00039     {
00040         SgDebug() << "error: " << e.what() << '\n';
00041         return false;
00042     }
00043     SgDebug() << "ok\n";
00044     return true;
00045 }
00046 
00047 } // namespace
00048 
00049 //----------------------------------------------------------------------------
00050 
00051 void FuegoMainUtil::LoadBook(GoBook& book,
00052                              const boost::filesystem::path& programDir)
00053 {
00054     const string fileName = "book.dat";
00055     if (LoadBookFile(book, programDir / fileName))
00056         return;
00057 #ifdef ABS_TOP_SRCDIR
00058     if (LoadBookFile(book, path(ABS_TOP_SRCDIR) / "book" / fileName))
00059         return;
00060 #endif
00061 #if defined(DATADIR) && defined(PACKAGE)
00062     if (LoadBookFile(book, path(DATADIR) / PACKAGE / fileName))
00063         return;
00064 #endif
00065     throw SgException("Could not find opening book.");
00066 }
00067 
00068 std::string FuegoMainUtil::Version()
00069 {
00070     ostringstream s;
00071 #ifdef VERSION
00072     s << VERSION;
00073 #else
00074     s << "(" __DATE__ ")";
00075 #endif
00076 #ifdef SVNREV
00077     s << "(" SVNREV ")";
00078 #endif
00079 #ifndef NDEBUG
00080     s << " (dbg)";
00081 #endif
00082     return s.str();
00083 }
00084 
00085 //----------------------------------------------------------------------------


17 Jun 2010 Doxygen 1.4.7