• Welcome to Jose's Read Only Forum 2023.
 

Change Line in Source-Code

Started by Theo Gottwald, October 15, 2020, 08:06:45 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Theo Gottwald

I am using the SPR to start PB-Compiler via Commandline.
So I need to change a Single line in the Code before starting the automatic Build (of the SPR itself).
This Macro will check the complete Sourcefile for a Line:
%Quicktest=
and will replace it with a
%Quicktest=1
or
%Quicktest=0
depending on Parameter 2. This way the Build can run completely automatic.
Due to the new "TXT." Commands of the SPR, the most work is done in just 4 lines.
Could also have used "TXT.Replace" then it would have been one line less.
But i wanted to catch the case if the line is not found and eventually stop the process.
Here is a short explanation of the Code.

Generally its a Macros-Definiton with 2 Parameters (that is the Part between ": %F_Set_Quicktest 2" and "END%".
that will call a Subroutine (using GSB. = GOSUB).
Note that the MACRO as well as the GSB. take each 2 Parameters.
The SAV.-Command makes all following Variables LOCAL Variables means they are saved and later restored (with SAV.Restore).

The work is done in just 4 Lines:
TXT.Load_Textfile|$$BAF  - > Wil load the whole Sourcefile into an internal Buffer
TXT.Find_Line_with|$$SEA||$$LIN -> Will find the Line with "%Quicktest=" and return the Linenumber and Position 1-based.
TXT.Set_Line_To|$$LIN|$$NEW  -> This will set the Line to whatever we want (in $$NEW)
and finally
TXT.Save  -> Will save the file to the Filename where it was loaded.

Finally the Macro can be used in the SPR-Code like this (with 2 Parameters split with the |-Pipe Sign):

%F_Set_Quicktest $$FIQ|0


'#######################################################################
'#######################################################################
' Parameter sind P1: Source-File, P2: 0 oder 1  (Quicktest-Value)
: %F_Set_Quicktest 2
GSB.F_Set_QTest|§§§01|§§§02
END%
'#######################################################################
:F_Set_QTest
SAV.Save|$$BAF|$$NUM|$$SEA|$$LIN|$$NEW
$$BAF=§§_01
$$NUM=§§_02
VBT.$$NUM
VBT.$$BAF
TXT.Load_Textfile|$$BAF
VAR.$$SEA=%Quicktest=
TXT.Find_Line_with|$$SEA||$$LIN
JIZ.$$LIN|Itsfine
$$NEW=%Quicktest=$$NUM
TXT.Set_Line_To|$$LIN|$$NEW
:Itsfine
TXT.Save
RET.