From 9d2669d218d03d64c69a702a96fc87ee1fd3a9d0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 15 Mar 2004 21:51:14 +0000 Subject: * Added a utility that can be used to produce nice HTML pages from Nix build logs. The program `log2xml' converts a Nix build log (read from standard input) into XML file that can then be converted to XHTML by the `log2html.xsl' stylesheet. The CSS stylesheet `logfile.css' is necessary to make it look good. This is primarily useful if the log file has a *tree structure*, i.e., that sub-tasks such as the various phases of a build (unpack, configure, make, etc.) or recursive invocations of Make are represented as such. While a log file is in principle an unstructured plain text file, builders can communicate this tree structure to `log2xml' by using escape sequences: - "\e[p" starts a new nesting level; the first line following the escape code is the header; - "\e[q" ends the current nesting level. The generic builder in nixpkgs (not yet committed) uses this. It shouldn't be to hard to patch GNU Make to speak this protocol. Further improvements to the generated HTML pages are to allow collapsing/expanding of subtrees, and to abbreviate store paths (but to show the full path by hovering the mouse over it). --- src/log2xml/log2xml.cc | 102 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/log2xml/log2xml.cc (limited to 'src/log2xml/log2xml.cc') diff --git a/src/log2xml/log2xml.cc b/src/log2xml/log2xml.cc new file mode 100644 index 000000000..711fc82b8 --- /dev/null +++ b/src/log2xml/log2xml.cc @@ -0,0 +1,102 @@ +#include +#include +#include + +using namespace std; + + +struct Decoder +{ + enum { stTop, stEscape, stCSI } state; + string line; + bool inHeader; + int level; + + Decoder() + { + state = stTop; + line = ""; + inHeader = false; + level = 0; + } + + void pushChar(char c); + + void finishLine(); +}; + + +void Decoder::pushChar(char c) +{ + switch (state) { + + case stTop: + if (c == '\e') { + state = stEscape; + } else if (c == '\n') { + finishLine(); + } else if (c == '<') + line += "<"; + else if (c == '&') + line += "&"; + else + line += c; + break; + + case stEscape: + if (c == '[') + state = stCSI; + else + state = stTop; /* !!! wrong */ + break; + + case stCSI: + if (c >= 0x40 && c != 0x7e) { + state = stTop; + switch (c) { + case 'p': + if (line.size()) finishLine(); + level++; + inHeader = true; + cout << "" << endl; + break; + case 'q': + if (line.size()) finishLine(); + if (level > 0) { + level--; + cout << "" << endl; + } else + cerr << "not enough nesting levels" << endl; + break; + } + } + break; + + } +} + + +void Decoder::finishLine() +{ + string tag = inHeader ? "head" : "line"; + cout << "<" << tag << ">"; + cout << line; + cout << "" << endl; + line = ""; + inHeader = false; +} + + +int main(int argc, char * * argv) +{ + Decoder dec; + int c; + + cout << "" << endl; + + while ((c = getchar()) != EOF) { + dec.pushChar(c); + } + + cout << "" << endl; +} -- cgit v1.2.3