Go to the documentation of this file.00001
00005 #include "osl/record/ki2.h"
00006 #include "osl/record/checkDuplicate.h"
00007 #include "osl/record/ki2IOError.h"
00008
00009 #include <boost/algorithm/string/trim.hpp>
00010 #include <boost/foreach.hpp>
00011 #include <boost/program_options.hpp>
00012 #include <boost/lambda/lambda.hpp>
00013 #include <boost/lambda/bind.hpp>
00014 #include <iostream>
00015 #include <fstream>
00016 #include <string>
00017 #include <vector>
00018 #include <algorithm>
00019
00020
00021
00022
00023 boost::program_options::variables_map vm;
00024 osl::record::CheckDuplicate check_duplicate;
00025
00026 using namespace boost::lambda;
00027
00028 void process( const std::string& file_name)
00029 {
00030 try {
00031 bool verbose = false;
00032 if (vm.count("verbose"))
00033 verbose = true;
00034 if (verbose)
00035 std::cout << "Processing... " << file_name << std::endl;
00036 const osl::Ki2File ki2(file_name, verbose);
00037 const osl::Record& record = ki2.getRecord();
00038 const osl::stl::vector<osl::Move>& moves = record.getMoves();
00039
00040 if (check_duplicate.regist(moves)) {
00041 std::cerr << "Found a duplicated play: " << file_name << "\n";
00042 return;
00043 }
00044
00045 osl::NumEffectState state;
00046 BOOST_FOREACH(const osl::Move& move, moves)
00047 {
00048 if (!state.isValidMove(move, false))
00049 {
00050 std::cout << file_name << "\n";
00051 continue;
00052 }
00053 state.makeMove(move);
00054 }
00055 } catch (osl::Ki2IOError& err) {
00056 std::cerr << err.what() << "\n";
00057 std::cerr << "Found an error: " << file_name << "\n";
00058 return;
00059 }
00060 }
00061
00062 int main(int argc, char **argv)
00063 {
00064 boost::program_options::options_description command_line_options;
00065 command_line_options.add_options()
00066 ("input-file", boost::program_options::value< std::vector<std::string> >(),
00067 "input files in ki2 format (.ki2)")
00068 ("verbose,v", "Verbose mode")
00069 ("help,h", "Show this help message");
00070 boost::program_options::positional_options_description p;
00071 p.add("input-file", -1);
00072
00073 try
00074 {
00075 boost::program_options::store(
00076 boost::program_options::command_line_parser(
00077 argc, argv).options(command_line_options).positional(p).run(), vm);
00078 boost::program_options::notify(vm);
00079 if (vm.count("help"))
00080 {
00081 std::cout << "Usage: " << argv[0] << " [options] ki2-file [ki2-file...]\n";
00082 std::cout << " " << argv[0] << " [options]\n";
00083 std::cout << command_line_options << std::endl;
00084 return 0;
00085 }
00086 }
00087 catch (std::exception &e)
00088 {
00089 std::cerr << "error in parsing options" << std::endl
00090 << e.what() << std::endl;
00091 std::cerr << "Usage: " << argv[0] << " [options] ki2-file [ki2-file...]\n";
00092 std::cerr << " " << argv[0] << " [options]\n";
00093 std::cerr << command_line_options << std::endl;
00094 return 1;
00095 }
00096
00097 std::vector<std::string> files;
00098 if (vm.count("input-file"))
00099 {
00100 const std::vector<std::string> temp = vm["input-file"].as<std::vector<std::string> >();
00101 files.insert(files.end(), temp.begin(), temp.end());
00102 }
00103 else
00104 {
00105 std::string line;
00106 while(std::getline(std::cin , line))
00107 {
00108 boost::algorithm::trim(line);
00109 files.push_back(line);
00110 }
00111 }
00112
00113
00114 std::for_each(files.begin(), files.end(), bind(&process, _1));
00115
00116 check_duplicate.print(std::cout);
00117
00118 return 0;
00119 }
00120
00121
00122
00123