Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ug_splice_arglist.cc « program_options « generic « UG « TranslationModel « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7dc2cd18f0b423617d4b836e1f56528129287615 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//-*- c++ -*-
#include "ug_splice_arglist.h"
#include "moses/Util.h"
#include "util/exception.hh"
#include <boost/foreach.hpp>

namespace Moses {
  
  void 
  filter_arguments(int const argc_in, char const* const* const argv_in,
		   int & argc_moses, char*** argv_moses,  
		   int & argc_other, char*** argv_other,
		   vector<pair<string,int> > const& filter)
  {
    *argv_moses = new char*[argc_in];
    *argv_other = new char*[argc_in]; 
    (*argv_moses)[0] = new char[strlen(argv_in[0])+1];
    strcpy((*argv_moses)[0], argv_in[0]);
    argc_moses = 1;
    argc_other = 0;
    typedef pair<string,int> option;
    int i = 1;
    while (i < argc_in)
      {
	BOOST_FOREACH(option const& o, filter)
	  {
	    if (o.first == argv_in[i])
	      {
		(*argv_other)[argc_other] = new char[strlen(argv_in[i])+1];
		strcpy((*argv_other)[argc_other++],argv_in[i]);
		for (int k = 0; k < o.second; ++k)
		{
		  UTIL_THROW_IF2(++i >= argc_in || argv_in[i][0] == '-', 
				 "[" << HERE << "] Missing argument for "
				 << "parameter " << o.first << "!");
		  (*argv_other)[argc_other] = new char[strlen(argv_in[i])+1];
		  strcpy((*argv_other)[argc_other++],argv_in[i]);
		}
		if (++i >= argc_in) break;
	      }
	  }
	if (i >= argc_in) break;
	(*argv_moses)[argc_moses] = new char[strlen(argv_in[i])+1];
	strcpy((*argv_moses)[argc_moses++], argv_in[i++]);
      }
  }
  
} // namespace Moses