PB CodeLine - Evaluate expression of Constant + "xyz"
PB CodeLine - Evaluate expression of Constant + "xyz"
I am analyzing a PureBasic Programm code.
When I am looping throught my code I extract my XInclude strings and get: "#PB_Compiler_Home + "projects\test.pb"
where #PB_Compiler_Home = 'D:\ProgramFiles(x86)\PureBasic\' in my constellation.
Now i will convert this "#PB_Compiler_Home + "projects\test.pb" expression to the expected D:\ProgramFiles(x86)\PureBasic\projects\test.pb
How can I do that.
code.s = Chr(34) + "#PB_Compiler_Home + " + Chr(34) + "projects\test.pb" + Chr(34) + Chr(34)
IncludeFile.s = ?????
Please hlep me
When I am looping throught my code I extract my XInclude strings and get: "#PB_Compiler_Home + "projects\test.pb"
where #PB_Compiler_Home = 'D:\ProgramFiles(x86)\PureBasic\' in my constellation.
Now i will convert this "#PB_Compiler_Home + "projects\test.pb" expression to the expected D:\ProgramFiles(x86)\PureBasic\projects\test.pb
How can I do that.
code.s = Chr(34) + "#PB_Compiler_Home + " + Chr(34) + "projects\test.pb" + Chr(34) + Chr(34)
IncludeFile.s = ?????
Please hlep me
I may not know much, but I try a lot
Re: PB CodeLine - Evaluate expression of Constant + "xyz"
Hi,
Maybe you want IncludePath
Or simply do
If you want to store this path into a variable:
But what will you do with this variable?
I think it's not possible to load the file as include with it.
You can only use it for OpenFile() or something like that.
Bernd
Maybe you want IncludePath
Or simply do
Code: Select all
IncludeFile #PB_Compiler_Home + "projects\test.pb"
Code: Select all
IncludeFile$ = #PB_Compiler_Home + "projects\test.pb"
I think it's not possible to load the file as include with it.
You can only use it for OpenFile() or something like that.
Bernd
Re: PB CodeLine - Evaluate expression of Constant + "xyz"
I got lost in my Include-usage, i dont know where ond how often my 'xyz.pbi' is used. So my goal is to get a cross reference list of oll my code files and usage of includes.
So I loop through ... and i do not want to output
So I loop through ... and i do not want to output
into my log.file, instead i want the whole path, likeFound include: #PB_Compiler_Home + "projects\test.pbi" in file: xxxx
Therefore I need an approach to convert the String "#PB_Compiler_Home + "projects\test.pbi"" into a var that contains the real Path and File nameFound include: D:\ProgramFiles(x86)\PureBasic\projects\test.pbi in file: xxxx
I may not know much, but I try a lot
-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: PB CodeLine - Evaluate expression of Constant + "xyz"
My procedure GetPBFolder() might yield the result that you are looking for.
Re: PB CodeLine - Evaluate expression of Constant + "xyz"
Noooooooooo, maybe I can't see it . But MessageRequester("", #PB_Compiler_Home ) give me that path already.
My point is to translate the piece of Code in a string "#PB_Compiler_Home + "projects\test.pb" to D:\ProgramFiles(x86)\PureBasic\projects\test.pb
Yes I know I can do it that long laborious way.
But I am then finally at the end of my wisdom, if another variable was used to create the 'include path+name' e.g.
My point is to translate the piece of Code in a string "#PB_Compiler_Home + "projects\test.pb" to D:\ProgramFiles(x86)\PureBasic\projects\test.pb
Yes I know I can do it that long laborious way.
Code: Select all
; e.g. CodePiece$ = "#PB_Compiler_Home + "projects\test.pb"
; create this CodePiece$:
CodePiece$ = Chr(34) + "#PB_Compiler_Home + " + Chr(34) + "projects\test.pb" + Chr(34) + Chr(34)
Debug CodePiece$
If FindString( CodePiece$, "#PB_Compiler_Home" )
CodePiece$ = ReplaceString( CodePiece$, "#PB_Compiler_Home + ", "" )
CodePiece$ = Trim( CodePiece$, Chr(34) )
CodePiece$ = #PB_Compiler_Home + CodePiece$
EndIf
Debug CodePiece$
; Installpath is D:\ProgramFiles(x86)\PureBasic
MySubFolder.s = "Includes\"
XIncludeFile #PB_Compiler_Home + MySubFfolder + "NumInput.pbi" which means
XIncludeFile #PB_Compiler_Home + "Includes\NumInput.pbi" which means
D:\ProgramFiles(x86)\PureBasic\Includes\NumInput.pbi
and i want finally ___ Debug CodePiece$ give me: ___ D:\ProgramFiles(x86)\PureBasic\Includes\NumInput.pbi
instead of _________ Debug CodePiece$ give me: ___ #PB_Compiler_Home + "projects\test.pb"
I may not know much, but I try a lot
-
- Addict
- Posts: 4777
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: PB CodeLine - Evaluate expression of Constant + "xyz"
Sorry, then I don't understand what the problem is.EfDschoma wrote:MessageRequester("", #PB_Compiler_Home ) give me that path already.
Re: PB CodeLine - Evaluate expression of Constant + "xyz"
thank you Little John, that you are dealing with my problem.
In short: I am analyzing source code files, and this is my desire:
In short: I am analyzing source code files, and this is my desire:
Sorry if I couldnt explain it better; Installpath is e.g. D:\ProgramFiles(x86)\PureBasic and vor XIncludeFile i used:
;---
MySubFolder.s = "Includes\" : XIncludeFile #PB_Compiler_Home + MySubFfolder + "NumInput.pbi" which means
XIncludeFile #PB_Compiler_Home + "Includes\NumInput.pbi" which means
D:\ProgramFiles(x86)\PureBasic\Includes\NumInput.pbi
and in my analyze procedure i read the source file will extract the full IncludeFilePath.
i want finally ___ Debug CodePiece$ give me: ___ D:\ProgramFiles(x86)\PureBasic\Includes\NumInput.pbi
instead of _____ Debug CodePiece$ give me: ___ #PB_Compiler_Home + "projects\test.pb"
I may not know much, but I try a lot
Re: PB CodeLine - Evaluate expression of Constant + "xyz"
Hi I think I understand now what you want to do,
but correct me if I'm wrong.
You scan your sourcecodes by an own program an read each line in a variable.
So you get something like this:
Line$ contains
it should show you something like:
Bernd
but correct me if I'm wrong.
You scan your sourcecodes by an own program an read each line in a variable.
So you get something like this:
Line$ contains
Now you want to 'expand' this line, so when you doIncludeFile #PB_Compiler_Home + "projects\test.pb"
Code: Select all
Debug Line$
Is this right?IncludeFile C:\Programme\PureBasic\projects\test.pb
Bernd
Re: PB CodeLine - Evaluate expression of Constant + "xyz"
And if this right,
more evil, you use also a string 'constant' in your code which you want also to be 'expanded'
But this you have todo 'alone', because the scanning program does not know what your string variable contains.
Line1: MyPath$ = "Include\"
Line2: IncludeFile #PB_Compiler_Home + MyPath$ + "projects\test.pb"
And you want that your scanning program tells you at the end:
Than you have to parse the line:
Find all constants, find all variables and replace them.
That's a complicated task.
Especially when you use String.s variables instead of String$.
Becasue that it is more difficult to detect if it is a string variable.
Than you need also to scan for = " after a variable.
Is it that what you want todo in final ?
It will be a hard work.
Bernd
more evil, you use also a string 'constant' in your code which you want also to be 'expanded'
But this you have todo 'alone', because the scanning program does not know what your string variable contains.
Line1: MyPath$ = "Include\"
Line2: IncludeFile #PB_Compiler_Home + MyPath$ + "projects\test.pb"
And you want that your scanning program tells you at the end:
So you have to save all string variables in a map, to know what they contain.IncludeFile C:\Programme\PureBasic\Include\projects\test.pb
Than you have to parse the line:
Find all constants, find all variables and replace them.
That's a complicated task.
Especially when you use String.s variables instead of String$.
Becasue that it is more difficult to detect if it is a string variable.
Than you need also to scan for = " after a variable.
Is it that what you want todo in final ?
It will be a hard work.
Bernd
Last edited by infratec on Sat Mar 01, 2014 3:32 pm, edited 1 time in total.
Re: PB CodeLine - Evaluate expression of Constant + "xyz"
Yes, that is exactly what i want!
I may not know much, but I try a lot
Re: PB CodeLine - Evaluate expression of Constant + "xyz"
It's all a question of the explanation 

