--------------------------------------------------------------------------------
-- InsertAllFunctionsHeaders()
--
-- Generates a headers for all functions and inserts them into the document.
--
-- Tool: AutoItTools.InsertAllFunctionsHeaders $(au3) savebefore:no,groupundo:yes Ctrl+Alt+U Insert Functions Headers
--------------------------------------------------------------------------------
function AutoItTools:InsertAllFunctionsHeaders()
local iL = 0
local iAdded = 0
local iExists = 0
while iL < editor.LineCount - 1 do
local continue = 1
local line, len = editor:GetLine(iL)
local pos = editor:PositionFromLine(iL)
local lineNum = iL
local from, to, name = line:find("[Ff][Uu][Nn][Cc][%s]*([%w%s_]*)")
local struct = false
if to == nil then
from, to, name = line:find("[Gg][Ll][Oo][Bb][Aa][Ll]%s+[Cc][Oo][Nn][Ss][Tt]%s+($[%w_]+)")
struct = true
if to == nil then
continue = 0
end
end
if continue == 1 then
-- remove comments from the line
from, to = line:find(";")
while from ~= nil do
-- print(pos+from .. " type:" .. editor.StyleAt[pos+from])
if editor.StyleAt[pos+from] == SCE_AU3_COMMENT then
line = string.sub (line, 1 , from-1) -- remove comment
from = nil -- exit loop
else
from, to = line:find(";",from+1) -- find next ; as this one is not a comment
end
end
-- print(" line:" .. line)
local pfrom, pto = line:find("%(") -- check for opening parenthesis
if struct then
pfrom, pto = line:find("[\"']")
end
if pto ~= nil then
local i = 0
local tmp
while line:find("%s+_%s*$") do -- found a line continuation
line = line:gsub("%s+_%s*$", "") -- remove it
i = i + 1
pos = editor:PositionFromLine(lineNum+i) -- set new position
tmp = editor:GetLine(lineNum+i)
-- remove comments from the line
from, to = tmp:find(";")
while from ~= nil do
-- print(pos+from .. " type:" .. editor.StyleAt[pos+from])
if editor.StyleAt[pos+from] == SCE_AU3_COMMENT then
tmp = string.sub (tmp, 1 , from-1) -- remove comment
from = nil -- exit loop
else
from, to = tmp:find(";",from+1) -- find next ; as this one is not a comment
end
end
tmp = tmp:gsub("^%s*", "") -- remove leading white space
line = line .. tmp
end
line = line:gsub("[\r\n]", "") -- remove line breaks
line = line:gsub("[\"']%s*&%s*[\"']", "") -- remove string joins
tmp = editor:GetLine(iL-2)
if tmp == nil or tmp:find("^; Example .......:") == nil then
local sText
if name:sub(1, 1) == "$" then
sText = self:CreateStructureHeader(name, line)
else
sText = self:CreateFunctionHeader(name, line)
end
editor:InsertText(editor:PositionFromLine(iL), sText)
iAdded = iAdded + 1
sText, lines = sText:gsub("(\r?\n)", "%1")
iL = iL + lines
else
iExists = 1
end
else
-- print("Argument list not found, unable to insert header.")
end
end
iL = iL + 1
end
if iAdded == 0 then
if iExists == 1 then
print("All UDFs have headers.")
else
print("Function or struct definition not found, unable to insert headers.")
end
end
end -- InsertAllFunctionsHeaders()