mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-08-16 23:10:31 +03:00
Enforce const-ness of command line arguments; bug fix in mosesserver.cpp.
This commit is contained in:
parent
d727829387
commit
9826599cb0
@ -10,21 +10,20 @@
|
||||
// The future is this:
|
||||
|
||||
/** main function of the command line version of the decoder **/
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char const** argv)
|
||||
{
|
||||
// Map double-dash long options back to single-dash long options
|
||||
// as used in legacy moses.
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
char* a = argv[i];
|
||||
if (a[0] == '-' && a[1] == '-')
|
||||
for (size_t k = 1; (a[k] = a[k+1]); ++k);
|
||||
if (argv[i][0] == '-' && argv[i][1] == '-')
|
||||
++argv[i];
|
||||
}
|
||||
char const* argv2[argc+1];
|
||||
for (int i = 1; i < argc; ++i)
|
||||
for (int i = 0; i < argc; ++i)
|
||||
argv2[i] = argv[i];
|
||||
argv2[argc] = "server";
|
||||
return decoder_main(argc, argv);
|
||||
argv2[argc] = "--server";
|
||||
return decoder_main(argc+1, argv2);
|
||||
}
|
||||
#else
|
||||
|
||||
|
@ -53,7 +53,7 @@ using namespace std;
|
||||
namespace po = boost::program_options;
|
||||
typedef multimap<float,string> Lines;
|
||||
|
||||
static void usage(const po::options_description& desc, char** argv)
|
||||
static void usage(const po::options_description& desc, char const** argv)
|
||||
{
|
||||
cerr << "Usage: " + string(argv[0]) + " [options] input-file output-file" << endl;
|
||||
cerr << desc << endl;
|
||||
@ -94,7 +94,7 @@ static void outputTopN(const Phrase& sourcePhrase, const multimap<float,const Ta
|
||||
out << endl;
|
||||
}
|
||||
}*/
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char const** argv)
|
||||
{
|
||||
bool help;
|
||||
string input_file;
|
||||
@ -138,10 +138,11 @@ int main(int argc, char** argv)
|
||||
mosesargs.push_back(config_file);
|
||||
|
||||
boost::scoped_ptr<Parameter> params(new Parameter());
|
||||
char** mosesargv = new char*[mosesargs.size()];
|
||||
char const** mosesargv = new char const*[mosesargs.size()];
|
||||
for (size_t i = 0; i < mosesargs.size(); ++i) {
|
||||
mosesargv[i] = new char[mosesargs[i].length() + 1];
|
||||
strcpy(mosesargv[i], mosesargs[i].c_str());
|
||||
mosesargv[i] = mosesargs[i].c_str();
|
||||
// mosesargv[i] = new char[mosesargs[i].length() + 1];
|
||||
// strcpy(mosesargv[i], mosesargs[i].c_str());
|
||||
}
|
||||
|
||||
if (!params->LoadParam(mosesargs.size(), mosesargv)) {
|
||||
|
@ -76,8 +76,8 @@ public:
|
||||
}
|
||||
|
||||
/** Parse the arguments, removing those that define the grid and returning a copy of the rest */
|
||||
void parseArgs(int& argc, char**& argv) {
|
||||
char** newargv = new char*[argc+1]; //Space to add mbr parameter
|
||||
void parseArgs(int& argc, char const**& argv) {
|
||||
char const** newargv = new char const*[argc+1]; //Space to add mbr parameter
|
||||
int newargc = 0;
|
||||
for (int i = 0; i < argc; ++i) {
|
||||
bool consumed = false;
|
||||
@ -113,8 +113,9 @@ public:
|
||||
}
|
||||
}
|
||||
if (!consumed) {
|
||||
newargv[newargc] = new char[strlen(argv[i]) + 1];
|
||||
strcpy(newargv[newargc],argv[i]);
|
||||
// newargv[newargc] = new char[strlen(argv[i]) + 1];
|
||||
// strcpy(newargv[newargc],argv[i]);
|
||||
newargv[newargc] = argv[i];
|
||||
++newargc;
|
||||
}
|
||||
}
|
||||
@ -137,7 +138,7 @@ private:
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char const* argv[])
|
||||
{
|
||||
cerr << "Lattice MBR Grid search" << endl;
|
||||
|
||||
|
@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#include "util/string_stream.hh"
|
||||
|
||||
/** main function of the command line version of the decoder **/
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char const** argv)
|
||||
{
|
||||
return decoder_main(argc, argv);
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ void OutputFeatureWeightsForHypergraph(std::ostream &outputSearchGraphStream)
|
||||
} //namespace
|
||||
|
||||
/** main function of the command line version of the decoder **/
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char const** argv)
|
||||
{
|
||||
try {
|
||||
|
||||
|
@ -289,7 +289,7 @@ batch_run()
|
||||
}
|
||||
|
||||
/** Called by main function of the command line version of the decoder **/
|
||||
int decoder_main(int argc, char** argv)
|
||||
int decoder_main(int argc, char const** argv)
|
||||
{
|
||||
#ifdef NDEBUG
|
||||
try
|
||||
|
@ -55,5 +55,5 @@ private:
|
||||
const Moses::StaticData& m_staticData;
|
||||
};
|
||||
|
||||
int decoder_main(int argc, char* argv[]);
|
||||
int decoder_main(int argc, char const* argv[]);
|
||||
|
||||
|
@ -444,17 +444,17 @@ Parameter::
|
||||
LoadParam(const string &filePath)
|
||||
{
|
||||
const char *argv[] = {"executable", "-f", filePath.c_str() };
|
||||
return LoadParam(3, (char**) argv);
|
||||
return LoadParam(3, (char const**) argv);
|
||||
}
|
||||
|
||||
/** load all parameters from the configuration file and the command line switches */
|
||||
bool
|
||||
Parameter::
|
||||
LoadParam(int argc, char* xargv[])
|
||||
LoadParam(int argc, char const* xargv[])
|
||||
{
|
||||
// legacy parameter handling: all parameters are expected
|
||||
// to start with a single dash
|
||||
char* argv[argc+1];
|
||||
char const* argv[argc+1];
|
||||
for (int i = 0; i < argc; ++i) {
|
||||
argv[i] = xargv[i];
|
||||
if (strlen(argv[i]) > 2 && argv[i][0] == '-' && argv[i][1] == '-')
|
||||
@ -1330,7 +1330,7 @@ FilesExist(const string ¶mName, int fieldNo,
|
||||
// in moses-cmd
|
||||
string
|
||||
Parameter::
|
||||
FindParam(const string ¶mSwitch, int argc, char* argv[])
|
||||
FindParam(const string ¶mSwitch, int argc, char const* argv[])
|
||||
{
|
||||
for (int i = 0 ; i < argc ; i++) {
|
||||
if (string(argv[i]) == paramSwitch) {
|
||||
@ -1352,7 +1352,8 @@ FindParam(const string ¶mSwitch, int argc, char* argv[])
|
||||
* \param argv values of paramters on command line */
|
||||
void
|
||||
Parameter::
|
||||
OverwriteParam(const string ¶mSwitch, const string ¶mName, int argc, char* argv[])
|
||||
OverwriteParam(const string ¶mSwitch, const string ¶mName,
|
||||
int argc, char const* argv[])
|
||||
{
|
||||
int startPos = -1;
|
||||
for (int i = 0 ; i < argc ; i++) {
|
||||
|
@ -57,8 +57,9 @@ protected:
|
||||
|
||||
std::map<std::string, std::vector<float> > m_weights;
|
||||
|
||||
std::string FindParam(const std::string ¶mSwitch, int argc, char* argv[]);
|
||||
void OverwriteParam(const std::string ¶mSwitch, const std::string ¶mName, int argc, char* argv[]);
|
||||
std::string FindParam(const std::string ¶mSwitch, int argc, char const* argv[]);
|
||||
void OverwriteParam(const std::string ¶mSwitch, const std::string ¶mName,
|
||||
int argc, char const* argv[]);
|
||||
bool ReadConfigFile(const std::string &filePath );
|
||||
bool FilesExist(const std::string ¶mName, int fieldNo, std::vector<std::string> const& fileExtension=std::vector<std::string>(1,""));
|
||||
bool isOption(const char* token);
|
||||
@ -113,7 +114,7 @@ protected:
|
||||
public:
|
||||
Parameter();
|
||||
~Parameter();
|
||||
bool LoadParam(int argc, char* argv[]);
|
||||
bool LoadParam(int argc, char const* argv[]);
|
||||
bool LoadParam(const std::string &filePath);
|
||||
void Explain();
|
||||
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
int main(int argc, char const* argv[])
|
||||
{
|
||||
Parameter params;
|
||||
if (!params.LoadParam(argc,argv) || !StaticData::LoadDataStatic(¶ms, argv[0]))
|
||||
|
Loading…
Reference in New Issue
Block a user