Re: PB CodeLine - Evaluate expression of Constant + "xyz"
Btw. it makes no sense to use a variable in an Include statement.
It is not executed during runtime
If you modify the variable later, it has no influence.
Better use also a constant for this.
It is not executed during runtime

If you modify the variable later, it has no influence.
Better use also a constant for this.
Re: PB CodeLine - Evaluate expression of Constant + "xyz"
Since PB has no Eval() procedure you have to do it like this
Bernd
Code: Select all
Global NewMap ConstantMap.s()
ConstantMap("#PB_Compiler_Home") = #PB_Compiler_Home
Procedure.s ScanLine(Line$)
Protected.i Pos1, Pos2
Repeat
Pos1 = FindString(Line$, " #", Pos1)
If Pos1
Pos1 + 1
Pos2 = FindString(Line$, " ", Pos1)
If Pos2
Const$ = Mid(Line$, Pos1, Pos2 - Pos1)
;Debug Const$
If FindMapElement(ConstantMap(), Const$)
Line$ = ReplaceString(Line$, Const$, ConstantMap())
EndIf
EndIf
EndIf
Until Pos1 = 0
ProcedureReturn Line$
EndProcedure
Test$ = "IncludeFile #PB_Compiler_Home + " + #DQUOTE$ + "projects\test.pb" + #DQUOTE$
Debug Test$
Debug ScanLine(Test$)
Re: PB CodeLine - Evaluate expression of Constant + "xyz"
Enhanced version
But I'm not sure if this will really solves your problem.
Bernd
Code: Select all
Global NewMap ConstantMap.s()
ConstantMap("#PB_Compiler_Home") = #PB_Compiler_Home
Procedure.s ScanLine(Line$)
Protected.i Pos1, Pos2
Protected Const$, Value$
Repeat
Pos1 = FindString(Line$, "#", Pos1)
If Pos1
Pos2 = FindString(Line$, " ", Pos1)
If Pos2
Const$ = Mid(Line$, Pos1, Pos2 - Pos1)
;Debug Const$
If FindMapElement(ConstantMap(), Const$)
Line$ = ReplaceString(Line$, Const$, ConstantMap())
Else
Pos1 = FindString(Line$, "=", Pos2)
If Pos1
Pos1 + 1
Value$ = Trim(Mid(Line$, Pos1))
AddMapElement(ConstantMap(), Const$)
ConstantMap() = Value$
EndIf
EndIf
EndIf
EndIf
Until Pos1 = 0
ProcedureReturn Line$
EndProcedure
Test$ = "#MyPath = Include\"
Debug ScanLine(Test$)
Test$ = "IncludeFile #PB_Compiler_Home + #MyPath + " + #DQUOTE$ + "projects\test.pb" + #DQUOTE$
Debug Test$
Debug ScanLine(Test$)
Bernd
Re: PB CodeLine - Evaluate expression of Constant + "xyz"
Thank you, for the hint about no influence during runtime und your sample code.
Its a great help and I think my solution will be to evaluate onle the #PB_Compiler_Home.
With your help I am learning quickly the use of the possibilities of purepasic.
Its a great help and I think my solution will be to evaluate onle the #PB_Compiler_Home.
With your help I am learning quickly the use of the possibilities of purepasic.

I may not know much, but I try a lot