Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
<no random message>
  • Loading branch information
opussf committed Jan 30, 2024
2 parents bea0adf + 175c7fd commit b0b4ba8
Show file tree
Hide file tree
Showing 5 changed files with 412 additions and 15 deletions.
8 changes: 8 additions & 0 deletions FEATURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## FEATURES

# xml2src

Write a SAX parser to handle the wow.xml files for addons.

http://www.jelks.nu/XML/xmlebnf.html

23 changes: 21 additions & 2 deletions buildFiles/build.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<project name="MeToo" default="package">
<!-- version 7.1 -->
<project name="" default="package">
<!-- version 7.3 -->

<tstamp/>
<property file="build.properties"/>
Expand Down Expand Up @@ -136,11 +136,30 @@

<target name="curse" depends="package" description="copy files to a folder for deploy to curseforge">
<property name="curse.dir" location="${ant.project.name}-cf"/>
<exec executable="git" dir="${curse.dir}" failifexecutionfails="true" errorproperty="">
<arg line="reset --hard HEAD" />
</exec>
<copy todir="${curse.dir}">
<fileset dir="${package.dir}"/>
</copy>
<exec executable="git" dir="${curse.dir}" failifexecutionfails="true" errorproperty="">
<arg line="status" />
</exec>
<fail message="Not a tagged release.">
<condition>
<not>
<equals arg1="${version.number}" arg2="${git.tag}"/>
</not>
</condition>
</fail>
<exec executable="git" dir="${curse.dir}" failifexecutionfails="true" errorproperty="">
<arg line="add ." />
</exec>
<exec executable="git" dir="${curse.dir}" failifexecutionfails="true" errorproperty="">
<arg line="commit -a -m '${git.tag}'" />
</exec>
<exec executable="git" dir="${curse.dir}" failifexecutionfails="true" errorproperty="">
<arg line="tag -a ${git.tag} -m '${git.tag}'" />
</exec>
</target>
</project>
5 changes: 3 additions & 2 deletions src/scripts/runmany.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ for n in $(seq -f "%05g" 9999 1) ; do
if [ ! "$?" == "0" ]; then
cp target/reports/antout.txt target/reports/antOut$n.txt
#mv $reportFile target/reports/testOut$n.xml
ls -alt target/reports/testOut$n.xml
ls -alt $reportFile
until $(~/Scripts/checkFileChanged.sh ./test/test.lua); do
sleep 1
done
else
ls -alt $reportFile
#ls -alt $reportFile
sleep 1
fi
done
191 changes: 180 additions & 11 deletions src/wowStubs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,12 @@ ITEM_BIND_ON_PICKUP="Binds when picked up"
Frame = {
["__isShown"] = true,
["Events"] = {},
["points"] = {},
["Hide"] = function( self ) self.__isShown = false; end,
["Show"] = function( self ) self.__isShown = true; end,
["IsVisible"] = function( self ) return( self.__isShown ) end,
["RegisterEvent"] = function(self, event) self.Events[event] = true; end,
["SetPoint"] = function() end,
["SetPoint"] = function(self, ... ) table.insert( self.points, {...} ); end,
["UnregisterEvent"] = function(self, event) self.Events[event] = nil; end,
["GetName"] = function(self) return self.framename end,
["SetFrameStrata"] = function() end,
Expand All @@ -399,7 +400,9 @@ Frame = {
["GetHeight"] = function(self) return( self.height ); end,
["CreateFontString"] = function(self, ...) return(CreateFontString(...)) end,
["SetSize"] = function(self, x, y) end,
["ClearAllPoints"] = function(self) end,
["ClearAllPoints"] = function(self) self.points={}; end,
["GetPoint"] = function(self) end,
["GetNumPoints"] = function(self) end,

["SetMinMaxValues"] = function(self, min, max) self.min=min; self.max=max; end,
["SetValue"] = function(self, value) self.value=value end,
Expand Down Expand Up @@ -1727,9 +1730,170 @@ function C_ChatInfo.SendAddonMessage()
return true
end

-----------------------------------------
-- XML functions
-- A SAX parser takes a content handler, which provides these methods:
-- startDocument() -- called at the start of the Document
-- endDocument() -- called at the end of the Document
-- startElement( tagName, attrs ) -- with each tag start. attrs is a table of attributes and values
-- endElement( tagName ) -- when a tag ends
-- characters( char ) -- for each character not being in a tag
-- The parser calls each of these methods as these events happen.

-- A SAX parser defines a parser (created with makeParser)
-- a Parser has a ContentHandler assigned
-- a Parser also defines these methods:
-- setContentHandler( contentHandler )
-- setFeature() -- prob not going to implement
-- parse( text )
-- parse( file )

-- https://www.w3schools.com/xml/xml_elements.asp
-- https://www.w3schools.com/xml/xml_syntax.asp


contentHandler = {}
-- normally the contentHandler is an object, where data structures are created in the new object.
function contentHandler.startDocument( this )
end
function contentHandler.endDocument( this )
end
function contentHandler.startElement( this, tagName, attrs )
end
function contentHandler.endElement( this, tagName )
end
function contentHandler.characters( this, char )
end

saxParser = {}
-- SAX Parser
-- interface
function saxParser.makeParser()
-- make a parser. This is probably intended to be a factory function
return saxParser
end
function saxParser.setContentHandler( contentHandlerIn )
-- takes a table
saxParser.contentHandler = contentHandlerIn
end
function saxParser.setFeature()
-- research this
end
function saxParser.parse( fileIn )
f = io.open( fileIn, "r" )
if f then fileIn = f:read( "*all" ) end -- read the contents of the file

-- call the startDocument method for the given contentHandler
if saxParser.contentHandler and saxParser.contentHandler.startDocument then
saxParser.contentHandler:startDocument()
end

-- loop through each char
State = {
Outside = { 0 }, -- outside of a tag
ElementName = { 1 }, -- When to parse for a name
InElement = { 2 }, -- In the element
}
currentState = State.Outside
elementDepth = {} -- table of current element depth
elementName = ""
chars = ""

while( #fileIn > 0 ) do
-- print( currentState[1].."\t"..#fileIn, "fileIn: "..string.sub( fileIn, 1, 60 ) )
c = string.sub( fileIn, 1, 1 )
n = string.sub( fileIn, 2, 2 )
handled = false
if currentState == State.Outside then
if c == "<" then
if n == "?" then
local endProlog = string.find( fileIn, "?>" )
if endProlog then
fileIn = string.sub( fileIn, endProlog+2 )
end
elseif n == "!" then
local endComment = string.find( fileIn, "-->" )
if endComment then
fileIn = string.sub( fileIn, endComment+3 )
end
else
currentState = State.ElementName
elementName = ""
fileIn = string.sub( fileIn, 2 )
end
else
saxParser.contentHandler:characters( c )
fileIn = string.sub( fileIn, 2 )
end
elseif currentState == State.ElementName then
tagStart, tagEnd, tagName = string.find( fileIn, "^([%a_][%a%d-_.]*)" )
if tagStart then
elementName = tagName
attributes = {}
currentState = State.InElement
fileIn = string.sub( fileIn, tagEnd + 1 )
end
tagStart, tagEnd, tagName = string.find( fileIn, "^/([%a_][%a%d-_.]*)" )
if tagStart then
elementName = tagName
-- print( "Fire endElement( "..tagName.." )" )
depthElement = table.remove( elementDepth )
saxParser.contentHandler:endElement( tagName )
if depthElement ~= elementName then
fail( "ERROR: Closing "..elementName.." is not the expected element to close; "..depthElement.." is expected." )
end
currentState = State.Outside
fileIn = string.sub( fileIn, tagEnd + 2 )
end
elseif currentState == State.InElement then
attribStart, attribEnd, key, value = string.find( fileIn, "^%s*(%S+)%s*=%s*[\"\'](.-)[\"\']" )
if attribStart then
attributes[key] = value
fileIn = string.sub( fileIn, attribEnd+1 )
elseif c == " " then
fileIn = string.sub( fileIn, 2 )
elseif c == ">" or n == ">" then
-- print( "Fire startElement( "..elementName.." )" )
-- print( "\twith attributes: ")
-- for k,v in pairs( attributes ) do
-- print( "\t\t"..k..":="..v )
-- end
table.insert( elementDepth, elementName )
saxParser.contentHandler:startElement( elementName, attributes )
currentState = State.Outside
if c == "/" and n == ">" then
-- print( "Fire endElement( "..elementName.." )" )
depthElement = table.remove( elementDepth )
saxParser.contentHandler:endElement( elementName )
if depthElement ~= elementName then
fail( "ERROR: Closing "..elementName.." is not the expected element to close; "..depthElement.." is expected." )
end
currentState = State.Outside
end
fileIn = string.sub( fileIn, (n==">" and 3 or 2) )
end
end
-- print( "elementDepth: "..table.concat( elementDepth, "\t" ) )
end

-- call the endDocument method for the given contentHandler
if saxParser.contentHandler and saxParser.contentHandler.endDocument then
saxParser.contentHandler:endDocument()
end
end
function ParseXML( xmlFile )
ch = contentHandler
ch.startElement = function( self, tagIn, attribs )
if _G["Create"..tagIn] then
if attribs.name then
_G[attribs.name] = _G["Create"..tagIn]( attribs.name )
_G[attribs.name].framename = attribs.name
else
fail("A "..tagIn.." needs a name")
end
end
end
parser = saxParser.makeParser()
parser.setContentHandler( ch )
parser.parse( xmlFile )
end

-----------------------------------------
Expand All @@ -1752,7 +1916,9 @@ function ParseTOC( tocFile, useRequire )
if( hash ) then
addonData[ hashKey ] = hashValue
elseif( lua ) then
table.insert( tocFileTable, luaFile )
table.insert( tocFileTable, { "lua", luaFile } )
elseif( xml ) then
table.insert( tocFileTable, { "xml", xmlFile } )
end
tocContents = string.sub( tocContents, lineend+1 )
else
Expand All @@ -1771,15 +1937,18 @@ function ParseTOC( tocFile, useRequire )
--add to the include package.path
package.path = includePath.."?.lua;" .. package.path
end

sharedTable = {}

for _,f in pairs( tocFileTable ) do
if( useRequire ) then
require( f )
else
local loadedfile = assert( loadfile( includePath..f..".lua" ) )
loadedfile( addonName, sharedTable )
if( f[1] == "lua" ) then
if( useRequire ) then
require( f[2] )
else
local loadedfile = assert( loadfile( includePath..f[2]..".lua" ) )
loadedfile( addonName, sharedTable )
end
elseif( f[1] == "xml" ) then
ParseXML( includePath..f[2]..".xml" )
end
end
end
Expand Down
Loading

0 comments on commit b0b4ba8

Please sign in to comment.