07-31-2024, 04:33 PM
(This post was last modified: 07-31-2024, 04:34 PM by aadityap0901.)
Here is my update about my text editor:
Advanced Controls: F4 to toggle Symbol Viewer, F6 or Mouseclick for Single Cursor, Alt + Mouseclick for multiple cursors
Symbol Viewer is made for qb64 only, may not work correctly...
Advanced Controls: F4 to toggle Symbol Viewer, F6 or Mouseclick for Single Cursor, Alt + Mouseclick for multiple cursors
Symbol Viewer is made for qb64 only, may not work correctly...
Code: (Select All)
'$Dynamic
$Resize:On
Do While _Resize: Loop
Screen _NewImage(960, 540, 32)
Type Vec2
As _Unsigned Integer X, Y
End Type
Dim As Vec2 Cursor_Position(1 To 1)
Cursor_Position(1).X = 1
Cursor_Position(1).Y = 1
Cursor_Character$ = Chr$(95)
Dim Shared Lines$(0), SymbolVariableList$, SymbolTypeList$, SymbolFunctionList$, SymbolSubroutinesList$: SymbolVariableList$ = ListNew$: SymbolTypeList$ = ListNew$: SymbolFunctionList$ = ListNew$: SymbolSubroutinesList$ = ListNew$
Dim Shared As Long SymbolsWindowScrollOffset, VerticalScrollOffset, HorizontalScrollOffset, TextFrameOffset, VerticalLines
SymbolsWindowScrollOffset = 1
VerticalScrollOffset = 1
HorizontalScrollOffset = 1
Dim Shared As _Byte GenerateSymbols, SymbolsWindow: SymbolsWindow = -1
Const LineNumbersWidth = 5
$If WIN Then
If _FileExists(Command$(1)) Then
FilePath$ = Command$(1)
ElseIf _FileExists(_StartDir$ + "\" + Command$(1)) Then
FilePath$ = _StartDir$ + "\" + Command$(1)
End If
$Else
If _FileExists(Command$(1)) Then
FilePath$ = Command$(1)
ElseIf _FileExists(_StartDir$ + "/" + Command$(1)) Then
FilePath$ = _StartDir$ + "/" + Command$(1)
End If
$End If
If FilePath$ = "" Then FilePath$ = "Untitled.txt"
If _FileExists(FilePath$) Then GoSub OpenFile
$If WIN Then
If _InStrRev(FilePath$, "\") Then FileName$ = Mid$(FilePath$, _InStrRev(FilePath$, "\") + 1) Else FileName$ = FilePath$
$Else
If _InStrRev(FilePath$, "/") Then FileName$ = Mid$(FilePath$, _InStrRev(FilePath$, "/") + 1) Else FileName$ = FilePath$
$End If
TITLE$ = FileName$ + " - TEdi"
Color _RGB32(255), _RGB32(0)
Do
_Limit 30
If _Resize Then
Screen _NewImage(_ResizeWidth, _ResizeHeight, 32)
Color _RGB32(255), _RGB32(16)
End If
Cls , _RGB32(16)
If SymbolsWindow Then TextFrameOffset = Min(_Width * 0.3, 256) Else TextFrameOffset = 16
HorizontalCharsVisible = (_Width - 16 - TextFrameOffset) \ _FontWidth - LineNumbersWidth - 1
VerticalLines = _Height \ _FontHeight
'Mouse Inputs
LastMouseWheel = 0
MouseWheel = 0
While _MouseInput
LastMouseWheel = _MouseWheel: If LastMouseWheel Then MouseWheel = LastMouseWheel
Wend
If InRange(0, _MouseX, TextFrameOffset) And SymbolsWindow Then SymbolsWindowScrollOffset = SymbolsWindowScrollOffset + MouseWheel
If InRange(TextFrameOffset, _MouseX, _Width) Then VerticalScrollOffset = VerticalScrollOffset + MouseWheel
ScrollBP = _Height * VerticalLines / (UBound(Lines$) - VerticalLines \ 2): ScrollBO = _Height - ScrollBP: ScrollBO = ScrollBO * VerticalScrollOffset / UBound(Lines$)
If InRange(_Width - 16, _MouseX, _Width) Then
If _MouseButton(1) Then
ScrollBarTemp = _MouseY - ScrollMouseY: ScrollBarTemp = ScrollBarTemp * UBound(Lines$) / _Height
VerticalScrollOffset = Max(1, Min(VerticalScrollOffset + ScrollBarTemp, UBound(Lines$) - VerticalLines \ 2))
End If
ScrollMouseY = _MouseY
End If
'------------
'Keyboard Inputs
Key$ = InKey$
KeyShift = _KeyDown(100304) Or _KeyDown(100303)
KeyCtrl = _KeyDown(100306) Or _KeyDown(100305)
KeyAlt = _KeyDown(100308) Or _KeyDown(100307)
KeyHit = _KeyHit
If InRange(TextFrameOffset, _MouseX, _Width - 16) And _MouseButton(1) Then
If KeyAlt Then
ReDim _Preserve Cursor_Position(1 To UBound(Cursor_Position) + 1) As Vec2
Cursor_Position(UBound(Cursor_Position)).Y = Min(_MouseY \ _FontHeight + VerticalScrollOffset, UBound(Lines$))
Cursor_Position(UBound(Cursor_Position)).X = Min((_MouseX - TextFrameOffset) \ _FontWidth - LineNumbersWidth - 1 + HorizontalScrollOffset, Len(Lines$(Cursor_Position(UBound(Cursor_Position)).Y)) + 1)
Else
ReDim _Preserve Cursor_Position(1 To 1) As Vec2
Cursor_Position(1).Y = Min(_MouseY \ _FontHeight + VerticalScrollOffset, UBound(Lines$))
Cursor_Position(1).X = Min((_MouseX - TextFrameOffset) \ _FontWidth - LineNumbersWidth - 1 + HorizontalScrollOffset, Len(Lines$(Cursor_Position(1).Y)) + 1)
End If
While _MouseButton(1) Or _MouseInput: Wend
End If
For CursorID = LBound(Cursor_Position) To UBound(Cursor_Position)
If Len(Key$) = 1 Then
Select Case Asc(Key$)
Case 8: 'Backspace
If Cursor_Position(CursorID).X > 1 Then
Lines$(Cursor_Position(CursorID).Y) = Left$(Lines$(Cursor_Position(CursorID).Y), Cursor_Position(CursorID).X - 2) + Mid$(Lines$(Cursor_Position(CursorID).Y), Cursor_Position(CursorID).X)
DecrementINT Cursor_Position(CursorID).X
ElseIf Cursor_Position(CursorID).Y > 1 Then
DecrementINT Cursor_Position(CursorID).Y
Cursor_Position(CursorID).X = Len(Lines$(Cursor_Position(CursorID).Y)) + 1
If Cursor_Position(CursorID).Y < UBound(Lines$) Then Lines$(Cursor_Position(CursorID).Y) = Lines$(Cursor_Position(CursorID).Y) + Lines$(Cursor_Position(CursorID).Y + 1)
For J = Cursor_Position(CursorID).Y + 1 To UBound(Lines$) - 1
Swap Lines$(J), Lines$(J + 1)
Next J
ReDim _Preserve Lines$(1 To UBound(Lines$) - 1)
If Cursor_Position(CursorID).Y < VerticalScrollOffset Then VerticalScrollOffset = VerticalScrollOffset - 1
End If
Case 9: 'Tab
If UBound(Lines$) < Cursor_Position(CursorID).Y Then ReDim _Preserve Lines$(1 To UBound(Lines$) + 1)
Lines$(Cursor_Position(CursorID).Y) = Left$(Lines$(Cursor_Position(CursorID).Y), Cursor_Position(CursorID).X - 1) + " " + Mid$(Lines$(Cursor_Position(CursorID).Y), Cursor_Position(CursorID).X) 'Tab Character
Cursor_Position(CursorID).X = Cursor_Position(CursorID).X + 4
Case 13: 'Enter
ReDim _Preserve Lines$(1 To UBound(Lines$) + 1)
For J = UBound(Lines$) - 1 To Cursor_Position(CursorID).Y + 1 Step -1
Swap Lines$(J), Lines$(J + 1)
Next J
Lines$(Cursor_Position(CursorID).Y + 1) = Mid$(Lines$(Cursor_Position(CursorID).Y), Cursor_Position(CursorID).X)
Lines$(Cursor_Position(CursorID).Y) = Left$(Lines$(Cursor_Position(CursorID).Y), Cursor_Position(CursorID).X - 1)
IncrementINT Cursor_Position(CursorID).Y
If Cursor_Position(CursorID).Y + 2 > VerticalScrollOffset + VerticalLines Then VerticalScrollOffset = VerticalScrollOffset + 1
Cursor_Position(CursorID).X = 1
HorizontalScrollOffset = 1
Case 32 To 125:
If UBound(Lines$) < Cursor_Position(CursorID).Y Then ReDim _Preserve Lines$(1 To Cursor_Position(CursorID).Y)
Lines$(Cursor_Position(CursorID).Y) = Left$(Lines$(Cursor_Position(CursorID).Y), Cursor_Position(CursorID).X - 1) + Key$ + Mid$(Lines$(Cursor_Position(CursorID).Y), Cursor_Position(CursorID).X) 'Printable Characters
IncrementINT Cursor_Position(CursorID).X
End Select
If CursorID = 1 Then
VerticalScrollOffset = Max(1, Cursor_Position(1).Y - VerticalLines \ 2)
HorizontalScrollOffset = Max(1, Cursor_Position(1).X - HorizontalCharsVisible \ 2)
End If
KeyPressTimer = Timer
FileSaved = 0
End If
Select Case KeyHit
Case 15872 'F4
SymbolsWindow = Not SymbolsWindow
Case 16384 'F6
ReDim _Preserve Cursor_Position(1 To 1) As Vec2: If CursorID > 1 Then Exit For
Case 18432 'Up
If KeyCtrl Then
VerticalScrollOffset = Max(VerticalScrollOffset - 1, 1)
If Cursor_Position(CursorID).Y + 2 > VerticalScrollOffset + VerticalLines Then Cursor_Position(CursorID).Y = Cursor_Position(CursorID).Y - 1
ElseIf KeyAlt Then
SymbolsWindowScrollOffset = Max(SymbolsWindowScrollOffset - 1, 1)
Else
If Cursor_Position(CursorID).Y > 1 Then DecrementINT Cursor_Position(CursorID).Y
Cursor_Position(CursorID).X = Min(Len(Lines$(Cursor_Position(CursorID).Y)) + 1, Cursor_Position(CursorID).X)
If InRange(VerticalScrollOffset - 2, Cursor_Position(CursorID).Y, VerticalScrollOffset + VerticalLines) And Cursor_Position(CursorID).Y < VerticalScrollOffset Then VerticalScrollOffset = VerticalScrollOffset - 1
End If
Case 20480 'Down
If KeyCtrl Then
VerticalScrollOffset = Min(VerticalScrollOffset + 1, UBound(Lines$))
If Cursor_Position(CursorID).Y < VerticalScrollOffset Then Cursor_Position(CursorID).Y = Cursor_Position(CursorID).Y + 1
ElseIf KeyAlt Then
SymbolsWindowScrollOffset = SymbolsWindowScrollOffset + 1
Else
If Cursor_Position(CursorID).Y < UBound(Lines$) Then IncrementINT Cursor_Position(CursorID).Y
Cursor_Position(CursorID).X = Min(Len(Lines$(Cursor_Position(CursorID).Y)) + 1, Cursor_Position(CursorID).X)
If InRange(VerticalScrollOffset, Cursor_Position(CursorID).Y, VerticalScrollOffset + VerticalLines) And Cursor_Position(CursorID).Y + 2 > VerticalScrollOffset + VerticalLines Then VerticalScrollOffset = VerticalScrollOffset + 1
End If
Case 19200 'Left
If KeyCtrl Then
HorizontalScrollOffset = Max(HorizontalScrollOffset - 1, 1)
Else
If Cursor_Position(CursorID).X > 1 Then
DecrementINT Cursor_Position(CursorID).X
Else
HorizontalScrollOffset = 1
End If
End If
Case 19712 'Right
If KeyCtrl Then
HorizontalScrollOffset = HorizontalScrollOffset + 1
Else
Cursor_Position(CursorID).X = Min(Len(Lines$(Cursor_Position(CursorID).Y)) + 1, Cursor_Position(CursorID).X + 1)
End If
Case 18176 'Home
If KeyCtrl Then
Cursor_Position(CursorID).X = 1
Cursor_Position(CursorID).Y = 1
HorizontalScrollOffset = 1
VerticalScrollOffset = 1
Else
Cursor_Position(CursorID).X = 1
HorizontalScrollOffset = 1
End If
Case 20224 'End
If KeyCtrl Then
Cursor_Position(CursorID).Y = UBound(Lines$)
Cursor_Position(CursorID).X = Len(Lines$(Cursor_Position(CursorID).Y)) + 1
HorizontalScrollOffset = Max(Len(Lines$(Cursor_Position(CursorID).Y)) - HorizontalCharsVisible + 1, 1)
VerticalScrollOffset = Max(UBound(Lines$) - VerticalLines + 2, 1)
Else
Cursor_Position(CursorID).X = Len(Lines$(Cursor_Position(CursorID).Y)) + 1
HorizontalScrollOffset = Max(Len(Lines$(Cursor_Position(CursorID).Y)) - HorizontalCharsVisible + 1, 1)
End If
Case 18688 'PgUp
If KeyCtrl Then
VerticalScrollOffset = 1
HorizontalScrollOffset = Max(Len(Lines$(Cursor_Position(CursorID).Y)) - HorizontalCharsVisible + 1, 1)
Else
VerticalScrollOffset = Max(VerticalScrollOffset - VerticalLines, 1)
End If
Case 20736 'PgDn
If KeyCtrl Then
VerticalScrollOffset = Max(UBound(lines$) - VerticalLines + 2, 1)
HorizontalScrollOffset = Max(Len(Lines$(Cursor_Position(CursorID).Y)) - HorizontalCharsVisible + 1, 1)
Else
VerticalScrollOffset = Min(VerticalScrollOffset + VerticalLines, UBound(Lines$) - VerticalLines + 2)
End If
Case 21248 'Delete
If Cursor_Position(CursorID).X = Len(Lines$(Cursor_Position(CursorID).Y)) + 1 Then
If Cursor_Position(CursorID).Y < UBound(Lines$) Then
Lines$(Cursor_Position(CursorID).Y) = Lines$(Cursor_Position(CursorID).Y) + Lines$(Cursor_Position(CursorID).Y + 1)
For J = Cursor_Position(CursorID).Y + 1 To UBound(Lines$) - 1
Swap Lines$(J), Lines$(J + 1)
Next J
ReDim _Preserve Lines$(1 To UBound(Lines$) - 1)
End If
Else
Lines$(Cursor_Position(CursorID).Y) = Left$(Lines$(Cursor_Position(CursorID).Y), Cursor_Position(CursorID).X - 1) + Mid$(Lines$(Cursor_Position(CursorID).Y), Cursor_Position(CursorID).X + 1)
End If
KeyPressTimer = Timer
FileSaved = 0
End Select
'---------------
If HorizontalScrollOffset > Cursor_Position(CursorID).X Then DecrementULNG HorizontalScrollOffset
If Cursor_Position(CursorID).X - HorizontalScrollOffset > HorizontalCharsVisible + 1 Then IncrementULNG HorizontalScrollOffset
'Show Cursor
Line (TextFrameOffset + (LineNumbersWidth + 1) * _FontWidth, (Cursor_Position(CursorID).Y - VerticalScrollOffset) * _FontHeight)-(_Width - 1, (Cursor_Position(CursorID).Y - VerticalScrollOffset + 1) * _FontHeight), _RGB32(32), BF
If 2 * Timer(0.1) - Int(2 * Timer) > 0.5 Then
Line (TextFrameOffset + (Cursor_Position(CursorID).X + LineNumbersWidth + 1 - HorizontalScrollOffset) * _FontWidth, (Cursor_Position(CursorID).Y - VerticalScrollOffset) * _FontHeight)-(TextFrameOffset + (Cursor_Position(CursorID).X + LineNumbersWidth + 1 - HorizontalScrollOffset) * _FontWidth + 2, (Cursor_Position(CursorID).Y - VerticalScrollOffset + 1) * _FontHeight), _RGB32(0, 255, 0), BF
'Line (TextFrameOffset + (Cursor_Position(CursorID).X + LineNumbersWidth + 1 - HorizontalScrollOffset) * _FontWidth, (Cursor_Position(CursorID).Y - VerticalScrollOffset + 1) * _FontHeight - 2)-(TextFrameOffset + (Cursor_Position(CursorID).X + LineNumbersWidth + 2 - HorizontalScrollOffset) * _FontWidth, (Cursor_Position(CursorID).Y - VerticalScrollOffset + 1) * _FontHeight), _RGB32(0, 255, 0), BF
End If
'-----------
Next CursorID
'Print Text
J = 0
For I = VerticalScrollOffset To VerticalScrollOffset + VerticalLines
If UBound(Lines$) < I Then Exit For
Color _RGB32(255), _RGB32(32)
_PrintString (TextFrameOffset, J * _FontHeight), " " + _Trim$(Str$(I)) + Space$(LineNumbersWidth - Len(_Trim$(Str$(I))))
Color _RGB32(255), 0
_PrintString (TextFrameOffset + (LineNumbersWidth + 1) * _FontWidth, J * _FontHeight), Mid$(Lines$(I), HorizontalScrollOffset, HorizontalCharsVisible)
J = J + 1
Next I
Line (TextFrameOffset, 0)-(TextFrameOffset, _Height - 1), _RGB32(255)
'----------
'Show Scroll Bar
Line (_Width - 16, 0)-(_Width, _Height), _RGB32(16), BF
Line (_Width - 16, ScrollBO)-(_Width, ScrollBO + ScrollBP), _RGB32(64), BF
'---------------
'Generate Symbols
If FileSaved = 0 Then GenerateSymbols = -1
For I = 1 To 16
If GenerateSymbolsI >= UBound(Lines$) Then GenerateSymbolsI = 0: GenerateSymbols = 0
If GenerateSymbols Then
GenerateSymbolsI = GenerateSymbolsI + 1
If InRange(LBound(Lines$), GenerateSymbolsI, UBound(Lines$)) Then T$ = Tokenizer$(Lines$(GenerateSymbolsI)) Else T$ = ListNew$
If GenerateSymbolsFunction = 0 And GenerateSymbolsSubroutine = 0 Then
T = ListISearch~&(T$, "Dim")
If T Then
For J = 1 To ListLength~&(T$)
E$ = ListGet$(T$, J)
If InStr("dimsharedcommonas_bit_byteintegerlong_integer64singledouble_float_unsigned_mem_offsetto", LCase$(E$)) Or InRange(65, Asc(UCase$(E$), 1), 90) = 0 Then _Continue
If ListISearch~&(SymbolVariableList$, E$) = 0 And ListISearch~&(SymbolTypeList$, E$) = 0 Then SymbolVariableList$ = ListAdd$(SymbolVariableList$, E$)
Next J
End If
T = ListISearch~&(T$, "Type")
If InStr(LCase$(Lines$(GenerateSymbolsI)), "end type") Then
GenerateSymbolsType = 0
SymbolTypeList$ = ListAdd$(SymbolTypeList$, Left$(SymbolType$, Len(SymbolType$) - 1) + "}")
SymbolType$ = ""
End If
If T Or GenerateSymbolsType Then
For J = 1 To ListLength~&(T$)
E$ = ListGet$(T$, J)
If _StriCmp(E$, "Type") = 0 Then
J = J + 1
SymbolType$ = ListGet$(T$, J) + " {"
_Continue
End If
If E$ = "," Then _Continue
If _StriCmp(E$, "As") = 0 Then
J = J + 1
_Continue
End If
SymbolType$ = SymbolType$ + E$ + ","
Next J
If T Then GenerateSymbolsType = -1
End If
End If
T = ListISearch~&(T$, "Function")
If T Then
For J = 1 To ListLength~&(T$)
E$ = ListGet$(T$, J)
If _StriCmp(E$, "Function") = 0 Then
GenerateSymbolsFunction = -1
J = J + 1
E$ = ListGet$(T$, J)
If ListISearch(SymbolFunctionList$, E$) = 0 Then SymbolFunctionList$ = ListAdd$(SymbolFunctionList$, E$)
End If
If _StriCmp(E$, "End") = 0 And _StriCmp(ListGet$(T$, J + 1), "Function") = 0 Then J = J + 1: GenerateSymbolsFunction = 0
Next J
End If
T = ListISearch~&(T$, "Sub")
If T Then
For J = 1 To ListLength~&(T$)
E$ = ListGet$(T$, J)
If _StriCmp(E$, "Sub") = 0 Then
GenerateSymbolsSubroutine = -1
J = J + 1
E$ = ListGet$(T$, J)
If ListISearch(SymbolSubroutinesList$, E$) = 0 Then SymbolSubroutinesList$ = ListAdd$(SymbolSubroutinesList$, E$)
End If
If _StriCmp(E$, "End") = 0 And _StriCmp(ListGet$(T$, J + 1), "Sub") = 0 Then J = J + 1: GenerateSymbolsSubroutine = 0
Next J
End If
End If
Next I
If SymbolsWindow Then
Color _RGB32(255), 0
Line (0, _FontHeight + _Height \ 4)-(TextFrameOffset, _FontHeight + _Height \ 4), _RGB32(255)
Line (0, _FontHeight + _Height \ 2)-(TextFrameOffset, _FontHeight + _Height \ 2), _RGB32(255)
Line (0, _FontHeight + 3 * _Height \ 4)-(TextFrameOffset, _FontHeight + 3 * _Height \ 4), _RGB32(255)
_PrintString (0, 0), "Variables:"
_PrintString (0, _FontHeight + _Height \ 4), "Types:"
_PrintString (0, _FontHeight + _Height \ 2), "Functions:"
_PrintString (0, _FontHeight + 3 * _Height \ 4), "Subroutines:"
For I = SymbolsWindowScrollOffset To Min(ListLength~&(SymbolVariableList$), SymbolsWindowScrollOffset + VerticalLines \ 4 - 1)
_PrintString (0, (I - SymbolsWindowScrollOffset + 1) * _FontHeight), Left$(ListGet$(SymbolVariableList$, I), TextFrameOffset \ _FontWidth)
Next I: For I = SymbolsWindowScrollOffset To Min(ListLength~&(SymbolTypeList$), SymbolsWindowScrollOffset + VerticalLines \ 4 - 2)
_PrintString (0, (I - SymbolsWindowScrollOffset + 2) * _FontHeight + _Height / 4), Left$(ListGet$(SymbolTypeList$, I), TextFrameOffset \ _FontWidth)
Next I: For I = SymbolsWindowScrollOffset To Min(ListLength~&(SymbolFunctionList$), SymbolsWindowScrollOffset + VerticalLines \ 4 - 2)
_PrintString (0, (I - SymbolsWindowScrollOffset + 2) * _FontHeight + _Height / 2), Left$(ListGet$(SymbolFunctionList$, I), TextFrameOffset \ _FontWidth)
Next I: For I = SymbolsWindowScrollOffset To Min(ListLength~&(SymbolSubroutinesList$), SymbolsWindowScrollOffset + VerticalLines \ 4 - 2)
_PrintString (0, (I - SymbolsWindowScrollOffset + 2) * _FontHeight + 3 * _Height / 4), Left$(ListGet$(SymbolSubroutinesList$, I), TextFrameOffset \ _FontWidth)
Next I
End If
'AutoSave after 0.5 Second of Sleep
If Timer(0.1) - KeyPressTimer >= 0.5 And FileSaved = 0 Then
GoSub SaveFile
FileSaved = -1
End If
'------------------------
On _Exit GOTO SaveExit
If FileSaved <> OldFileSaved Then
OldFileSaved = FileSaved
If FileSaved Then _Title TITLE$ Else _Title TITLE$ + "*"
End If
_Display
Loop
System
SaveExit:
GoSub SaveFile
System
ClearFile:
ReDim Lines$(0 To 0)
Return
OpenFile:
If _FileExists(FilePath$) = 0 Then Return
Open FilePath$ For Input As #1
If LOF(1) Then
Do
Line Input #1, L$
If UBound(Lines$) = 0 Then ReDim _Preserve Lines$(1 To 1) Else ReDim _Preserve Lines$(1 To UBound(Lines$) + 1)
Lines$(UBound(Lines$)) = L$
If EOF(1) Then Exit Do
Loop
End If
Close #1
Return
SaveFile:
If FilePath$ = "" Then Return
Open FilePath$ For Output As #1
For I = 1 To UBound(Lines$)
If I = UBound(Lines$) And Lines$(I) = "" Then _Continue
Print #1, Lines$(I)
Next I
Close #1
Return
Function Tokenizer$ (L$)
Dim Tokens(1) As String, nToken As _Unsigned Integer
nToken = 1
TokenList$ = ListNew$
For I = 1 To Len(L$)
Select Case Asc(L$, I)
Case 32
If StringMode = 0 Then
If Tokens(nToken) <> "" Then
TokenList$ = ListAdd$(TokenList$, Tokens(nToken))
nToken = nToken + 1
ReDim _Preserve Tokens(nToken) As String
End If
Else
Tokens(nToken) = Tokens(nToken) + Mid$(L$, I, 1)
End If
Case 34: StringMode = Not StringMode: Tokens(nToken) = Tokens(nToken) + Chr$(34)
Case 40 To 47, 58 To 64, 91 To 94, 96, 123 To 125
If StringMode = 0 Then
If Tokens(nToken) <> "" Then
TokenList$ = ListAdd$(TokenList$, Tokens(nToken))
nToken = nToken + 1
ReDim _Preserve Tokens(nToken) As String
End If
Tokens(nToken) = Mid$(L$, I, 1)
TokenList$ = ListAdd$(TokenList$, Tokens(nToken))
nToken = nToken + 1
ReDim _Preserve Tokens(nToken) As String
Else
Tokens(nToken) = Tokens(nToken) + Mid$(L$, I, 1)
End If
Case 39: If StringMode = 0 Then Exit For
Case Else: Tokens(nToken) = Tokens(nToken) + Mid$(L$, I, 1)
End Select
Next I
If Len(Tokens(nToken)) Then TokenList$ = ListAdd$(TokenList$, Tokens(nToken))
Tokenizer$ = TokenList$
End Function
Sub IncrementINT (A As Integer)
A = A + 1
End Sub
Sub DecrementINT (A As Integer)
A = A - 1
End Sub
Sub IncrementULNG (A As _Unsigned Long)
A = A + 1
End Sub
Sub DecrementULNG (A As _Unsigned Long)
A = A - 1
End Sub
Function Max (A, B)
If A > B Then Max = A Else Max = B
End Function
Function Min (A, B)
If A < B Then Min = A Else Min = B
End Function
Function InRange (A, B, C)
If A < B And B < C Then InRange = -1
End Function
Function ListNew$
ListNew$ = MKL$(0)
End Function
Function ListNewRaw$ (__ListRaw As String)
Dim As _Unsigned Long __I, __nItem, __Nested
Dim As _Unsigned _Byte __C, __StringMode1, __StringMode2
Dim As String __List, __ListArray(0): __nItem = 1
For __I = 2 To Len(__ListRaw) - 1
__C = Asc(__ListRaw, __I)
Select Case __C
Case 34: __StringMode1 = Not __StringMode1
Case 39: __StringMode2 = Not __StringMode2
Case 44: If __StringMode1 = 0 And __StringMode2 = 0 And __Nested = 0 Then __nItem = __nItem + 1: _Continue
Case 91, 123: __Nested = __Nested + 1
Case 93, 125: __Nested = __Nested - 1
End Select
If __nItem > UBound(__ListArray) Then ReDim _Preserve __ListArray(1 To __nItem) As String
__ListArray(__nItem) = __ListArray(__nItem) + Chr$(__C)
Next __I
__List = MKL$(__nItem)
For __I = 1 To __nItem
__List = __List + MKI$(Len(__ListArray(__I))) + __ListArray(__I)
Next __I
ListNewRaw$ = __List
End Function
Function ListLength~& (__List As String)
ListLength~& = CVL(Mid$(__List, 1, 4))
End Function
Function ListAdd$ (__List As String, __Item As String)
ListAdd$ = MKL$(CVL(Mid$(__List, 1, 4)) + 1) + Mid$(__List, 5) + MKI$(Len(__Item)) + __Item
End Function
Sub ListPrint (__List As String)
Dim As _Unsigned Long __nItems, __I, __OFFSET
Dim As _Unsigned Integer __LEN
__nItems = CVL(Mid$(__List, 1, 4))
__OFFSET = 5
Print "[";
For __I = 1 To __nItems
__LEN = CVI(Mid$(__List, __OFFSET, 2))
Print Mid$(__List, __OFFSET + 2, __LEN);
If __I < __nItems Then Print ",";
__OFFSET = __OFFSET + __LEN + 2
Next __I
Print "]"
End Sub
Function ListGet$ (__List As String, __ItemNumber As _Unsigned Long)
Dim As _Unsigned Long __nItems, __I, __OFFSET
Dim As _Unsigned Integer __LEN
__nItems = CVL(Mid$(__List, 1, 4))
If __ItemNumber > __nItems Then Exit Function
__OFFSET = 5
For __I = 1 To __nItems
__LEN = CVI(Mid$(__List, __OFFSET, 2))
If __I = __ItemNumber Then ListGet$ = Mid$(__List, __OFFSET + 2, __LEN): Exit Function
__OFFSET = __OFFSET + __LEN + 2
Next __I
End Function
Function ListSearch~& (__List As String, __Item As String)
Dim As _Unsigned Long __nItems, __I, __OFFSET
Dim As _Unsigned Integer __LEN
__nItems = CVL(Mid$(__List, 1, 4))
__OFFSET = 5
For __I = 1 To __nItems
__LEN = CVI(Mid$(__List, __OFFSET, 2))
If _StrCmp(Mid$(__List, __OFFSET + 2, __LEN), __Item) = 0 Then ListSearch~& = __I: Exit Function
__OFFSET = __OFFSET + __LEN + 2
Next __I
End Function
Function ListISearch~& (__List As String, __Item As String)
Dim As _Unsigned Long __nItems, __I, __OFFSET
Dim As _Unsigned Integer __LEN
__nItems = CVL(Mid$(__List, 1, 4))
__OFFSET = 5
For __I = 1 To __nItems
__LEN = CVI(Mid$(__List, __OFFSET, 2))
If _StriCmp(Mid$(__List, __OFFSET + 2, __LEN), __Item) = 0 Then ListISearch~& = __I: Exit Function
__OFFSET = __OFFSET + __LEN + 2
Next __I
End Function
Function ListEdit$ (__List As String, __ItemNumber As _Unsigned Long, __Item As String)
Dim As _Unsigned Long __nItems, __I, __OFFSET
Dim As _Unsigned Integer __LEN
__nItems = CVL(Mid$(__List, 1, 4))
__OFFSET = 5
If __ItemNumber > __nItems Then Exit Function
For __I = 1 To __nItems
__LEN = CVI(Mid$(__List, __OFFSET, 2))
If __I = __ItemNumber Then
Mid$(__List, __OFFSET, 2) = MKI$(Len(__Item))
ListEdit$ = Left$(__List, __OFFSET + 1) + __Item + Mid$(__List, __OFFSET + __LEN + 2)
Exit Function
End If
__OFFSET = __OFFSET + __LEN + 2
Next __I
End Function
Function ListDelete$ (__List As String, __ItemNumber As _Unsigned Long)
Dim As _Unsigned Long __nItems, __I, __OFFSET
Dim As _Unsigned Integer __LEN
__nItems = CVL(Mid$(__List, 1, 4))
__OFFSET = 5
For __I = 1 To __nItems
__LEN = CVI(Mid$(__List, __OFFSET, 2))
If __I = __ItemNumber Then
ListDelete$ = MKL$(__nItems - 1) + Mid$(__List, 5, __OFFSET - 5) + Mid$(__List, __OFFSET + __LEN + 2)
Exit Function
End If
__OFFSET = __OFFSET + __LEN + 2
Next __I
End Function
Function ListAppend$ (__List As String, __ListAppend As String)
ListAppend$ = MKL$(CVL(Mid$(__List, 1, 4)) + CVL(Mid$(__ListAppend, 1, 4))) + Mid$(__List, 5) + Mid$(__ListAppend, 5)
End Function
Its nearly VS Code now