2003-07-06 15:11:02 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "hash.hh"
|
|
|
|
#include "shared.hh"
|
2003-12-01 15:55:05 +00:00
|
|
|
#include "help.txt.hh"
|
|
|
|
|
|
|
|
|
|
|
|
void printHelp()
|
|
|
|
{
|
|
|
|
cout << string((char *) helpText, sizeof helpText);
|
|
|
|
}
|
2003-07-06 15:11:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
void run(Strings args)
|
|
|
|
{
|
2005-01-13 17:39:26 +00:00
|
|
|
HashType ht = htMD5;
|
2003-08-06 09:06:32 +00:00
|
|
|
bool flat = false;
|
2005-01-13 17:39:26 +00:00
|
|
|
|
2003-08-06 09:06:32 +00:00
|
|
|
for (Strings::iterator i = args.begin();
|
|
|
|
i != args.end(); i++)
|
2005-01-13 17:39:26 +00:00
|
|
|
{
|
2003-08-06 09:06:32 +00:00
|
|
|
if (*i == "--flat") flat = true;
|
2005-01-13 17:39:26 +00:00
|
|
|
else if (*i == "--type") {
|
|
|
|
++i;
|
|
|
|
if (i == args.end()) throw UsageError("`--type' requires an argument");
|
|
|
|
if (*i == "md5") ht = htMD5;
|
|
|
|
else if (*i == "sha1") ht = htSHA1;
|
2005-01-14 12:03:04 +00:00
|
|
|
else if (*i == "sha256") ht = htSHA256;
|
2005-01-13 17:39:26 +00:00
|
|
|
else throw UsageError(format("unknown hash type `%1%'") % *i);
|
|
|
|
}
|
2003-08-06 09:06:32 +00:00
|
|
|
else
|
2005-01-14 16:04:03 +00:00
|
|
|
cout << format("%1%\n") % printHash(
|
|
|
|
(flat ? hashFile(*i, ht) : hashPath(*i, ht)));
|
2005-01-13 17:39:26 +00:00
|
|
|
}
|
2003-07-06 15:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string programId = "nix-hash";
|
|
|
|
|