00001
00002 #include "ug_splice_arglist.h"
00003 #include "moses/Util.h"
00004 #include "util/exception.hh"
00005 #include <boost/foreach.hpp>
00006
00007 namespace Moses {
00008
00009 void
00010 filter_arguments(int const argc_in, char const* const* const argv_in,
00011 int & argc_moses, char*** argv_moses,
00012 int & argc_other, char*** argv_other,
00013 std::vector<std::pair<std::string,int> > const& filter)
00014 {
00015 *argv_moses = new char*[argc_in];
00016 *argv_other = new char*[argc_in];
00017 (*argv_moses)[0] = new char[strlen(argv_in[0])+1];
00018 strcpy((*argv_moses)[0], argv_in[0]);
00019 argc_moses = 1;
00020 argc_other = 0;
00021 typedef std::pair<std::string,int> option;
00022 int i = 1;
00023 while (i < argc_in)
00024 {
00025 BOOST_FOREACH(option const& o, filter)
00026 {
00027 if (o.first == argv_in[i])
00028 {
00029 (*argv_other)[argc_other] = new char[strlen(argv_in[i])+1];
00030 strcpy((*argv_other)[argc_other++],argv_in[i]);
00031 for (int k = 0; k < o.second; ++k)
00032 {
00033 UTIL_THROW_IF2(++i >= argc_in || argv_in[i][0] == '-',
00034 "[" << HERE << "] Missing argument for "
00035 << "parameter " << o.first << "!");
00036 (*argv_other)[argc_other] = new char[strlen(argv_in[i])+1];
00037 strcpy((*argv_other)[argc_other++],argv_in[i]);
00038 }
00039 if (++i >= argc_in) break;
00040 }
00041 }
00042 if (i >= argc_in) break;
00043 (*argv_moses)[argc_moses] = new char[strlen(argv_in[i])+1];
00044 strcpy((*argv_moses)[argc_moses++], argv_in[i++]);
00045 }
00046 }
00047
00048 }
00049
00050