Author Topic: OpenInclude, soon to be made a SMART code merger.  (Read 8264 times)

0 Members and 1 Guest are viewing this topic.

Offline codeguy

  • Forum Regular
  • Posts: 174
    • View Profile
OpenInclude, soon to be made a SMART code merger.
« on: February 23, 2018, 09:52:22 pm »
Hi everyone, I'm not a BOT. I am the VERY same CodeGuy from QB64(net), which I think is PERMANENTLY dead. I have coded this nice little recursive merger for creating monolithic array of code, including nested $include: so you can save or load entire programs, exclusive of data files like BMP, jpeg and such. The smart version will exclude subs and functions not referenced by the source and will be left as an option in later releases. It successfully merged all 46050+ lines of the latest qb64 stable release (v1.2).
OpenInclude() v.009 dynamically resizes the string array, here TextArray$() approximately 10% at a time. It does not resize the array to the actual number of lines of code merged when finished, in this example, TextArrayLines& (yet, if ever). One caveat, it does not stop if an $include: file is not present. Thanks to those on QB64(org) who pointed the way to a successful download of the newest QB64. The new changes are GREAT. For those who want to STEAL MY CODE, feel free.
Code: QB64: [Select]
  1. '************************
  2. '* this is a test
  3. cwdsave$ = _CWD$
  4. CHDIR _CWD$ + "\source"
  5.  
  6. REDIM TextArray$(0 TO 1023)
  7. TextArrayLines& = 0
  8.  
  9. REDIM alert$(0 TO 511)
  10. alertcount& = 0
  11.  
  12. Result& = OpenInclude&("qb64.bas", TextArray$(), TextArrayLines&, alert$(), alertcount&)
  13. IF alertcount& > 0 THEN
  14.     FOR p& = 0 TO alertcount& - 1
  15.         PRINT alert$(p&); " was not merged"
  16.     NEXT
  17.     DO
  18.         x$ = INKEY$
  19.     LOOP UNTIL x$ > ""
  20. Result& = RemoveUnreferencedCode(TextArray$(), -1, -1)
  21. CHDIR cwdsave$
  22. beforelines& = TextArrayLines&
  23. WHILE TextArray$(TextArrayLines&) = "" AND TextArrayLines& > 0
  24.     TextArrayLines& = TextArrayLines& - 1
  25.  
  26. FOR x& = 0 TO TextArrayLines&
  27.     PRINT x&; " "; TextArray$(x&)
  28. PRINT TextArrayLines&; Result&; beforelines&; UBOUND(textarray$)
  29. '* this was only a test
  30. '************************
  31.  
Squashed some bugs:
Now Lists files that could not be merged. all files must be within the _cwd$.
Code: QB64: [Select]
  1. '*********************
  2. '* Loads QB64 source,i ncluding $include: files
  3. '* accepts forms:
  4. '*      $include:<any number of spaces>'whateverfile' -- if $ is the first non-blank character on a line, this is handled like an implied apostrophe before
  5. '* also REM      <any number of spaces>$include:'whateverfile'
  6. '* also '$include:<any number of spaces>'whateverfile'
  7. '* provided the $include: files are present, this loads them into a string array provided the file exists
  8. '*********************
  9.  
  10. FUNCTION OpenInclude& (OIFile$, OICodeText() AS STRING, OILinesIn&, Warning$(), WarningCount&)
  11.     IF _FILEEXISTS(OIFile$) THEN
  12.         OIFileIO& = FREEFILE
  13.         IF OIFileIO& > 0 THEN
  14.             OPEN OIFile$ FOR INPUT AS #OIFileIO&
  15.             WHILE NOT EOF(OIFileIO&)
  16.                 IF OILinesIn& > UBOUND(OICodeText) THEN
  17.                     units& = 10 - UBOUND(OICodeText) MOD 10
  18.                     NewUbound& = (UBOUND(OICodeText) + units&)
  19.                     REDIM _PRESERVE OICodeText(LBOUND(OICodeText) TO NewUbound&)
  20.                 END IF
  21.                 LINE INPUT #OIFileIO&, OICodeText(OILinesIn&)
  22.                 fx$ = IncludeFile$(OICodeText(OILinesIn&))
  23.                 IF fx$ > "" THEN
  24.                     OICodeText(OILinesIn&) = "'* Merged " + fx$ + " *"
  25.                     r& = OpenInclude(fx$, OICodeText(), OILinesIn&, Warning$(), WarningCount&)
  26.                 END IF
  27.                 OILinesIn& = OILinesIn& + 1
  28.             WEND
  29.             CLOSE #OIFileIO&
  30.             OpenInclude& = 1
  31.             EXIT FUNCTION
  32.         END IF
  33.     ELSE
  34.         Warning$(WarningCount&) = OIFile$
  35.         WarningCount& = WarningCount& + 1
  36.         '**********************
  37.         '* maybe a dialog box for path or store in list of warnings
  38.         '*******************
  39.     END IF
  40.     '* if this returns a 0 value, OpenInclude&() was not successful
  41.     OpenInclude& = 0
  42.  
  43. FUNCTION IncludeFile$ (IncludeFileTextX$)
  44.     IncludeFile$ = ""
  45.     '* do not alter the original code text
  46.     TextX$ = LCASE$(LTRIM$(RTRIM$(IncludeFileTextX$)))
  47.     q& = 1
  48.     WHILE q& <= 3
  49.         IF MID$(TextX$, q&, LEN("$include:")) = "$include:" THEN
  50.             TextX$ = LTRIM$(MID$(TextX$, q& + LEN("$include:")))
  51.             insc1& = INSTR(TextX$, "'")
  52.             IF insc1& THEN
  53.                 insc2& = INSTR(insc1& + 1, TextX$, "'")
  54.                 IF insc2& > insc1& THEN
  55.                     IncludeFile$ = MID$(TextX$, insc1& + 1, insc2& - (insc1& + 1))
  56.                 END IF
  57.             END IF
  58.             EXIT FUNCTION
  59.         END IF
  60.         SELECT CASE LCASE$(LEFT$(TextX$, q&))
  61.             CASE "$"
  62.                 EXIT WHILE
  63.             CASE "'$"
  64.                 EXIT WHILE
  65.             CASE "rem"
  66.                 SELECT CASE MID$(TextX$, q& + 1, 1)
  67.                     CASE " "
  68.                         TextX$ = LTRIM$(MID$(TextX$, q& + 2))
  69.                     CASE "$"
  70.                         TextX$ = MID$(TextX$, q& + 1)
  71.                     CASE ELSE
  72.                         EXIT FUNCTION
  73.                 END SELECT
  74.                 q& = 1
  75.         END SELECT
  76.         q& = q& + 1
  77.     WEND
  78.  
  79. FUNCTION RemoveUnreferencedCode (CodeIn() AS STRING, stripRemarks&, RemoveWhiteSpaceLines&)
  80.     RUCCleanedLines& = LBOUND(codeIn)
  81.     FOR RUCq& = LBOUND(codein) TO UBOUND(codein)
  82.         t$ = LCASE$(LTRIM$(CodeIn(RUCq&)))
  83.         T& = LEN(t$)
  84.         DO
  85.             IF T& > 0 THEN
  86.                 IF MID$(t$, T&, 1) = CHR$(34) THEN
  87.                     '* skip anything inside quotes -- might miss some
  88.                     '* comments, but better safe than sorry
  89.                     EXIT DO
  90.                 END IF
  91.                 IF MID$(t$, T&, 1) = "'" THEN
  92.                     t$ = LEFT$(t$, T& - 1)
  93.                     EXIT DO
  94.                 ELSE
  95.                     T& = T& - 1
  96.                 END IF
  97.             ELSE
  98.                 EXIT DO
  99.             END IF
  100.         LOOP
  101.         SELECT CASE LEFT$(t$, 1)
  102.             CASE "'", ""
  103.                 _CONTINUE
  104.             CASE ELSE
  105.                 IF IsWord&(t$, "rem", 1) THEN
  106.                     SELECT CASE MID$(t$, LEN("rem") + 1, 1)
  107.                         CASE " ", "", CHR$(13)
  108.                         CASE ELSE
  109.                     END SELECT
  110.                     _CONTINUE
  111.                 ELSEIF IsWord&(t$, "sub", 1) THEN
  112.                     PRINT RUCCleanedLines&; t$
  113.                 ELSEIF IsWord(t$, "function", 1) THEN
  114.                     PRINT RUCCleanedLines&; t$
  115.                 END IF
  116.         END SELECT
  117.         CodeIn(RUCCleanedLines&) = CodeIn(RUCq&)
  118.         RUCCleanedLines& = RUCCleanedLines& + 1
  119.     NEXT
  120.     '* clear remaining lines of code that have been processed
  121.     WHILE RUCCleanedLines& <= UBOUND(codein)
  122.         CodeIn(RUCCleanedLines&) = ""
  123.         RUCCleanedLines& = RUCCleanedLines& + 1
  124.     WEND
  125.  
  126. FUNCTION IsWord& (t$, word$, position&)
  127.     IF position& > 1 THEN
  128.         SELECT CASE MID$(t$, position& - 1, 1)
  129.             CASE "0" TO "9", "A" TO "Z", "a" TO "z", "_", "%", "$", "&", "#", "!", "~"
  130.                 IsWord& = 0
  131.                 EXIT FUNCTION
  132.             CASE ELSE
  133.                 SELECT CASE MID$(t$, position& + LEN(word$), 1)
  134.                     CASE "0" TO "9", "A" TO "Z", "a" TO "z", "_", "%", "$", "&", "#", "!", "~"
  135.                         IsWord& = 0
  136.                         EXIT FUNCTION
  137.                     CASE ELSE
  138.                 END SELECT
  139.         END SELECT
  140.     END IF
  141.     SELECT CASE MID$(t$, position& + LEN(word$), 1)
  142.         CASE "0" TO "9", "A" TO "Z", "a" TO "z", "_", "%", "$", "&", "#", "!", "~"
  143.             IsWord& = 0
  144.             EXIT FUNCTION
  145.         CASE ELSE
  146.     END SELECT
  147.     IF MID$(t$, position&, 1) = word$ THEN
  148.         IsWord& = -1
  149.     END IF
  150.  
« Last Edit: February 24, 2018, 12:25:03 am by codeguy »

Offline codeguy

  • Forum Regular
  • Posts: 174
    • View Profile
Re: OpenInclude, soon to be made a SMART code merger.
« Reply #1 on: February 24, 2018, 10:00:21 am »
Code: QB64: [Select]
  1. WIDTH 160
  2.  
  3. TYPE BeginsEnds
  4.     TheSubName AS STRING * 64
  5.     Begins AS LONG
  6.     ends AS LONG
  7.  
  8. '************************
  9. '* this is a test
  10. cwdsave$ = _CWD$
  11. CHDIR _CWD$ + "\source"
  12. junkcount& = 0
  13. REDIM junk(0 TO 3) AS STRING
  14. junk(0) = "sub testofbyval(byval T as integer, byval register as long, byval yellow as single, byref purple, byval a$())"
  15. PRINT "BEFORE PROCESSING:"
  16. PRINT junk(0)
  17. PRINT junkcount&
  18. HandleBYVAL junk(), junkcount&
  19. PRINT "AFTER PROCESSING:"
  20. FOR X& = 0 TO junkcount& - 1
  21.     PRINT X&; junk(X&)
  22. ERASE junk
  23. PRINT junkcount&
  24. PRINT "------------DONE press a key"
  25.     X$ = INKEY$
  26. LOOP UNTIL X$ > ""
  27. REDIM TextArray$(0 TO 1023)
  28. TextArrayLines& = 0
  29.  
  30. REDIM alert$(0 TO 511)
  31. alertcount& = 0
  32. TimeStartMerge! = TIMER(.001)
  33. Result& = OpenInclude&("qb64.bas", TextArray$(), TextArrayLines&, alert$(), alertcount&)
  34. TimeEndMerge! = TIMER(.001)
  35. IF alertcount& > 0 THEN
  36.     FOR p& = 0 TO alertcount& - 1
  37.         PRINT alert$(p&); " was not merged"
  38.     NEXT
  39.     DO
  40.         X$ = INKEY$
  41.     LOOP UNTIL X$ > ""
  42. TimeStartRemoveRemarks! = TIMER(.001)
  43. Result& = RemoveCodeRemarks(TextArray$(), -1, -1)
  44. TimeEndRemoveRemarks! = TIMER(.001)
  45.  
  46. MergeSubsCount& = 0
  47. REDIM Subs(0 TO 511) AS BeginsEnds
  48. FindSubsFunctions TextArray$(), "sub", "end", Subs(), MergeSubsCount&
  49. IF MergeSubsCount& > 0 THEN
  50.     PRINT MergeSubsCount&; " SUB found"
  51.     _DELAY 10
  52.  
  53.  
  54. MergeFunctionsCount& = 0
  55. REDIM Functions(0 TO 511) AS BeginsEnds
  56. FindSubsFunctions TextArray$(), "function", "end", Functions(), MergeFunctionsCount&
  57. IF MergeFunctionsCount& THEN
  58.     PRINT MergeFunctionsCount&; " FUNCTION found"
  59.     _DELAY 10
  60.  
  61. CHDIR cwdsave$
  62. beforelines& = TextArrayLines&
  63. WHILE TextArray$(TextArrayLines&) = "" AND TextArrayLines& > 0
  64.     TextArrayLines& = TextArrayLines& - 1
  65.  
  66. FOR X& = 0 TO TextArrayLines&
  67.     PRINT X&; " "; TextArray$(X&)
  68. PRINT TextArrayLines&; Result&; beforelines&; UBOUND(textarray$)
  69. PRINT "time to merge:"; (TimeEndMerge! - TimeStartMerge!)
  70. PRINT "time to remove comments/unreferenced subs/functions:"; (TimeEndRemoveRemarks! - TimeStartRemoveRemarks!)
  71. '* this was only a test
  72. '************************
  73. '*********************
  74. '* Loads QB64 source, including $include: files
  75. '* accepts forms:
  76. '*      $include:<any number of spaces>'whateverfile' -- if $ is the first non-blank character on a line, this is handled like an implied apostrophe before
  77. '* also REM      <any number of spaces>$include:'whateverfile'
  78. '* also '$include:<any number of spaces>'whateverfile'
  79. '* provided the $include: files are present, this loads them into a string array provided the file exists
  80. '*********************
  81.  
  82. FUNCTION OpenInclude& (OIFile$, OICodeText() AS STRING, OILinesIn&, Warning$(), WarningCount&)
  83.     IF _FILEEXISTS(OIFile$) THEN
  84.         OIFileIO& = FREEFILE
  85.         IF OIFileIO& > 0 THEN
  86.             OPEN OIFile$ FOR INPUT AS #OIFileIO&
  87.             WHILE NOT EOF(OIFileIO&)
  88.                 IF OILinesIn& > UBOUND(OICodeText) THEN
  89.                     units& = 10 - UBOUND(OICodeText) MOD 10
  90.                     NewUbound& = (UBOUND(OICodeText) + units&) / 10 + 1
  91.                     REDIM _PRESERVE OICodeText(LBOUND(OICodeText) TO UBOUND(OICodeText) + NewUbound&)
  92.                 END IF
  93.                 LINE INPUT #OIFileIO&, OICodeText(OILinesIn&)
  94.                 fx$ = IncludeFile$(OICodeText(OILinesIn&))
  95.                 IF fx$ > "" THEN
  96.                     OICodeText(OILinesIn&) = "'* Merged " + fx$ + " *"
  97.                     r& = OpenInclude(fx$, OICodeText(), OILinesIn&, Warning$(), WarningCount&)
  98.                 ELSE
  99.                     currentlines& = OILinesIn&
  100.                     HandleBYVAL OICodeText(), OILinesIn&
  101.                     IF OILinesIn& <> currentlines& THEN
  102.                         OILinesIn& = OILinesIn& - 1
  103.                     END IF
  104.                 END IF
  105.                 OILinesIn& = OILinesIn& + 1
  106.             WEND
  107.             CLOSE #OIFileIO&
  108.             OpenInclude& = 1
  109.             EXIT FUNCTION
  110.         END IF
  111.     ELSE
  112.         Warning$(WarningCount&) = OIFile$
  113.         WarningCount& = WarningCount& + 1
  114.         '**********************
  115.         '* maybe a dialog box for path or store in list of warnings
  116.         '*******************
  117.     END IF
  118.     '* if this returns a 0 value, OpenInclude&() was not successful
  119.     OpenInclude& = 0
  120.  
  121. FUNCTION IncludeFile$ (IncludeFileTextX$)
  122.     IncludeFile$ = ""
  123.     '* do not alter the original code text
  124.     TextX$ = LCASE$(LTRIM$(RTRIM$(IncludeFileTextX$)))
  125.     q& = 1
  126.     WHILE q& <= 3
  127.         IF MID$(TextX$, q&, LEN("$include:")) = "$include:" THEN
  128.             TextX$ = LTRIM$(MID$(TextX$, q& + LEN("$include:")))
  129.             insc1& = INSTR(TextX$, "'")
  130.             IF insc1& THEN
  131.                 insc2& = INSTR(insc1& + 1, TextX$, "'")
  132.                 IF insc2& > insc1& THEN
  133.                     IncludeFile$ = MID$(TextX$, insc1& + 1, insc2& - (insc1& + 1))
  134.                 END IF
  135.             END IF
  136.             EXIT FUNCTION
  137.         END IF
  138.         SELECT CASE LCASE$(LEFT$(TextX$, q&))
  139.             CASE "$"
  140.                 EXIT WHILE
  141.             CASE "'$"
  142.                 EXIT WHILE
  143.             CASE "rem"
  144.                 SELECT CASE MID$(TextX$, q& + 1, 1)
  145.                     CASE " "
  146.                         TextX$ = LTRIM$(MID$(TextX$, q& + 2))
  147.                     CASE "$"
  148.                         TextX$ = MID$(TextX$, q& + 1)
  149.                     CASE ELSE
  150.                         EXIT FUNCTION
  151.                 END SELECT
  152.                 q& = 1
  153.         END SELECT
  154.         q& = q& + 1
  155.     WEND
  156.  
  157. FUNCTION RemoveCodeRemarks (CodeIn() AS STRING, stripRemarks&, RemoveWhiteSpaceLines&)
  158.     RUCCleanedLines& = LBOUND(codeIn)
  159.     FOR RUCq& = LBOUND(codein) TO UBOUND(codein)
  160.         t$ = LCASE$(LTRIM$(CodeIn(RUCq&)))
  161.         T& = LEN(t$)
  162.         DO
  163.             IF T& > 0 THEN
  164.                 IF MID$(t$, T&, 1) = CHR$(34) THEN
  165.                     '* skip anything inside quotes -- might miss some
  166.                     '* comments, but better safe than sorry
  167.                     EXIT DO
  168.                 END IF
  169.                 IF MID$(t$, T&, 1) = "'" THEN
  170.                     t$ = LEFT$(t$, T& - 1)
  171.                     EXIT DO
  172.                 ELSE
  173.                     T& = T& - 1
  174.                 END IF
  175.             ELSE
  176.                 EXIT DO
  177.             END IF
  178.         LOOP
  179.         SELECT CASE LEFT$(t$, 1)
  180.             CASE "'", ""
  181.                 _CONTINUE
  182.             CASE ELSE
  183.                 IF IsWord&(t$, "rem", 1) THEN
  184.                     SELECT CASE MID$(t$, LEN("rem") + 1, 1)
  185.                         CASE " ", "", CHR$(13)
  186.                         CASE ELSE
  187.                     END SELECT
  188.                     _CONTINUE
  189.                 ELSEIF IsWord&(t$, "sub", 1) THEN
  190.                     PRINT RUCCleanedLines&; t$
  191.                 ELSEIF IsWord(t$, "function", 1) THEN
  192.                     PRINT RUCCleanedLines&; t$
  193.                 END IF
  194.         END SELECT
  195.         CodeIn(RUCCleanedLines&) = CodeIn(RUCq&)
  196.         RUCCleanedLines& = RUCCleanedLines& + 1
  197.     NEXT
  198.     '* clear remaining lines of code that have been processed
  199.     WHILE RUCCleanedLines& <= UBOUND(codein)
  200.         CodeIn(RUCCleanedLines&) = ""
  201.         RUCCleanedLines& = RUCCleanedLines& + 1
  202.     WEND
  203.  
  204. FUNCTION IsWord& (t$, word$, position&)
  205.     IF position& > 1 THEN
  206.         SELECT CASE MID$(t$, position& - 1, 1)
  207.             CASE "0" TO "9", "A" TO "Z", "a" TO "z", "_", "%", "$", "&", "#", "!", "~"
  208.                 IsWord& = 0
  209.                 EXIT FUNCTION
  210.             CASE ELSE
  211.                 SELECT CASE MID$(t$, position& + LEN(word$), 1)
  212.                     CASE "0" TO "9", "A" TO "Z", "a" TO "z", "_", "%", "$", "&", "#", "!", "~"
  213.                         IsWord& = 0
  214.                         EXIT FUNCTION
  215.                     CASE ELSE
  216.                 END SELECT
  217.         END SELECT
  218.     END IF
  219.     SELECT CASE MID$(t$, position& + LEN(word$), 1)
  220.         CASE "0" TO "9", "A" TO "Z", "a" TO "z", "_", "%", "$", "&", "#", "!", "~"
  221.             IsWord& = 0
  222.             EXIT FUNCTION
  223.         CASE ELSE
  224.     END SELECT
  225.     IF MID$(t$, position&, 1) = word$ THEN
  226.         IsWord& = -1
  227.     END IF
  228.  
  229.  
  230. '* FindSubsFunctions will scan for subs, functions once the code is merged and/or optionally comments stripped
  231. SUB FindSubsFunctions (CodeIn() AS STRING, whattype$, terminal$, SubFunctionBeginEnd() AS BeginsEnds, subfunctioncount&)
  232.     '* TheSubName AS STRING * 64
  233.     '* Begins AS LONG
  234.     '* ends AS LONG
  235.     fsfx$ = LCASE$(whattype$) + " ": PRINT fsfx$
  236.     FOR FSFScan& = LBOUND(CodeIn) TO UBOUND(CodeIn)
  237.         text$ = LCASE$(LTRIM$(CodeIn(FSFScan&)))
  238.         IF LEFT$(text$, LEN(whattype$) + 1) = fsfx$ THEN
  239.             fsfxp& = INSTR(LEN(fsfx$), text$, "(")
  240.             SubFunctionBeginEnd(subfunctioncount&).TheSubName = RTRIM$(LEFT$(text$, fsfxp& - 1))
  241.             SubFunctionBeginEnd(subfunctioncount&).Begins = FSFScan&
  242.         ELSEIF LEFT$(text$, LEN(terminal$ + " " + whattype$)) = terminal$ + " " + whattype$ THEN
  243.             SubFunctionBeginEnd(subfunctioncount&).ends = FSFScan&
  244.             'PRINT SubFunctionBeginEnd(subfunctioncount&).TheSubName
  245.             'PRINT SubFunctionBeginEnd(subfunctioncount&).Begins
  246.             'PRINT SubFunctionBeginEnd(subfunctioncount&).ends
  247.             subfunctioncount& = subfunctioncount& + 1
  248.         END IF
  249.     NEXT
  250.  
  251. SUB StringRemove (The$, whattoremove$, replaceitwith$)
  252.     IF whattoremove$ <> replacewith$ THEN
  253.         DO
  254.             i& = INSTR(The$, whattoremove$)
  255.             IF i& > 0 THEN
  256.                 IF LEN(whattoremove$) = LEN(replacewith$) THEN
  257.                     MID$(The$, i&, LEN(replacewith$)) = replacewith$
  258.                 ELSE
  259.                     The$ = LEFT$(The$, i& - 1) + replacewith$ + MID$(The$, i& + LEN(whattoremove$))
  260.                 END IF
  261.             ELSE
  262.                 EXIT DO
  263.             END IF
  264.         LOOP
  265.     END IF
  266.  
  267. SUB HandleBYVAL (CodeIn() AS STRING, linecount&)
  268.     text1$ = LCASE$(LTRIM$(RTRIM$(CodeIn(linecount&))))
  269.     IF LEFT$(text1$, LEN("sub ")) = "sub " OR LEFT$(text1$, LEN("function ")) = "function " THEN
  270.         IF INSTR(text1$, "byval ") OR INSTR(text1$, "byref ") THEN
  271.             StringRemove text1$, "byref ", SPACE$(LEN("byref "))
  272.             StringRemove text1$, SPACE$(2), SPACE$(1)
  273.             StringRemove text1$, " )", ")"
  274.             PRINT text1$
  275.             inleftparen& = INSTR(text1$, "(")
  276.             prefix$ = LEFT$(text1$, inleftparen& - 1)
  277.             text1$ = MID$(text1$, inleftparen& + 1, LEN(text1$) - (inleftparen& + 1))
  278.  
  279.             '* isolate variables that are BYVAL by "[" and "]"
  280.             DO
  281.                 inbyval& = INSTR(text1$, "byval ")
  282.                 IF inbyval& THEN
  283.                     MID$(text1$, inbyval&, LEN("byval ") - 1) = SPACE$(LEN("byval ") - 1)
  284.                     MID$(text1$, inbyval& + LEN("byval ") - 1, 1) = "["
  285.                     sp& = INSTR(inbyval& + LEN("byval ") - 1, text1$, " ")
  286.                     IF sp& > LEN(text1$) OR sp& = 0 THEN
  287.                         text1$ = text1$ + "]"
  288.                         EXIT DO
  289.                     ELSE
  290.                         MID$(text1$, sp&, 1) = "]"
  291.                     END IF
  292.                 ELSE
  293.                     EXIT DO
  294.                 END IF
  295.             LOOP
  296.             '* PRINT text1$
  297.             '* BYVAL variables are now isolated between "[" and "]"
  298.             '* knowing this, the appropriate DIM statements can be generated
  299.             '* make a copy of this string -- copyText1$
  300.             copytext1$ = text1$
  301.             copytext2$ = ""
  302.             dimreplace$ = "dim "
  303.             DO
  304.                 leftsquarebracket& = INSTR(copytext1$, "[")
  305.                 IF leftsquarebracket& > 0 THEN
  306.                     rightbracket& = INSTR(leftsquarebracket&, copytext1$, "]")
  307.                     w$ = MID$(copytext1$, leftsquarebracket& + 1, rightbracket& - (leftsquarebracket& + 1))
  308.                     '* PRINT w$
  309.                     copytext2$ = copytext2$ + w$ + " = " + "byval_" + w$ + ": "
  310.                     MID$(copytext1$, rightbracket&, 1) = " "
  311.                     position& = leftsquarebracket& - LEN(dimreplace$) + 1
  312.                     MID$(copytext1$, position&, LEN(dimreplace$)) = dimreplace$
  313.                 ELSE
  314.                     EXIT DO
  315.                 END IF
  316.             LOOP
  317.             '* now replace all the "byval " in copytext1$ with "byval_"
  318.             StringRemove copytext1$, "byval ", "byval_"
  319.             'PRINT text1$; "---------- still yet to be transformed sub declaration ->"; prefix$
  320.             'PRINT copytext1$; " in-sub declaration"
  321.             'PRINT copytext2$; " in-sub assignments"
  322.             DO
  323.                 lb& = INSTR(text1$, "[")
  324.                 IF lb& > 0 THEN
  325.                     MID$(text1$, lb&, 1) = " "
  326.                     rb& = INSTR(lb&, text1$, "]")
  327.                     IF rb& > lb& THEN
  328.                         MID$(text1$, rb&, 1) = " "
  329.                         w$ = MID$(text1$, lb& + 1, rb& - (lb& + 1))
  330.                         MID$(text1$, lb& - (LEN("byval_") - 1)) = "byval_"
  331.                         '* PRINT w$
  332.                     END IF
  333.                 ELSE
  334.                     EXIT DO
  335.                 END IF
  336.             LOOP
  337.  
  338.             '*************************
  339.             '* now the transformations are done -- whew! what a mess
  340.             '* PRINT text1$; "<------------------ transformed sub decclaration ---------->"; prefix$
  341.             COPYTEXT0$ = prefix$ + " (" + LTRIM$(RTRIM$(text1$)) + ")"
  342.             InsertCode CodeIn(), linecount&, COPYTEXT0$ '* insert the transformed sub/function line
  343.             'InsertCode CodeIn(), linecount&, copytext1$ '* insert the in-sub/function declarations
  344.             T& = 1
  345.             DO
  346.                 M& = INSTR(T& + 1, copytext1$, ",")
  347.                 IF M& > T& THEN
  348.                     '* PRINT MID$(copytext1$, T&, M& - T&)\
  349.                     x$ = LTRIM$(MID$(copytext1$, T&, M& - T&))
  350.                     IF INSTR(" " + x$, " dim ") THEN
  351.                         InsertCode CodeIn(), linecount&, x$
  352.                     END IF
  353.                     T& = M& + 1
  354.                 ELSE
  355.                     '* PRINT MID$(copytext1$, T&)
  356.                     x$ = LTRIM$(MID$(copytext1$, T&))
  357.                     IF INSTR(" " + x$, " dim") THEN
  358.                         InsertCode CodeIn(), linecount&, x$
  359.                     END IF
  360.                     EXIT DO
  361.                 END IF
  362.             LOOP
  363.             '* PRINT "IN-SUB/FUNCTION VARIABLE DECLARATIONS FINISHED..."
  364.             PRINT copytext2$
  365.             T& = 1
  366.             DO
  367.                 M& = INSTR(T& + 1, copytext2$, ":")
  368.                 IF M& > T& THEN
  369.                     '* PRINT MID$(copytext2$, T&, M& - T&)
  370.                     x$ = LTRIM$(MID$(copytext2$, T&, M& - T&))
  371.                     IF x$ > "" THEN
  372.                         InsertCode CodeIn(), linecount&, LTRIM$(MID$(copytext2$, T&, M& - T&))
  373.                     END IF
  374.                     T& = M& + 1
  375.                 ELSE
  376.                     '* PRINT MID$(copytext1$, T&)
  377.                     x$ = LTRIM$(MID$(copytext2$, T&))
  378.                     IF x$ > "" THEN
  379.                         InsertCode CodeIn(), linecount&, LTRIM$(MID$(copytext2$, T&))
  380.                     END IF
  381.                     EXIT DO
  382.                 END IF
  383.             LOOP
  384.             '* PRINT "in-sub/finction variable assignments finished"
  385.             'InsertCode CodeIn(), linecount&, copytext2$ '* finally, insert the in-sub variable assignments
  386.  
  387.             '* now we can do the BYVAL variables, parsing between "{" and "_byv")
  388.             'WHILE INSTR(text$, "()")
  389.             '    k& = INSTR(text$, "()")
  390.             '    typ$ = ""
  391.             '    dontmess = -1
  392.             '    FOR u& = 2 TO 1 STEP -1
  393.             '        j& = k& - u&
  394.             '        PRINT MID$(text$, j&, u&)
  395.             '        SELECT CASE MID$(text$, j&, u&)
  396.             '            CASE "~%"
  397.             '                typ$ = "_byte"
  398.             '            CASE "~%"
  399.             '                typ$ = "_unsigned integer"
  400.             '            CASE "~&"
  401.             '                typ$ = "_unsigned long"
  402.             '            CASE "~#"
  403.             '                typ$ = "_unsigned double"
  404.             '            CASE "%%"
  405.             '                typ$ = "_integer64"
  406.             '            CASE "##"
  407.             '                typ$ = "_float"
  408.  
  409.             '            CASE "%" '* unary types here
  410.             '                typ$ = "integer"
  411.             '            CASE "$"
  412.             '                typ$ = "string"
  413.             '            CASE "&"
  414.             '                typ$ = "long"
  415.             '            CASE "#"
  416.             '                typ$ = "double"
  417.             '            CASE "!"
  418.             '                typ$ = "single"
  419.             '            CASE "~"
  420.             '                typ$ = "_bit"
  421.             '            CASE "0" TO "9", "A" TO "Z", "a" TO "z"
  422.             '                dontmess = -1
  423.             '                EXIT FOR
  424.             '            CASE ELSE
  425.             '        END SELECT
  426.             '        IF typ$ > "" THEN EXIT FOR
  427.             '    NEXT
  428.             '    IF (dontmess) THEN '* this array has an alphanumeric character before (), not determined what type it is
  429.             '        '****************
  430.             '        '* project for later
  431.             '        '****************
  432.             '    ELSE
  433.             '        text$ = LEFT$(text$, k& + 1) + " as " + typ$ + MID$(text$, k& + 2)
  434.             '    END IF
  435.             '    MID$(text$, k&, 2) = "??"
  436.             'WEND
  437.             'PRINT "Press a key..."
  438.             'DO
  439.             '    x$ = INKEY$
  440.             'LOOP UNTIL x$ > ""
  441.         END IF
  442.     END IF
  443.  
  444. SUB InsertCode (OICodetext() AS STRING, OILineIn&, the$)
  445.     IF OILineIn& > UBOUND(OICodeText) THEN
  446.         units& = 10 - UBOUND(OICodeText) MOD 10
  447.         NewUbound& = (UBOUND(OICodeText) + units&) / 10 + 1
  448.         REDIM _PRESERVE OICodetext(LBOUND(OICodeText) TO UBOUND(OICodeText) + NewUbound&) AS STRING
  449.     END IF
  450.     OICodetext(OILineIn&) = the$
  451.     OILineIn& = OILineIn& + 1
  452.  
« Last Edit: February 24, 2018, 11:54:54 am by codeguy »

Offline codeguy

  • Forum Regular
  • Posts: 174
    • View Profile
Re: OpenInclude, soon to be made a SMART code merger.
« Reply #2 on: February 25, 2018, 07:23:49 am »
do you have difficulty remembering ALL the data types in QB64 and/or their symbols? Well, here you go.
Code: QB64: [Select]
  1. '* given a symbol, returns the string name of the type
  2. '* or the symbol if given the name of the type
  3. FUNCTION CodeGuyNameToSymbol$ (xName$)
  4.     SELECT CASE xName$
  5.         CASE "_BIT"
  6.             s$ = "`"
  7.         CASE "`"
  8.             s$ = "_BIT"
  9.         CASE "_BIT *"
  10.         CASE "`"
  11.         CASE "_UNSIGNED _BIT"
  12.             s$ = "~`"
  13.         CASE "~`"
  14.             s$ = "_UNSIGNED _BIT"
  15.         CASE "_BYTE"
  16.             s$ = "%%"
  17.         CASE "%%"
  18.             s$ = "_BYTE"
  19.         CASE "_UNSIGNED _BYTE"
  20.             s$ = "~%%"
  21.         CASE "~%%"
  22.             s$ = "_UNSIGNED _BYTE"
  23.         CASE "INTEGER"
  24.             s$ = "%"
  25.         CASE "%"
  26.             s$ = "INTEGER"
  27.         CASE "_UNSIGNED INTEGER"
  28.             s$ = "~%"
  29.         CASE "~%"
  30.             s$ = "__UNSIGNED INTEGER"
  31.         CASE "LONG"
  32.             s$ = "&"
  33.         CASE "&"
  34.             s$ = "LONG"
  35.         CASE "_UNSIGNED LONG"
  36.             s$ = "~&"
  37.         CASE "~&"
  38.             s$ = "_UNSIGNED LONG"
  39.         CASE "_INTEGER64"
  40.             s$ = "&&"
  41.         CASE "&&"
  42.             s$ = "_INTEGER64"
  43.         CASE "_UNSIGNED _INTEGER64"
  44.             s$ = "~&&"
  45.         CASE "~&&"
  46.             s$ = "_UNSIGNED _INTEGER64"
  47.         CASE "SINGLE"
  48.             s$ = "!"
  49.         CASE "!"
  50.             s$ = "SINGLE"
  51.         CASE "DOUBLE"
  52.             s$ = "#"
  53.         CASE "#"
  54.             s$ = "DOUBLE"
  55.         CASE "_FLOAT"
  56.             s$ = "##"
  57.         CASE "##"
  58.             s$ = "_FLOAT"
  59.         CASE "_OFFSET"
  60.             s$ = "%&"
  61.         CASE "%&"
  62.             s$ = "_OFFSET"
  63.         CASE "_UNSIGNED _OFFSET"
  64.             s$ = "~%&"
  65.         CASE "~%&"
  66.             s$ = "_UNSIGNED _OFFSET"
  67.         CASE ""
  68.             s$ = "!"
  69.         CASE "$"
  70.             s$ = "STRING"
  71.         CASE "STRING"
  72.             s$ = "$"
  73.         CASE ELSE
  74.             IF LEFT$(xName$, LEN("BIT *")) = "BIT *" THEN
  75.                 s$ = "`" + MID$(xName$, LEN("BIT *") + 1)
  76.             ELSEIF LEFT$(xName$, LEN("`")) = "`" THEN
  77.                 s$ = "BIT * " + MID$(xName$, LEN("`") + 1)
  78.             END IF
  79.     END SELECT
  80.     CodeGuyNameToSymbol$ = s$
  81. /code]
« Last Edit: February 25, 2018, 07:37:19 am by codeguy »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: OpenInclude, soon to be made a SMART code merger.
« Reply #3 on: February 25, 2018, 07:32:10 am »
Hi codeguy,

Here's my cheat sheet:
Code: QB64: [Select]
  1. 5 Integers Types:
  2.  
  3. name:           suffix: range:               unsigned:
  4. _BIT            `       0 or 1               2 ^ 1
  5. _BYTE           %%      -128 to 127          2 ^ 8 = 256 ^ 1
  6. INTEGER         %       -32,768 to 32,767    256 ^ 2
  7. LONG            &       10 digits            256 ^ 4
  8. _INTEGER64      &&      very many digits     256 ^ 8
  9.  
  10.  
  11. 3 Float Types:
  12.  
  13. SINGLE          !       4 bytes, 7 decimal
  14. DOUBLE          #       8 bytes, 15 decimal
  15. _FLOAT          ##      max precision
  16.  
  17. STRING          $      
  18.  

eeeh spacing not preserved in quotes, try code then guys...
« Last Edit: February 25, 2018, 07:53:13 am by bplus »

Offline codeguy

  • Forum Regular
  • Posts: 174
    • View Profile
Re: OpenInclude, soon to be made a SMART code merger.
« Reply #4 on: February 25, 2018, 07:44:01 am »
I made code so you can find the appropriate extensions. It's to save time when tracking down variable types. Does not handle STRING *, but there are no symbolic replacements that will work in qb64. I think making $n usable in these cases would be nice. Wouldn't take much code to expand $1038 to STRING * 1023 or $(variable name) similarly. This code was made to be part of HandleBYVAL(), a mostly working prototype of being able to use variables in subs by value and not by reference, if you don't want the originals altered. In my Djikstra SmoothSort() code, this was necessary or the code would not work. VB can use BYVAL for all code. QB64 cannot, only for LIBRARY. I used HandleBYVAL() to convert other code too, saving me copy/paste/editing time. The only thing not worked out is array copying, so this function was made to be a power assist with a template idea I have. This could also allow other things using the same kind of code, just using different data types. This is essentially what BYVAL does: creates local copies of variables and uses them instead of the originals.
Quote
SUB SmoothSift (plngArray() AS dataelement, NodeIndex AS LONG, SubTreeSize AS LONG, LeftSubTreeSize AS LONG)
    DIM lngNodeIndex AS LONG: lngNodeIndex = NodeIndex
    DIM lngSubTreeSize AS LONG: lngSubTreeSize = SubTreeSize
    DIM lngLeftSubTreeSize AS LONG: lngLeftSubTreeSize = LeftSubTreeSize
    DIM lngChildIndex AS LONG

Code: QB64: [Select]
  1. '* converted with thorough testing by CodeGuy 20Feb2018
  2.  
  3. TYPE dataelement
  4.     thekey AS DOUBLE
  5.     originalorder AS LONG
  6. REDIM array(0 TO 2097151) AS dataelement
  7. BitonicM& = LBOUND(array) + (UBOUND(array) - LBOUND(array)) \ 2
  8. FOR method% = 0 TO 5
  9.     FOR s& = LBOUND(array) TO UBOUND(array)
  10.         SELECT CASE method%
  11.             CASE 0
  12.                 o$ = "descending"
  13.                 '* (5.18s)
  14.                 array(s&).thekey = UBOUND(ARRAy) - s&
  15.             CASE 1
  16.                 o$ = "ascending"
  17.                 '* (.523s)
  18.                 array(s&).thekey = s&
  19.             CASE 2
  20.                 o$ = "random"
  21.                 '* (7.36s)
  22.                 array(s&).thekey = RND
  23.             CASE 3
  24.                 o$ = "monotonic"
  25.                 array(s&).thekey = 0
  26.                 '*
  27.             CASE 4
  28.                 o$ = "bitonic"
  29.                 '* (7.19s)
  30.                 IF s& - 1 > BitonicM& THEN
  31.                     array(s&).thekey = a&
  32.                     a& = a& - 1
  33.                 ELSE
  34.                     array(s&).thekey = s&
  35.                     a& = s&
  36.                 END IF
  37.             CASE 5
  38.                 o$ = "few unique"
  39.                 IF RND > .987654321 THEN
  40.                     array(s&).thekey = RND
  41.                 ELSE
  42.                     array(s&).thekey = 0
  43.                 END IF
  44.         END SELECT
  45.         array(s&).originalorder = s&
  46.     NEXT
  47.     startTimer! = TIMER(.001)
  48.     SmoothSort array()
  49.     endtimer! = TIMER(.001)
  50.     h& = LBOUND(ARRAy)
  51.     FOR s& = LBOUND(ARRAy) TO UBOUND(ARRAy)
  52.         IF array(s&).thekey < array(h&).thekey THEN
  53.             STOP
  54.         ELSE
  55.             'PRINT array(s&).thekey, ;
  56.             'PRINT array(s&).originalorder
  57.             IF array(s&).thekey > array(h&).thekey THEN
  58.                 h& = s&
  59.             END IF
  60.         END IF
  61.     NEXT
  62.     PRINT (UBOUND(ARRAy) - LBOUND(ARRAy) + 1); " elements presented in "; o$; " order"
  63.     PRINT (UBOUND(ARRAy) - LBOUND(ARRAy) + 1) / (endtimer! - startTimer!); " elements/second"; (endtimer! - startTimer!); "seconds..."
  64. '********************
  65. '* Djikstra SmoothSort converted from VB 2018Feb20 by CodeGuy
  66. '* There is no BYVAL, in QB64, so I did a workaround
  67. '*************************
  68. SUB SmoothSort (plngArray() AS dataelement)
  69.     DIM lngOneBasedIndex AS LONG
  70.     DIM lngNodeIndex AS LONG
  71.     DIM lngLeftRightTreeAddress AS LONG
  72.     DIM lngSubTreeSize AS LONG
  73.     DIM lngLeftSubTreeSize AS LONG
  74.  
  75.     lngLeftRightTreeAddress = 1
  76.     lngSubTreeSize = 1
  77.     lngLeftSubTreeSize = 1
  78.     lngOneBasedIndex = 1
  79.     lngNodeIndex = 0
  80.  
  81.     DO WHILE lngOneBasedIndex <> UBOUND(plngArray) + 1
  82.         IF lngLeftRightTreeAddress MOD 8 = 3 THEN
  83.             SmoothSift plngArray(), lngNodeIndex, lngSubTreeSize, lngLeftSubTreeSize
  84.             lngLeftRightTreeAddress = (lngLeftRightTreeAddress + 1) \ 4
  85.             SmoothUp lngSubTreeSize, lngLeftSubTreeSize
  86.             SmoothUp lngSubTreeSize, lngLeftSubTreeSize
  87.         ELSEIF lngLeftRightTreeAddress MOD 4 = 1 THEN 'This is always true if it gets here
  88.             IF lngOneBasedIndex + lngLeftSubTreeSize < UBOUND(plngArray) + 1 THEN
  89.                 SmoothSift plngArray(), lngNodeIndex, lngSubTreeSize, lngLeftSubTreeSize
  90.             ELSE
  91.                 SmoothTrinkle plngArray(), lngNodeIndex, lngLeftRightTreeAddress, lngSubTreeSize, lngLeftSubTreeSize
  92.             END IF
  93.             DO
  94.                 SmoothDown lngSubTreeSize, lngLeftSubTreeSize
  95.                 lngLeftRightTreeAddress = lngLeftRightTreeAddress * 2
  96.             LOOP WHILE lngSubTreeSize <> 1 'Continue until we reach the bottom of the tree
  97.             lngLeftRightTreeAddress = lngLeftRightTreeAddress + 1
  98.         END IF
  99.         lngOneBasedIndex = lngOneBasedIndex + 1
  100.         lngNodeIndex = lngNodeIndex + 1
  101.     LOOP
  102.  
  103.     SmoothTrinkle plngArray(), lngNodeIndex, lngLeftRightTreeAddress, lngSubTreeSize, lngLeftSubTreeSize
  104.     DO WHILE lngOneBasedIndex <> 1
  105.         lngOneBasedIndex = lngOneBasedIndex - 1
  106.         IF lngSubTreeSize = 1 THEN
  107.             lngNodeIndex = lngNodeIndex - 1
  108.             lngLeftRightTreeAddress = lngLeftRightTreeAddress - 1
  109.             DO WHILE lngLeftRightTreeAddress MOD 2 = 0
  110.                 lngLeftRightTreeAddress = lngLeftRightTreeAddress / 2
  111.                 SmoothUp lngSubTreeSize, lngLeftSubTreeSize
  112.             LOOP
  113.         ELSEIF lngSubTreeSize >= 3 THEN 'It must fall in here, sub trees are either size 1,1,3,5,9,15 etc
  114.             lngLeftRightTreeAddress = lngLeftRightTreeAddress - 1
  115.             lngNodeIndex = lngNodeIndex + lngLeftSubTreeSize - lngSubTreeSize
  116.             IF lngLeftRightTreeAddress <> 0 THEN
  117.                 SmoothSemiTrinkle plngArray(), lngNodeIndex, lngLeftRightTreeAddress, lngSubTreeSize, lngLeftSubTreeSize
  118.             END IF
  119.             SmoothDown lngSubTreeSize, lngLeftSubTreeSize
  120.             lngLeftRightTreeAddress = lngLeftRightTreeAddress * 2 + 1
  121.             lngNodeIndex = lngNodeIndex + lngLeftSubTreeSize
  122.             SmoothSemiTrinkle plngArray(), lngNodeIndex, lngLeftRightTreeAddress, lngSubTreeSize, lngLeftSubTreeSize
  123.             SmoothDown lngSubTreeSize, lngLeftSubTreeSize
  124.             lngLeftRightTreeAddress = lngLeftRightTreeAddress * 2 + 1
  125.         END IF
  126.     LOOP
  127.  
  128. SUB SmoothUp (lngSubTreeSize AS LONG, lngLeftSubTreeSize AS LONG)
  129.     DIM sutemp AS LONG
  130.     sutemp = lngSubTreeSize + lngLeftSubTreeSize + 1
  131.     lngLeftSubTreeSize = lngSubTreeSize
  132.     lngSubTreeSize = sutemp
  133.  
  134. SUB SmoothDown (lngSubTreeSize AS LONG, lngLeftSubTreeSize AS LONG)
  135.     DIM sdtemp AS LONG
  136.     sdtemp = lngSubTreeSize - lngLeftSubTreeSize - 1
  137.     lngSubTreeSize = lngLeftSubTreeSize
  138.     lngLeftSubTreeSize = sdtemp
  139.  
  140. SUB SmoothSift (plngArray() AS dataelement, NodeIndex AS LONG, SubTreeSize AS LONG, LeftSubTreeSize AS LONG)
  141.     DIM lngNodeIndex AS LONG: lngNodeIndex = NodeIndex
  142.     DIM lngSubTreeSize AS LONG: lngSubTreeSize = SubTreeSize
  143.     DIM lngLeftSubTreeSize AS LONG: lngLeftSubTreeSize = LeftSubTreeSize
  144.     DIM lngChildIndex AS LONG
  145.  
  146.     DO WHILE lngSubTreeSize >= 3
  147.         lngChildIndex = lngNodeIndex - lngSubTreeSize + lngLeftSubTreeSize
  148.         IF plngArray(lngChildIndex).thekey < plngArray(lngNodeIndex - 1).thekey THEN
  149.             lngChildIndex = lngNodeIndex - 1
  150.             SmoothDown lngSubTreeSize, lngLeftSubTreeSize
  151.         END IF
  152.  
  153.         IF plngArray(lngNodeIndex).thekey >= plngArray(lngChildIndex).thekey THEN
  154.             lngSubTreeSize = 1
  155.         ELSE
  156.             Exchange plngArray(), lngNodeIndex, lngChildIndex
  157.             lngNodeIndex = lngChildIndex
  158.             SmoothDown lngSubTreeSize, lngLeftSubTreeSize
  159.         END IF
  160.     LOOP
  161.  
  162. SUB SmoothTrinkle (plngArray() AS dataelement, NodeIndex AS LONG, LeftRightTreeAddress AS LONG, SubTreeSize AS LONG, LeftSubTreeSize AS LONG)
  163.     DIM lngNodeIndex AS LONG: lngNodeIndex = NodeIndex
  164.     DIM lngLeftRightTreeAddress AS LONG: lngLeftRightTreeAddress = LeftRightTreeAddress
  165.     DIM lngSubTreeSize AS LONG: lngSubTreeSize = SubTreeSize
  166.     DIM lngLeftSubTreeSize AS LONG: lngLeftSubTreeSize = LeftSubTreeSize
  167.     DIM lngChildIndex AS LONG
  168.     DIM lngPreviousCompleteTreeIndex AS LONG
  169.     DO WHILE lngLeftRightTreeAddress > 0
  170.         DO WHILE lngLeftRightTreeAddress MOD 2 = 0
  171.             lngLeftRightTreeAddress = lngLeftRightTreeAddress \ 2
  172.             SmoothUp lngSubTreeSize, lngLeftSubTreeSize
  173.         LOOP
  174.         lngPreviousCompleteTreeIndex = lngNodeIndex - lngSubTreeSize
  175.         IF lngLeftRightTreeAddress = 1 THEN
  176.             lngLeftRightTreeAddress = 0
  177.         ELSEIF plngArray(lngPreviousCompleteTreeIndex).thekey <= plngArray(lngNodeIndex).thekey THEN
  178.             lngLeftRightTreeAddress = 0
  179.         ELSE
  180.             lngLeftRightTreeAddress = lngLeftRightTreeAddress - 1
  181.             IF lngSubTreeSize = 1 THEN
  182.                 Exchange plngArray(), lngNodeIndex, lngPreviousCompleteTreeIndex
  183.                 lngNodeIndex = lngPreviousCompleteTreeIndex
  184.             ELSEIF lngSubTreeSize >= 3 THEN
  185.                 lngChildIndex = lngNodeIndex - lngSubTreeSize + lngLeftSubTreeSize
  186.                 IF plngArray(lngChildIndex).thekey < plngArray(lngNodeIndex - 1).thekey THEN
  187.                     lngChildIndex = lngNodeIndex - 1
  188.                     SmoothDown lngSubTreeSize, lngLeftSubTreeSize
  189.                     lngLeftRightTreeAddress = lngLeftRightTreeAddress * 2
  190.                 END IF
  191.                 IF plngArray(lngPreviousCompleteTreeIndex).thekey >= plngArray(lngChildIndex).thekey THEN
  192.                     Exchange plngArray(), lngNodeIndex, lngPreviousCompleteTreeIndex
  193.                     lngNodeIndex = lngPreviousCompleteTreeIndex
  194.                 ELSE
  195.                     Exchange plngArray(), lngNodeIndex, lngChildIndex
  196.                     lngNodeIndex = lngChildIndex
  197.                     SmoothDown lngSubTreeSize, lngLeftSubTreeSize
  198.                     lngLeftRightTreeAddress = 0
  199.                 END IF
  200.             END IF
  201.         END IF
  202.     LOOP
  203.     SmoothSift plngArray(), lngNodeIndex, lngSubTreeSize, lngLeftSubTreeSize
  204.  
  205. SUB SmoothSemiTrinkle (plngArray() AS dataelement, NodeIndex AS LONG, LeftRightTreeAddress AS LONG, SubTreeSize AS LONG, LeftSubTreeSize AS LONG)
  206.     DIM lngNodeIndex AS LONG: lngNodeIndex = NodeIndex
  207.     DIM lngLeftRightTreeAddress AS LONG: lngLeftRightTreeAddress = LeftRightTreeAddress
  208.     DIM lngSubTreeSize AS LONG: lngSubTreeSize = SubTreeSize
  209.     DIM lngLeftSubTreeSize AS LONG: lngLeftSubTreeSize = LeftSubTreeSize
  210.     DIM lngIndexTopPreviousCompleteHeap AS LONG
  211.     lngIndexTopPreviousCompleteHeap = lngNodeIndex - lngLeftSubTreeSize
  212.     IF plngArray(lngIndexTopPreviousCompleteHeap).thekey > plngArray(lngNodeIndex).thekey THEN
  213.         Exchange plngArray(), lngNodeIndex, lngIndexTopPreviousCompleteHeap
  214.         SmoothTrinkle plngArray(), lngIndexTopPreviousCompleteHeap, lngLeftRightTreeAddress, lngSubTreeSize, lngLeftSubTreeSize
  215.     END IF
  216.  
  217. SUB Exchange (mlngArray() AS dataelement, plng1 AS LONG, plng2 AS LONG)
  218.     SWAP mlngArray(plng1), mlngArray(plng2)
  219.  
  220.     'lngSwap.thekey = mlngArray(plng1).thekey
  221.     'mlngArray(plng1).thekey = mlngArray(plng2).thekey
  222.     'mlngArray(plng2).thekey = lngSwap.thekey
  223.  
  224.     'lngSwap.originalorder = mlngArray(plng1).originalorder
  225.     'mlngArray(plng1).originalorder = mlngArray(plng2).originalorder
  226.     'mlngArray(plng2).originalorder = lngSwap.originalorder
  227.  
« Last Edit: February 25, 2018, 08:04:24 am by codeguy »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: OpenInclude, soon to be made a SMART code merger.
« Reply #5 on: February 25, 2018, 07:49:08 am »
Hi codeguy,

Oh yeah, I forgot about fixed strings too. As I recall, that is all you can use in a TYPE definition.

I use to do fixed strings all the time with Database stuff for file records QBsomething... and VBDOS

Ran into host of problems using fixed strings in Defined Type because of spacing.
« Last Edit: February 25, 2018, 07:53:35 am by bplus »

Offline codeguy

  • Forum Regular
  • Posts: 174
    • View Profile
Re: OpenInclude, soon to be made a SMART code merger.
« Reply #6 on: February 25, 2018, 08:21:12 am »
SUB GenericCopyArray(GenericDataTypeArrayDest@(),GenericDataTypeArraySource@())
GenericCopyArrayLBBV&=LBOUND(GenericDataTypeArraySource@)
GenericCopyArrayUBBV&=UBOUND(GenericDataTypeArraySource@)
REDIM (GenericDataTypeArrayDest@(GenericCopyArrayLBBV& to GenericCopyArrayUBBV&)
    FOR GenericDataTypeArraySource& = GenericCopyArrayLBBV& to GenericCopyArrayUBBV&
    GenericDataTypeArrayDest@(GenericDataTypeArraySource&) = GenericDataTypeArraySource@(GenericDataTypeArraySource&)
NEXT
END SUB

this would allow me to include code like this array copy code and change the @ with the actual data types of the array.