It is currently Wed Sep 18, 2019 7:04 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Get final full expanded source?
PostPosted: Wed Jul 17, 2019 10:02 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 264
Hi guys, is there a way I can get the final full expanded source of my app after all included files and macros have been expanded, and save it as a new single big PureBasic source code to disk? I'm talking about what would be considered the "finished" source just before the compiler starts compiling it. Thank you.


Top
 Profile  
Reply with quote  
 Post subject: Re: Get final full expanded source?
PostPosted: Wed Jul 17, 2019 10:23 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 359
Location: Germany
-pp, --preprocess, /PREPROCESS "filename": preprocess the source code and write the output in the specified "Filename". The processed file is a single file with all macro expanded, compiler directive handled and multiline resolved. This allows an easier parsing of a PureBasic source file, as all is expanded and is available in a flat file format. No comments are included by default, but the flag '--commented' can be used to have all untouched original source as comments and allow comments processing. The preprocessed file can be recompiled as any other PureBasic source file to create the final executable.

Here is an example with RunProgram().

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download -- Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Top
 Profile  
Reply with quote  
 Post subject: Re: Get final full expanded source?
PostPosted: Wed Jul 17, 2019 10:25 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 13, 2010 3:45 pm
Posts: 885
Search in help for 'PREPROCESS'

_________________
sorry for my bad english


Top
 Profile  
Reply with quote  
 Post subject: Re: Get final full expanded source?
PostPosted: Thu Jul 18, 2019 8:49 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 264
Thank you both. :) I'm amazed that it even splits multiple commands onto separate lines.

Is there a way to specify the output file, so it doesn't go to c:\commented?


Top
 Profile  
Reply with quote  
 Post subject: Re: Get final full expanded source?
PostPosted: Thu Jul 18, 2019 4:18 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 359
Location: Germany
BarryG wrote:
Is there a way to specify the output file, so it doesn't go to c:\commented?
As you can see from the PB help, the output file name is specified after the preprocess command. Instead of specifying only the output file name, you can also specify the full path to the output file. You can see that in my example code, too.

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download -- Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Top
 Profile  
Reply with quote  
 Post subject: Re: Get final full expanded source?
PostPosted: Thu Jul 18, 2019 10:05 pm 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 264
Hi Sicro, I already did look at your source but when I tried to adapt it to this simple batch file, it doesn't work:

Code:
C:\PureBasic\Compilers\pbcompiler.exe C:\Source\Orig.pb /preprocess C:\Source\Full.pb

The parameters match the order of what you did:

Code:
compilerFilePath$, ~"\"" + codeFilePath$ + ~"\" --preprocess \"" + tempCodeFilePath$

So I don't know why it's failing.


Top
 Profile  
Reply with quote  
 Post subject: Re: Get final full expanded source?
PostPosted: Fri Jul 19, 2019 2:13 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 359
Location: Germany
Possibly a restriction of the Windows version of the PB compiler.

Please take my procedure linked above and execute it:
Code:
fullCode$ = GetContentOfPreProcessedFile("C:\Source\Orig.pb", "C:\PureBasic\Compilers\pbcompiler.exe")
If fullCode <> ""
  Debug "ok"
Else
  Debug "error"
EndIf
What is the result?

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download -- Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Top
 Profile  
Reply with quote  
 Post subject: Re: Get final full expanded source?
PostPosted: Sat Jul 20, 2019 5:31 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4502
Location: Lyon - France
For me works perfectly with "fullCode$" :wink:
Thanks a lot SICRO for sharing 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: Get final full expanded source?
PostPosted: Sun Jul 21, 2019 6:26 am 
Offline
Enthusiast
Enthusiast

Joined: Thu Apr 18, 2019 8:17 am
Posts: 264
Sicro wrote:
Please take my procedure linked above and execute it

Hi Sicro, I tried your procedure and it worked, so I deleted my batch file and recreated it, and it works for me now. No idea why. All sorted, anyway. Thanks!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: mrv2k and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye