Advertisement
xThomas

Untitled

Jul 15th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.05 KB | None | 0 0
  1. -- mapbugcheck.lua
  2. local t,i = {}, 1
  3. for line in io.lines("ragequit random 10.rms") do
  4.   t[i] = line
  5.   i=i+1
  6. end
  7. local str_map = table.concat(t,"\n")
  8.  
  9.  
  10. --Note: We need to remove comments first before we can count the if statements
  11.  
  12.  function clean(STRING)
  13.     local captures,i, ignore,keep = {},1, 0,{}
  14.     for c in string.gmatch(STRING, "%g+") do    
  15.         captures[i],i = c,i+1
  16.     end  
  17.     for i,v in ipairs(captures) do
  18.         if v == "/*" then
  19.             ignore=ignore+1
  20.         end
  21.         if ignore == 0 then
  22.             table.insert(keep, v)
  23.         end    
  24.         if v == "*/" then
  25.             ignore=ignore-1
  26.         end
  27.     end
  28.     return table.concat(keep," ")
  29. end  
  30.  
  31. str_map = clean(str_map)
  32.  
  33. print(string.sub(str_map,1,200))
  34.  
  35. local cnt_if = 0
  36. local cnt_endif = 0
  37.  
  38. for word in string.gmatch(str_map,"%g+") do
  39.     if word == "if" then
  40.         cnt_if = cnt_if + 1
  41.     elseif word == "endif" then
  42.         cnt_endif = cnt_endif + 1
  43.     end
  44. end
  45.  
  46. print("cnt_if=",cnt_if) --if cnt_if is greater than 0 , we have a problem
  47. print("cnt_endif=",cnt_endif)
  48.  
  49.  
  50. -- check for consts inside if statements: sometimes they bug out
  51.  
  52. -- check for consts where the next word is bad and the third word is not a number
  53.  
  54. local constants = {}
  55. local cnt = 0
  56. local str = ""
  57. for word in string.gmatch(str_map, "%g+") do
  58.   if word == "#const" then
  59.     cnt = 1
  60.     str = "#const"
  61.   elseif cnt == 1 then
  62.     str = str .. " " .. word
  63.     cnt = 2
  64.   elseif cnt == 2 then
  65.     str = str .. " " .. word
  66.     table.insert(constants, str)
  67.     str = ""
  68.     cnt = 0
  69.   end
  70. end
  71.  
  72. file = io.open("ragequit constants.txt","w")
  73. for i,v in ipairs(constants) do
  74.   file:write(v .. "\n")
  75. end
  76. io.close()
  77.  
  78. local defines = {}
  79. local cnt = 0
  80. local str = ""
  81. for word in string.gmatch(str_map, "%g+") do
  82.   if word == "#define" then
  83.     cnt = 1
  84.     str = "#define"
  85.   elseif cnt == 1 then
  86.     str = str .. " " .. word
  87.     cnt = 0
  88.     table.insert(defines, str)
  89.     str = ""
  90.   end
  91. end
  92.  
  93. file = io.open("ragequit defines.txt","w")
  94. for i,v in ipairs(defines) do
  95.   file:write(v .. "\n")
  96. end
  97. io.close()
  98.  
  99. --make a file that only has if statements and whatever in between if and endif
  100. --since there are extra endifs it could be educational
  101.  
  102.  
  103.  
  104. local stuff = {}
  105. local if_depth = {}
  106. local push_if = function()
  107.   table.insert(if_depth, "if")
  108. end
  109. local pop_if = function()
  110.   table.remove(if_depth, #if_depth)
  111. end
  112.  
  113. local tab = function()
  114.   local s = "" for i = 1, #if_depth do s=s.."  " end return s
  115. end
  116.  
  117. local elsetab = function()
  118.   local s = "" for i = 2, #if_depth do s=s.."  " end return s
  119. end
  120.  
  121. for word in string.gmatch(str_map, "%g+") do
  122.   if word == "if" then
  123.     push_if()
  124.     table.insert(stuff, tab()..#if_depth.." "..word)
  125.   elseif word == "endif" then
  126.     table.insert(stuff, tab()..#if_depth.." "..word)
  127.     pop_if()
  128.   elseif word == "else" or word == "elseif" then
  129.     table.insert(stuff, tab()..#if_depth.." "..word)
  130.   end
  131. end
  132.  
  133. file = io.open("ragequit ifs.txt","w")
  134. for i,v in ipairs(stuff) do
  135.   file:write(v .. "\n")
  136. end
  137. io.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement