show-ki2.cc
Go to the documentation of this file.
00001 /* show-ki2.cc
00002  */
00003 
00004 #include "osl/record/kanjiMove.h"
00005 #include "osl/record/ki2.h"
00006 #include <boost/program_options.hpp>
00007 #include <boost/lambda/lambda.hpp>
00008 #include <boost/lambda/bind.hpp>
00009 #include <iostream>
00010 #include <fstream>
00011 #include <string>
00012 #include <vector>
00013 #include <algorithm>
00014 
00015 using namespace boost::lambda;
00016 
00017 bool quiet = false;
00018 
00019 void process( const std::string& file_name)
00020 {
00021   std::cout << "Processing... " << file_name << std::endl;
00022   osl::Ki2File ki2(file_name, !quiet);
00023   if (quiet)
00024     return;
00025 
00026   const osl::Record record = ki2.getRecord();
00027   const osl::stl::vector<osl::Move> moves = record.getMoves();
00028   std::for_each(moves.begin(), moves.end(),
00029                 std::cout << _1 << "\n"  );
00030 }
00031 
00039 int main(int argc, char **argv)
00040 {
00041   boost::program_options::options_description command_line_options;
00042   command_line_options.add_options()
00043     ("quiet,q", "quiet output")
00044     ("input-file", boost::program_options::value< std::vector<std::string> >(),
00045      "input files in ki2 format (.ki2)")
00046     ("help,h", "Show help message");
00047   boost::program_options::variables_map vm;
00048   boost::program_options::positional_options_description p;
00049   p.add("input-file", -1);
00050 
00051   try
00052   {
00053     boost::program_options::store(
00054       boost::program_options::command_line_parser(
00055         argc, argv).options(command_line_options).positional(p).run(), vm);
00056     boost::program_options::notify(vm);
00057     if (vm.count("help"))
00058     {
00059       std::cout << 
00060         "Usage: " << argv[0] << " [options] ki2-file [ki2-file...]"
00061                   << std::endl;
00062       std::cout << command_line_options << std::endl;
00063       return 0;
00064     }
00065     if (vm.count("quiet"))
00066       quiet = true;
00067   }
00068   catch (std::exception &e)
00069   {
00070     std::cerr << "error in parsing options" << std::endl
00071               << e.what() << std::endl;
00072     std::cerr << 
00073         "Usage: " << argv[0] << " [options] ki2-file [ki2-file...]"
00074                   << std::endl;
00075     std::cerr << command_line_options << std::endl;
00076     return 1;
00077   }
00078 
00079   const std::vector<std::string> files =
00080     vm["input-file"].as< std::vector<std::string> >();
00081   std::for_each(files.begin(), files.end(), bind(&process, _1));
00082 
00083   return 0;
00084 }
00085 // ;;; Local Variables:
00086 // ;;; mode:c++
00087 // ;;; c-basic-offset:2
00088 // ;;; End:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines