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