Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- mapbugcheck.lua
- local t,i = {}, 1
- for line in io.lines("ragequit random 10.rms") do
- t[i] = line
- i=i+1
- end
- local str_map = table.concat(t,"\n")
- --Note: We need to remove comments first before we can count the if statements
- function clean(STRING)
- local captures,i, ignore,keep = {},1, 0,{}
- for c in string.gmatch(STRING, "%g+") do
- captures[i],i = c,i+1
- end
- for i,v in ipairs(captures) do
- if v == "/*" then
- ignore=ignore+1
- end
- if ignore == 0 then
- table.insert(keep, v)
- end
- if v == "*/" then
- ignore=ignore-1
- end
- end
- return table.concat(keep," ")
- end
- str_map = clean(str_map)
- print(string.sub(str_map,1,200))
- local cnt_if = 0
- local cnt_endif = 0
- for word in string.gmatch(str_map,"%g+") do
- if word == "if" then
- cnt_if = cnt_if + 1
- elseif word == "endif" then
- cnt_endif = cnt_endif + 1
- end
- end
- print("cnt_if=",cnt_if) --if cnt_if is greater than 0 , we have a problem
- print("cnt_endif=",cnt_endif)
- -- check for consts inside if statements: sometimes they bug out
- -- check for consts where the next word is bad and the third word is not a number
- local constants = {}
- local cnt = 0
- local str = ""
- for word in string.gmatch(str_map, "%g+") do
- if word == "#const" then
- cnt = 1
- str = "#const"
- elseif cnt == 1 then
- str = str .. " " .. word
- cnt = 2
- elseif cnt == 2 then
- str = str .. " " .. word
- table.insert(constants, str)
- str = ""
- cnt = 0
- end
- end
- file = io.open("ragequit constants.txt","w")
- for i,v in ipairs(constants) do
- file:write(v .. "\n")
- end
- io.close()
- local defines = {}
- local cnt = 0
- local str = ""
- for word in string.gmatch(str_map, "%g+") do
- if word == "#define" then
- cnt = 1
- str = "#define"
- elseif cnt == 1 then
- str = str .. " " .. word
- cnt = 0
- table.insert(defines, str)
- str = ""
- end
- end
- file = io.open("ragequit defines.txt","w")
- for i,v in ipairs(defines) do
- file:write(v .. "\n")
- end
- io.close()
- --make a file that only has if statements and whatever in between if and endif
- --since there are extra endifs it could be educational
- local stuff = {}
- local if_depth = {}
- local push_if = function()
- table.insert(if_depth, "if")
- end
- local pop_if = function()
- table.remove(if_depth, #if_depth)
- end
- local tab = function()
- local s = "" for i = 1, #if_depth do s=s.." " end return s
- end
- local elsetab = function()
- local s = "" for i = 2, #if_depth do s=s.." " end return s
- end
- for word in string.gmatch(str_map, "%g+") do
- if word == "if" then
- push_if()
- table.insert(stuff, tab()..#if_depth.." "..word)
- elseif word == "endif" then
- table.insert(stuff, tab()..#if_depth.." "..word)
- pop_if()
- elseif word == "else" or word == "elseif" then
- table.insert(stuff, tab()..#if_depth.." "..word)
- end
- end
- file = io.open("ragequit ifs.txt","w")
- for i,v in ipairs(stuff) do
- file:write(v .. "\n")
- end
- io.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement