* 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:
Eelco Dolstra 2003-07-24 08:53:43 +00:00
parent b75719b984
commit 1a7468a57a
8 changed files with 68 additions and 25 deletions

View file

@ -310,6 +310,16 @@ void run(Strings args)
throw UsageError(format("argument required in `%1%'") % arg); throw UsageError(format("argument required in `%1%'") % arg);
state.searchDirs.push_back(*it++); 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] == '-') else if (arg[0] == '-')
throw UsageError(format("unknown flag `%1%`") % arg); throw UsageError(format("unknown flag `%1%`") % arg);
else else

View file

@ -1,4 +1,5 @@
#include <iostream> #include <iostream>
#include <sstream>
#include "globals.hh" #include "globals.hh"
#include "normalise.hh" #include "normalise.hh"
@ -278,10 +279,9 @@ void run(Strings args)
Strings opFlags, opArgs; Strings opFlags, opArgs;
Operation op = 0; Operation op = 0;
for (Strings::iterator it = args.begin(); for (Strings::iterator it = args.begin(); it != args.end(); )
it != args.end(); it++)
{ {
string arg = *it; string arg = *it++;
Operation oldOp = op; Operation oldOp = op;
@ -307,6 +307,16 @@ void run(Strings args)
op = opVerify; op = opVerify;
else if (arg == "--path" || arg == "-p") else if (arg == "--path" || arg == "-p")
pathArgs = true; 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] == '-') else if (arg[0] == '-')
opFlags.push_back(arg); opFlags.push_back(arg);
else else

View file

@ -26,8 +26,7 @@ typedef set<FSId> FSIdSet;
Slice normaliseFState(FSId id, FSIdSet pending) Slice normaliseFState(FSId id, FSIdSet pending)
{ {
debug(format("normalising fstate %1%") % (string) id); Nest nest(lvlDebug, format("normalising fstate %1%") % (string) id);
Nest nest(true);
/* Try to substitute $id$ by any known successors in order to /* Try to substitute $id$ by any known successors in order to
speed up the rewrite process. */ speed up the rewrite process. */
@ -177,8 +176,7 @@ Slice normaliseFState(FSId id, FSIdSet pending)
void realiseSlice(const Slice & slice, FSIdSet pending) void realiseSlice(const Slice & slice, FSIdSet pending)
{ {
debug(format("realising slice")); Nest nest(lvlDebug, format("realising slice"));
Nest nest(true);
/* Perhaps all paths already contain the right id? */ /* Perhaps all paths already contain the right id? */

View file

@ -1,4 +1,5 @@
#include <iostream> #include <iostream>
#include <cctype>
extern "C" { extern "C" {
#include <aterm2.h> #include <aterm2.h>
@ -32,7 +33,12 @@ static void initAndRun(int argc, char * * argv)
string arg = *it; string arg = *it;
if (arg.length() > 2 && arg[0] == '-' && arg[1] != '-') { if (arg.length() > 2 && arg[0] == '-' && arg[1] != '-') {
for (unsigned int i = 1; i < arg.length(); i++) for (unsigned int i = 1; i < arg.length(); i++)
args.insert(it, (string) "-" + arg[i]); if (isalpha(arg[i]))
args.insert(it, (string) "-" + arg[i]);
else {
args.insert(it, string(arg, i));
break;
}
it = args.erase(it); it = args.erase(it);
} else it++; } else it++;
} }
@ -50,18 +56,21 @@ int main(int argc, char * * argv)
try { try {
initAndRun(argc, argv); initAndRun(argc, argv);
} catch (UsageError & e) { } catch (UsageError & e) {
cerr << format( msg(lvlError,
"error: %1%\n" format(
"Try `%2% --help' for more information.\n") "error: %1%\n"
% e.what() % programId; "Try `%2% --help' for more information.")
% e.what() % programId);
return 1; return 1;
} catch (Error & e) { } catch (Error & e) {
cerr << format("error: %1%\n") % e.msg(); msg(lvlError, format("error: %1%") % e.msg());
return 1; return 1;
} catch (exception & e) { } catch (exception & e) {
cerr << format("error: %1%\n") % e.what(); msg(lvlError, format("error: %1%") % e.what());
return 1; return 1;
} }
return 0; return 0;
} }

View file

@ -168,7 +168,7 @@ string expandId(const FSId & id, const string & target,
const string & prefix, FSIdSet pending) const string & prefix, FSIdSet pending)
{ {
debug(format("expanding %1%") % (string) id); debug(format("expanding %1%") % (string) id);
Nest nest(true); Nest nest(lvlDebug, format("expanding %1%") % (string) id);
Strings paths; Strings paths;

View file

@ -12,8 +12,7 @@
void realise(FSId id) void realise(FSId id)
{ {
debug(format("TEST: realising %1%") % (string) id); Nest nest(lvlDebug, format("TEST: realising %1%") % (string) id);
Nest nest(true);
Slice slice = normaliseFState(id); Slice slice = normaliseFState(id);
realiseSlice(slice); realiseSlice(slice);
} }

View file

@ -130,13 +130,20 @@ void deletePath(string path)
} }
Verbosity verbosity = lvlNormal;
static int nestingLevel = 0; static int nestingLevel = 0;
Nest::Nest(bool nest) Nest::Nest(Verbosity level, const format & f)
{ {
this->nest = nest; if (level > verbosity)
if (nest) nestingLevel++; 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; string spaces;
for (int i = 0; i < nestingLevel; i++) for (int i = 0; i < nestingLevel; i++)
spaces += "| "; spaces += "| ";
@ -157,7 +165,7 @@ void msg(const format & f)
void debug(const format & f) void debug(const format & f)
{ {
msg(format("debug: %1%") % f.str()); msg(lvlDebug, format("debug: %1%") % f.str());
} }

View file

@ -72,17 +72,26 @@ void deletePath(string path);
/* Messages. */ /* Messages. */
typedef enum {
lvlError = 0,
lvlNormal = 5,
lvlDebug = 10,
lvlDebugMore = 15
} Verbosity;
extern Verbosity verbosity; /* supress msgs > this */
class Nest class Nest
{ {
private: private:
bool nest; bool nest;
public: public:
Nest(bool nest); Nest(Verbosity level, const format & f);
~Nest(); ~Nest();
}; };
void msg(const format & f); void msg(Verbosity level, const format & f);
void debug(const format & f); void debug(const format & f); /* shorthand */
/* Wrappers arount read()/write() that read/write exactly the /* Wrappers arount read()/write() that read/write exactly the