Tool: Create Preprocess
Posted: Tue Sep 22, 2015 12:59 pm
When you work with macros, you maybe get the problem, that an error is in your code and PureBasic only mark the line of the call of the macro.
This tool call the compiler with the "/preprocess"-command combined with "/command" and remove unnecassary commands and macros. The result is one big file with all macros exand, compilerif removed and all file included.
Add the execute under "tools\configurate tools..." with "%FILE" as parameter (with "-Quote!)
This tool call the compiler with the "/preprocess"-command combined with "/command" and remove unnecassary commands and macros. The result is one big file with all macros exand, compilerif removed and all file included.
Add the execute under "tools\configurate tools..." with "%FILE" as parameter (with "-Quote!)
Code: Select all
;"%FILE"
Procedure FindCommend(*pos.character)
Protected *start=*pos
Protected isDQuote
Protected isQuote
While *pos\c>0
If isDQuote
If *pos\c='"'
isDQuote=#False
EndIf
ElseIf isQuote
If *pos\c=39 ;'
isQuote=#False
EndIf
Else
Select *pos\c
Case '"'
isDQuote=#True
Case 39;'
isQuote=#True
Case ';'
Break
EndSelect
EndIf
*pos+SizeOf(character)
Wend
ProcedureReturn (*pos-*start )/SizeOf(character)
EndProcedure
file$=ProgramParameter()
pb$=GetEnvironmentVariable("PB_TOOL_Compiler")
If file$ And FileSize(file$)>0
dir$ = GetPathPart(file$)
outfile$=file$+".pre.pb"
DeleteFile(dir$+outfile$)
OpenConsole()
Compiler = RunProgram(pb$, Chr(34)+file$+Chr(34)+" /COMMENTED /PREPROCESS "+Chr(34)+outfile$+Chr(34), dir$,#PB_Program_Wait)
NewList file.s()
Define in,str.s,lastcom.s
Macro output(a)
AddElement(file())
file()=a
EndMacro
PrintN("")
Print("Remove unnecassary comments...")
in=ReadFile(#PB_Any,outfile$)
If in
While Not Eof(in)
line+1
str=ReadString(in)
If Left(str,1)=";"
If lastcom<>""
If Trim(Left(lastcom,FindCommend(@lastcom)))=""
output(" "+lastcom)
Else
output("; "+lastcom)
EndIf
EndIf
lastcom=Right(str,Len(str)-2)
Else
If Left(Trim(str),6)="Macro "
isMacro=#True
str=""
ElseIf Left(Trim(str),8)="EndMacro"
isMacro=#False
str=""
ElseIf isMacro
str=""
EndIf
If lastcom<>""
x=FindCommend(@lastcom)
If str<>Left(lastcom,x)
output( "; "+lastcom)
If str<>""
output( str)
EndIf
Else
output(lastcom)
EndIf
lastcom=""
ElseIf str<>""
output(str)
EndIf
EndIf
Wend
CloseFile(in)
EndIf
PrintN("done")
PrintN("Removed lines:"+Str(line-ListSize(file())))
Print("Write File ...")
out=CreateFile(#PB_Any,outfile$)
If out
ForEach file()
WriteStringN(out,file())
Next
CloseFile(out)
EndIf
PrintN("done")
PrintN("")
PrintN("Press [Return]")
Input()
RunProgram(outfile$)
EndIf