Guest User

Untitled

a guest
Jan 14th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. --
  2. -- list_defines.lua; probably the very first lua header defines fetcher created in 2018 ;)
  3. -- 01.01.2018 / Thorsten Kani / Marcedo { at } habMalNeFrage. { de}
  4. -- License: BSD three Clause
  5. -- grab all function defines, list their names (with parameters)
  6. -- exclude Constants, exclude _underscoredStuff, exclude multiline stuff.
  7. -- (see code Docs and modify the --filter section)
  8. --
  9.  
  10.  
  11. dirSep="\\" --change to match your systems Platform
  12.  
  13. --
  14. -- splits a string at a given separator
  15. -- returns string when no sep was found.
  16. --
  17. local function split_last (s,ch)
  18. local i = #s
  19. while i > 0 do
  20. if string.sub(s,i,i) == ch then
  21. return string.sub(s,i+1)
  22. end
  23. i = i - 1
  24. end
  25. return s
  26. end
  27.  
  28. --
  29. -- Iterates through a given headerfile
  30. -- Lists defines according to the --Filter Section
  31. --
  32. function list_defines(filePath)
  33. outline=" "
  34.  
  35. -- input section --
  36. if not filePath then filePath="ndis.h" end --testing
  37. if not filePath:match(".h") then return end
  38. if filePath:match("^_") then return end --c std / mingw internal functions
  39.  
  40. print("["..split_last(filePath,dirSep).."]")
  41. for entry in io.lines(filePath) do
  42. -- parse section --
  43. local name=nil rest=nil func1=nil func2=nil multiline=false write=true
  44.  
  45. name, rest=entry:match("#define ([%w_]+)(%(.*)") -- funcName, param and rest of line [#define ble(...) blo(...)]
  46. if rest then
  47. rest=string.gsub(rest," ","") -- Normalises function deco containing spaces.
  48. param,func2=rest:match("^([%(|%w|%d|%,|%.|%_|]+%))(.*)" ) -- funcNameParam to nothing [#define bly(qwe)]
  49. if rest:match("%\\") then multiline=true param="multi_line" end
  50. func1=name..param
  51. end
  52. if not func1 then func1,func2=entry:match("#define ([%w_]+)%s+([a-zA-Z_]+)$") end -- names without parameter [#define bla blubb]
  53. if not func1 then func1,func2=entry:match("#define ([%w_]+)%s+([a-zA-Z_]+%(.*)") end -- name to function [#define bla __mingwname(...)]
  54. if not func2 then func2 ="" else
  55. if func2:match("%\\") then multiline=true func2="multi_line" func1 = name end -- tag and include names of multiline defines
  56. end
  57.  
  58. -- Filter section --
  59. if func1 then
  60. if func2 then together= func1..func2 end
  61. if multiline then write=false end -- strip multiline defines (param has Backslash)
  62. if func2:match("^[%s_]+") then write=false end -- strip compiler internals (param begins with underscore)
  63. if func2:match("sizeof") then write=false end -- strip sizeof Macro based constants
  64. if together:match("^[%s_]+") then write=false end --strip compiler internals (func Name begins with underscore)
  65. if together:match("TEXT") then write=false end -- strip TEXT Macro based constants
  66. if together:match("IID") then write=false end -- strip GUID Constants
  67. if together:match("GUID_BUILDER") then write=false end
  68. if func1:match("^[^%l]+$") then write=false end -- strip all Uppercases constants
  69. --if func1:match("^[^%l]+%(") then write=false end -- strip all Uppercases functions
  70. if together:match("__MINGW_NAME_AW") then write=true end
  71. if write then outline=outline.."{"..func1.."}{"..func2.."}".."\n" end
  72. end
  73. end
  74.  
  75. print(outline)
  76. --outFile=io.open("outFile","a+")
  77. --if outline then outFile:write(outline) end
  78. --io.close(outFile)
  79. end
  80.  
  81. list_defines(arg[1])
Add Comment
Please, Sign In to add comment