Debian Codegraph @

texmf-dist/tex/luatex/luaxml/luaxml-testxml.lua

raw
1 #!/usr/bin/lua
2 ---Simple command line test parser - applies handler[s] specified
3 -- to XML file (or STDIN) and dumps results<br/>
4 --
5 -- $Id: testxml.lua,v 1.1.1.1 2001/11/28 06:11:33 paulc Exp $<br/>
6 --
7 -- $Log: testxml.lua,v $<br/>
8 -- Revision 1.1.1.1 2001/11/28 06:11:33 paulc<br/>
9 -- Initial Import
10 --
11
12 local modxml
13 local handler
14 local pretty
15 if kpse then
16 modxml = require('luaxml-mod-xml')
17 handler = require('luaxml-mod-handler')
18 pretty = require('luaxml-pretty')
19 else
20 modxml = require('luaxml.mod-xml')
21 handler = require('luaxml.mod-handler')
22 pretty = require('luaxml.pretty')
23 end
24
25
26 -- Defaults
27 _print = nil
28 _simpletree = nil
29 _dom = nil
30 _file = nil
31 _xmlrpc = nil
32 _debug = nil
33 _ws = nil
34 _noentity = nil
35
36 _usage = [[
37 textxml.lua [-print] [-simpletree] [-dom] [-xmlrpc] [-debug]
38 [-ws] [-noentity] [-help] [file]
39 ]]
40
41 _help = [[
42 testxml.lua - Simple command line XML processor
43
44 Options:
45
46 -print : Generate event dump (default)
47 -simpletree : Generate simple tree
48 -dom : Generate DOM-like tree
49 -debug : Print debug info (filename/text)
50 -ws : Do not strip whitespace
51 -noentity : Do not expand entities
52 -help : Print help
53 file : XML File (parse stdin in nil)
54 ]]
55
56 index = 1
57 local exit = os.exit
58
59 function setOptions(x)
60 if _ws then
61 x.options.stripWS = nil
62 end
63 if _noentity then
64 x.options.expandEntities = nil
65 end
66 end
67
68 while arg[index] do
69 --print (arg[index])
70 if (string.sub(arg[index],1,1)=='-') then
71 if arg[index] == "-print" then
72 _print = 1
73 elseif arg[index] == "-simpletree" then
74 _simpletree= 1
75 elseif arg[index] == "-dom" then
76 _dom= 1
77 elseif arg[index] == "-xmlrpc" then
78 _xmlrpc= 1
79 elseif arg[index] == "-debug" then
80 _debug = 1
81 elseif arg[index] == "-ws" then
82 _ws = 1
83 elseif arg[index] == "-noentity" then
84 _noentity = 1
85 elseif arg[index] == "-help" then
86 print(_usage)
87 exit()
88 else
89 print(_usage)
90 exit()
91 end
92 else
93 -- Filename is last argument if present
94 if arg[index+1] then
95 print(_usage)
96 exit()
97 else
98 _file = arg[index]
99 end
100 end
101 index = index + 1
102 end
103
104 if _file then
105 print("File",_file)
106 if (_debug) then
107 io.write ( "File: ".._file.."\n" )
108 end
109 --xml = read(openfile(_file,"r"),"*a")
110
111 local f, e = io.open(_file, "r")
112 if f then
113 xml = f:read("*a")
114 else
115 error(e)
116 end
117
118 else
119 xml = io.read("*a")
120 end
121
122 if _debug then
123 io.write ( "----------- XML\n" )
124 io.write (xml.."\n")
125 end
126
127 if _print or not (_print or _dom or _simpletree or _print or _xmlrpc) then
128 io.write ( "----------- Print\n" )
129 h = handler.printHandler()
130 x = modxml.xmlParser(h)
131 setOptions(x)
132 x:parse(xml)
133 end
134
135 if _simpletree then
136 io.write ( "----------- SimpleTree\n" )
137 h = handler.simpleTreeHandler()
138 x = modxml.xmlParser(h)
139 setOptions(x)
140 x:parse(xml)
141 pretty.pretty('root',h.root)
142 end
143
144 if _dom then
145 io.write ( "----------- Dom\n" )
146 h = handler.domHandler()
147 x = modxml.xmlParser(h)
148 setOptions(x)
149 x:parse(xml)
150 pretty.pretty('root',h.root)
151 io.write ( "-----------\n" )
152 end
153
154
155
156