}
}
+enum LogParserState {
+ NONE,
+ METADATA,
+ TRACK,
+ WPT,
+}
+
+class LogParser: Object
+{
+ const MarkupParser parser = { // It's a structure, not an object
+ start,// when an element opens
+ end, // when an element closes
+ text, // when text is found
+ null, // when comments are found
+ null // when errors occur
+ };
+
+ MarkupParseContext context = null;
+ public Log result = null;
+ LogParserState state = LogParserState.NONE;
+ string cur_text = "";
+
+ construct
+ {
+ context = new MarkupParseContext(
+ parser, // the structure with the callbacks
+ 0, // MarkupParseFlags
+ this, // extra argument for the callbacks, methods in this case
+ destroy // when the parsing ends
+ );
+ }
+
+ void destroy()
+ {
+ cur_text = "";
+ }
+
+ public bool parse(string content, ssize_t len = -1) throws MarkupError
+ {
+ return context.parse(content, len);
+ }
+
+
+ /*
+ outfd.puts(" <metadata>\n");
+ outfd.printf(" <name>%s</name>\n", Markup.escape_text(title));
+ outfd.puts(" </metadata>\n");
+ if (track != null) writeTrack(outfd);
+ if (entries != null) writeEntries(outfd);
+ outfd.puts(" </gpx>\n");
+ */
+
+
+ void start (MarkupParseContext context, string name,
+ string[] attr_names, string[] attr_values) throws MarkupError
+ {
+ if (name == "gpx")
+ {
+ state = LogParserState.NONE;
+ result = new Log("TODO:TAG", "TODO:TITLE");
+ } else if (name == "metadata") {
+ state = LogParserState.METADATA;
+ } else if (name == "wpt") {
+ state = LogParserState.WPT;
+ } else if (name == "trkseg") {
+ state = LogParserState.TRACK;
+ }
+ cur_text = "";
+ }
+
+ void end (MarkupParseContext context, string name) throws MarkupError
+ {
+ if (name == "state")
+ if (state == LogParserState.METADATA)
+ result.title = cur_text;
+ }
+
+ void text (MarkupParseContext context,
+ string text, size_t text_len) throws MarkupError
+ {
+ cur_text += text;
+ }
+}
+
public class Logger : Resource, Object
{
protected List<Log> logs;
if (logs == null) end_trace();
}
+ public Log load(string fname)
+ {
+ string contents;
+ size_t length;
+ FileUtils.get_contents(fname, out contents, out length);
+ LogParser parser = new LogParser();
+ parser.parse(contents, (ssize_t)length);
+ return parser.result;
+ }
+
public void instant(string tag, string msg)
{
var log = new Log(tag, msg);