From 26e01ebe90de42d540b6f22ed1a0a276282c0bfc Mon Sep 17 00:00:00 2001 From: Ralf Gerlich Date: Sun, 16 Dec 2007 10:12:14 +0100 Subject: [PATCH] Added commandline parser to terrafit.cc --- src/Prep/TerraFit/terrafit.cc | 49 ++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/Prep/TerraFit/terrafit.cc b/src/Prep/TerraFit/terrafit.cc index 4005951c..3e9c8382 100644 --- a/src/Prep/TerraFit/terrafit.cc +++ b/src/Prep/TerraFit/terrafit.cc @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include #include #include @@ -198,8 +200,8 @@ void walk_path(const std::string& path) { } } -void usage(char* progname, char* msg) { - if (msg!=NULL) +void usage(char* progname, const std::string& msg) { + if (msg.size()!=0) SG_LOG(SG_GENERAL,SG_ALERT, msg); SG_LOG(SG_GENERAL,SG_INFO, "Usage: " << progname << " [options] "); SG_LOG(SG_GENERAL,SG_INFO, "\t -h | --help "); @@ -228,8 +230,49 @@ void usage(char* progname, char* msg) { SG_LOG(SG_GENERAL,SG_INFO, ".fit.gz file will need to retriangulate the surface."); } +struct option options[]={ + {"help",no_argument,NULL,'h'}, + {"minnodes",required_argument,NULL,'m'}, + {"maxnodes",required_argument,NULL,'x'}, + {"maxerror",required_argument,NULL,'e'}, + {"version",no_argument,NULL,'v'}, + {NULL,0,NULL,0} +}; + int main(int argc, char** argv) { sglog().setLogLevels( SG_ALL, SG_DEBUG ); - walk_path(argv[1]); // FIXME: parse options + int option; + + while ((option=getopt_long(argc,argv,"",options,NULL))!=-1) { + switch (option) { + case 'h': + usage(argv[0],""); + break; + case 'm': + min_points=atoi(optarg); + break; + case 'x': + point_limit=atoi(optarg); + break; + case 'e': + error_threshold=atof(optarg); + break; + case 'v': + SG_LOG(SG_GENERAL,SG_INFO,argv[0] << " Version 1.0"); + exit(0); + break; + case '?': + usage(argv[0],std::string("Unknown option:")+(char)optopt); + exit(1); + } + } + if (optind