From 5024bde8f407582c9cb5a916f3b5603184f76eb7 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 25 Nov 2008 01:06:15 +0000 Subject: [PATCH] * Handle prematurely ended logfiles, i.e. make sure we emit enough close tags. --- src/nix-log2xml/log2xml.cc | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/nix-log2xml/log2xml.cc b/src/nix-log2xml/log2xml.cc index 9be3978a9..8a3cbc8c4 100644 --- a/src/nix-log2xml/log2xml.cc +++ b/src/nix-log2xml/log2xml.cc @@ -34,6 +34,8 @@ struct Decoder void pushChar(char c); void finishLine(); + + void decodeFile(istream & st); }; @@ -158,16 +160,26 @@ void Decoder::finishLine() } +void Decoder::decodeFile(istream & st) +{ + int c; + + cout << "" << endl; + + while ((c = st.get()) != EOF) { + pushChar(c); + } + + if (line.size()) finishLine(); + + while (level--) cout << "" << endl; + + cout << "" << endl; +} + + int main(int argc, char * * argv) { Decoder dec; - int c; - - cout << "" << endl; - - while ((c = getchar()) != EOF) { - dec.pushChar(c); - } - - cout << "" << endl; + dec.decodeFile(cin); }