forked from clintbellanger/flare-engine-next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_xml.sh
executable file
·38 lines (37 loc) · 1.06 KB
/
extract_xml.sh
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
#!/bin/bash
IFS=$'\n'
HAVE_CLASS=0
echo "<?xml version=\"1.0\"?>"
echo "<classes>"
for line in `grep '@CLASS\|@ATTR\|@TYPE' src/*.cpp | sed s/^.*@//g | sed 's/CLASS /CLASS|/g' | sed 's/ATTR /ATTR|/g' | sed 's/TYPE /TYPE|/g' | sed 's/"/\"/g'`
do
IFS='|'
fields=($line)
# Handle CLASS
if [ "${fields[0]}" == "CLASS" ]; then
if [ $HAVE_CLASS -eq 1 ]; then
echo ' </attributes>'
echo ' </class>'
fi
echo ' <class name="'${fields[1]}'">'
HAVE_CLASS=1
echo ' <description>'${fields[2]}'</description>'
echo ' <attributes>'
fi
# Handle ATTR
if [ "${fields[0]}" == "ATTR" ]; then
IFS=':'
TYPE_VAL=(${fields[2]})
echo ' <attribute name="'${fields[1]}'" type="'$(echo "${TYPE_VAL[0]}" | xargs)'" vars="'$(echo "${TYPE_VAL[1]}" | xargs)'">'${fields[3]}'</attribute>'
fi
# Handle TYPE
if [ "${fields[0]}" == "TYPE" ]; then
echo ' <type name="'${fields[1]}'">'${fields[2]}'</type>'
fi
done
# close last class if available
if [ $HAVE_CLASS -eq 1 ]; then
echo ' </attributes>'
echo ' </class>'
fi
echo "</classes>"