'************************
'* this is a test
junkcount& = 0
junk(0) = "sub testofbyval(byval T as integer, byval register as long, byval yellow as single, byref purple, byval a$())"
PRINT "BEFORE PROCESSING:" HandleBYVAL junk(), junkcount&
PRINT "AFTER PROCESSING:" FOR X&
= 0 TO junkcount&
- 1 PRINT "------------DONE press a key" TextArrayLines& = 0
alertcount& = 0
TimeStartMerge!
= TIMER(.001)Result& = OpenInclude&("qb64.bas", TextArray$(), TextArrayLines&, alert$(), alertcount&)
TimeEndMerge!
= TIMER(.001) FOR p&
= 0 TO alertcount&
- 1 PRINT alert$
(p&
);
" was not merged" TimeStartRemoveRemarks!
= TIMER(.001)Result& = RemoveCodeRemarks(TextArray$(), -1, -1)
TimeEndRemoveRemarks!
= TIMER(.001)
MergeSubsCount& = 0
FindSubsFunctions TextArray$(), "sub", "end", Subs(), MergeSubsCount&
PRINT MergeSubsCount&;
" SUB found"
MergeFunctionsCount& = 0
FindSubsFunctions TextArray$(), "function", "end", Functions(), MergeFunctionsCount&
PRINT MergeFunctionsCount&;
" FUNCTION found"
beforelines& = TextArrayLines&
WHILE TextArray$
(TextArrayLines&
) = "" AND TextArrayLines&
> 0 TextArrayLines& = TextArrayLines& - 1
FOR X&
= 0 TO TextArrayLines&
PRINT X&;
" "; TextArray$
(X&
) PRINT TextArrayLines&; Result&; beforelines&;
UBOUND(textarray$
) PRINT "time to merge:";
(TimeEndMerge!
- TimeStartMerge!
) PRINT "time to remove comments/unreferenced subs/functions:";
(TimeEndRemoveRemarks!
- TimeStartRemoveRemarks!
) '* this was only a test
'************************
'*********************
'* Loads QB64 source, including $include: files
'* accepts forms:
'* $include:<any number of spaces>'whateverfile' -- if $ is the first non-blank character on a line, this is handled like an implied apostrophe before
'* also REM <any number of spaces>$include:'whateverfile'
'* also '$include:<any number of spaces>'whateverfile'
'* provided the $include: files are present, this loads them into a string array provided the file exists
'*********************
FUNCTION OpenInclude&
(OIFile$
, OICodeText
() AS STRING, OILinesIn&
, Warning$
(), WarningCount&
) NewUbound&
= (UBOUND(OICodeText
) + units&
) / 10 + 1 LINE INPUT #OIFileIO&
, OICodeText
(OILinesIn&
) fx$ = IncludeFile$(OICodeText(OILinesIn&))
OICodeText(OILinesIn&) = "'* Merged " + fx$ + " *"
r& = OpenInclude(fx$, OICodeText(), OILinesIn&, Warning$(), WarningCount&)
currentlines& = OILinesIn&
HandleBYVAL OICodeText(), OILinesIn&
IF OILinesIn&
<> currentlines&
THEN OILinesIn& = OILinesIn& - 1
OILinesIn& = OILinesIn& + 1
OpenInclude& = 1
Warning$(WarningCount&) = OIFile$
WarningCount& = WarningCount& + 1
'**********************
'* maybe a dialog box for path or store in list of warnings
'*******************
'* if this returns a 0 value, OpenInclude&() was not successful
OpenInclude& = 0
FUNCTION IncludeFile$
(IncludeFileTextX$
) IncludeFile$ = ""
'* do not alter the original code text
q& = 1
insc1&
= INSTR(TextX$
, "'") insc2&
= INSTR(insc1&
+ 1, TextX$
, "'") IncludeFile$
= MID$(TextX$
, insc1&
+ 1, insc2&
- (insc1&
+ 1)) TextX$
= MID$(TextX$
, q&
+ 1) q& = 1
q& = q& + 1
FUNCTION RemoveCodeRemarks
(CodeIn
() AS STRING, stripRemarks&
, RemoveWhiteSpaceLines&
) RUCCleanedLines&
= LBOUND(codeIn
) '* skip anything inside quotes -- might miss some
'* comments, but better safe than sorry
T& = T& - 1
PRINT RUCCleanedLines&; t$
PRINT RUCCleanedLines&; t$
CodeIn(RUCCleanedLines&) = CodeIn(RUCq&)
RUCCleanedLines& = RUCCleanedLines& + 1
'* clear remaining lines of code that have been processed
CodeIn(RUCCleanedLines&) = ""
RUCCleanedLines& = RUCCleanedLines& + 1
CASE "0" TO "9", "A" TO "Z", "a" TO "z", "_", "%", "$", "&", "#", "!", "~" IsWord& = 0
CASE "0" TO "9", "A" TO "Z", "a" TO "z", "_", "%", "$", "&", "#", "!", "~" IsWord& = 0
CASE "0" TO "9", "A" TO "Z", "a" TO "z", "_", "%", "$", "&", "#", "!", "~" IsWord& = 0
IsWord& = -1
'* FindSubsFunctions will scan for subs, functions once the code is merged and/or optionally comments stripped
SUB FindSubsFunctions
(CodeIn
() AS STRING, whattype$
, terminal$
, SubFunctionBeginEnd
() AS BeginsEnds
, subfunctioncount&
) '* TheSubName AS STRING * 64
'* Begins AS LONG
'* ends AS LONG
SubFunctionBeginEnd
(subfunctioncount&
).TheSubName
= RTRIM$(LEFT$(text$
, fsfxp&
- 1)) SubFunctionBeginEnd(subfunctioncount&).Begins = FSFScan&
SubFunctionBeginEnd(subfunctioncount&).ends = FSFScan&
'PRINT SubFunctionBeginEnd(subfunctioncount&).TheSubName
'PRINT SubFunctionBeginEnd(subfunctioncount&).Begins
'PRINT SubFunctionBeginEnd(subfunctioncount&).ends
subfunctioncount& = subfunctioncount& + 1
SUB StringRemove
(The$
, whattoremove$
, replaceitwith$
) IF whattoremove$
<> replacewith$
THEN i&
= INSTR(The$
, whattoremove$
) MID$(The$
, i&
, LEN(replacewith$
)) = replacewith$
The$
= LEFT$(The$
, i&
- 1) + replacewith$
+ MID$(The$
, i&
+ LEN(whattoremove$
))
StringRemove text1$
, "byref ", SPACE$(LEN("byref ")) StringRemove text1$, " )", ")"
inleftparen&
= INSTR(text1$
, "(") prefix$
= LEFT$(text1$
, inleftparen&
- 1) text1$
= MID$(text1$
, inleftparen&
+ 1, LEN(text1$
) - (inleftparen&
+ 1))
'* isolate variables that are BYVAL by "[" and "]"
inbyval&
= INSTR(text1$
, "byval ") MID$(text1$
, inbyval&
+ LEN("byval ") - 1, 1) = "[" sp&
= INSTR(inbyval&
+ LEN("byval ") - 1, text1$
, " ") text1$ = text1$ + "]"
MID$(text1$
, sp&
, 1) = "]" '* PRINT text1$
'* BYVAL variables are now isolated between "[" and "]"
'* knowing this, the appropriate DIM statements can be generated
'* make a copy of this string -- copyText1$
copytext1$ = text1$
copytext2$ = ""
dimreplace$ = "dim "
leftsquarebracket&
= INSTR(copytext1$
, "[") IF leftsquarebracket&
> 0 THEN rightbracket&
= INSTR(leftsquarebracket&
, copytext1$
, "]") w$
= MID$(copytext1$
, leftsquarebracket&
+ 1, rightbracket&
- (leftsquarebracket&
+ 1)) '* PRINT w$
copytext2$ = copytext2$ + w$ + " = " + "byval_" + w$ + ": "
MID$(copytext1$
, rightbracket&
, 1) = " " position&
= leftsquarebracket&
- LEN(dimreplace$
) + 1 MID$(copytext1$
, position&
, LEN(dimreplace$
)) = dimreplace$
'* now replace all the "byval " in copytext1$ with "byval_"
StringRemove copytext1$, "byval ", "byval_"
'PRINT text1$; "---------- still yet to be transformed sub declaration ->"; prefix$
'PRINT copytext1$; " in-sub declaration"
'PRINT copytext2$; " in-sub assignments"
MID$(text1$
, lb&
, 1) = " " rb&
= INSTR(lb&
, text1$
, "]") MID$(text1$
, rb&
, 1) = " " w$
= MID$(text1$
, lb&
+ 1, rb&
- (lb&
+ 1)) MID$(text1$
, lb&
- (LEN("byval_") - 1)) = "byval_" '* PRINT w$
'*************************
'* now the transformations are done -- whew! what a mess
'* PRINT text1$; "<------------------ transformed sub decclaration ---------->"; prefix$
InsertCode CodeIn(), linecount&, COPYTEXT0$ '* insert the transformed sub/function line
'InsertCode CodeIn(), linecount&, copytext1$ '* insert the in-sub/function declarations
T& = 1
M&
= INSTR(T&
+ 1, copytext1$
, ",") '* PRINT MID$(copytext1$, T&, M& - T&)\
InsertCode CodeIn(), linecount&, x$
T& = M& + 1
'* PRINT MID$(copytext1$, T&)
InsertCode CodeIn(), linecount&, x$
'* PRINT "IN-SUB/FUNCTION VARIABLE DECLARATIONS FINISHED..."
T& = 1
M&
= INSTR(T&
+ 1, copytext2$
, ":") '* PRINT MID$(copytext2$, T&, M& - T&)
InsertCode CodeIn
(), linecount&
, LTRIM$(MID$(copytext2$
, T&
, M&
- T&
)) T& = M& + 1
'* PRINT MID$(copytext1$, T&)
InsertCode CodeIn
(), linecount&
, LTRIM$(MID$(copytext2$
, T&
)) '* PRINT "in-sub/finction variable assignments finished"
'InsertCode CodeIn(), linecount&, copytext2$ '* finally, insert the in-sub variable assignments
'* now we can do the BYVAL variables, parsing between "{" and "_byv")
'WHILE INSTR(text$, "()")
' k& = INSTR(text$, "()")
' typ$ = ""
' dontmess = -1
' FOR u& = 2 TO 1 STEP -1
' j& = k& - u&
' PRINT MID$(text$, j&, u&)
' SELECT CASE MID$(text$, j&, u&)
' CASE "~%"
' typ$ = "_byte"
' CASE "~%"
' typ$ = "_unsigned integer"
' CASE "~&"
' typ$ = "_unsigned long"
' CASE "~#"
' typ$ = "_unsigned double"
' CASE "%%"
' typ$ = "_integer64"
' CASE "##"
' typ$ = "_float"
' CASE "%" '* unary types here
' typ$ = "integer"
' CASE "$"
' typ$ = "string"
' CASE "&"
' typ$ = "long"
' CASE "#"
' typ$ = "double"
' CASE "!"
' typ$ = "single"
' CASE "~"
' typ$ = "_bit"
' CASE "0" TO "9", "A" TO "Z", "a" TO "z"
' dontmess = -1
' EXIT FOR
' CASE ELSE
' END SELECT
' IF typ$ > "" THEN EXIT FOR
' NEXT
' IF (dontmess) THEN '* this array has an alphanumeric character before (), not determined what type it is
' '****************
' '* project for later
' '****************
' ELSE
' text$ = LEFT$(text$, k& + 1) + " as " + typ$ + MID$(text$, k& + 2)
' END IF
' MID$(text$, k&, 2) = "??"
'WEND
'PRINT "Press a key..."
'DO
' x$ = INKEY$
'LOOP UNTIL x$ > ""
SUB InsertCode
(OICodetext
() AS STRING, OILineIn&
, the$
) NewUbound&
= (UBOUND(OICodeText
) + units&
) / 10 + 1 OICodetext(OILineIn&) = the$
OILineIn& = OILineIn& + 1