Get final full expanded source?

Everything else that doesn't fall into one of the other PB categories.
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Get final full expanded source?

Post by BarryG »

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.
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Get final full expanded source?

Post by Sicro »

https://www.purebasic.com/documentation/reference/cli_compiler.html wrote:-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 :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Get final full expanded source?

Post by Josh »

Search in help for 'PREPROCESS'
sorry for my bad english
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Get final full expanded source?

Post by BarryG »

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?
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Get final full expanded source?

Post by Sicro »

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 :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Get final full expanded source?

Post by BarryG »

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: Select all

C:\PureBasic\Compilers\pbcompiler.exe C:\Source\Orig.pb /preprocess C:\Source\Full.pb
The parameters match the order of what you did:

Code: Select all

compilerFilePath$, ~"\"" + codeFilePath$ + ~"\" --preprocess \"" + tempCodeFilePath$
So I don't know why it's failing.
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Get final full expanded source?

Post by Sicro »

Possibly a restriction of the Windows version of the PB compiler.

Please take my procedure linked above and execute it:

Code: Select all

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 :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Get final full expanded source?

Post by Kwai chang caine »

For me works perfectly with "fullCode$" :wink:
Thanks a lot SICRO for sharing 8)
ImageThe happiness is a road...
Not a destination
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Get final full expanded source?

Post by BarryG »

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!
Post Reply