16ce39ea982186be6dabf4ba31d5a96135d6e373
[moonshot-ui.git] / src / moonshot-webp-parser.vala
1 namespace WebProvisioning
2 {
3   class WebProvisionParser
4   {
5     public WebProvisionParser (string path)
6     {
7       
8     }
9   }
10   
11   public void start_element_func (MarkupParseContext context,
12                                   string             element_name,
13                                   string[]           attribute_names,
14                                   string[]           attribute_values) throws MarkupError
15   {
16     debug ("Start: %s", element_name);
17   }
18
19   public void end_element_func (MarkupParseContext context,
20                                 string             element_name) throws MarkupError
21   {
22     debug ("End: %s", element_name);
23   }
24   
25   public void text_element_func (MarkupParseContext context,
26                                  string text,
27                                  size_t text_len) throws MarkupError
28   {
29     debug ("Text element: %s", text); 
30     foreach (string elm in context.get_element_stack ())
31     {
32       stdout.printf("%s\n", elm);
33     }
34   }
35   
36
37   public static int main (string[] args)
38   {
39     string text = "";
40     if (args.length < 2)
41     {
42       error ("Usage %s [-a] WEB_PROVISIONING_FILE", args[0]);
43     }
44     
45     if (!FileUtils.test (args[1], FileTest.EXISTS | FileTest.IS_REGULAR))
46     {
47       error ("%s does not exist", args[1]);
48     }
49     
50     var file = File.new_for_path (args[1]);
51     
52     try
53     {
54       var dis = new DataInputStream (file.read ());
55       string line;
56       while ((line = dis.read_line (null)) != null)
57         text += line;
58     }
59     catch (Error e)
60     {
61       error ("Could not retreive file size");
62     }
63     
64     MarkupParser parser = {start_element_func, end_element_func, text_element_func, null, null};
65     
66     var ctx = new MarkupParseContext(parser, 0, null, null);
67     
68     try
69     {
70       ctx.parse (text, text.length);
71     }
72     catch (Error e)
73     {
74       error ("Could not parse %s, invalid content", args[1]);
75     }
76     
77     
78     return 0;
79   }
80 }