PB CodeLine - Evaluate expression of Constant + "xyz"

Just starting out? Need help? Post your questions and find answers here.
User avatar
EfDschoma
User
User
Posts: 17
Joined: Fri Feb 21, 2014 11:46 am

PB CodeLine - Evaluate expression of Constant + "xyz"

Post by EfDschoma »

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
I may not know much, but I try a lot
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PB CodeLine - Evaluate expression of Constant + "xyz"

Post by infratec »

Hi,

Maybe you want IncludePath

Or simply do

Code: Select all

IncludeFile #PB_Compiler_Home + "projects\test.pb"
If you want to store this path into a variable:

Code: Select all

IncludeFile$ = #PB_Compiler_Home + "projects\test.pb"
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
User avatar
EfDschoma
User
User
Posts: 17
Joined: Fri Feb 21, 2014 11:46 am

Re: PB CodeLine - Evaluate expression of Constant + "xyz"

Post by EfDschoma »

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
Found include: #PB_Compiler_Home + "projects\test.pbi" in file: xxxx
into my log.file, instead i want the whole path, like
Found include: D:\ProgramFiles(x86)\PureBasic\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 name
I may not know much, but I try a lot
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: PB CodeLine - Evaluate expression of Constant + "xyz"

Post by Little John »

My procedure GetPBFolder() might yield the result that you are looking for.
User avatar
EfDschoma
User
User
Posts: 17
Joined: Fri Feb 21, 2014 11:46 am

Re: PB CodeLine - Evaluate expression of Constant + "xyz"

Post by EfDschoma »

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.

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$
But I am then finally at the end of my wisdom, if another variable was used to create the 'include path+name' e.g.
; 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
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: PB CodeLine - Evaluate expression of Constant + "xyz"

Post by Little John »

EfDschoma wrote:MessageRequester("", #PB_Compiler_Home ) give me that path already.
Sorry, then I don't understand what the problem is.
User avatar
EfDschoma
User
User
Posts: 17
Joined: Fri Feb 21, 2014 11:46 am

Re: PB CodeLine - Evaluate expression of Constant + "xyz"

Post by EfDschoma »

thank you Little John, that you are dealing with my problem.

In short: I am analyzing source code files, and this is my desire:
; 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"
Sorry if I couldnt explain it better
I may not know much, but I try a lot
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PB CodeLine - Evaluate expression of Constant + "xyz"

Post by infratec »

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
IncludeFile #PB_Compiler_Home + "projects\test.pb"
Now you want to 'expand' this line, so when you do

Code: Select all

Debug Line$
it should show you something like:
IncludeFile C:\Programme\PureBasic\projects\test.pb
Is this right?

Bernd
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PB CodeLine - Evaluate expression of Constant + "xyz"

Post by infratec »

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:
IncludeFile C:\Programme\PureBasic\Include\projects\test.pb
So you have to save all string variables in a map, to know what they contain.
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.
User avatar
EfDschoma
User
User
Posts: 17
Joined: Fri Feb 21, 2014 11:46 am

Re: PB CodeLine - Evaluate expression of Constant + "xyz"

Post by EfDschoma »

Yes, that is exactly what i want!
I may not know much, but I try a lot
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PB CodeLine - Evaluate expression of Constant + "xyz"

Post by infratec »

It's all a question of the explanation :wink:
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PB CodeLine - Evaluate expression of Constant + "xyz"

Post by infratec »

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.
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PB CodeLine - Evaluate expression of Constant + "xyz"

Post by infratec »

Since PB has no Eval() procedure you have to do it like this

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$)
Bernd
infratec
Always Here
Always Here
Posts: 7581
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: PB CodeLine - Evaluate expression of Constant + "xyz"

Post by infratec »

Enhanced version

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$)
But I'm not sure if this will really solves your problem.

Bernd
User avatar
EfDschoma
User
User
Posts: 17
Joined: Fri Feb 21, 2014 11:46 am

Re: PB CodeLine - Evaluate expression of Constant + "xyz"

Post by EfDschoma »

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. :D
I may not know much, but I try a lot
Post Reply