aboutsummaryrefslogtreecommitdiff
path: root/src/log2xml/log2xml.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/log2xml/log2xml.cc')
-rw-r--r--src/log2xml/log2xml.cc102
1 files changed, 102 insertions, 0 deletions
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 <iostream>
+#include <cstdio>
+#include <string>
+
+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 += "&lt;";
+ else if (c == '&')
+ line += "&amp;";
+ 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 << "<nest>" << endl;
+ break;
+ case 'q':
+ if (line.size()) finishLine();
+ if (level > 0) {
+ level--;
+ cout << "</nest>" << endl;
+ } else
+ cerr << "not enough nesting levels" << endl;
+ break;
+ }
+ }
+ break;
+
+ }
+}
+
+
+void Decoder::finishLine()
+{
+ string tag = inHeader ? "head" : "line";
+ cout << "<" << tag << ">";
+ cout << line;
+ cout << "</" << tag << ">" << endl;
+ line = "";
+ inHeader = false;
+}
+
+
+int main(int argc, char * * argv)
+{
+ Decoder dec;
+ int c;
+
+ cout << "<logfile>" << endl;
+
+ while ((c = getchar()) != EOF) {
+ dec.pushChar(c);
+ }
+
+ cout << "</logfile>" << endl;
+}