12-27-2022, 06:37 PM
(This post was last modified: 12-27-2022, 08:05 PM by grymmjack.
Edit Reason: Added documentation for latest version of MergeFile. Thanks again Steve.
)
Thanks SMcNeill - I tried to tag you, but it didn't seem to work.
Any way... This is just what I needed!
After the discord DMs we figured out a few things.
First, I have gone a little crazy on how scaffolded the project I needed this for is! LOL. https://github.com/grymmjack/DRAW (this is the one).
Second, for some reason the "../" relative paths were breaking the flattener process. I removed those and we got it to churn through the entire thing.
Third, as the source has evolved a little bit I'll post the one I used here:
Last here is a video showing how the stack counter and indention helps to see what includes are including other includes (lol):
https://app.screencast.com/v89y1GUNVSQG4...0FLXws7IsI
Any way... This is just what I needed!
After the discord DMs we figured out a few things.
First, I have gone a little crazy on how scaffolded the project I needed this for is! LOL. https://github.com/grymmjack/DRAW (this is the one).
Second, for some reason the "../" relative paths were breaking the flattener process. I removed those and we got it to churn through the entire thing.
Third, as the source has evolved a little bit I'll post the one I used here:
Code: (Select All)
''
' MergeFile
'
' Takes a source target basic file and flattens all the includes to be in a
' single file. This lets you see what the compiler is compiling if you have
' multiple file includes. It works across directories, too.
'
' HOW TO USE:
' -----------
' Change target$ to your source basic file you want to flatten into one file.
' Change outfile$ to the file path of the flattened/merged file.
' Change indent to a number you prefer. This helps debug stuff in code folding.
'
' @author Steve McNeill (every thing)
' @author Rick Christy <grymmjack@gmail.com> (idea)
' @see https://staging.qb64phoenix.com/showthread.php?tid=1335&pid=12085#pid12085
'
$Debug
$If WIN Then
Const Slash$ = "\"
$Else
const Slash$ = "/"
$End If
' CHANGE THIS STUFF
const indent = 8
target$ = "I:\git\DRAW\DRAW.BAS"
outfile$ = "I:\git\DRAW\DRAW_FLATTENED.BAS"
' -----------------------------------------------------------------------------
' MAIN PROGRAM
' -----------------------------------------------------------------------------
If target$ = "" Then
Print "Give me a QB64 program to unravel => ";
Input target$
Print "Give me a name to save the new file under => ";
Input outfile$
End If
Open outfile$ For Output As #1
MergeFile target$
Dim SHARED stack AS INTEGER
stack% = 0
Sub MergeFile (whatfile$)
f = FreeFile
CurrentDir$ = _CWD$
i = _InStrRev(whatfile$, Slash$)
newdir$ = Left$(whatfile$, i)
If i > 0 Then
ChDir newdir$
whatfile$ = Mid$(whatfile$, i + 1)
End If
Print whatfile$
Open whatfile$ For Binary As #f
If LOF(f) Then
Do
Line Input #f, temp$
If Left$(UCase$(_Trim$(temp$)), 11) = "'$INCLUDE:'" Then
temp$ = _Trim$(temp$)
file$ = Mid$(temp$, 12)
file$ = Left$(file$, Len(file$) - 1)
stack% = stack% +1
MergeFile file$
Else
Print #1, STRING$(stack% * indent, " ") + temp$
End If
Loop Until EOF(f)
End If
ChDir CurrentDir$
' See below comment
IF LOF(f) = 0 THEN killempty = 1 ELSE killempty = 0
Close #f
' In severe cases of nesting (the catalyst for this MergeFile program LOL)
' the program can get confused and output 0 byte files in the same dir it
' ran from. This is a kludge to get rid of those after it runs.
if killempty = 1 THEN KILL whatfile$
stack% = stack% - 1
End Sub
Last here is a video showing how the stack counter and indention helps to see what includes are including other includes (lol):
https://app.screencast.com/v89y1GUNVSQG4...0FLXws7IsI