Procedure to pull procedure info from .pb files

Share your advanced PureBasic knowledge/code with the community.
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 796
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Procedure to pull procedure info from .pb files

Post by Zebuddi123 »

Hi to all just wrote this as part of something im working on thought it would maybe be usefull to someone.

Any comments for improvements i could have done :!: (Still learning :D ) welcomed.

Code: Select all

; ==============================================================
; ==============================================================
; COMPILER OPTIONS:
;  [ ] Enable inline ASM support
;  [ ] Create unicode executable
;  [ ] Create threadsafe executable
;  [ ] Enable OnError lines support
;  [x] Enable XP skin support
;  [ ] Request Administrator mode for Windows Vista
;  [ ] Request User mode for Windows Vista (no virtualization)
; Library Subsystem:  
; File Format:        ASCII
; Executable Format:  Windows
;
; Created on:         07/11/2012 12:30
; App/Lib-Name:       convert to explicit
; Author:             zebuddi
; Version:            1.00
; Compiler:           PureBasic 5.00  (Windows - x86)
; ==============================================================
Pattern$ = "PureBasic (*.pb)|*.pb|*.pbi|All files (*.*)|*.*"

Global f$=OpenFileRequester("Select a .pb File to convert to explicit",pattern$,Pattern$,0)

Structure Procdata
	List Procstring$()
	posstart.l
	posend.l
EndStructure

Global NewList result$()

;----------------------------------------------------------------------------------------------------------------

;-- Procedure  ProcInfoFromFile(f$,  dll.b, internal.b,   procreturn.b, List result$())
;-- f$ - path & filename to scan
;-- dll.b if =1 only show ProcedureDll`s  
;-- internal.b if =1  only show none ProcedureDll`s  (for Lib files)
;-- dll.b=1 and interna;.b=1 for both types
;-- preocreturn.b  
;		0 = proc only 
;		1 = proc+line numbers 
;		2 = proc +number of code lines
;		3 = proc +linenumbers+number of code lines
;		4 = path+proc +linenumbers+number of code lines
;
;-- List result$() for for returned data 
;----------------------------------------------------------------------------------------------------------------

