All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
check-ki2.cc
Go to the documentation of this file.
1 
5 #include "osl/record/ki2.h"
8 
9 #include <boost/algorithm/string/trim.hpp>
10 #include <boost/foreach.hpp>
11 #include <boost/program_options.hpp>
12 #include <boost/lambda/lambda.hpp>
13 #include <boost/lambda/bind.hpp>
14 #include <iostream>
15 #include <fstream>
16 #include <string>
17 #include <vector>
18 #include <algorithm>
19 
20 // ----------------------------------------------
21 // Global variables
22 // ----------------------------------------------
23 boost::program_options::variables_map vm;
25 
26 using namespace boost::lambda;
27 
28 void process( const std::string& file_name)
29 {
30  try {
31  bool verbose = false;
32  if (vm.count("verbose"))
33  verbose = true;
34  if (verbose)
35  std::cout << "Processing... " << file_name << std::endl;
36  const osl::Ki2File ki2(file_name, verbose);
37  const osl::Record& record = ki2.getRecord();
38  const osl::stl::vector<osl::Move>& moves = record.getMoves();
39 
40  if (check_duplicate.regist(moves)) {
41  std::cerr << "Found a duplicated play: " << file_name << "\n";
42  return;
43  }
44 
45  osl::NumEffectState state;
46  BOOST_FOREACH(const osl::Move& move, moves)
47  {
48  if (!state.isValidMove(move, false))
49  {
50  std::cout << file_name << "\n";
51  continue;
52  }
53  state.makeMove(move);
54  }
55  } catch (osl::Ki2IOError& err) {
56  std::cerr << err.what() << "\n";
57  std::cerr << "Found an error: " << file_name << "\n";
58  return;
59  }
60 }
61 
62 int main(int argc, char **argv)
63 {
64  boost::program_options::options_description command_line_options;
65  command_line_options.add_options()
66  ("input-file", boost::program_options::value< std::vector<std::string> >(),
67  "input files in ki2 format (.ki2)")
68  ("verbose,v", "Verbose mode")
69  ("help,h", "Show this help message");
70  boost::program_options::positional_options_description p;
71  p.add("input-file", -1);
72 
73  try
74  {
76  boost::program_options::command_line_parser(
77  argc, argv).options(command_line_options).positional(p).run(), vm);
78  boost::program_options::notify(vm);
79  if (vm.count("help"))
80  {
81  std::cout << "Usage: " << argv[0] << " [options] ki2-file [ki2-file...]\n";
82  std::cout << " " << argv[0] << " [options]\n";
83  std::cout << command_line_options << std::endl;
84  return 0;
85  }
86  }
87  catch (std::exception &e)
88  {
89  std::cerr << "error in parsing options" << std::endl
90  << e.what() << std::endl;
91  std::cerr << "Usage: " << argv[0] << " [options] ki2-file [ki2-file...]\n";
92  std::cerr << " " << argv[0] << " [options]\n";
93  std::cerr << command_line_options << std::endl;
94  return 1;
95  }
96 
97  std::vector<std::string> files;
98  if (vm.count("input-file"))
99  {
100  const std::vector<std::string> temp = vm["input-file"].as<std::vector<std::string> >();
101  files.insert(files.end(), temp.begin(), temp.end());
102  }
103  else
104  {
105  std::string line;
106  while(std::getline(std::cin , line))
107  {
108  boost::algorithm::trim(line);
109  files.push_back(line);
110  }
111  }
112 
113  // main
114  std::for_each(files.begin(), files.end(), bind(&process, _1));
115 
116  check_duplicate.print(std::cout);
117 
118  return 0;
119 }
120 // ;;; Local Variables:
121 // ;;; mode:c++
122 // ;;; c-basic-offset:2
123 // ;;; End: