forked from lix-project/lix
* Debug levels. Use `--verbose / -v LEVEL' to display only messages
up to the given verbosity levels. These currently are: lvlError = 0, lvlNormal = 5, lvlDebug = 10, lvlDebugMore = 15 although only lvlError and lvlDebug are actually used right now.
This commit is contained in:
parent
b75719b984
commit
1a7468a57a
10
src/fix.cc
10
src/fix.cc
|
@ -310,6 +310,16 @@ void run(Strings args)
|
|||
throw UsageError(format("argument required in `%1%'") % arg);
|
||||
state.searchDirs.push_back(*it++);
|
||||
}
|
||||
else if (arg == "--verbose" || arg == "-v") {
|
||||
if (it == args.end()) throw UsageError(
|
||||
format("`%1%' requires an argument") % arg);
|
||||
istringstream str(*it++);
|
||||
int lvl;
|
||||
str >> lvl;
|
||||
if (str.fail()) throw UsageError(
|
||||
format("`%1%' requires an integer argument") % arg);
|
||||
verbosity = (Verbosity) lvl;
|
||||
}
|
||||
else if (arg[0] == '-')
|
||||
throw UsageError(format("unknown flag `%1%`") % arg);
|
||||
else
|
||||
|
|
16
src/nix.cc
16
src/nix.cc
|
@ -1,4 +1,5 @@
|
|||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include "globals.hh"
|
||||
#include "normalise.hh"
|
||||
|
@ -278,10 +279,9 @@ void run(Strings args)
|
|||
Strings opFlags, opArgs;
|
||||
Operation op = 0;
|
||||
|
||||
for (Strings::iterator it = args.begin();
|
||||
it != args.end(); it++)
|
||||
for (Strings::iterator it = args.begin(); it != args.end(); )
|
||||
{
|
||||
string arg = *it;
|
||||
string arg = *it++;
|
||||
|
||||
Operation oldOp = op;
|
||||
|
||||
|
@ -307,6 +307,16 @@ void run(Strings args)
|
|||
op = opVerify;
|
||||
else if (arg == "--path" || arg == "-p")
|
||||
pathArgs = true;
|
||||
else if (arg == "--verbose" || arg == "-v") {
|
||||
if (it == args.end()) throw UsageError(
|
||||
format("`%1%' requires an argument") % arg);
|
||||
istringstream str(*it++);
|
||||
int lvl;
|
||||
str >> lvl;
|
||||
if (str.fail()) throw UsageError(
|
||||
format("`%1%' requires an integer argument") % arg);
|
||||
verbosity = (Verbosity) lvl;
|
||||
}
|
||||
else if (arg[0] == '-')
|
||||
opFlags.push_back(arg);
|
||||
else
|
||||
|
|
|
@ -26,8 +26,7 @@ typedef set<FSId> FSIdSet;
|
|||
|
||||
Slice normaliseFState(FSId id, FSIdSet pending)
|
||||
{
|
||||
debug(format("normalising fstate %1%") % (string) id);
|
||||
Nest nest(true);
|
||||
Nest nest(lvlDebug, format("normalising fstate %1%") % (string) id);
|
||||
|
||||
/* Try to substitute $id$ by any known successors in order to
|
||||
speed up the rewrite process. */
|
||||
|
@ -177,8 +176,7 @@ Slice normaliseFState(FSId id, FSIdSet pending)
|
|||
|
||||
void realiseSlice(const Slice & slice, FSIdSet pending)
|
||||
{
|
||||
debug(format("realising slice"));
|
||||
Nest nest(true);
|
||||
Nest nest(lvlDebug, format("realising slice"));
|
||||
|
||||
/* Perhaps all paths already contain the right id? */
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <iostream>
|
||||
#include <cctype>
|
||||
|
||||
extern "C" {
|
||||
#include <aterm2.h>
|
||||
|
@ -32,7 +33,12 @@ static void initAndRun(int argc, char * * argv)
|
|||
string arg = *it;
|
||||
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]);
|
||||
else {
|
||||
args.insert(it, string(arg, i));
|
||||
break;
|
||||
}
|
||||
it = args.erase(it);
|
||||
} else it++;
|
||||
}
|
||||
|
@ -50,18 +56,21 @@ int main(int argc, char * * argv)
|
|||
try {
|
||||
initAndRun(argc, argv);
|
||||
} catch (UsageError & e) {
|
||||
cerr << format(
|
||||
msg(lvlError,
|
||||
format(
|
||||
"error: %1%\n"
|
||||
"Try `%2% --help' for more information.\n")
|
||||
% e.what() % programId;
|
||||
"Try `%2% --help' for more information.")
|
||||
% e.what() % programId);
|
||||
return 1;
|
||||
} catch (Error & e) {
|
||||
cerr << format("error: %1%\n") % e.msg();
|
||||
msg(lvlError, format("error: %1%") % e.msg());
|
||||
return 1;
|
||||
} catch (exception & e) {
|
||||
cerr << format("error: %1%\n") % e.what();
|
||||
msg(lvlError, format("error: %1%") % e.what());
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ string expandId(const FSId & id, const string & target,
|
|||
const string & prefix, FSIdSet pending)
|
||||
{
|
||||
debug(format("expanding %1%") % (string) id);
|
||||
Nest nest(true);
|
||||
Nest nest(lvlDebug, format("expanding %1%") % (string) id);
|
||||
|
||||
Strings paths;
|
||||
|
||||
|
|
|
@ -12,8 +12,7 @@
|
|||
|
||||
void realise(FSId id)
|
||||
{
|
||||
debug(format("TEST: realising %1%") % (string) id);
|
||||
Nest nest(true);
|
||||
Nest nest(lvlDebug, format("TEST: realising %1%") % (string) id);
|
||||
Slice slice = normaliseFState(id);
|
||||
realiseSlice(slice);
|
||||
}
|
||||
|
|
18
src/util.cc
18
src/util.cc
|
@ -130,13 +130,20 @@ void deletePath(string path)
|
|||
}
|
||||
|
||||
|
||||
Verbosity verbosity = lvlNormal;
|
||||
|
||||
static int nestingLevel = 0;
|
||||
|
||||
|
||||
Nest::Nest(bool nest)
|
||||
Nest::Nest(Verbosity level, const format & f)
|
||||
{
|
||||
this->nest = nest;
|
||||
if (nest) nestingLevel++;
|
||||
if (level > verbosity)
|
||||
nest = false;
|
||||
else {
|
||||
msg(level, f);
|
||||
nest = true;
|
||||
nestingLevel++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -146,8 +153,9 @@ Nest::~Nest()
|
|||
}
|
||||
|
||||
|
||||
void msg(const format & f)
|
||||
void msg(Verbosity level, const format & f)
|
||||
{
|
||||
if (level > verbosity) return;
|
||||
string spaces;
|
||||
for (int i = 0; i < nestingLevel; i++)
|
||||
spaces += "| ";
|
||||
|
@ -157,7 +165,7 @@ void msg(const format & f)
|
|||
|
||||
void debug(const format & f)
|
||||
{
|
||||
msg(format("debug: %1%") % f.str());
|
||||
msg(lvlDebug, format("debug: %1%") % f.str());
|
||||
}
|
||||
|
||||
|
||||
|
|
15
src/util.hh
15
src/util.hh
|
@ -72,17 +72,26 @@ void deletePath(string path);
|
|||
|
||||
/* Messages. */
|
||||
|
||||
typedef enum {
|
||||
lvlError = 0,
|
||||
lvlNormal = 5,
|
||||
lvlDebug = 10,
|
||||
lvlDebugMore = 15
|
||||
} Verbosity;
|
||||
|
||||
extern Verbosity verbosity; /* supress msgs > this */
|
||||
|
||||
class Nest
|
||||
{
|
||||
private:
|
||||
bool nest;
|
||||
public:
|
||||
Nest(bool nest);
|
||||
Nest(Verbosity level, const format & f);
|
||||
~Nest();
|
||||
};
|
||||
|
||||
void msg(const format & f);
|
||||
void debug(const format & f);
|
||||
void msg(Verbosity level, const format & f);
|
||||
void debug(const format & f); /* shorthand */
|
||||
|
||||
|
||||
/* Wrappers arount read()/write() that read/write exactly the
|
||||
|
|
Loading…
Reference in a new issue