From: Enrico Zini Date: Sat, 27 Mar 2010 20:55:52 +0000 (+0000) Subject: Parse back the log entries X-Git-Url: https://git.toastfreeware.priv.at/gregoa/zavai.git/commitdiff_plain/76b0521eb37f6b8f4f3c7bc516b2c48331b78407 Parse back the log entries --- diff --git a/src/log.vala b/src/log.vala index 607fffe..b8aac43 100644 --- a/src/log.vala +++ b/src/log.vala @@ -47,7 +47,7 @@ public class Waypoint : Object public void writeInside(FileStream outfd) { var t = Time.gm(ts); - outfd.printf(" \n", t.format("%Y-%m-%dT%H:%M:%SZ")); + outfd.printf(" \n", t.format("%Y-%m-%dT%H:%M:%S%z")); } } @@ -143,6 +143,11 @@ public class Log : Object outfd.flush(); } + public void dump() + { + write(stderr); + } + protected void writeTrack(FileStream outfd) { outfd.puts(" \n"); @@ -155,10 +160,8 @@ public class Log : Object protected void writeEntries(FileStream outfd) { - outfd.puts(" \n"); for (weak List i = entries; i != null; i = i.next) i.data.write(outfd); - outfd.puts(" \n"); } protected void write(FileStream outfd) @@ -199,6 +202,8 @@ class LogParser: Object public Log result = null; LogParserState state = LogParserState.NONE; string cur_text = ""; + LogEntry cur_logentry = null; + TrackEntry cur_trackentry = null; construct { @@ -213,23 +218,34 @@ class LogParser: Object void destroy() { cur_text = ""; + cur_logentry = null; + cur_trackentry = null; } public bool parse(string content, ssize_t len = -1) throws MarkupError { - return context.parse(content, len); + string oldtz = Environment.get_variable("TZ"); + Environment.set_variable("TZ", "UTC", true); + bool res = context.parse(content, len); + if (oldtz == null) + Environment.unset_variable("TZ"); + else + Environment.set_variable("TZ", oldtz, true); + return res; } - - /* - outfd.puts(" \n"); - outfd.printf(" %s\n", Markup.escape_text(title)); - outfd.puts(" \n"); - if (track != null) writeTrack(outfd); - if (entries != null) writeEntries(outfd); - outfd.puts(" \n"); - */ - + void parse_attrs(Waypoint w, string[] attr_names, string[] attr_values) + { + w.lat = 1000; + w.lon = 1000; + for (int i = 0; attr_names[i] != null; ++i) + { + if (attr_names[i] == "lat") + w.lat = attr_values[i].to_double(); + else if (attr_names[i] == "lon") + w.lon = attr_values[i].to_double(); + } + } void start (MarkupParseContext context, string name, string[] attr_names, string[] attr_values) throws MarkupError @@ -241,8 +257,14 @@ class LogParser: Object } else if (name == "metadata") { state = LogParserState.METADATA; } else if (name == "wpt") { + cur_logentry = new LogEntry(); + parse_attrs(cur_logentry, attr_names, attr_values); + result.entries.append(cur_logentry); state = LogParserState.WPT; - } else if (name == "trkseg") { + } else if (name == "trkpt") { + cur_trackentry = new TrackEntry(); + parse_attrs(cur_trackentry, attr_names, attr_values); + result.track.append(cur_trackentry); state = LogParserState.TRACK; } cur_text = ""; @@ -250,9 +272,27 @@ class LogParser: Object void end (MarkupParseContext context, string name) throws MarkupError { - if (name == "state") - if (state == LogParserState.METADATA) - result.title = cur_text; + if (name == "name") + { + switch (state) + { + case LogParserState.METADATA: + result.title = cur_text; + break; + case LogParserState.WPT: + cur_logentry.msg = cur_text; + break; + } + } + else if (name == "time") + { + Time t = Time(); + t.strptime(cur_text, "%Y-%m-%dT%H:%M:%S%z"); + if (state == LogParserState.WPT) + cur_logentry.ts = t.mktime(); + else if (state == LogParserState.TRACK) + cur_trackentry.ts = t.mktime(); + } } void text (MarkupParseContext context, diff --git a/src/zavai.vala b/src/zavai.vala index 931edc0..d682e82 100644 --- a/src/zavai.vala +++ b/src/zavai.vala @@ -277,6 +277,13 @@ static int main (string[] args) { zavai.clock.alarm_trigger_queue.enqueue_trigger(alarm); } + if (args.length > 2 && args[1] == "showlog") + { + zavai.log.Log l = zavai.log.log.load(args[2]); + l.dump(); + return 0; + } + if (args.length > 2 && args[1] == "play") { zavai.audio.musicplayer.play("file://" + args[2]);