Skip to content

Commit 68aed24

Browse files
committed
Fix single GOSUB on line reported as with variable line number
1 parent 5e5bf9c commit 68aed24

3 files changed

Lines changed: 13 additions & 4 deletions

File tree

SharpPocketToolsGUI/frmMain.vb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ Public Class frmMain
423423

424424
'Parse lines again to find GOTO or GOSUB statements to replace the line numbers
425425
For Each line In newLines
426+
Dim goSubEncountered As Boolean = False
427+
426428
match = Regex.Match(line, "^ *[']") 'skip lines starting with comments
427429
If match.Success Then
428430
changedLines &= line & vbCrLf
@@ -433,6 +435,7 @@ Public Class frmMain
433435
'Find lines that contain GOTO, GOSUB or THEN
434436
match = Regex.Match(line, "(GOTO|GOSUB|THEN)", RegexOptions.IgnoreCase)
435437
If Not match.Success Then
438+
'If the line does not contain GOTO, GOSUB or THEN, skip it.
436439
changedLines &= line & vbCrLf
437440
Continue For
438441
End If
@@ -455,6 +458,8 @@ Public Class frmMain
455458
Next
456459
editLine &= line.Substring(curIndex, line.Length - curIndex) 'copy the rest of the line untill the end
457460
line = editLine
461+
'Do not Continue For here, as there might be other GOTO or THEN statements in the same line
462+
goSubEncountered = True
458463
End If
459464

460465
match = Regex.Match(line, "(GOTO|THEN) *[0-9]+$", RegexOptions.IgnoreCase)
@@ -463,7 +468,7 @@ Public Class frmMain
463468
Dim line_no As Match = Regex.Match(match.Value, "[0-9]+$") 'get the original line number reference
464469
If Not matchMap.Contains(line_no.Value.Trim()) Then
465470
Dim lineMatch = Regex.Match(line, "^ *[0-9]+")
466-
txtLog.Text &= vbCrLf & "Warning: Invalid line reference at line " & lineMatch.Value.Trim() & ": Line " & line_no.Value.Trim() & " does not exist!" & vbCrLf & vbCrLf
471+
txtLog.Text &= vbCrLf & "Warning: Invalid line reference at line " & lineMatch.Value.Trim() & ": Line " & line_no.Value.Trim() & " does not exist!" & vbCrLf
467472
End If
468473
line = Regex.Replace(line, "GOTO *[0-9]+$", "GOTO " & matchMap(line_no.Value.Trim()), RegexOptions.IgnoreCase)
469474
line = Regex.Replace(line, "THEN *[0-9]+$", "THEN " & matchMap(line_no.Value.Trim()), RegexOptions.IgnoreCase)
@@ -486,9 +491,11 @@ Public Class frmMain
486491
Continue For
487492
End If
488493

489-
match = Regex.Match(line, "^ *[0-9]+")
490-
txtLog.Text &= vbCrLf & "Warning: At line " & match.Value.Trim() & ": GOTO/GOSUB/THEN with non-constant line number found! Please adjust logic manually!" & vbCrLf & vbCrLf
491-
494+
If Not goSubEncountered Then
495+
'If there was a GOSUB statement and it was not changed, it means that it was GOSUB with integer variable
496+
match = Regex.Match(line, "^ *[0-9]+")
497+
txtLog.Text &= vbCrLf & "Warning: At line " & match.Value.Trim() & ": GOTO/GOSUB/THEN with non-constant line number found! Please adjust logic manually!" & vbCrLf
498+
End If
492499
changedLines &= line & vbCrLf
493500
Next
494501

SharpPocketToolsGUI/test_files/renumber_test.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
930 GOSUB "WVR": GOSUB 100
1414
940 GOSUB B$
1515
950 GOTO 123
16+
960 GOSUB 200

SharpPocketToolsGUI/test_files/renumber_test_pass.bas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
120 GOSUB "WVR": GOSUB 10
1414
130 GOSUB B$
1515
140 GOTO
16+
150 GOSUB 20

0 commit comments

Comments
 (0)