It pastes all occurances of #Include (only 1st, of course) and #IncludeAgain of a interactively selected script to an output file.
It does not work with the '-i'-option, though.
Here it goes, hope it helps you too :wink: :
; ************************************************************ ; ** ; ** Purpose: Expand all occurances of #Include(Again) in AHK scripts ; ** ; ** Prerequisites: tested with AHK versions 1.0.26.01 and 1.0.43.09 ; ** on Win98SE, WinME, WinXP_SP2, Win2003_SP1 ; ** ; ** known deficiency: file names to be included ; ** must comply with rules for variable names ; ** (e.g. "test-id.ahk" will not work) ; ** ; ** Author: TeeJay ; ** ; ** History: ; ** 2006-04-30 Genesis ; ** 2006-05-03 Beautification of Script ; ** and Testing on different platforms ; ** 2006-05-04 Processing of '-i'-option ; ** ; ************************************************************ GoSub InitScript GoSub ScriptAction Goto EndofScript ; ************************************************************ ; start business ScriptAction: GoSub SelectFileNames if ("" <> SaveToFile) { ; create array of file names with initial file OpenFile = 0 OrigScriptFile%OpenFile% := OrigScriptFile OrigScriptFile = GoSub AnalyzeAHK } SaveToFile = return ; ************************************************************ ; check status of commenting CheckComment: if (0 = comment) { IfInString, PutString, %startComment% { comment = 1 } } else { IfInString, PutString, %endComment% { comment = 0 } } return ; ************************************************************ ; change of comment status within this line? CheckCommentInLine: StringGetPos, commpos, PutString, %endComment% if (0 = ErrorLevel) { ; found endComment if (pos < commpos) { validInclude = 0 } } else { StringGetPos, commpos, PutString, `; if (0 = ErrorLevel) { if (pos > commpos) { validInclude = 0 } } } return ; ************************************************************ ; get filename to include (= to paste) FindIncludeName: GoSub CheckComment if (0 = comment) { ; what type of include? StringGetPos, commpos, PutString, #IncludeAgain if (0 = ErrorLevel) { again = 1 } else { again = 0 StringGetPos, pos, PutString, #Include } ; within or outside comment? GoSub CheckCommentInLine if (1 = validInclude) { ; "#Include " = 9 characters ; "#IncludeAgain " = 14 characters if (1 = again) { pos += 14 } else { pos += 9 } ; handle '-i'-option StringGetPos, ipos, PutString, -i if (0 = ErrorLevel) { if (pos = ipos) { pos +=3 } } ; some bureaucracy (array handling) StringTrimLeft, incname, PutString, %pos% OpenFile++ OrigScriptFile%OpenFile% := incname StringTrimRight, incname, incname, 4 tmpcnt := Counter%incname% if ("" = tmpcnt) { Counter%incname% = 1 } else { Counter%incname% += 1 } pos = tmpcnt = } } return ; ************************************************************ ; actual analyzing of script ; OrigScriptFile - array of file names (-> nesting; recursively) ; OpenFile - index AnalyzeAHK: IncludeFile := OrigScriptFile%OpenFile% IfExist, %IncludeFile% { Loop, READ, %IncludeFile% { PutString = %A_LoopReadLine% ; check whether in comment or not GoSub CheckComment if (0 = comment) { IfInString, PutString, #Include { ; get filename to paste GoSub FindIncludeName if (1 = validInclude) { ; get current file name and its occurance IncludeFile := OrigScriptFile%OpenFile% Counter := Counter%incname% IncludeComment = `; ## %whoami%: %Counter%. occurance of "%IncludeFile%" ; write to expanded file PutString = %Separator%`n%IncludeComment%`n`; -- %PutString% -- If (1 = Counter) or (1 = again) { PutString = %PutString%`n%DoubleSeparator%`n`; ########## BEGIN pasting of "%IncludeFile%"`n%Separator% FileAppend, %PutString%`n, %SaveToFile% GoSub AnalyzeAHK PutString = %Separator%`n`; ########## END pasting of "%IncludeFile%"`n%DoubleSeparator% } else { PutString = %PutString%`n%Separator% } OpenFile-- IncludeFile := OrigScriptFile%OpenFile% } else { ; reset flag for next occurance validInclude = 1 } } } FileAppend, %PutString%`n, %SaveToFile% } } else { ; did you actually run this script?? :) FileAppend, `; >>> Could not locate "%IncludeFile%" <<<`n, %SaveToFile% } return ; ************************************************************ ; Let user select interactively script to expand SelectFileNames: FileSelectFile, OrigScriptFile, 1, %A_ScriptDir%, %whoami%: Select File to Expand, *.ahk if ("" <> OrigScriptFile) { StringTrimRight, ExpandedFile, OrigScriptFile, 4 ExpandedFile = %ExpandedFile%_ExpandedIncludes.ahk InputBox, SaveToFile, %whoami%, Filename to Expand into?,,,,,,,, %ExpandedFile% IfExist, %SaveToFile% { MsgBox, 292, %whoami%, File exists already...`nFilename: "%SaveToFile%"`nOK to overwrite? IfMsgBox, No { SaveToFile = } else { FileDelete, %SaveToFile% } } ExpandedFile = } return ; ************************************************************ ; Initialization InitScript: whoami = %A_ScriptName% StringTrimRight, whoami, whoami, 4 Separator = `; ###################################################################### DoubleSeparator = %Separator%`n%Separator% comment = 0 startComment := "/*" endComment := "*/" validInclude = 1 return ; ************************************************************ ; Bye Bye EndOfScript: ExitApp