PureBasic Forum
https://www.purebasic.fr/english/

Get final full expanded source?
https://www.purebasic.fr/english/viewtopic.php?f=7&t=73211
Page 1 of 1

Author:  BarryG [ Wed Jul 17, 2019 10:02 pm ]
Post subject:  Get final full expanded source?

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.

Author:  Sicro [ Wed Jul 17, 2019 10:23 pm ]
Post subject:  Re: Get final full expanded source?

-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().

Author:  Josh [ Wed Jul 17, 2019 10:25 pm ]
Post subject:  Re: Get final full expanded source?

Search in help for 'PREPROCESS'

Author:  BarryG [ Thu Jul 18, 2019 8:49 am ]
Post subject:  Re: Get final full expanded source?

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?

Author:  Sicro [ Thu Jul 18, 2019 4:18 pm ]
Post subject:  Re: Get final full expanded source?

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.

Author:  BarryG [ Thu Jul 18, 2019 10:05 pm ]
Post subject:  Re: Get final full expanded source?

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.

Author:  Sicro [ Fri Jul 19, 2019 2:13 pm ]
Post subject:  Re: Get final full expanded source?

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?

Author:  Kwai chang caine [ Sat Jul 20, 2019 5:31 pm ]
Post subject:  Re: Get final full expanded source?

For me works perfectly with "fullCode$" :wink:
Thanks a lot SICRO for sharing 8)

Author:  BarryG [ Sun Jul 21, 2019 6:26 am ]
Post subject:  Re: Get final full expanded source?

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!

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/