show-ki2.cc Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
show-ki2.cc
Go to the documentation of this file.
1 /* show-ki2.cc
2 */
3
4 #include "osl/record/kanjiMove.h"
5 #include "osl/record/ki2.h"
6 #include <boost/program_options.hpp>
7 #include <boost/lambda/lambda.hpp>
8 #include <boost/lambda/bind.hpp>
9 #include <iostream>
10 #include <fstream>
11 #include <string>
12 #include <vector>
13 #include <algorithm>
14
15 using namespace boost::lambda;
16
17 bool quiet = false;
18
19 void process( const std::string& file_name)
20 {
21 std::cout << "Processing... " << file_name << std::endl;
22 osl::Ki2File ki2(file_name, !quiet);
23 if (quiet)
24 return;
25
26 const osl::Record record = ki2.getRecord();
27 const osl::stl::vector<osl::Move> moves = record.getMoves();
28 std::for_each(moves.begin(), moves.end(),
29 std::cout << _1 << "\n" );
30 }
31
39 int main(int argc, char **argv)
40 {
41 boost::program_options::options_description command_line_options;
42 command_line_options.add_options()
43 ("quiet,q", "quiet output")
44 ("input-file", boost::program_options::value< std::vector<std::string> >(),
45 "input files in ki2 format (.ki2)")
46 ("help,h", "Show help message");
47 boost::program_options::variables_map vm;
48 boost::program_options::positional_options_description p;
49 p.add("input-file", -1);
50
51 try
52 {
53 boost::program_options::store(
54 boost::program_options::command_line_parser(
55 argc, argv).options(command_line_options).positional(p).run(), vm);
56 boost::program_options::notify(vm);
57 if (vm.count("help"))
58 {
59 std::cout <<
60 "Usage: " << argv[0] << " [options] ki2-file [ki2-file...]"
61 << std::endl;
62 std::cout << command_line_options << std::endl;
63 return 0;
64 }
65 if (vm.count("quiet"))
66 quiet = true;
67 }
68 catch (std::exception &e)
69 {
70 std::cerr << "error in parsing options" << std::endl
71 << e.what() << std::endl;
72 std::cerr <<
73 "Usage: " << argv[0] << " [options] ki2-file [ki2-file...]"
74 << std::endl;
75 std::cerr << command_line_options << std::endl;
76 return 1;
77 }
78
79 const std::vector<std::string> files =
80 vm["input-file"].as< std::vector<std::string> >();
81 std::for_each(files.begin(), files.end(), bind(&process, _1));
82
83 return 0;
84 }
85 // ;;; Local Variables:
86 // ;;; mode:c++
87 // ;;; c-basic-offset:2
88 // ;;; End: