[IDE tool] Generate procedure local variables
Posted: Sat Mar 18, 2023 3:21 pm
First try.
1. Select the procedure in the source code and press Ctrl+C
2. The tool will find all variables in the procedure body and exclude from them those declared in the procedure parameters.
3. The finished string will be pasted into the clipboard. Now you can press Ctrl+V on the second empty line of the procedure.
That is, you do not have to manually copy all the variable names. You won't get an undeclared variable error every time you run it using EnableExplicit.
1. Select the procedure in the source code and press Ctrl+C
2. The tool will find all variables in the procedure body and exclude from them those declared in the procedure parameters.
3. The finished string will be pasted into the clipboard. Now you can press Ctrl+V on the second empty line of the procedure.
That is, you do not have to manually copy all the variable names. You won't get an undeclared variable error every time you run it using EnableExplicit.
Code: Select all
EnableExplicit
Enumeration
#SYNTAX_Text
#SYNTAX_Keyword
#SYNTAX_Comment
#SYNTAX_Constant
#SYNTAX_String
#SYNTAX_Function
#SYNTAX_Asm
#SYNTAX_Operator
#SYNTAX_Structure
#SYNTAX_Number
#SYNTAX_Pointer
#SYNTAX_Separator
#SYNTAX_Label
#SYNTAX_Module
EndEnumeration
#Dll = 0
Global NewMap Var.s()
Global Buffer$, Buffer2$, Length, NotSuccess, *Buffer, Pos, Pos2, flgAdd
Declare.s LTrimChar(String$, TrimChar$ = #CRLF$ + #TAB$ + #FF$ + #VT$ + " ")
Declare.s RTrimChar(String$, TrimChar$ = #CRLF$ + #TAB$ + #FF$ + #VT$ + " ")
Procedure Callback(*Position, Length, Color)
Protected token$
; Debug 2
Select Color
Case #SYNTAX_Text, #SYNTAX_Pointer
token$ = PeekS(*Position, Length, #PB_Ascii)
token$ = LTrimChar(token$, #TAB$ + " ")
token$ = RTrimChar(token$, #CRLF$ + #TAB$ + " ")
; AddMapElement(LCase(token$))
If flgAdd
Var(LCase(token$)) = ""
Else
Var(LCase(token$)) = token$
EndIf
; Debug "|" + token$ + "|"; + Str(*Position)
EndSelect
EndProcedure
If OpenLibrary(#Dll, #PB_Compiler_Home + "SDK\Syntax Highlighting\SyntaxHighlighting.dll")
; MessageRequester("", #PB_Compiler_Home + "SDK\Syntax Highlighting\SyntaxHighlighting.dll")
Buffer$ = GetClipboardText()
Pos = FindString(Buffer$, "Procedure", 1, #PB_String_NoCase)
If Pos
Pos2 = FindString(Buffer$, #LF$, Pos + 9)
If Pos
Buffer2$ = Mid(Buffer$, Pos, Pos2 - Pos)
; Debug Buffer2$
EndIf
EndIf
*Buffer = UTF8(Buffer$)
Length = MemorySize(*Buffer)
CallFunction(#Dll, "SyntaxHighlight", *Buffer, Length, @Callback(), 0)
FreeMemory(*Buffer)
If Asc(Buffer2$)
flgAdd = 1
*Buffer = UTF8(Buffer2$)
Length = MemorySize(*Buffer)
CallFunction(#Dll, "SyntaxHighlight", *Buffer, Length, @Callback(), 0)
FreeMemory(*Buffer)
EndIf
CloseLibrary(#Dll)
Buffer$ = "Protected "
ForEach Var()
If Asc(Var())
Buffer$ + Var() + ", "
EndIf
Next
Buffer$ = Left(Buffer$, Len(Buffer$) - 2)
Debug Buffer$
SetClipboardText(Buffer$)
EndIf
Procedure.s LTrimChar(String$, TrimChar$ = #CRLF$ + #TAB$ + #FF$ + #VT$ + " ")
Protected *jc0, *c.Character, *jc.Character
If Not Asc(String$)
ProcedureReturn ""
EndIf
*c = @String$
*jc0 = @TrimChar$
While *c\c
*jc = *jc0
While *jc\c
If *c\c = *jc\c
*c\c = 0
Break
EndIf
*jc + SizeOf(Character)
Wend
If *c\c
String$ = PeekS(*c)
Break
EndIf
*c + SizeOf(Character)
Wend
ProcedureReturn String$
EndProcedure
Procedure.s RTrimChar(String$, TrimChar$ = #CRLF$ + #TAB$ + #FF$ + #VT$ + " ")
Protected Len2, Blen, i
Protected *jc0, *c.Character, *jc.Character
Len2 = Len(String$)
Blen = StringByteLength(String$)
If Not Asc(String$)
ProcedureReturn ""
EndIf
*c = @String$ + Blen - SizeOf(Character)
*jc0 = @TrimChar$
For i = Len2 To 1 Step - 1
*jc = *jc0
While *jc\c
If *c\c = *jc\c
*c\c = 0
Break
EndIf
*jc + SizeOf(Character)
Wend
If *c\c
Break
EndIf
*c - SizeOf(Character)
Next
ProcedureReturn String$
EndProcedure