-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnifxml.ijs
executable file
·120 lines (106 loc) · 2.74 KB
/
nifxml.ijs
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
require 'xml/sax/x2j strings'
require jcwdpath 'nifexpr.ijs'
NB. FIXME: to support multiple versions will need to
NB. use an object instance of nifexpr or continually update as a singleton
cocurrent 'nifexpr'
NB. nif versioning:
vton=: (256 #. '.' 0&".;._1@, ]) ::]
Version=: vton '4.0.0.2' NB. Morrowind
UserVersion=: 0
UserVersion2=: 0
NB. utility
lr=: 3 : '5!:5 <''y'''
NB. comment out second definition to see emitted definitions from readnif/writenif
debug=: smoutput
debug=: ]
NB. this will extract a small part of the xml from nif.xml
NB. it's not particularly fast, but it's good enough for now
NB. FIXME: parse the file "just once"
x2jclass 'nifxml'
coinsert 'nifexpr'
NIFNames=: ''
NIFMembers=: ''
extract=:3 :0
if. 0=#NIFNames do. process_nifxml_ fread jcwdpath 'nif.xml' end.
restrictVersion&> ($~ $-.1:)NIFMembers {~ NIFNames i.;: y
:
Version_nifexpr_=: vton ::] x
extract y
)
'Items' x2jDefn NB. dispatch xml event handlers
/ := post'' : NIFNames=: NIFMembers=: ''
compound := defEnd y : x defStart y
compound := defDoc y
basic := defEnd y : x defStart y
basic := defDoc y
bitflags := defEnd y : x defStart y
bitflags := defDoc y
enum := defEnd y : x defStart y
enum := defDoc y
niobject := defEnd y : x defStart y
niobject := defDoc y
add := aEnd y : x aStart y
add := aChr y
option := aEnd y : x aStart y
option := aChr y
)
NB. quick hack: post results from object back into class
post=:3 :0
NIFNames_nifxml_ =: NIFNames
NIFMembers_nifxml_ =: NIFMembers
i.0 0
)
NB. ------- "glue" ------------------------------
defStart=:4 :0 NB. event handlers for <compound>
Name=: atr 'name'
Element=: y
Attributes=: attributes x
Doc=: ''
Details=: i.0 1
)
defEnd=:3 :0
NIFNames=: NIFNames,<Name
NIFMembers=: NIFMembers,<(cleanDoc Element);Attributes;<Details
)
defDoc=:3 :0
Doc=: Doc,y
)
cleanDoc=:3 :0
,.y;;:inv~.<@dltb;._2 Doc,LF
)
validVer=:3 :0
if. _1-: y do. 1 return.end.
expr=. fixexpr y
".expr
)
restrictVersion=:3 :0
'elem attr adds'=. y
elem;attr;<,.(#~ goodAdds&>), adds
)
goodAdds=:3 :0
attrs=. |: 1 {:: y
names=. {. attrs
vals1=: ({: attrs),<'1:1'
valsv=. ({: attrs),<Version
get=. {::~ names i. <
if. Version >: vton valsv get 'ver1' do.
if. Version <: vton valsv get 'ver2' do.
if. validVer vals1 get 'vercond' do.
if. '1:1' -: vals1 get 'userver' do.
1 return.
end.
end.
end.
end.
0
)
aStart=:4 :0 NB. event handlers for <add>
Attribute=: y;<attributes x
Comment=: ''
)
aEnd=:3 :0
Details=: Details,<Attribute,<Comment
)
aChr=:3 :0
Comment=: Comment,y
)