2003-07-04 15:42:03 +00:00
|
|
|
#include <iostream>
|
2003-07-24 08:53:43 +00:00
|
|
|
#include <cctype>
|
2003-07-04 15:42:03 +00:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <aterm2.h>
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "globals.hh"
|
|
|
|
#include "shared.hh"
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize and reorder arguments, then call the actual argument
|
|
|
|
processor. */
|
|
|
|
static void initAndRun(int argc, char * * argv)
|
|
|
|
{
|
|
|
|
/* Setup Nix paths. */
|
|
|
|
nixStore = NIX_STORE_DIR;
|
2003-07-10 13:41:28 +00:00
|
|
|
nixDataDir = NIX_DATA_DIR;
|
2003-07-04 15:42:03 +00:00
|
|
|
nixLogDir = NIX_LOG_DIR;
|
2003-11-19 17:27:16 +00:00
|
|
|
nixStateDir = (string) NIX_STATE_DIR;
|
2003-07-31 13:47:13 +00:00
|
|
|
nixDBPath = (string) NIX_STATE_DIR + "/db";
|
2003-07-04 15:42:03 +00:00
|
|
|
|
|
|
|
/* Put the arguments in a vector. */
|
2003-12-01 15:55:05 +00:00
|
|
|
Strings args, remaining;
|
2003-07-04 15:42:03 +00:00
|
|
|
while (argc--) args.push_back(*argv++);
|
|
|
|
args.erase(args.begin());
|
|
|
|
|
2003-11-03 18:21:53 +00:00
|
|
|
/* Expand compound dash options (i.e., `-qlf' -> `-q -l -f'), and
|
|
|
|
ignore options for the ATerm library. */
|
2003-12-01 15:55:05 +00:00
|
|
|
for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
|
|
|
|
string arg = *i;
|
|
|
|
if (string(arg, 0, 4) == "-at-") ;
|
2003-11-03 18:21:53 +00:00
|
|
|
else if (arg.length() > 2 && arg[0] == '-' && arg[1] != '-') {
|
2003-12-01 15:55:05 +00:00
|
|
|
for (unsigned int j = 1; j < arg.length(); j++)
|
|
|
|
if (isalpha(arg[j]))
|
|
|
|
remaining.push_back((string) "-" + arg[j]);
|
2003-07-24 08:53:43 +00:00
|
|
|
else {
|
2003-12-01 15:55:05 +00:00
|
|
|
remaining.push_back(string(arg, j));
|
2003-07-24 08:53:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-12-01 15:55:05 +00:00
|
|
|
} else remaining.push_back(arg);
|
2003-07-04 15:42:03 +00:00
|
|
|
}
|
2003-12-01 15:55:05 +00:00
|
|
|
args = remaining;
|
|
|
|
remaining.clear();
|
2003-07-04 15:42:03 +00:00
|
|
|
|
2003-12-01 15:55:05 +00:00
|
|
|
/* 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);
|
2003-07-04 15:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-16 16:29:57 +00:00
|
|
|
static char buf[1024];
|
|
|
|
|
2003-07-04 15:42:03 +00:00
|
|
|
int main(int argc, char * * argv)
|
|
|
|
{
|
|
|
|
/* ATerm setup. */
|
|
|
|
ATerm bottomOfStack;
|
|
|
|
ATinit(argc, argv, &bottomOfStack);
|
|
|
|
|
2003-10-16 11:55:37 +00:00
|
|
|
/* Turn on buffering for cerr. */
|
|
|
|
cerr.rdbuf()->pubsetbuf(buf, sizeof(buf));
|
|
|
|
|
2003-07-04 15:42:03 +00:00
|
|
|
try {
|
|
|
|
initAndRun(argc, argv);
|
|
|
|
} catch (UsageError & e) {
|
2003-11-09 10:35:45 +00:00
|
|
|
printMsg(lvlError,
|
2003-07-24 08:53:43 +00:00
|
|
|
format(
|
|
|
|
"error: %1%\n"
|
|
|
|
"Try `%2% --help' for more information.")
|
|
|
|
% e.what() % programId);
|
2003-07-04 15:42:03 +00:00
|
|
|
return 1;
|
2003-07-07 09:25:26 +00:00
|
|
|
} catch (Error & e) {
|
2003-11-09 10:35:45 +00:00
|
|
|
printMsg(lvlError, format("error: %1%") % e.msg());
|
2003-07-07 09:25:26 +00:00
|
|
|
return 1;
|
2003-07-04 15:42:03 +00:00
|
|
|
} catch (exception & e) {
|
2003-11-09 10:35:45 +00:00
|
|
|
printMsg(lvlError, format("error: %1%") % e.what());
|
2003-07-04 15:42:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|