10 #include <boost/program_options.hpp> 
   11 #include <boost/lambda/lambda.hpp> 
   12 #include <boost/lambda/bind.hpp> 
   21 namespace po = boost::program_options;
 
   27 void run(
const std::string& filename);
 
   29 int main(
int argc, 
char **argv)
 
   31   boost::program_options::options_description command_line_options;
 
   32   command_line_options.add_options()
 
   33     (
"header,h", boost::program_options::value<std::string>(&
header)->default_value(
""),
 
   34      "header for kifu-file")
 
   35     (
"input-file", boost::program_options::value< std::vector<std::string> >(),
 
   36      "input files in csa format (.csa)")
 
   37     (
"help,h", 
"Show help message");
 
   38   boost::program_options::variables_map 
vm;
 
   39   boost::program_options::positional_options_description p;
 
   40   p.add(
"input-file", -1);
 
   45       boost::program_options::command_line_parser(
 
   46         argc, argv).options(command_line_options).positional(p).
run(), vm);
 
   47     boost::program_options::notify(vm);
 
   48     files = vm[
"input-file"].as< std::vector<std::string> >();
 
   51       std::cout << command_line_options << std::endl;
 
   55   catch (std::exception &e)
 
   57     std::cerr << 
"error in parsing options" << std::endl
 
   58               << e.what() << std::endl;
 
   59     std::cerr << command_line_options << std::endl;
 
   65     for (
size_t i=0; i<
files.size(); ++i)
 
   75 void run(
const std::string& filename)
 
   78     std::ifstream is(
header.c_str()); 
 
   80     while (std::getline(is, line))
 
   81       std::cout << line << 
"\n";
 
   89     CsaFile file(filename.c_str());
 
   93     vector<record::SearchInfo> search_info;
 
   94     vector<std::string> raw_comments;
 
   95     record.getMoves(moves, time, raw_comments, search_info);
 
   97     NumEffectState state(file.getInitialState());
 
   98     CArray<int,2> total = {{0,0}};
 
   99     for (
size_t i=0; i<moves.size(); ++i) {
 
  100       if (! moves[i].isNormal() || ! state.isValidMove(moves[i]))
 
  102       const Square to = moves[i].to();
 
  103       std::ostringstream ss;
 
  104       ss << std::setw(4) << std::setfill(
' ') << i+1 << 
' ' 
  108       if (moves[i].isPromotion())
 
  110       const Square from = moves[i].from();
 
  114         ss << 
"(" << from.
x() << from.
y() << 
")";
 
  116       if (time.size() > i) {
 
  117         total[i%2] += time[i];
 
  118         ss << 
"(" << std::setw(2) << std::setfill(
' ') << time[i]/60
 
  119            << 
':' << std::setw(2) << std::setfill(
'0') << time[i]%60
 
  120            << 
"/" << std::setw(2) << total[i%2]/60/60
 
  121            << 
':' << std::setw(2) << total[i%2]/60%60
 
  122            << 
':' << std::setw(2) << total[i%2]%60
 
  127       state.makeMove(moves[i]); 
 
  129       if (search_info.size() > i && ! search_info[i].moves.empty()) {
 
  131            << search_info[i].value << 
" ";
 
  132         NumEffectState copy(state);
 
  133         for (
size_t j=0; j<search_info[i].moves.size(); ++j) {
 
  134           const Move move = search_info[i].moves[j];
 
  136               || (! move.
isPass() && ! copy.isValidMove(move)))
 
  146   catch (CsaIOError&) {
 
  147     std::cerr << 
"parse error\n";