File: outline.sl

package info (click to toggle)
slexpat 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 112 kB
  • ctags: 120
  • sloc: ansic: 776; makefile: 37
file content (42 lines) | stat: -rwxr-xr-x 919 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env slsh
require("expat");

define startElement(p, name, atts) {
   variable i;
   ()=printf("%*s%s\n", p.userdata, "", name);
   foreach i (atts)
     {
	()=printf("%*s%s=%s;\n", p.userdata, "", i.name, i.value);
     }
   p.userdata++;
}                                                                          


define endElement (p, name)
{
   p.userdata--;
}

define slsh_main()
{
   !if (__argc)
     {
	() = fprintf (stderr, "Usage: %s [xml file]\n", __argv[0]);
	exit (1);
     }
   
   variable file = __argv[1];
   variable xml_parser = xml_new();
   
   variable data;
   xml_set_user_data(xml_parser, 0);
   xml_parser.startelementhandler = &startElement;
   xml_parser.endelementhandler = &endElement;
   
   variable fp = fopen(file, "r");
   if (fp == NULL)
     verror("could not open XML input");
   while (-1 != fread_bytes(&data, 4096, fp))
     xml_parse(xml_parser, data, feof(fp));
}