Code: Select all
; source : http://www.forums.purebasic.com/english/viewtopic.php?f=12&t=53701#p406202
; GetPBInfo.pb
;
;- original work by Danilo - 2013
;
; Version: PureBasic 5.60
;
;- modified by Blue - 2017-04-16
; 1. compiler output encoding specified as Ascii
; 2. insertion of IDE index markers in PB output files
; 3. re-use of common lists
; 4. output into source code folder
; NB : ";-." (start) and ";." (end) are used as keywords for code folding
; add those to your preferences, to fold the following as intended
;- modified by Sicro - 2017-05-21
; Added Linux (and Mac?) support
EnableExplicit
Macro Debugg : Debug "" : EndMacro
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
#Compiler = #PB_Compiler_Home+"compilers\pbcompiler.exe"
CompilerDefault
#Compiler = #PB_Compiler_Home+"compilers/pbcompiler"
CompilerEndSelect
;-. variables et constantes
NewList out.s()
NewList outHeader.s()
Define.s out, items
Define compiler, count
#marge = 2
#detailed_infos = 01
;.
;-
; ***************************
;-******* Procédures ********
Procedure StartCompiler()
ProcedureReturn RunProgram(#Compiler,"--standby","",
#PB_Program_Open|#PB_Program_Read|#PB_Program_Write|#PB_Program_Hide)
EndProcedure
Procedure StopCompiler(pb)
WriteProgramStringN(pb, "END", #PB_Ascii)
WaitProgram(pb,5000)
CloseProgram(pb)
EndProcedure
Procedure SendCompilerCommand(pb,command$)
If ProgramRunning(pb)
WriteProgramStringN(pb, command$, #PB_Ascii)
EndIf
EndProcedure
Procedure.s GetCompilerOutput(pb)
If AvailableProgramOutput(pb)
ProcedureReturn ReadProgramString(pb, #PB_Ascii)
EndIf
EndProcedure
Procedure WaitCompilerReady(pb)
Protected out$
While out$<>"READY" And Left(out$,5)<>"ERROR"
out$ = GetCompilerOutput(pb)
If out$
Debug out$
EndIf
Wend
EndProcedure
Procedure FillList(pb,List out.s(),marge=0)
Protected out$
Protected marge$=Space(marge)
While out$<>"OUTPUT"+#TAB$+"COMPLETE" And Left(out$,5)<>"ERROR"
out$=GetCompilerOutput(pb)
If out$ And out$<>"OUTPUT"+#TAB$+"COMPLETE" And Left(out$,5)<>"ERROR" And FindString("0123456789",Mid(out$,1,1))=0
AddElement(out())
out()= marge$ + out$
EndIf
Wend
EndProcedure
Procedure Insert_markers(List out.s(),i=1)
; in a sorted listed, it's possible and useful
; to add indexed markers for quick browsing in PB IDE
Protected.s temp, car
ForEach out()
If UCase(Mid(out(),i,1)) <> car
temp = out() ; mémoriser la ligne courante
car = UCase(Mid(temp,i,1))
out() = ";- " + car ; insérer la lettre à utiliser dans l'IDE
AddElement(out()) ; nouvelle ligne...
out() = temp ; et ré-insérer la ligne remplacée
EndIf
Next
EndProcedure
Procedure Insert_Interface_markers(List out.s())
; of 2011 interfaces, 1926 start with I !
; useful then to index the I group by smaller sub-groups.
Protected.s temp, car, car2
ForEach out()
If Asc(out()) = 'I'
If Left(out(),2) <> car2 ; for I, use 2 letters for index
temp = out() ; mémoriser la ligne courante
car2 = Left(temp,2)
out() = ";- " + car2 ; insérer les 2 lettres à utiliser dans l'IDE
AddElement(out()) ; ajouter une ligne ...
out() = temp ; et ré-insérer la ligne remplacée
EndIf
Else
If Asc(out()) <> Asc(car)
temp = out() ; mémoriser la ligne courante
car = Left(temp,1)
out() = ";- " + car ; insérer la lettre à utiliser dans l'IDE
AddElement(out()) ; ajouter une ligne ...
out() = temp ; et ré-insérer la ligne remplacée
EndIf
EndIf
Next
EndProcedure
Procedure Save_outList(items.s, how_many)
Shared out()
Protected pbFile.s
pbFile.s = items +".pb"
If CreateFile(0, #PB_Compiler_FilePath + pbFile)
Debug " >> writing " + pbFile
WriteStringN(0,";- "+Str(how_many) + " " + items)
ForEach out()
WriteStringN(0,out())
Next
CloseFile(0)
EndIf
EndProcedure
;- ...procedures
Procedure.i GetProcedureList(pb,List out.s())
If ProgramRunning(pb)
SendCompilerCommand(pb,"FUNCTIONLIST")
FillList(pb,out())
EndIf
; comment out the procedure description/help text
ForEach out()
ReplaceString(out(),"-",";",#PB_String_InPlace,8,1)
Next
ProcedureReturn ListSize(out())
EndProcedure
;- ...constants
Procedure FillConstantList(pb,List out.s(),space=0)
Protected out$
Protected space$=Space(space)
While out$<>"OUTPUT"+#TAB$+"COMPLETE" And Left(out$,5)<>"ERROR"
out$=GetCompilerOutput(pb)
If out$<>"" And out$<>"OUTPUT"+#TAB$+"COMPLETE" And Left(out$,5)<>"ERROR" And FindString("0123456789",Mid(out$,2,1))=0
If FindString("01",Mid(out$,1,1))
out$ = "#"+Mid(out$,2,Len(out$)-1)
out$ = ReplaceString(out$,#TAB$," = ")
out$ = ReplaceString(out$,"# = ","#")
ElseIf FindString("2",Mid(out$,1,1))
Protected i, found_non_printable = #False
Protected oldout$ = out$
Protected sconst_value$ = StringField(oldout$,3,Chr(9))
out$ = "#"+StringField(oldout$,2,#TAB$)
For i = 1 To Len(sconst_value$)
If Asc(Mid(sconst_value$,i)) < 32 Or Asc(Mid(sconst_value$,i)) > 126
found_non_printable = #True
EndIf
Next i
If out$ = "#TAB$" : out$ + " = Chr(9)"
ElseIf out$ = "#HT$" : out$ + " = Chr(9)"
ElseIf out$ = "#CRLF$" : out$ + " = Chr(13) + Chr(10)"
ElseIf out$ = "#LFCR$" : out$ + " = Chr(10) + Chr(13)"
ElseIf out$ = "#LF$" : out$ + " = Chr(10)"
ElseIf out$ = "#CR$" : out$ + " = Chr(13)"
ElseIf out$ = "#DOUBLEQUOTE$" : out$ + " = Chr(34)"
ElseIf out$ = "#DQUOTE$" : out$ + " = Chr(34)"
ElseIf found_non_printable = #False
out$ + " = " + #DQUOTE$ + StringField(oldout$,3,#TAB$) + #DQUOTE$
Else
out$ + " ="
Protected temp$ = StringField(oldout$,3,#TAB$)
For i = 0 To Len(sconst_value$)-1
out$ + " Chr("+Str(PeekB(@temp$+(i*SizeOf(Character)))) + ") +"
Next
EndIf
out$ = RTrim(out$,"+")
Else
Debug out$
EndIf
out$ = Trim(out$)
If out$
AddElement(out())
out() = space$ + out$
EndIf
EndIf
Wend
EndProcedure
Procedure.i GetConstantsList(pb,List out.s())
If ProgramRunning(pb)
SendCompilerCommand(pb,"CONSTANTLIST")
FillConstantList(pb,out())
EndIf
ProcedureReturn ListSize(out())
EndProcedure
;- ...interfaces
Procedure GetInterfaceList(pb,List out.s())
If ProgramRunning(pb)
SendCompilerCommand(pb,"INTERFACELIST")
FillList(pb,out())
EndIf
ProcedureReturn ListSize(out())
EndProcedure
Procedure.i GetInterfaceInfo(pb,interf$,List out.s())
If ProgramRunning(pb)
SendCompilerCommand(pb,"INTERFACE"+#TAB$+interf$)
FillList(pb,out(),#marge)
EndIf
ProcedureReturn ListSize(out())
EndProcedure
;- ...structures
Procedure.i GetStructureInfo(pb,struct$,List out.s())
If ProgramRunning(pb)
SendCompilerCommand(pb,"STRUCTURE"+#TAB$+struct$)
FillList(pb,out(),#marge)
EndIf
ProcedureReturn ListSize(out())
EndProcedure
Procedure.i GetStructureList(pb,List out.s())
If ProgramRunning(pb)
SendCompilerCommand(pb,"STRUCTURELIST")
FillList(pb,out())
EndIf
ProcedureReturn ListSize(out())
EndProcedure
;-
; ************************
;- ********** START ***
compiler = StartCompiler()
If compiler = 0
End
EndIf
Debug "Output folder : "
Debug " >> " + #PB_Compiler_FilePath
#sort_infos = 01
If #sort_infos
Debug "Sorting ? Yes"
Else
Debug "Sorting ? NO"
EndIf
Debug "*******************************"
WaitCompilerReady(compiler)
;-.. Constants
items = "constants"
ClearList(out())
count = GetConstantsList(compiler,out())
Debug "*******************************"
Debug items + ": " + "found "+Str(count)
If #sort_infos
Debug " >> sorting..."
SortList(out(),#PB_Sort_Ascending|#PB_Sort_NoCase)
Insert_markers(out(),2)
EndIf
Save_outList(items,count)
;.
;-.. Procedures
items = "procedures"
ClearList(out())
count = GetProcedureList(compiler,out())
Debug "*******************************"
Debug items + ": " + "found "+Str(count)
If #sort_infos
Debug " >> sorting..."
SortList(out(),#PB_Sort_Ascending)
; when sorted, insert indexed markers used by PB IDE
Insert_markers(out())
EndIf
Save_OutList(items, count)
;.
;-.. Interfaces
items = "interfaces"
ClearList(outHeader())
count = GetInterfaceList(compiler,outHeader())
Debug "*******************************"
Debug items + ": " + "found "+Str(count)
If #sort_infos
Debug " >> sorting..."
SortList(outHeader(),#PB_Sort_Ascending|#PB_Sort_NoCase)
Insert_Interface_markers(outHeader())
EndIf
Debug " >> inserting method declarations"
ClearList(out())
ForEach outHeader()
AddElement(out())
If Asc(outHeader()) = ';'
out()= outHeader()
Else
out()="Interface " + outHeader()
If #detailed_infos
GetInterfaceInfo(compiler,outHeader(),out())
AddElement(out()) : out()= "EndInterface"
AddElement(out()) : out()= ""
EndIf
EndIf
Next
Save_OutList(items,count)
;.
;-.. Structures
items = "structures"
ClearList(outHeader())
count = GetStructureList(compiler,outHeader())
Debug "*******************************"
Debug items + ": " + "found "+Str(count)
If #sort_infos
Debug " >> sorting..."
SortList(outHeader(),#PB_Sort_Ascending)
EndIf
Debug " >> inserting components"
ClearList(out())
ForEach outHeader()
AddElement(out()) : out() = ";- " + outHeader()
AddElement(out()) : out() = "Structure " + outHeader()
If #detailed_infos
GetStructureInfo(compiler,outHeader(),out())
AddElement(out()) : out() = "EndStructure"
AddElement(out()) : out() = ""
EndIf
Next
Save_OutList(items, count)
;.
;- ********** FINISH ***
StopCompiler(compiler)
Debug "*******************************"
Debugg
Debug "DONE."
Debugg
Debugg
End