ProcedureDLL  ProcInfoFromFile(f$,  dll.b, internal.b,   procreturn.b, List result$()); 0 = proc only, 1 = proc+line numbers, 2 = proc +number of code lines, 3 = proc +linenumbers+number of code lines , 4 = path+proc +linenumbers+number of code lines
	
	Protected  NewList string$()
	Protected  NewList Procdata.Procdata()
	If ReadFile(0,f$)
		While  Eof(0)=0
			AddElement(string$())
			string$()=Trim(ReadString(0))
		Wend
	EndIf
	
	
	ResetList(string$())
	FirstElement(string$())
	With Procdata()
		ForEach  string$()
			If UCase(Left(string$(),9))=UCase("Procedure")
				AddElement(Procdata())
				\posstart=ListIndex(string$())
				While UCase(Left(string$(),12))<>UCase("EndProcedure")
					AddElement(\Procstring$())
					\Procstring$()=string$()
					NextElement(string$())
				Wend
				If UCase(Left(string$(),12))=UCase("EndProcedure")
					AddElement(\Procstring$())
					\Procstring$()=string$()
					\posend=ListIndex(string$())
				EndIf
			EndIf
		Next
	EndWith
	
	
	ResetList(Procdata())
	FirstElement(Procdata())
	
	ResetList(Procdata()\Procstring$())
	FirstElement(Procdata()\Procstring$())
	
	With Procdata()
		If ListSize(Procdata())>0
			Repeat 
				Select dll
					Case 1
						If UCase(Left(\Procstring$(),12))="PROCEDUREDLL"
							c+1
							Select procreturn
								Case 0
									AddElement(result$()) : result$()= Str(c)+".  "+\Procstring$()
								Case 1
									AddElement(result$()) : result$()= Str(c)+".  "+\Procstring$()+"  ( Start Line:"+Str(\posstart)+"  End Line:"+Str(\posend)+" )"
								Case 2
									AddElement(result$()) : result$()= Str(c)+".  "+\Procstring$()+" ---  #Code Lines:"+Str(\posend-\posstart)
								Case 3
									AddElement(result$()) : result$()= Str(c)+".  "+\Procstring$()+" ---  #Code Lines:"+Str(\posend-\posstart)+"  ( Start Line:"+Str(\posstart)+"  End Line:"+Str(\posend)+" )"
								Case 4
									AddElement(result$()) : result$()= f$+" ---  "+Str(c)+".  "+\Procstring$()+" ---  #Code Lines:"+Str(\posend-\posstart)+"  ( Start Line:"+Str(\posstart)+"  End Line:"+Str(\posend)+" )"
									
							EndSelect
						EndIf
					Case 2
						c+1
						Select procreturn
							Case 0
								AddElement(result$()) : result$()= Str(c)+".  "+\Procstring$()
							Case 1
								AddElement(result$()) : result$()= Str(c)+".  "+\Procstring$()+"  ( Start Line:"+Str(\posstart)+"  End Line:"+Str(\posend)+" )"
							Case 2
								AddElement(result$()) : result$()= Str(c)+".  "+\Procstring$()+" ---  #Code Lines:"+Str(\posend-\posstart)
							Case 3
								AddElement(result$()) : result$()= Str(c)+".  "+\Procstring$()+" ---  #Code Lines:"+Str(\posend-\posstart)+"  ( Start Line:"+Str(\posstart)+"  End Line:"+Str(\posend)+" )"
							Case 4
								AddElement(result$()) : result$()= f$+" ---  "+Str(c)+".  "+\Procstring$()+" ---  #Code Lines:"+Str(\posend-\posstart)+"  ( Start Line:"+Str(\posstart)+"  End Line:"+Str(\posend)+" )"
							Case 0		
								
						EndSelect
				EndSelect
				Select  internal
					Case 1
						If UCase(Mid(\Procstring$(),10,3))<>"DLL"
							c+1
							Select procreturn
								Case 0
									AddElement(result$()) : result$()= Str(c)+".  "+\Procstring$()
								Case 1
									AddElement(result$()) : result$()= Str(c)+".  "+\Procstring$()+"  ( Start Line:"+Str(\posstart)+"  End Line:"+Str(\posend)+" )"
								Case 2
									AddElement(result$()) : result$()= Str(c)+".  "+\Procstring$()+" ---  #Code Lines:"+Str(\posend-\posstart)
								Case 3
									AddElement(result$()) : result$()= Str(c)+".  "+\Procstring$()+" ---  #Code Lines:"+Str(\posend-\posstart)+"  ( Start Line:"+Str(\posstart)+"  End Line:"+Str(\posend)+" )"
								Case 4
									AddElement(result$()) : result$()= f$+" ---  "+Str(c)+".  "+\Procstring$()+" ---  #Code Lines:"+Str(\posend-\posstart)+"  ( Start Line:"+Str(\posstart)+"  End Line:"+Str(\posend)+" )"
								Case 0		
									
							EndSelect
						EndIf
						
				EndSelect
				
				result=NextElement(Procdata())
				ResetList(\Procstring$())
				FirstElement(\Procstring$())
				
			Until result=0
		EndIf
	EndWith
	FreeList(Procdata())
	FreeList(string$())
EndProcedure


ProcInfoFromFile( f$,1,1,3, result$())

ResetList(result$())
FirstElement(result$())
ForEach result$()
	Debug result$()
Next

CallDebugger
FreeList(result$())


Zebuddi. :D
malleo, caput, bang. Ego, comprehendunt in tempore
User avatar
kenmo
Addict
Addict
Posts: 2047
Joined: Tue Dec 23, 2003 3:54 am

Re: Procedure to pull procedure info from .pb files

Post by kenmo »

Thanks for sharing. I wonder what you are working on? Some sort of source code browser?
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 796
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Re: Procedure to pull procedure info from .pb files

Post by Zebuddi123 »

Hi Kenmo its part of an app to select a source file and convert it to explicit status. ( dont like .s for strings, i look at lots of code from our forum and there are some amazing programmers here. explicit makes it easier to follow what they are doing and learn from (self taught so its my only avenue of improvement)).

and for the http://www.purebasic.fr/english/viewtop ... 13&t=51049

Zebuddi. :D
malleo, caput, bang. Ego, comprehendunt in tempore
Post Reply