Adapt source code to work with old/new PB versions

Everything else that doesn't fall into one of the other PB categories.
User avatar
Michael Vogel
Addict
Addict
Posts: 2867
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Adapt source code to work with old/new PB versions

Post by Michael Vogel »

Since some "Button up" events from windows got lost during the update from PB 5.10 to 5.11 I was thinking about creating a tool to check a source code for compatibility issues with newer PB releases. The next step would be to allow changing the code automatically to work fine with (the newest) release of PB.

Here's just a quick start, will need some time to think about useful enhancements etc.

Code: Select all

Procedure Init()

	DataSection

		;Data.s Title / Keyword,Search-Criteria,Parameter,Replacement,Parameter,Information,Link / Version,Type
		Data.s "Button Up Message","Some Windows-Messages got lost","..."
		Data.s "#WM_LBUTTONUP","Case","","",""
		Data.i 511,3

		Data.s "Sort Constants","No Info","..."
		Data.s "PB_Sort_Ascending","SortStructuredArray|SortStructuredList|SortList|SortArray","","PB_Ascending",""
		Data.i 511,2

		Data.s "Sort Constants","No Info","..."
		Data.s "#PB_Sort_Descending","SortStructuredArray|SortStructuredList|SortList|SortArray","","#PB_Descending",""
		Data.i 511,2

		Data.s "Sort Constants","No Info","..."
		Data.s "#PB_Sort_NoCase","SortStructuredArray|SortStructuredList|SortList|SortArray","","#PB_NoCase",""
		Data.i 511,2

		Data.s "Function Name changed","No Info","..."
		Data.s "SoundFrequency(","","","SetSoundFrequency(",""
		Data.i 511,2

		Data.s "Function Name changed","No Info","..."
		Data.s "ResizeEntity(","","1,2,3,4)","ScaleEntity(","1,2,3,4,#PB_Absolute)"
		Data.i 511,2

		Data.s "Parameter change","No Info","..."
		Data.s "FlipBuffers(","","1)","FlipBuffers(",")"
		Data.i 440,2
		
		Data.s "Obsolete command","No Info","..."
		Data.s "CreateGadgetList(","","","; CreateGadgetList(",""
		Data.i 430,2

		Data.s ""

	EndDataSection

	Structure ErrorType
		Title.s
		Version.i
		Type.i
		Key.s
		KeySearch.s
		KeyParam.s
		New.s
		NewParam.s
		Info.s
		Link.s
	EndStructure

	Global Zeile.s
	Global NewList Error.ErrorType()

	Repeat
		Read.s Zeile
		If Zeile
			AddElement(Error())
			With Error()
				\Title=Zeile
				Read.s \Info
				Read.s \Link
				Read.s \Key
				Read.s \KeySearch
				Read.s \KeyParam
				Read.s \New
				Read.s \NewParam
				Read.i \Version
				Read.i \Type
			EndWith
		Else
			Break
		EndIf
	ForEver

	Enumeration
		;
		#CCTypeUnknown;
		#CCTypeInfo;			No Change needed
		#CCTypeNormal;		Problem can be solved
		#CCTypeAlarm;		Problem unsolved
		;
		#CCInfo
		#CCAutoFix
		;
		#CCFileIn
		#CCFileOut
		;
	EndEnumeration

EndProcedure
Procedure Max(a,b)

	If a>b
		ProcedureReturn a
	Else
		ProcedureReturn b
	EndIf

EndProcedure

Procedure XCheck(s.s,t.s)

	Protected n
	Protected flag

	n=CountString(t,"|")
	If n
		While n
			flag+FindString(s,StringField(t,n,"|"))
			n-1
		Wend
		ProcedureReturn flag
	Else
		ProcedureReturn FindString(s,t)
	EndIf

EndProcedure
Procedure KCheck(s.s)

	Protected pos

	ResetList(Error())
	While NextElement(Error())
		With Error()
			pos=FindString(s,LCase(\Key))
			If pos
				If \KeySearch="" Or XCheck(s,LCase(\KeySearch))
					ProcedureReturn pos
				EndIf
			EndIf
		EndWith
	Wend

EndProcedure
Procedure CCheck(file.s,version=#Null,mode=#CCInfo)

	Protected KeyNr

	If FileSize(file)>0
		If ReadFile(#CCFileIn,file)

			If version=#Null
				FileSeek(#CCFileIn,Max(Lof(#CCFileIn)-3000,0))
				While Eof(#CCFileIn)=#Null
					Zeile=ReadString(#CCFileIn)
					If Left(Zeile,25)="; IDE Options = PureBasic"
						version=Val(ReplaceString(Trim(Mid(Zeile,26,6)),".",""))
						Break
					EndIf
				Wend
				FileSeek(#CCFileIn,0)
			EndIf
			Debug "Version: "+Str(version)

			While Eof(#CCFileIn)=#Null
				With Error()
					Zeile=ReadString(#CCFileIn)
					KeyNr=KCheck(LCase(Zeile))
					If KeyNr>0
						Debug ""
						Debug "ERROR "+\Title+" ("+\Info+")"
						Debug Trim(Zeile,#TAB$)
						If mode=#CCAutoFix
							Select \Type
							Case #CCTypeInfo
								Debug Mid(Zeile,KeyNr,Len(\Key))+" warning "
							Case #CCTypeNormal
								Debug Mid(Zeile,KeyNr,Len(\Key))+" >> "+\New
							Case #CCTypeAlarm
								Debug Mid(Zeile,KeyNr,Len(\Key))+" can't be resolved "
							EndSelect
						EndIf
					EndIf
				EndWith
			Wend
			CloseFile(#CCFileIn)

		EndIf
	EndIf

EndProcedure

Procedure Main()

	Init()
	CCheck("SourceCode.pb",#Null,#CCAutoFix)

EndProcedure

Main()