]> git.tdb.fi Git - builder.git/commitdiff
Convert to the rewritten getopt++
authorMikko Rasa <tdb@tdb.fi>
Fri, 24 Nov 2006 14:49:44 +0000 (14:49 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 24 Nov 2006 14:49:44 +0000 (14:49 +0000)
source/builder.cpp
source/builder.h

index 8ac06f6b6133caf82924a03ccb5f69256661297a..8cb836abed682b9b49bf5541bc11f83f8f2b9ec3 100644 (file)
@@ -29,84 +29,72 @@ using namespace Msp;
 
 Builder::Builder(int argc, char **argv):
        analyzer(0),
-       do_build(true),
+       do_build(false),
        verbose(1),
        chrome(false),
        build_file("Build"),
        jobs(1)
 {
+       string   analyze_mode;
+       string   work_dir;
+       bool     full_paths=false;
+       unsigned max_depth=5;
+       
        GetOpt getopt;
-       getopt.add_option(GetOpt::Option('a', "analyze", GetOpt::REQUIRED));
-       getopt.add_option(GetOpt::Option('b', "build", GetOpt::NONE));
-       getopt.add_option(GetOpt::Option('c', "clean", GetOpt::NONE));
-       getopt.add_option(GetOpt::Option('f', "file", GetOpt::REQUIRED, "Build"));
-       getopt.add_option(GetOpt::Option('h', "help", GetOpt::NONE));
-       getopt.add_option(GetOpt::Option('j', "jobs", GetOpt::REQUIRED, "1"));
-       getopt.add_option(GetOpt::Option('n', "dry-run", GetOpt::NONE));
-       getopt.add_option(GetOpt::Option('v', "verbose", GetOpt::NONE));
-       getopt.add_option(GetOpt::Option('A', "conf-all", GetOpt::NONE));
-       getopt.add_option(GetOpt::Option('B', "build-all", GetOpt::NONE));
-       getopt.add_option(GetOpt::Option('C', "chdir", GetOpt::REQUIRED));
-       getopt.add_option(GetOpt::Option('W', "what-if", GetOpt::REQUIRED));
-       getopt.add_option(GetOpt::Option("chrome", GetOpt::NONE));
-       getopt.add_option(GetOpt::Option("conf-only", GetOpt::NONE));
-       getopt.add_option(GetOpt::Option("full-paths", GetOpt::NONE));
-       getopt.add_option(GetOpt::Option("max-depth", GetOpt::REQUIRED));
-       int index=getopt(argc, argv);
-
-       verbose+=getopt['v'].count();
-
-       if(getopt['a'])
+       getopt.add_option('a', "analyze",    analyze_mode, GetOpt::REQUIRED_ARG);
+       getopt.add_option('b', "build",      do_build,     GetOpt::NO_ARG);
+//     getopt.add_option('c', "clean",      clean,        GetOpt::NO_ARG);
+       getopt.add_option('f', "file",       build_file,   GetOpt::REQUIRED_ARG);
+       getopt.add_option('h', "help",       help,         GetOpt::NO_ARG);
+       getopt.add_option('j', "jobs",       jobs,         GetOpt::REQUIRED_ARG);
+       getopt.add_option('n', "dry-run",    dry_run,      GetOpt::NO_ARG);
+       getopt.add_option('v', "verbose",    verbose,      GetOpt::NO_ARG);
+       getopt.add_option('A', "conf-all",   conf_all,     GetOpt::NO_ARG);
+       getopt.add_option('B', "build-all",  build_all,    GetOpt::NO_ARG);
+       getopt.add_option('C', "chdir",      work_dir,     GetOpt::REQUIRED_ARG);
+       getopt.add_option('W', "what-if",    what_if,      GetOpt::REQUIRED_ARG);
+       getopt.add_option(     "chrome",     chrome,       GetOpt::NO_ARG);
+       getopt.add_option(     "conf-only",  conf_only,    GetOpt::NO_ARG);
+       getopt.add_option(     "full-paths", full_paths,   GetOpt::NO_ARG);
+       getopt.add_option(     "max-depth",  max_depth,    GetOpt::REQUIRED_ARG);
+       getopt(argc, argv);
+
+       if(!analyze_mode.empty())
        {
                analyzer=new Analyzer(*this);
 
-               string mode=getopt['a'].arg();
-               if(mode=="deps")
+               if(analyze_mode=="deps")
                        analyzer->set_mode(Analyzer::DEPS);
-               else if(mode=="alldeps")
+               else if(analyze_mode=="alldeps")
                        analyzer->set_mode(Analyzer::ALLDEPS);
-               else if(mode=="rebuild")
+               else if(analyze_mode=="rebuild")
                        analyzer->set_mode(Analyzer::REBUILD);
-               else if(mode=="rdeps")
+               else if(analyze_mode=="rdeps")
                        analyzer->set_mode(Analyzer::RDEPS);
                else
-                       throw UsageError("Invalid analysis mode");
-
-               if(getopt["max-depth"])
-                       analyzer->set_max_depth(strtol(getopt["max-depth"].arg()));
-               analyzer->set_full_paths(getopt["full-paths"]);
+                       throw UsageError("Invalid analyze mode");
 
-               if(!getopt['b'])
-                       do_build=false;
+               analyzer->set_max_depth(max_depth);
+               analyzer->set_full_paths(full_paths);
        }
+       else
+               do_build=true;
 
-       dry_run=getopt['n'];
-       jobs=max(strtol(getopt['j'].arg()), 1L);
-       chrome=getopt["chrome"];
-       conf_all=getopt['A'];
-       conf_only=getopt["conf-only"];
-       build_file=getopt['f'].arg();
-       build_all=getopt['B'];
-       help=getopt['h'];
-
-       if(getopt['C'])
-               chdir(getopt['C'].arg().c_str());
-
-       for(int i=index; i<argc; ++i)
+       const list<string> &args=getopt.get_args();
+       for(list<string>::const_iterator i=args.begin(); i!=args.end(); ++i)
        {
-               string v(argv[i]);
-               unsigned equal=v.find('=');
+               unsigned equal=i->find('=');
                if(equal!=string::npos)
-                       cmdline_options.insert(RawOptionMap::value_type(v.substr(0, equal), v.substr(equal+1)));
+                       cmdline_options.insert(RawOptionMap::value_type(i->substr(0, equal), i->substr(equal+1)));
                else
-                       cmdline_targets.push_back(argv[i]);
+                       cmdline_targets.push_back(*i);
        }
 
        if(cmdline_targets.empty())
                cmdline_targets.push_back("default");
 
-       if(getopt['W'])
-               what_if.push_back(getopt['W'].arg());
+       if(!work_dir.empty())
+               chdir(work_dir.c_str());
 
        cwd=Path::getcwd();
 }
index 074b6d14536d2bef723ec4d4ea8e6e9d7540ddcc..830d356b28959c1d35e22c5eedbc1959256f7d5f 100644 (file)
@@ -71,7 +71,7 @@ private:
        bool            help;
        unsigned        verbose;
        bool            chrome;
-       Msp::Path::Path build_file;
+       std::string     build_file;
        unsigned        jobs;
        StringList      what_if;
        bool            conf_all;