diff options
Diffstat (limited to 'src/libmain')
-rw-r--r-- | src/libmain/shared.cc | 39 | ||||
-rw-r--r-- | src/libmain/shared.hh | 9 |
2 files changed, 34 insertions, 14 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 632794db3d8d..b99a74bb4027 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -23,31 +23,42 @@ static void initAndRun(int argc, char * * argv) nixDBPath = (string) NIX_STATE_DIR + "/db"; /* Put the arguments in a vector. */ - Strings args; + Strings args, remaining; while (argc--) args.push_back(*argv++); args.erase(args.begin()); /* Expand compound dash options (i.e., `-qlf' -> `-q -l -f'), and ignore options for the ATerm library. */ - for (Strings::iterator it = args.begin(); - it != args.end(); ) - { - string arg = *it; - if (string(arg, 0, 4) == "-at-") - it = args.erase(it); + for (Strings::iterator i = args.begin(); i != args.end(); ++i) { + string arg = *i; + if (string(arg, 0, 4) == "-at-") ; else if (arg.length() > 2 && arg[0] == '-' && arg[1] != '-') { - for (unsigned int i = 1; i < arg.length(); i++) - if (isalpha(arg[i])) - args.insert(it, (string) "-" + arg[i]); + for (unsigned int j = 1; j < arg.length(); j++) + if (isalpha(arg[j])) + remaining.push_back((string) "-" + arg[j]); else { - args.insert(it, string(arg, i)); + remaining.push_back(string(arg, j)); break; } - it = args.erase(it); - } else it++; + } else remaining.push_back(arg); } + args = remaining; + remaining.clear(); - run(args); + /* Process default options. */ + for (Strings::iterator i = args.begin(); i != args.end(); ++i) { + string arg = *i; + if (arg == "--verbose" || arg == "-v") + verbosity = (Verbosity) ((int) verbosity + 1); + else if (arg == "--help") { + printHelp(); + return; + } else if (arg == "--keep-failed" || arg == "-K") + keepFailed = true; + else remaining.push_back(arg); + } + + run(remaining); } diff --git a/src/libmain/shared.hh b/src/libmain/shared.hh index 8ea637fd21ac..76b639e3785d 100644 --- a/src/libmain/shared.hh +++ b/src/libmain/shared.hh @@ -6,8 +6,17 @@ #include "util.hh" +/* These are not implemented here, but must be implemented by a + program linking against libmain. */ + +/* Main program. Called by main() after the ATerm library has been + initialised and some default arguments have been processed (and + removed from `args'). main() will catch all exceptions. */ void run(Strings args); +/* Should print a help message to stdout and return. */ +void printHelp(); + extern string programId; |