Page 1 of 1

Get final full expanded source?

Posted: Wed Jul 17, 2019 10:02 pm
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.

Re: Get final full expanded source?

Posted: Wed Jul 17, 2019 10:23 pm
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().

Re: Get final full expanded source?

Posted: Wed Jul 17, 2019 10:25 pm
by Josh
Search in help for 'PREPROCESS'

Re: Get final full expanded source?

Posted: Thu Jul 18, 2019 8:49 am
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?

Re: Get final full expanded source?

Posted: Thu Jul 18, 2019 4:18 pm
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.

Re: Get final full expanded source?

Posted: Thu Jul 18, 2019 10:05 pm
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.

Re: Get final full expanded source?

Posted: Fri Jul 19, 2019 2:13 pm
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?

Re: Get final full expanded source?

Posted: Sat Jul 20, 2019 5:31 pm
by Kwai chang caine
For me works perfectly with "fullCode$" :wink:
Thanks a lot SICRO for sharing 8)

Re: Get final full expanded source?

Posted: Sun Jul 21, 2019 6:26 am
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!