#endif
-inline Formatter *defaultFormatter(void) {
+inline Formatter *defaultFormatter(bool color = true) {
+ if (color) {
#ifdef _WIN32
- return new WindowsFormatter;
+ return new WindowsFormatter;
#else
- return new AnsiFormatter;
+ return new AnsiFormatter;
#endif
+ } else {
+ return new Formatter;
+ }
}
Formatter::Attribute *literal;
public:
- Dumper(std::ostream &_os) : os(_os) {
- formatter = Formatter::defaultFormatter();
+ Dumper(std::ostream &_os, bool color) : os(_os) {
+ formatter = Formatter::defaultFormatter(color);
normal = formatter->normal();
bold = formatter->bold();
italic = formatter->italic();
};
-std::ostream & operator <<(std::ostream &os, Value *value) {
- Dumper d(os);
- if (value) {
- value->visit(d);
- }
- return os;
+void Value::dump(std::ostream &os, bool color) {
+ Dumper d(os, color);
+ visit(d);
}
return null;
}
-std::ostream & operator <<(std::ostream &os, Call &call) {
- Dumper d(os);
- os << call.no << " ";
- d.visit(&call);
- return os;
+void Call::dump(std::ostream &os, bool color) {
+ Dumper d(os, color);
+ os << no << " ";
+ d.visit(this);
}
virtual const char *toString(void) const;
const Value & operator[](size_t index) const;
+
+ void dump(std::ostream &os, bool color=true);
};
};
-std::ostream & operator <<(std::ostream &os, Value *value);
+inline std::ostream & operator <<(std::ostream &os, Value *value) {
+ if (value) {
+ value->dump(os);
+ }
+ return os;
+}
class Call
assert(index < args.size());
return *(args[index]);
}
+
+ void dump(std::ostream &os, bool color=true);
};
-std::ostream & operator <<(std::ostream &os, Call &call);
+inline std::ostream & operator <<(std::ostream &os, Call &call) {
+ call.dump(os);
+ return os;
+}
} /* namespace Trace */
*/
+#include <string.h>
+
#include "trace_parser.hpp"
+static bool color = true;
+
+
+static void usage(void) {
+ std::cout <<
+ "Usage: tracedump [OPTION] [TRACE...]\n"
+ "Dump TRACE to standard output.\n"
+ "\n"
+ " --no-color no colored syntax highlightint\n"
+ " --no-colour alias for --no-color\n"
+ ;
+}
+
+
int main(int argc, char **argv)
{
- for (int i = 1; i < argc; ++i) {
+ int i;
+
+ for (i = 1; i < argc; ++i) {
+ const char *arg = argv[i];
+
+ if (arg[0] != '-') {
+ break;
+ }
+
+ if (!strcmp(arg, "--")) {
+ break;
+ } else if (!strcmp(arg, "--no-color") ||
+ !strcmp(arg, "--no-colour")) {
+ color = false;
+ } else {
+ std::cerr << "error: unknown option " << arg << "\n";
+ usage();
+ return 1;
+ }
+ }
+
+ for (; i < argc; ++i) {
Trace::Parser p;
if (!p.open(argv[i])) {
Trace::Call *call;
while ((call = p.parse_call())) {
- std::cout << *call;
+ call->dump(std::cout, color);
delete call;
}
}
+
return 0;
}