All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
unique-csa.cc
Go to the documentation of this file.
2 #include "osl/record/csaRecord.h"
4 #include <boost/algorithm/string/trim.hpp>
5 #include <boost/foreach.hpp>
6 #include <boost/program_options.hpp>
7 #include <iostream>
8 #include <string>
9 #include <vector>
10 
15 bool readFile(const std::string& csa_file,
16  osl::record::CheckDuplicate& duplicates)
17 {
18  const osl::record::csa::CsaFile csa(csa_file);
19  const osl::record::Record& record = csa.getRecord();
20  const osl::vector<osl::Move> moves = record.getMoves();
21 
22  return !duplicates.regist(moves);
23 }
24 
25 
26 int main(int argc, char **argv)
27 {
28  namespace bp = boost::program_options;
29 
30  bp::options_description command_line_options;
31  command_line_options.add_options()
32  ("input-file", bp::value<std::vector<std::string> >(),
33  "input files in the CSA format")
34  ("help", "Show help message");
35  bp::variables_map vm;
36  bp::positional_options_description p;
37  p.add("input-file", -1);
38 
39  try {
40  bp::store(
41  bp::command_line_parser(argc, argv).options(command_line_options).positional(p).run(), vm);
42  bp::notify(vm);
43  if (vm.count("help")) {
44  std::cerr << "Filter duplicated records from specified CSA files.\n";
45  std::cerr << "Usage: " << argv[0] << " [options] csa-file [...]\n";
46  std::cerr << " " << argv[0] << " [options]\n";
47  std::cout << command_line_options << std::endl;
48  return 0;
49  }
50  } catch (std::exception &e) {
51  std::cerr << "error in parsing options" << std::endl
52  << e.what() << std::endl;
53  std::cerr << "Filter duplicated records from specified CSA files.\n";
54  std::cerr << "Usage: " << argv[0] << " [options] csa-file [...]\n";
55  std::cerr << " " << argv[0] << " [options]\n";
56  std::cerr << command_line_options << std::endl;
57  return 1;
58  }
59 
60  std::vector<std::string> files;
61  if (vm.count("input-file")) {
62  const std::vector<std::string> temp = vm["input-file"].as<std::vector<std::string> >();
63  files.insert(files.end(), temp.begin(), temp.end());
64  } else {
65  std::string line;
66  while(std::getline(std::cin , line)) {
67  boost::algorithm::trim(line);
68  files.push_back(line);
69  }
70  }
71 
73 
74  BOOST_FOREACH(const std::string& file, files) {
75  if (readFile(file, check_duplicate))
76  std::cout << file << std::endl;
77  }
78 
79  check_duplicate.print(std::cerr);
80 
81  return 0;
82 }
83 
84 /* vim: set ts=2 sw=2 ft=cpp : */
85 // ;;; Local Variables:
86 // ;;; mode:c++
87 // ;;; c-basic-offset:2