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-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. */
|
|
|
|
Strings args;
|
|
|
|
while (argc--) args.push_back(*argv++);
|
|
|
|
args.erase(args.begin());
|
|
|
|
|
|
|
|
/* Expand compound dash options (i.e., `-qlf' -> `-q -l -f'). */
|
|
|
|
for (Strings::iterator it = args.begin();
|
|
|
|
it != args.end(); )
|
|
|
|
{
|
|
|
|
string arg = *it;
|
|
|
|
if (arg.length() > 2 && arg[0] == '-' && arg[1] != '-') {
|
|
|
|
for (unsigned int i = 1; i < arg.length(); i++)
|
2003-07-24 08:53:43 +00:00
|
|
|
if (isalpha(arg[i]))
|
|
|
|
args.insert(it, (string) "-" + arg[i]);
|
|
|
|
else {
|
|
|
|
args.insert(it, string(arg, i));
|
|
|
|
break;
|
|
|
|
}
|
2003-07-04 15:42:03 +00:00
|
|
|
it = args.erase(it);
|
|
|
|
} else it++;
|
|
|
|
}
|
|
|
|
|
|
|
|
run(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char * * argv)
|
|
|
|
{
|
|
|
|
/* ATerm setup. */
|
|
|
|
ATerm bottomOfStack;
|
|
|
|
ATinit(argc, argv, &bottomOfStack);
|
|
|
|
|
|
|
|
try {
|
|
|
|
initAndRun(argc, argv);
|
|
|
|
} catch (UsageError & e) {
|
2003-07-24 08:53:43 +00:00
|
|
|
msg(lvlError,
|
|
|
|
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-07-24 08:53:43 +00:00
|
|
|
msg(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-07-24 08:53:43 +00:00
|
|
|
msg(lvlError, format("error: %1%") % e.what());
|
2003-07-04 15:42:03 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2003-07-24 08:53:43 +00:00
|
|
|
|
|
|
|
|