Welcome, Guest
You have to register before you can post on our site.

Username/Email:
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 308
» Latest member: Donaldvem
» Forum threads: 1,741
» Forum posts: 17,901

Full Statistics

Latest Threads
The QB64 IDE shell
Forum: Utilities
Last Post: JasonPag
09-16-2024, 05:37 PM
» Replies: 9
» Views: 762
Importance regarding Ches...
Forum: Utilities
Last Post: JasonPag
09-01-2024, 06:34 PM
» Replies: 0
» Views: 31
Chess and Analysis and En...
Forum: Utilities
Last Post: JasonPag
08-28-2024, 02:37 PM
» Replies: 0
» Views: 32
DAY 009:_PutImage
Forum: Keyword of the Day!
Last Post: grymmjack
09-02-2023, 02:57 PM
» Replies: 54
» Views: 2,034
Fall Banner Contest?
Forum: Site Suggestions
Last Post: grymmjack
08-31-2023, 11:50 PM
» Replies: 36
» Views: 1,261
ColorPicker - Function th...
Forum: Dav
Last Post: Dav
08-31-2023, 11:04 PM
» Replies: 3
» Views: 315
Goals(1) = New Tile()
Forum: Works in Progress
Last Post: RhoSigma
08-31-2023, 09:45 PM
» Replies: 3
» Views: 127
micro(A)v11
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 09:14 PM
» Replies: 90
» Views: 3,589
Updating The Single Most ...
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 09:13 PM
» Replies: 7
» Views: 254
QBJS Image Question
Forum: QBJS, BAM, and Other BASICs
Last Post: bplus
08-31-2023, 05:49 PM
» Replies: 5
» Views: 155

 
  SQLite wrapper
Posted by: jakebullet70 - 05-25-2022, 09:23 AM - Forum: Utilities - Replies (1)

OK, this should be all you need to use SQLite 3 databases.  See GitHub for all code needed including sample stuff.

https://github.com/jakebullet70/QB64-SQLite

Supported Subs / Functions

Code: (Select All)
'--- open a sqlite DB
SUB DB_Open (CreateIfMissing AS _BYTE)
FUNCTION DB_Open%% (CreateIfMissing AS _BYTE)

'--- close a database
SUB DB_Close ()

'--- return primary key of last inserted record
FUNCTION DB_LastInsertedRowID& ()

'--- return number of rows the last query affected
FUNCTION DB_AffectedRows& ()

'--- return the last error message (if any)
FUNCTION DB_GetErrMsg$ ()

'--- return total of rows in a recordset
FUNCTION DB_RowCount& (RS() AS SQLITE_RESULTSET)

'--- return number of columns in a recordset
FUNCTION DB_ColCount& (RS() AS SQLITE_RESULTSET)

'--- Gets the value of a field
FUNCTION DB_GetField$ (RS() AS SQLITE_RESULTSET, Row AS LONG, FieldName AS STRING)

'--- Use for Scalar functions, returning 1 value
FUNCTION DB_ExecQuerySingleResult$ (sql_command AS STRING)

'--- Execute a SQL query and return a recordset
SUB DB_ExecQuery (sql_command AS STRING, RS() AS SQLITE_RESULTSET)
FUNCTION DB_ExecQuery& (sql_command AS STRING, RS() AS SQLITE_RESULTSET)

'--- Execute a SQL query with no return value
SUB DB_ExecNonQuery (sql_command AS STRING)
FUNCTION DB_ExecNonQuery& (sql_command AS STRING)

'--- Helper function to build SQL statements
FUNCTION DB_SqlParse$ (sql_str$, values_str$)

   
   

Print this item

  Command Line INI Editor
Posted by: AtomicSlaughter - 05-24-2022, 07:54 PM - Forum: Programs - No Replies

OK my ini include has been modified to work from the command line.

the usage format is

-add -f filename -s section -k key -d data

-del -f filename, -s section -k key

-delsec -f filename, -s section

-read -f filename, -s section -k key

-readsection -f filename, -s section

Code: (Select All)
$Console:Only
Type Sections
    lineNum As Integer
    section As String
End Type
If Command$ <> "" Then
    test$ = Command$(1)
    For i = 2 To _CommandCount Step 2
        Select Case Command$(i)
            Case "-f"
                FileName$ = Command$(i + 1)
            Case "-s"
                IniSection$ = Command$(i + 1)
            Case "-d"
                INIData$ = Command$(i + 1)
            Case "-k"
                INIKey$ = Command$(i + 1)
        End Select
    Next
    Select Case test$
        Case "-add": AddINI FileName$, IniSection$, INIKey$, INIData$: System
        Case "-del": DelINI FileName$, IniSection$, INIKey$: System
        Case "-delsec": DelSec FileName$, IniSection$: System
        Case "-read": Print ReadINI(FileName$, IniSection$, INIKey$): System
        Case "-readsection": ReadINISec FileName$, IniSection$: System
    End Select
    System
Else
    Input "Command      >", test$
    Select Case test$
        Case "add"
            Input "Filename     >", FileName$
            Input "Section      >", IniSection$
            Input "Key          >", INIKey$
            Input "Data         >", INIData$
            AddINI FileName$, IniSection$, INIKey$, INIData$: System
        Case "del"
            Input "Filename     >", FileName$
            Input "Section      >", IniSection$
            Input "Key          >", INIKey$
            DelINI FileName$, IniSection$, INIKey$: System
        Case "delsec"
            Input "Filename     >", FileName$
            Input "Section      >", IniSection$
            DelSec FileName$, IniSection$
        Case "read"
            Input "Filename     >", FileName$
            Input "Section      >", IniSection$
            Input "Key          >", INIKey$
            Print ReadINI(FileName$, IniSection$, INIKey$): System: System
    End Select
End If
Sub LoadINIFile (FileName As String, iniData() As String, iniSections() As Sections)
    ReDim As String iniData(0)
    ReDim As Sections iniSections(0)
    If _FileExists(FileName) Then
        file = FreeFile
        Open FileName For Binary As #file
        If LOF(file) = 0 Then Exit Sub
        Do
            Line Input #file, iniData(UBound(iniData))
            If InStr(iniData(UBound(iniData)), "[") > 0 Then
                iniSections(UBound(iniSections)).section = iniData(UBound(iniData))
                iniSections(UBound(iniSections)).lineNum = x
                ReDim _Preserve As Sections iniSections(UBound(iniSections) + 1)
            End If
            ReDim _Preserve iniData(UBound(iniData) + 1)
            x = x + 1
        Loop Until EOF(file)
        Close
    End If
    iniSections(UBound(iniSections)).section = "End of File"
    iniSections(UBound(iniSections)).lineNum = x
End Sub

Sub CheckSection (sec() As Sections, check As String, out1 As Single, out2 As Single, Ret As String)
    For i = 0 To UBound(sec)
        If LCase$(sec(i).section) = "[" + LCase$(check) + "]" Then
            out1 = sec(i).lineNum + 1
            out2 = sec(i + 1).lineNum - 1
            Exit Sub
        End If
    Next
    Ret = "New Section"
End Sub

Function ReadINI$ (FileName As String, Section As String, INIKey As String)
    Dim sec(0) As Sections: Dim ini(0) As String
    Dim As Single start, finish
    LoadINIFile FileName, ini(), sec()
    If Section <> "" Then
        CheckSection sec(), Section, start, finish, ret$
        For i = start To finish
            If Left$(LCase$(ini(i)), InStr(ini(i), "=") - 1) = LCase$(INIKey) Then
                ReadINI = Right$(ini(i), (Len(ini(i)) - InStr(ini(i), "=")))
            End If
        Next
    Else
        Do
            If Left$(LCase$(ini(i)), InStr(ini(i), "=") - 1) = LCase$(INIKey) Then
                ReadINI = Right$(ini(i), (Len(ini(i)) - InStr(ini(i), "=")))
            End If
            i = i + 1
        Loop Until ini(i) = ""
    End If
End Function

Sub DelINI (FileName As String, Section As String, INIKey As String)
    Dim sec(0) As Sections: Dim ini(0) As String
    Dim As Single start, finish
    LoadINIFile FileName, ini(), sec()
    If Section <> "" Then
        CheckSection sec(), Section, start, finish, ret$
        For i = start To finish
            If Left$(LCase$(ini(i)), InStr(ini(i), "=") - 1) = LCase$(INIKey) Then
                ReDim temp(UBound(ini) - 1) As String
                For a = 0 To (i - 1)
                    temp(a) = ini(a)
                Next
                For a = i To UBound(temp)
                    temp(a) = ini(a + 1)
                Next

            End If
        Next
    Else
        Do
            If Left$(LCase$(ini(i)), InStr(ini(i), "=") - 1) = LCase$(INIKey) Then
                ReDim temp(UBound(ini) - 1) As String
                For a = 0 To i - 1
                    temp(a) = ini(a)
                Next
                For a = x To UBound(ini)
                    temp(x) = ini(x + 1)
                Next
            End If
            i = i + 1
        Loop Until ini(i) = ""
    End If
    Do
        If temp(UBound(temp)) = "" Then ReDim _Preserve temp(UBound(temp) - 1)
    Loop Until temp(UBound(temp)) <> ""
    f = FreeFile
    Open FileName For Output As #f
    For i = 0 To UBound(temp)
        Print #f, temp(i)
    Next
    Close
End Sub

Sub DelSec (FileName As String, Section As String)
    Dim sec(0) As Sections: Dim ini(0) As String
    Dim As Single start, finish
    LoadINIFile FileName, ini(), sec()
    CheckSection sec(), Section, start, finish, ret$
    ReDim Temp(UBound(ini)) As String
    For i = 0 To start
        Temp(i) = ini(i)
    Next

    For i = finish To UBound(ini)
        Temp(i - finish) = ini(i)
    Next
    Do
        If Temp(UBound(Temp)) = "" Then ReDim _Preserve Temp(UBound(Temp) - 1)
    Loop Until Temp(UBound(Temp)) <> ""
    f = FreeFile
    Open FileName For Output As #f
    For i = 0 To UBound(Temp)
        Print #f, Temp(i)
    Next
    Close
End Sub

Sub AddINI (FileName As String, Section As String, INIKey As String, INIData As String)
    Dim sec(0) As Sections: Dim ini(0) As String
    Dim As Single start, finish
    LoadINIFile FileName, ini(), sec()
    CheckSection sec(), Section, start, finish, ret$
    ReDim temp(UBound(ini) + 1) As String
    If ret$ = "New Section" Then
        ReDim temp(UBound(ini) + 3)
        temp(0) = "[" + Section + "]"
        temp(1) = INIKey + "=" + INIData
        temp(2) = ""
        For i = 3 To UBound(ini)
            temp(i) = ini(i - 3)
        Next
    Else

        If Section <> "" Then
            For i = 0 To start

                temp(i) = ini(i)
            Next
            temp(start) = INIKey + "=" + INIData
            For i = start + 1 To UBound(ini)
                temp(i) = ini(i - 1)
            Next
        Else
            temp(0) = INIKey + "=" + INIData
            For i = 1 To UBound(ini)
                temp(i) = ini(i - 1)
            Next
        End If

    End If
    Do
        If temp(UBound(temp)) = "" Then ReDim _Preserve temp(UBound(temp) - 1)
    Loop Until temp(UBound(temp)) <> ""
    ff = FreeFile

    Open FileName For Output As #ff
    For i = 0 To UBound(temp)
        Print #ff, temp(i)
    Next
    Close

End Sub
Sub ReadINISec (FileName As String, Section As String)
    Cls
    Dim sec(0) As Sections: Dim ini(0) As String
    Dim As Single start, finish
    LoadINIFile FileName, ini(), sec()
    CheckSection sec(), Section, start, finish, ret$
    x = start: y = finish
    Print ini(start - 1)
    For i = x To y
        Print ">> ", ini(i)
    Next
End Sub

Print this item

  Found a bug in QB64
Posted by: Coolman - 05-24-2022, 11:57 AM - Forum: General Discussion - Replies (9)

i found a bug in qb64. if you have in the same location a *.bas file and a directory with the same name. the compilation will fail. example :

file test.bas and directory test

Print this item

  Wiki Downloader
Posted by: SMcNeill - 05-24-2022, 11:41 AM - Forum: SMcNeill - Replies (6)

Lots of folks are always asking about how to download the wiki for off-line use, and over the years we've always used tools such as HTTrack to download and copy the website to save a local copy.  The problem with this is that the archive we get is often huge as BLEEP!  The last wiki I downloaded and shared was an archive of over 1.1GB in size!

So, I wanted a much simpler alternative, and thus I came up with this little solution:

Code: (Select All)
$Console:Only
DefLng A-Z
Const HomePage$ = "https://qb64phoenix.com"
ReDim Shared PageNames(10000) As String
NumberOfPageLists = DownloadPageLists 'As of mid 2022, there are only 2 pages listing all the page names.
'NumberOfPageLists = 2 'hard coded for counting without having to download pages repeatedly while testing code

PageCount = CountPages(NumberOfPageLists)
Print PageCount
t# = Timer: t$ = Time$
For i = 1 To PageCount
    Cls
    Print "Downloading... (Started at: "; t$; ")"
    FileName$ = Mid$(PageNames(i), _InStrRev(PageNames(i), "/") + 1) + ".HTML"
    FileName$ = CleanHTML(FileName$)
    Print i; "of"; PageCount, FileName$
    Download PageNames(i), FileName$
    _Display
Next
_AutoDisplay
Print "FINISHED!!  (Finsihed at: "; Time$; ")"
Print
Print Using "##,###.## seconds to download everything on this PC."; Timer - t#



Function CountPages (NumberOfPageLists)
    FileLeft$ = "Page List("
    FileRight$ = ").txt"
    For i = 1 To NumberOfPageLists
        file$ = FileLeft$ + _Trim$(Str$(i)) + FileRight$
        Open file$ For Binary As #1
        l = LOF(1): t$ = Space$(l)
        Get #1, 1, t$
        Close #1
        start = InStr(t$, "<ul") 'skip down to the part of the page with the page listins
        finish = InStr(start, t$, "</ul") 'and we can quit parsing when we get down to this point
        p = start 'current position in file we're parsing
        Do Until p > finish
            p = InStr(p, t$, "<li><a href=") + 13
            If p = 13 Then Exit Do 'we've parsed all the lists from the page.  No need to keep going
            p2 = InStr(p, t$, Chr$(34))
            count = count + 1
            PageNames(count) = Mid$(t$, p, p2 - p)
        Loop
    Next
    CountPages = count
    ReDim _Preserve PageNames(count) As String
End Function


Function DownloadPageLists
    FileLeft$ = "Page List("
    FileRight$ = ").txt"
    FileCount = 1
    CurrentFile$ = ""
    url$ = "/qb64wiki/index.php/Special:AllPages" 'the first file that we download
    Do
        file$ = FileLeft$ + _Trim$(Str$(FileCount)) + FileRight$
        Download url$, file$
        url2$ = GetNextPage$(file$)
        P = InStr(url2$, "from=")
        If P = 0 Then Exit Do
        If Mid$(url2$, P + 5) > CurrentFile$ Then
            CurrentFile$ = Mid$(url2$, P + 5)
            FileCount = FileCount + 1
            url$ = url2$
        Else
            Exit Do
        End If
    Loop
    DownloadPageLists = FileCount
End Function

Function CleanHTML$ (OriginalText$)
    text$ = OriginalText$ 'don't corrupt incoming text
    Type ReplaceList
        original As String
        replacement As String
    End Type

    'Expandable HTML replacement system
    Dim HTML(200) As ReplaceList
    HTML(0).original = "&amp;": HTML(0).replacement = "&"
    '    HTML(1).original = "%24": HTML(1).replacement = "$"
    For i = 1 To 200
        HTML(i).original = "%" + Hex$(i + 16)
        HTML(i).replacement = Chr$(i + 16)
        'Print HTML(i).original, HTML(i).replacement
        'Sleep
    Next


    For i = 0 To UBound(HTML)
        Do
            P = InStr(text$, HTML(i).original)
            If P = 0 Then Exit Do
            text$ = Left$(text$, P - 1) + HTML(i).replacement + Mid$(text$, P + Len(HTML(i).original))
        Loop
    Next
    CleanHTML$ = text$
End Function

Sub Download (url$, outputFile$)
    url2$ = CleanHTML(url$)
    'Print "https://qb64phoenix.com/qb64wiki/index.php?title=Special:AllPages&from=KEY+n"
    'Print HomePage$ + url2$
    Shell _Hide "curl -o " + Chr$(34) + outputFile$ + Chr$(34) + " " + Chr$(34) + HomePage$ + url2$ + Chr$(34)
End Sub

Function GetNextPage$ (currentPage$)
    SpecialPageDivClass$ = "<div class=" + Chr$(34) + "mw-allpages-nav" + Chr$(34) + ">"
    SpecialPageLink$ = "<a href="
    SpecialPageEndLink$ = Chr$(34) + " title"
    Open currentPage$ For Binary As #1
    l = LOF(1)
    t$ = Space$(l)
    Get #1, 1, t$
    Close
    sp = InStr(t$, SpecialPageDivClass$)
    If sp Then
        lp = InStr(sp, t$, SpecialPageLink$)
        If lp Then
            lp = lp + 9
            lp2 = InStr(lp, t$, SpecialPageEndLink$)
            link$ = Mid$(t$, lp, lp2 - lp)
            GetNextPage$ = CleanHTML(link$)
        End If
    End If
End Function

With all of 130 lines of code, we fetch and save the whole wiki to disk!

NOTE:  If you run this, this will save over 600 files into the same directory where this program is ran from!  I'd suggest saving it into its own directly and running it from there!  Complaining over a messy QB64 folder after this warning wil only get me to laugh at you.  Tongue

Now, this creates a whole bunch of files with a *.HTML extension to them.  You can click on any of these files and open them in your web browser, but you should know in advance that the links between them aren't going to work as they expect a specific file structure on the wiki and we're not providing that here.  You'll have to click and open each file individually yourself.

There's a little more work with working with these files, but there's also a couple of large advantages as well:

1) Anytime you run the program, you'll know you have the most up to date version of information from the wiki.
2) You don't have to wait for someone to run HTTrack, grab a copy from the web, and share it with you.
3) The total size of this on disk is about 20MB -- not 1.2GB!!  It's a helluva lot more portable!

Pages aren't quite as pretty as what you'll find when you go to the wiki itself, as it doesn't have the templates to pull upon to format everything properly, but they're more than readable in my opinion.  Below is the way the scancode page looks for me, in microsoft edge, as an example page.

   

If there's anyone who just wants the files themselves, without having to download the pages on their own (as they take about 10 minutes or so on my machine to download all of them), I've zipped them all up in a 7z archive, which is available via the attachment below.



Attached Files
.7z   wiki.7z (Size: 845.61 KB / Downloads: 66)
Print this item

  The "Ulam Conjecture" (Collatz conjecture)
Posted by: Kernelpanic - 05-23-2022, 07:15 PM - Forum: Programs - Replies (6)

The Ulam conjecture is a popular task in IT teaching. This is an implementation in QB64.

A "problem" arises when the output is very long, because then the heading can no longer be read because the side scroll bars are missing.

Code: (Select All)
' EP in C' S.47, šb.4.6 'Ulamsches Problem': Von einer beliebigen Startzahl
' Erweitert fuer grosse Zahlen (Formatierung noch anpassen)                 -  09.04.2022
' QuickBasic 64 Version                                                     -  23.05.2022
'========================================================================================

OPTION _EXPLICIT

DIM startzahl AS LONG, sum AS LONG
DIM z AS INTEGER

CLS
PRINT TAB(25); "** ULAMSCHES PROBLEM **"
PRINT TAB(25); "======================="
PRINT TAB(10); "Erzeugt eine Folge von Zahlen aus einer gegebenen Startzahl"
PRINT TAB(10); "nach der Regel:"
PRINT TAB(10); "   1. Ist die Zahl 1, dann Stop (Ende)."
PRINT TAB(10); "   2. Ist die Zahl gerade, wird sie halbiert. Gehe nach (1.)"
PRINT TAB(10); "   3. Ist die Zahl ungerade, wird sie verdreifacht und um eins"
PRINT TAB(10); "      vermehrt. Gehe nach (1.)"

PRINT
INPUT "Geben Sie eine (ganze) Startzahl ein: ", startzahl

PRINT "Ergibt die Folge -->"
PRINT

z = 0
sum = 0
WHILE (startzahl <> 1)
  IF startzahl MOD 2 = 0 THEN
    startzahl = startzahl / 2 'Wenn startzahl gerade ist (Regel 2)
  ELSE
    startzahl = startzahl * 3 'Wenn startzahl ungerade ist (Regel 3)
    startzahl = startzahl + 1
  END IF
  PRINT USING "######"; startzahl;
  sum = sum + startzahl
  z = z + 1

  IF z MOD 11 = 0 THEN 'Fuer Formatierung der Ausgabe
    PRINT
  END IF
WEND

PRINT: PRINT
PRINT USING "Diese Folge besteht aus #### Zahlen. Ihre Summe betraegt ######"; z, sum

END


[Image: Normale-Darstellung2022-05-23.jpg]

Print this item

  Old vs. new version of QB64
Posted by: Kernelpanic - 05-23-2022, 06:55 PM - Forum: General Discussion - No Replies

I'll make a new thread.
I just read that there are new versions of QB64. Is there a special change compared to the versions from the old forum?

I'm using the latest version by the Old-Forum I think so: Version 2.02 from December 21, 2021.

Print this item

  Is there a 2001 trip effect written in QB64?
Posted by: TarotRedhand - 05-23-2022, 08:55 AM - Forum: General Discussion - Replies (4)

Simple question. Has anyone written a slit-scan effect program for QB64? That is like the "trip" sequence in the movie "2001 a Space Oddity". If not, is anyone up to the challenge of making one? If so one little rule, it should use an external image to scan. Here is a short YouTube video that shows the technique. I can almost understand how to do it from that myself. Final thought - it might make a good screensaver project too.

Thanks.

TR

Print this item

  Wiki TEXT pages downloader
Posted by: SMcNeill - 05-23-2022, 04:15 AM - Forum: Works in Progress - Replies (4)

Code: (Select All)
On Error GoTo errorchecker
GoTo skip_errorchecker

errorchecker:
glitch = glitch + 1
Locate 8 + glitch, 1
Print "Glitch in a file somewhere.  Something didn't get downloaded properly. :P"
Resume Next
skip_errorchecker:

Dim Shared Cache_Folder As String
Cache_Folder$ = "./"
If InStr(_OS$, "WIN") = 0 Then Cache_Folder$ = ".\"

'If _DirExists(Cache_Folder$) = 0 Then MkDir Cache_Folder$
Dim Shared Help_sx, Help_sy, Help_cx, Help_cy
Dim Shared Help_Select, Help_cx1, Help_cy1, Help_SelX1, Help_SelX2, Help_SelY1, Help_SelY2
Dim Shared Help_MSelect
Help_sx = 1: Help_sy = 1: Help_cx = 1: Help_cy = 1
Dim Shared Help_wx1, Help_wy1, Help_wx2, Help_wy2 'defines the text section of the help window on-screen
Dim Shared Help_ww, Help_wh 'width & height of text region
Dim Shared help_h, help_w 'width & height
Dim Shared Help_Txt$ '[chr][col][link-byte1][link-byte2]
Dim Shared Help_Txt_Len
Dim Shared Help_Line$ 'index of first txt element of a line
Dim Shared Help_Link$ 'the link info [sep][type:]...[sep]
Dim Shared Help_Link_Sep$: Help_Link_Sep$ = Chr$(13)
Dim Shared Help_LinkN
Dim Shared Help_NewLineIndent
Dim Shared Help_Underline
'Link Types:
' PAGE:wikipagename
' EXTL:external link url
Dim Shared Help_Pos, Help_Wrap_Pos
Dim Shared Help_BG_Col
Dim Shared Help_Col_Normal: Help_Col_Normal = 7
Dim Shared Help_Col_Link: Help_Col_Link = 9
Dim Shared Help_Col_Bold: Help_Col_Bold = 15
Dim Shared Help_Col_Italic: Help_Col_Italic = 15
Dim Shared Help_Col_Section: Help_Col_Section = 8
Dim Shared Help_Bold, Help_Italic, Help_DList
Dim Shared Help_LockWrap, Help_LockParse
Dim Shared Help_Center, Help_CIndent$
ReDim Shared Help_LineLen(1)
ReDim Shared Back$(1)
ReDim Shared Back_Name$(1)
Type Help_Back_Type
    sx As Long
    sy As Long
    cx As Long
    cy As Long
End Type
ReDim Shared Help_Back(1) As Help_Back_Type
Back$(1) = "QB64 Help Menu"
Back_Name$(1) = Back2BackName$(Back$(1))
Help_Back(1).sx = 1: Help_Back(1).sy = 1: Help_Back(1).cx = 1: Help_Back(1).cy = 1
Dim Shared Help_Back_Pos
Help_Back_Pos = 1
Dim Shared Help_Search_Time As Double
Dim Shared Help_Search_Str As String
Dim Shared Help_PageLoaded As String
Dim Shared Help_Recaching, Help_IgnoreCache

'Unicode replacements
Type wikiUtf8Replace
    utf8 As String * 4 '= MKI$(reversed hex 2-byte UTF-8 sequence) or MKL$(reversed hex 3/4-byte UTF-8 sequence)
    repl As String * 8 '= replacement string (1-8 chars)
End Type
Dim Shared wpUtfRepl(0 To 50) As wikiUtf8Replace
Dim Shared wpUtfReplCnt: wpUtfReplCnt = -1 'wpUtfRepl index counter (pre-increment, hence
'you don't need "wpUtfReplCnt - 1" when used in loops, just do "0 TO wpUtfReplCnt"
'Note: All UTF-8 values must be reversed in MKI$/MKL$, as it flips them to little endian.
'      In the wiki text they are noted in big endian, hence we need to pre-flip them.
'2-byte sequences
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA9C2): wpUtfRepl(wpUtfReplCnt).repl = "(c)" 'copyright
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA9C3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(130) 'accent (é)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA2C3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(131) 'accent (â)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA0C3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(133) 'accent (à)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA5C3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(134) 'accent (å)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA7C3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(135) 'accent (ç)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HAAC3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(136) 'accent (ê)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HABC3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(137) 'accent (ë)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA8C3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(138) 'accent (è)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HAFC3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(139) 'accent (ï)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HAEC3): wpUtfRepl(wpUtfReplCnt).repl = Chr$(140) 'accent (î)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA2C2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(155) 'cents (ø)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HBDC2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(171) 'fraction (½)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HBCC2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(172) 'fraction (¼)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKI$(&HA0C2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(255) 'non-breaking space
'3-byte sequences
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&HA680E2): wpUtfRepl(wpUtfReplCnt).repl = "..." 'ellipsis
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H8C94E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(218) 'single line draw (top/left corner)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H9094E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(191) 'single line draw (top/right corner)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H9494E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(192) 'single line draw (bottom/left corner)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H9894E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(217) 'single line draw (bottom/right corner)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H8094E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(196) 'single line draw (horizontal line)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H8294E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(179) 'single line draw (vertical line)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&HB494E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(193) 'single line draw (hori. line + up connection)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&HAC94E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(194) 'single line draw (hori. line + down connection)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&HA494E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(180) 'single line draw (vert. line + left connection)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H9C94E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(195) 'single line draw (vert. line + right connection)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&HBC94E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(197) 'single line draw (hori./vert. line cross)
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&HB296E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(30) 'triangle up
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&HBC96E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(31) 'triangle down
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H8497E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(17) 'triangle left
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&HBA96E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(16) 'triangle right
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H9186E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(24) 'arrow up
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H9386E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(25) 'arrow down
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H9086E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(27) 'arrow left
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H9286E2): wpUtfRepl(wpUtfReplCnt).repl = Chr$(26) 'arrow right
'4-byte sequences
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H80989FF0): wpUtfRepl(wpUtfReplCnt).repl = ":)" 'smily
wpUtfReplCnt = wpUtfReplCnt + 1: wpUtfRepl(wpUtfReplCnt).utf8 = MKL$(&H88989FF0): wpUtfRepl(wpUtfReplCnt).repl = ";)" 'wink
'========= END OF WIKI.BI

updatestep = 1
Do 'main loop

    '-------- custom display changes --------
    'update steps
    Select Case updatestep
        Case 1
            Print "Generating list of cached content..."
        Case 2
            Print "Adding core help pages to list..."
        Case 3
            Print "Regenerating keyword list..."
        Case 4
            Print "Building download queue..."
        Case 5
            Locate 8, 1: Print "Updating help content file...";
    End Select

    If updatestep = 5 Then
        maxprogresswidth = 52 'arbitrary
        percentage = Int(n / c * 100)
        percentagechars = Int(maxprogresswidth * n / c)
        'percentageMsg$ = "[" + STRING$(percentagechars, 254) + SPACE$(maxprogresswidth - percentagechars) + "]" + STR$(percentage) + "%"
        percentageMsg$ = Str$(percentage) + "%"
        Print percentageMsg$
    ElseIf updatestep = 6 Then
        percentageMsg$ = " 100%"
        Print percentageMsg$
    End If
    '-------- end of custom display changes --------

    '-------- update routine -------------------------------------
    Select Case updatestep
        Case 1
            'Create a list of all files to be recached
            f$ = Chr$(0)

            'Prepend core pages to list
            f$ = Chr$(0) + "Keyword_Reference_-_By_usage.txt" + f$
            f$ = Chr$(0) + "QB64_Help_Menu.txt" + f$
            f$ = Chr$(0) + "QB64_FAQ.txt" + f$
            updatestep = updatestep + 1
        Case 2
            updatestep = updatestep + 1
        Case 3
            'Download and PARSE alphabetical index to build required F1 help links
            FullMessage$(1) = "Regenerating keyword list..."
            Help_Recaching = 1: Help_IgnoreCache = 1
            Print "Downloading: Keyword Reference - Alphabetical "
            a$ = Wiki$("Keyword Reference - Alphabetical")
            Help_Recaching = 0: Help_IgnoreCache = 0
            WikiParse a$

            fh1 = FreeFile
            Open "Keyword_Reference_-_Alphabetical_1000000_100000000_-_100000000000.txt" For Binary As #fh1
            temp$ = Space$(LOF(fh1))
            Get #fh1, 1, temp$
            Close #fh1
            Open "links.txt" For Output As #fh1
            Print "GENERATING KEYWORDS..."

            Do
                p = InStr(p + 2, temp$, "]]")
                If p = 0 Then Exit Do
                p1 = _InStrRev(p, temp$, "[[")
                If p1 < oldp Or p1 = 0 Then Exit Do
                l$ = Mid$(temp$, p1 + 2, p - p1 - 2)
                If Left$(l$, 1) = "_" Then l$ = Mid$(l$, 2)
                If Left$(l$, 1) <> "#" Then Print #fh1, l$
                oldp = p + 2
            Loop
            Close #fh1
            Print "GENERATED KEYWORDS..."
            updatestep = updatestep + 1
        Case 4
            'Add all linked pages to download list (if not already in list)
            fh = FreeFile
            Open "links.txt" For Input As #fh
            Do Until EOF(fh)
                Line Input #fh, l$
                If Len(l$) Then
                    c = InStr(l$, ","): l$ = Right$(l$, Len(l$) - c)
                    'Escape all invalid and other critical chars in filenames
                    PageName2$ = ""
                    For i = 1 To Len(l$)
                        c = Asc(l$, i)
                        Select Case c
                            Case 32 '                                    '(space)
                                PageName2$ = PageName2$ + "_"
                            Case 34, 38, 42, 47, 58, 60, 62, 63, 92, 124 '("&*/:<>?\|)
                                PageName2$ = PageName2$ + "%" + Hex$(c)
                            Case Else
                                PageName2$ = PageName2$ + Chr$(c)
                        End Select
                    Next
                    PageName2$ = PageName2$ + ".txt"
                    If InStr(f$, Chr$(0) + PageName2$ + Chr$(0)) = 0 Then
                        f$ = f$ + PageName2$ + Chr$(0)
                    End If
                End If
            Loop
            Close #fh

            'Redownload all listed files
            If f$ <> Chr$(0) Then
                c = 0 'count files to download
                For x = 2 To Len(f$)
                    If Asc(f$, x) = 0 Then c = c + 1
                Next
                c = c - 1

                f$ = Right$(f$, Len(f$) - 1)
                z$ = Chr$(0)
                n = 0
            Else
                GoTo stoprecache
            End If
            FullMessage$(2) = ""
            updatestep = updatestep + 1
        Case 5
            If Len(f$) > 0 Then
                x2 = InStr(f$, z$)
                f2$ = Left$(f$, x2 - 1): f$ = Right$(f$, Len(f$) - x2)

                If Right$(f2$, 4) = ".txt" Then
                    f2$ = Left$(f2$, Len(f2$) - 4)
                    n = n + 1
                    FullMessage$(2) = "Page title: " + f2$
                    Help_IgnoreCache = 1: Help_Recaching = 1: ignore$ = Wiki(f2$): Help_Recaching = 0: Help_IgnoreCache = 0
                End If
            Else
                updatestep = updatestep + 1
            End If
        Case 6
            stoprecache:
            FullMessage$(1) = "All pages updated."
            FullMessage$(2) = ""
            Print "Finished!"
            End
            _Limit 20
    End Select
    '-------- end of update routine ------------------------------

    mousedown = 0
    mouseup = 0
Loop







'========= START OF WIKI.BM
Function Back2BackName$ (a$)
    If a$ = "Keyword Reference - Alphabetical" Then Back2BackName$ = "Alphabetical": Exit Function
    If a$ = "Keyword Reference - By usage" Then Back2BackName$ = "By Usage": Exit Function
    If a$ = "QB64 Help Menu" Then Back2BackName$ = "Help": Exit Function
    If a$ = "QB64 FAQ" Then Back2BackName$ = "FAQ": Exit Function
    Back2BackName$ = a$
End Function

Function Wiki$ (PageName$) 'Read cached wiki page (download, if not yet cached)
    Help_PageLoaded$ = PageName$

    'Escape all invalid and other critical chars in filenames
    PageName2$ = ""
    For i = 1 To Len(PageName$)
        c = Asc(PageName$, i)
        Select Case c
            Case 32 '                                    '(space)
                PageName2$ = PageName2$ + "_"
            Case 34, 38, 42, 47, 58, 60, 62, 63, 92, 124 '("&*/:<>?\|)
                PageName2$ = PageName2$ + "%" + Hex$(c)
            Case Else
                PageName2$ = PageName2$ + Chr$(c)
        End Select
    Next
    PageName3$ = wikiSafeName$(PageName2$) 'case independent name

    'Is this page in the cache?
    If Help_IgnoreCache = 0 Then
        If _FileExists(Cache_Folder$ + PageName3$ + ".txt") Then
            fh = FreeFile
            Open Cache_Folder$ + PageName3$ + ".txt" For Binary As #fh
            a$ = Space$(LOF(fh))
            Get #fh, , a$
            Close #fh
            chr13 = InStr(a$, Chr$(13))
            removedchr13 = 0
            Do While chr13 > 0
                removedchr13 = -1
                a$ = Left$(a$, chr13 - 1) + Mid$(a$, chr13 + 1)
                chr13 = InStr(a$, Chr$(13))
            Loop
            If removedchr13 Then
                fh = FreeFile
                Open Cache_Folder$ + PageName3$ + ".txt" For Output As #fh: Close #fh
                Open Cache_Folder$ + PageName3$ + ".txt" For Binary As #fh
                Put #fh, 1, a$
                Close #fh
            End If
            Wiki$ = a$
            Exit Function
        End If
    End If

    'Check for curl
    If _ShellHide("curl --version") <> 0 Then
        Print "Can not find cURL.  Terminating program."
        _Delay 3
        System
    End If

    'Download message (Status Bar)
    If Help_Recaching = 0 Then
        a$ = "Downloading '" + PageName$ + "' page..."
        If Len(a$) > 60 Then a$ = Left$(a$, 57) + String$(3, 250)
        If Len(a$) < 60 Then a$ = a$ + Space$(60 - Len(a$))
        Color 0, 3
        Print a$
    End If


    'Url query and output arguments for curl
    url$ = Chr$(34) + "https://www.qb64phoenix.com/qb64wiki/index.php?title=" + PageName2$ + "&action=edit" + Chr$(34)
    outputFile$ = Cache_Folder$ + PageName3$ + ".txt"
    'Wikitext delimiters
    s1$ = "name=" + Chr$(34) + "wpTextbox1" + Chr$(34) + ">"
    s2$ = "</textarea>"

    'Download page using curl
    Shell _Hide "curl -o " + Chr$(34) + outputFile$ + Chr$(34) + " " + url$
    fh = FreeFile
    Open outputFile$ For Binary As #fh 'get new content
    a$ = Space$(LOF(fh))
    Get #fh, 1, a$
    Close #fh



    'Find wikitext in the downloaded page
    s1 = InStr(a$, s1$)
    If s1 > 0 Then a$ = Mid$(a$, s1 + Len(s1$)): s2 = InStr(a$, s2$): Else s2 = 0
    If s2 > 0 Then a$ = Left$(a$, s2 - 1)
    If s1 > 0 And s2 > 0 And a$ <> "" Then
        'If wikitext was found, then substitute stuff & save it
        '--- first HTML specific entities
        While InStr(a$, "&amp;") > 0 '         '&amp; must be first and looped until all
            a$ = StrReplace$(a$, "&amp;", "&") 'multi-escapes are resolved (eg. &amp;lt; &amp;amp;lt; etc.)
        Wend
        a$ = StrReplace$(a$, "&lt;", "<")
        a$ = StrReplace$(a$, "&gt;", ">")
        a$ = StrReplace$(a$, "&quot;", Chr$(34))
        '--- then other entities
        a$ = StrReplace$(a$, "&verbar;", "|")
        a$ = StrReplace$(a$, "&pi;", Chr$(227))
        a$ = StrReplace$(a$, "&theta;", Chr$(233))
        a$ = StrReplace$(a$, "&sup1;", Chr$(252))
        a$ = StrReplace$(a$, "&sup2;", Chr$(253))
        a$ = StrReplace$(a$, "&nbsp;", Chr$(255))
        '--- useless styles in blocks
        a$ = StrReplace$(a$, "Start}}'' ''", "Start}}")
        a$ = StrReplace$(a$, "Start}} '' ''", "Start}}")
        a$ = StrReplace$(a$, "Start}}" + Chr$(10) + "'' ''", "Start}}")
        a$ = StrReplace$(a$, "'' ''" + Chr$(10) + "{{", Chr$(10) + "{{")
        a$ = StrReplace$(a$, "'' '' " + Chr$(10) + "{{", Chr$(10) + "{{")
        a$ = StrReplace$(a$, "'' ''" + MKI$(&H0A0A) + "{{", Chr$(10) + "{{")
        '--- wiki redirects
        a$ = StrReplace$(a$, "#REDIRECT", "See page")
        '--- put a download date/time entry
        a$ = "{{QBDLDATE:" + Date$ + "}}" + Chr$(10) + "{{QBDLTIME:" + Time$ + "}}" + Chr$(10) + a$
        '--- now save it
        fh = FreeFile
        Open outputFile$ For Output As #fh
        Print #fh, a$
        Close #fh
    Else
        'Delete page, if empty or corrupted (force re-download on next access)
        Kill outputFile$
        a$ = CHR$(10) + "{{PageInternalError}}" + CHR$(10) +_
             "* Either the requested page is not yet available in the Wiki," + CHR$(10) +_
             "* or the download from Wiki failed and corrupted the page data." + CHR$(10) +_
             "** You may try ''Update Current Page'' from the ''Help'' menu." + CHR$(10)
    End If



    Wiki$ = a$
End Function

Sub Help_AddTxt (t$, col, link) 'Add help text, handle word wrap
    If t$ = Chr$(13) Then Help_NewLine: Exit Sub

    For i = 1 To Len(t$)
        c = Asc(t$, i)

        If Help_LockParse = 0 And Help_LockWrap = 0 Then

            If c = 32 Then
                If Help_Pos = Help_ww Then Help_NewLine: _Continue

                Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = 32
                Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = col + Help_BG_Col * 16
                Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = link And 255
                Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = link \ 256

                Help_Wrap_Pos = Help_Txt_Len 'pos to backtrack to when wrapping content
                Help_Pos = Help_Pos + 1: _Continue
            End If

            If Help_Pos > Help_ww Then
                If Help_Wrap_Pos Then 'attempt to wrap
                    'backtrack, insert new line, continue

                    b$ = Mid$(Help_Txt$, Help_Wrap_Pos + 1, Help_Txt_Len - Help_Wrap_Pos)

                    Help_Txt_Len = Help_Wrap_Pos

                    Help_NewLine

                    Mid$(Help_Txt$, Help_Txt_Len + 1, Len(b$)) = b$: Help_Txt_Len = Help_Txt_Len + Len(b$)

                    Help_Pos = Help_Pos + Len(b$) \ 4
                End If
            End If

        End If

        Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = c
        Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = col + Help_BG_Col * 16
        Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = link And 255
        Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = link \ 256

        Help_Pos = Help_Pos + 1
    Next
End Sub

Sub Help_NewLine 'Start a new help line, apply indention (if any)
    If Help_Pos > help_w Then help_w = Help_Pos

    Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = 13
    Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = Help_BG_Col * 16
    Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = 0
    Help_Txt_Len = Help_Txt_Len + 1: Asc(Help_Txt$, Help_Txt_Len) = 0

    help_h = help_h + 1
    Help_Line$ = Help_Line$ + MKL$(Help_Txt_Len + 1)
    Help_Wrap_Pos = 0

    If Help_Underline Then
        w = Help_Pos
        Help_Pos = 1
        If Help_Underline = Help_Col_Section Then
            Help_AddTxt String$(w - 1, 205), Help_Underline, 0
        Else
            Help_AddTxt String$(w - 1, 196), Help_Underline, 0
        End If
        Help_Underline = 0 'keep before Help_NewLine (recursion)
        Help_NewLine
    End If
    Help_Pos = 1

    If Help_Center > 0 Then 'center overrides regular indent
        Help_NewLineIndent = 0
        Help_AddTxt Space$(Asc(Help_CIndent$, 1)), Help_Col, 0
        Help_CIndent$ = Mid$(Help_CIndent$, 2)
    ElseIf Help_NewLineIndent > 0 Then
        Help_AddTxt Space$(Help_NewLineIndent), Help_Col, 0
    End If
End Sub

Sub Help_CheckFinishLine 'Make sure the current help line is finished
    If Help_Txt_Len >= 4 Then
        If Asc(Help_Txt$, Help_Txt_Len - 3) <> 13 Then Help_NewLine
    End If
End Sub

Sub Help_CheckBlankLine 'Make sure the last help line is a blank line (implies finish current)
    If Help_Txt_Len >= 8 Then
        If Asc(Help_Txt$, Help_Txt_Len - 3) <> 13 Then Help_NewLine
        If Asc(Help_Txt$, Help_Txt_Len - 7) <> 13 Then Help_NewLine
    End If
End Sub

Sub Help_CheckRemoveBlankLine 'If the last help line is blank, then remove it
    If Help_Txt_Len >= 8 Then
        If Asc(Help_Txt$, Help_Txt_Len - 3) = 13 Then
            Help_Txt_Len = Help_Txt_Len - 4
            help_h = help_h - 1
            Help_Line$ = Left$(Help_Line$, Len(Help_Line$) - 4)
        End If
        For i = Help_Txt_Len - 3 To 1 Step -4
            If Asc(Help_Txt$, i) <> 32 Then
                Help_Txt_Len = i + 3: Exit For
            End If
        Next
        If Asc(Help_Txt$, Help_Txt_Len - 3) <> 13 Then Help_NewLine
    End If
End Sub

Function Help_Col 'Helps to calculate the default color
    col = Help_Col_Normal
    If Help_Italic Then col = Help_Col_Italic
    If Help_Bold Then col = Help_Col_Bold 'Note: Bold overrides italic
    Help_Col = col
End Function

Sub WikiParse (a$) 'Wiki page interpret

    'Clear info
    help_h = 0: help_w = 0: Help_Line$ = "": Help_Link$ = "": Help_LinkN = 0
    Help_Txt$ = Space$(1000000)
    Help_Txt_Len = 0

    Help_Pos = 1: Help_Wrap_Pos = 0
    Help_Line$ = MKL$(1)
    'Word wrap locks (lock wrapping only, but continue parsing regularly)
    Help_LockWrap = 0
    'Parser locks (neg: soft lock, zero: unlocked, pos: hard lock)
    'hard:  2 = inside code blocks,  1 = inside output blocks
    'soft: -1 = inside text blocks, -2 = inside fixed blocks
    '=> all parser locks also imply a wrapping lock
    '=> hard locks almost every parsing except utf-8 substitution and line breaks
    '=> soft allows all elements not disrupting the current block, hence only
    '   paragraph creating things are locked (eg. headings, lists, rulers etc.),
    '   but text styles, links and template processing is still possible
    Help_LockParse = 0
    Help_Bold = 0: Help_Italic = 0
    Help_Underline = 0
    Help_BG_Col = 0
    Help_Center = 0: Help_CIndent$ = ""
    Help_DList = 0

    link = 0: elink = 0: cb = 0: nl = 1

    col = Help_Col

    'Syntax Notes:
    '=============
    'everywhere in text
    '------------------
    ' ''' = bold text style
    ' ''  = italic text style
    ' [url text]    = external link to url with text to appear (url ends at 1st found space)
    ' [[page]]      = link to another wikipage
    ' [[page|text]] = link to another wikipage with alternative text to appear
    ' {{templatename|param|param|param}} or simply {{templatename}} = predefined styles
    '---------------------
    'at start of line only
    '---------------------
    ' *  = dot list point
    ' ** = sub (ie. further indented) dot list point
    ' ;def:desc = full definition/description list
    ' :desc     = description only, but indented as in a full def/desc list
    ' ;* def:desc = combi list, list dot always belongs to description
    ' :* desc     = combi, description only

    'First find and write the page title and last update
    d$ = "Page not yet updated, expect visual glitches.": i = InStr(a$, "{{QBDLDATE:")
    If i > 0 Then
        d$ = "Last updated: " + Mid$(a$, i + 11, InStr(i + 11, a$, "}}") - i - 11)
        i = InStr(a$, "{{QBDLTIME:")
        If i > 0 Then d$ = d$ + ", at " + Mid$(a$, i + 11, InStr(i + 11, a$, "}}") - i - 11)
    ElseIf InStr(a$, "{{PageInternalError}}") > 0 Then
        d$ = "Page not found."
    End If
    t$ = Help_PageLoaded$: i = InStr(a$, "{{DISPLAYTITLE:")
    If i > 0 Then t$ = Mid$(a$, i + 15, InStr(i + 15, a$, "}}") - i - 15)
    If Left$(t$, 4) = "agp@" Then
        d$ = "Auto-generated temporary page."
        t$ = Mid$(t$, 5)
    End If
    i = Len(d$): ii = Len(t$)
    Help_AddTxt "   Ú" + String$(ii + 2, "Ä") + "¿", 14, 0: Help_NewLine
    Help_AddTxt "   ³ ", 14, 0: Help_AddTxt t$, 12, 0: Help_AddTxt " ³", 14, 0
    Help_AddTxt Space$(Help_ww - i - 2 - Help_Pos) + Chr$(4), 14, 0
    If Left$(d$, 4) = "Page" Then i = 8: Else i = 7
    Help_AddTxt " " + d$, i, 0: Help_NewLine
    Help_AddTxt "ÄÄÄÁ" + String$(ii + 2, "Ä") + "Á" + String$(Help_ww - ii - 7, "Ä"), 14, 0: Help_NewLine

    'Init prefetch array
    prefetch = 20
    Dim c$(prefetch)
    For ii = 1 To prefetch
        c$(ii) = Space$(ii)
    Next

    'BEGIN_PARSE_LOOP
    n = Len(a$)
    i = 1
    Do While i <= n

        'Get next char and fill prefetch array
        c = Asc(a$, i): c$ = Chr$(c)
        For i1 = 1 To prefetch
            ii = i
            For i2 = 1 To i1
                If ii <= n Then
                    Asc(c$(i1), i2) = Asc(a$, ii)
                Else
                    Asc(c$(i1), i2) = 32
                End If
                ii = ii + 1
            Next
        Next

        'Wiki specific code handling (no restrictions)
        s$ = "__NOEDITSECTION__" + Chr$(10): If c$(Len(s$)) = s$ Then i = i + Len(s$) - 1: GoTo charDone
        s$ = "__NOEDITSECTION__": If c$(Len(s$)) = s$ Then i = i + Len(s$) - 1: GoTo charDone
        s$ = "__NOTOC__" + Chr$(10): If c$(Len(s$)) = s$ Then i = i + Len(s$) - 1: GoTo charDone
        s$ = "__NOTOC__": If c$(Len(s$)) = s$ Then i = i + Len(s$) - 1: GoTo charDone
        s$ = "<nowiki>": If c$(Len(s$)) = s$ Then i = i + Len(s$) - 1: GoTo charDone
        s$ = "</nowiki>": If c$(Len(s$)) = s$ Then i = i + Len(s$) - 1: GoTo charDone

        'Direct HTML code is not handled in Code/Output blocks (hard lock), as all text
        'could be part of the code example itself (just imagine a HTML parser/writer demo)
        If Help_LockParse <= 0 Then
            s$ = "<sup>": If c$(Len(s$)) = s$ Then Help_AddTxt "^", col, 0: i = i + Len(s$) - 1: GoTo charDone
            s$ = "</sup>": If c$(Len(s$)) = s$ Then i = i + Len(s$) - 1: GoTo charDone

            s$ = "<center>" 'centered section
            If c$(Len(s$)) = s$ Then
                i = i + Len(s$) - 1
                wla$ = wikiLookAhead$(a$, i + 1, "</center>")
                If InStr(wla$, "#toc") > 0 Or InStr(wla$, "to Top") > 0 Then
                    i = i + Len(wla$) + 9 'ignore TOC links
                Else
                    Help_Center = 1: Help_CIndent$ = wikiBuildCIndent$(wla$)
                    Help_AddTxt Space$(Asc(Help_CIndent$, 1)), col, 0 'center content
                    Help_CIndent$ = Mid$(Help_CIndent$, 2)
                End If
                GoTo charDone
            End If
            s$ = "</center>"
            If c$(Len(s$)) = s$ Then
                i = i + Len(s$) - 1
                Help_Center = 0
                Help_NewLine
                GoTo charDone
            End If
            s$ = "<p style=" 'custom paragraph (maybe centered)
            If c$(Len(s$)) = s$ Then
                i = i + Len(s$) - 1
                For ii = i To Len(a$) - 1
                    If Mid$(a$, ii, 1) = ">" Then
                        wla$ = wikiLookAhead$(a$, ii + 1, "</p>")
                        If InStr(wla$, "#toc") > 0 Or InStr(wla$, "to Top") > 0 Then
                            i = ii + Len(wla$) + 4 'ignore TOC links
                        ElseIf InStr(Mid$(a$, i, ii - i), "center") > 0 Then
                            Help_Center = 1: Help_CIndent$ = wikiBuildCIndent$(wla$)
                            Help_AddTxt Space$(Asc(Help_CIndent$, 1)), col, 0 'center (if in style)
                            Help_CIndent$ = Mid$(Help_CIndent$, 2)
                            i = ii
                        End If
                        Exit For
                    End If
                Next
                GoTo charDone
            End If
            s$ = "</p>"
            If c$(Len(s$)) = s$ Then
                i = i + Len(s$) - 1
                Help_Center = 0
                Help_NewLine
                GoTo charDone
            End If
            s$ = "<span" 'custom inline attributes ignored
            If c$(Len(s$)) = s$ Then
                i = i + Len(s$) - 1
                For ii = i To Len(a$) - 1
                    If Mid$(a$, ii, 1) = ">" Then i = ii: Exit For
                Next
                GoTo charDone
            End If
            s$ = "</span>"
            If c$(Len(s$)) = s$ Then
                i = i + Len(s$) - 1
                GoTo charDone
            End If

            s$ = "<div" 'ignore divisions (TOC and letter links)
            If c$(Len(s$)) = s$ Then
                i = i + Len(s$) - 1
                For ii = i To Len(a$) - 1
                    If Mid$(a$, ii, 6) = "</div>" Then i = ii + 5: Exit For
                Next
                GoTo charDone
            End If
            s$ = "<!--" 'ignore HTML comments
            If c$(Len(s$)) = s$ Then
                i = i + Len(s$) - 1
                For ii = i To Len(a$) - 1
                    If Mid$(a$, ii, 3) = "-->" Then i = ii + 2: Exit For
                Next
                GoTo charDone
            End If
        End If

        'Wiki text styles are not handled in Code/Output blocks (hard lock),
        'as they could be part of the code example itself
        If Help_LockParse <= 0 Then
            'Bold style
            If c$(3) = "'''" Then
                i = i + 2
                If Help_Bold = 0 Then Help_Bold = 1 Else Help_Bold = 0
                col = Help_Col
                GoTo charDone
            End If
            'Italic style
            If c$(2) = "''" Then
                i = i + 1
                If Help_Italic = 0 Then Help_Italic = 1 Else Help_Italic = 0
                col = Help_Col
                GoTo charDone
            End If
        End If

        'Wiki links ([ext], [[int]]) are not handled in Code/Output blocks (hard lock),
        'as all text could be part of the code example itself
        If Help_LockParse <= 0 Then
            'External links
            If c$(5) = "[http" And elink = 0 Then
                elink = 1
                elink$ = ""
                GoTo charDone
            End If
            If elink = 1 Then
                If c$ = "]" Then
                    elink = 0
                    etext$ = elink$
                    i2 = InStr(elink$, " ")
                    If i2 > 0 Then
                        etext$ = Right$(elink$, Len(elink$) - i2)
                        elink$ = Left$(elink$, i2 - 1)
                    End If

                    Help_LinkN = Help_LinkN + 1
                    Help_Link$ = Help_Link$ + "EXTL:" + elink$ + Help_Link_Sep$

                    If Help_LockParse = 0 Then
                        Help_AddTxt etext$, Help_Col_Link, Help_LinkN
                    Else
                        Help_AddTxt etext$, Help_Col_Bold, Help_LinkN
                    End If
                    GoTo charDone
                End If
                elink$ = elink$ + c$
                GoTo charDone
            End If
            'Internal links
            If c$(2) = "[[" And link = 0 Then
                i = i + 1
                link = 1
                link$ = ""
                GoTo charDone
            End If
        End If
        'However, the internal link logic must run always, as it also handles
        'the template {{Cb|, {{Cl| and {{KW| links used in code blocks
        If link = 1 Then
            If c$(2) = "]]" Or c$(2) = "}}" Then
                i = i + 1
                link = 0
                text$ = link$
                i2 = InStr(link$, "|")
                If i2 > 0 Then
                    text$ = Right$(link$, Len(link$) - i2)
                    link$ = Left$(link$, i2 - 1)
                End If

                If InStr(link$, "#") Then 'local page links not supported
                    Help_AddTxt text$, 8, 0
                    GoTo charDone
                ElseIf Left$(link$, 9) = "Category:" Then 'ignore category links
                    Help_CheckRemoveBlankLine
                    GoTo charDone
                End If

                Help_LinkN = Help_LinkN + 1
                Help_Link$ = Help_Link$ + "PAGE:" + link$ + Help_Link_Sep$

                If Help_LockParse = 0 Then
                    Help_AddTxt text$, Help_Col_Link, Help_LinkN
                Else
                    Help_AddTxt text$, Help_Col_Bold, Help_LinkN
                End If
                GoTo charDone
            End If
            link$ = link$ + c$
            GoTo charDone
        End If

        'Wiki tables ({|...|}) are not handled in Code/Output blocks (hard lock),
        'as everything could be part of the code example itself
        If Help_LockParse <= 0 Then
            'Tables (ignored, give info, if not in blocks)
            If c$(2) = "{|" Then
                wla$ = wikiLookAhead$(a$, i + 2, "|}"): iii = 0
                For ii = 1 To Len(wla$)
                    If Mid$(wla$, ii, 1) = "|" And Mid$(wla$, ii, 2) <> "|-" Then iii = iii + 1
                Next
                i = i + 1 + Len(wla$) + 2
                If iii > 1 Or InStr(wla$, "__TOC__") = 0 Then 'ignore TOC only tables
                    If Help_LockParse = 0 Then
                        Help_AddTxt Space$((Help_ww - 52) \ 2) + "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»", 8, 0: Help_NewLine
                        Help_AddTxt Space$((Help_ww - 52) \ 2) + "º ", 8, 0: Help_AddTxt "The original help page has a table here, please ", 15, 0: Help_AddTxt " º", 8, 0: Help_NewLine
                        Help_AddTxt Space$((Help_ww - 52) \ 2) + "º ", 8, 0: Help_AddTxt "use the ", 15, 0: ii = Help_BG_Col: Help_BG_Col = 3: Help_AddTxt " View on Wiki ", 15, 0: Help_BG_Col = ii: Help_AddTxt " button in the upper right", 15, 0: Help_AddTxt " º", 8, 0: Help_NewLine
                        Help_AddTxt Space$((Help_ww - 52) \ 2) + "º ", 8, 0: Help_AddTxt "corner to load the page into your browser.      ", 15, 0: Help_AddTxt " º", 8, 0: Help_NewLine
                        Help_AddTxt Space$((Help_ww - 52) \ 2) + "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ", 8, 0
                    End If
                End If
                GoTo charDone
            End If
        End If

        'Wiki templates are handled always, as these are the basic building blocks of all
        'the wiki pages, but look for special conditions inside (Help_LockParse checks)
        If c$(5) = "{{Cb|" Or c$(5) = "{{Cl|" Or c$(5) = "{{KW|" Then 'just nice wrapped links
            i = i + 4 '                                               'KW is deprecated (but kept for existing pages)
            link = 1
            link$ = ""
            GoTo charDone
        End If
        If c$(2) = "{{" Then 'any other templates
            i = i + 1
            cb = 1
            cb$ = ""
            GoTo charDone
        End If
        If cb > 0 Then
            If c$ = "|" Or c$(2) = "}}" Then
                If c$ = "|" And cb = 2 Then
                    wla$ = wikiLookAhead$(a$, i + 1, "}}")
                    cb = 0: i = i + Len(wla$) + 2 'after 1st, ignore all further template parameters
                ElseIf c$(2) = "}}" Then
                    If LCase$(Left$(cb$, 5)) = "small" Then
                        If Asc(cb$, 6) = 196 Then
                            Help_AddTxt " " + String$(Help_ww - Help_Pos, 196), 15, 0
                            Help_BG_Col = 0: col = Help_Col
                        Else
                            Help_Center = 0
                        End If
                        Help_NewLine: cb$ = "" 'avoid reactivation below
                    End If
                    cb = 0: i = i + 1
                End If
                If c$ = "|" And cb = 1 Then cb = 2

                If Help_LockParse = 0 Then 'no section headings in blocks
                    cbo$ = ""
                    'Standard section headings (section color, h3 w/o underline, h2 with underline)
                    'Recommended order of main page sections (h2) with it's considered sub-sections (h3)
                    If cb$ = "PageSyntax" Then cbo$ = "Syntax:"
                    If cb$ = "PageLegacySupport" Then cbo$ = "Legacy support" 'sub-sect
                    If cb$ = "PageParameters" Or cb$ = "Parameters" Then cbo$ = "Parameters:" 'w/o Page suffix is deprecated (but kept for existing pages)
                    If cb$ = "PageDescription" Then cbo$ = "Description:"
                    If cb$ = "PageQBasic" Then cbo$ = "QBasic/QuickBASIC" 'sub-sect
                    If cb$ = "PageNotes" Then cbo$ = "Notes" 'sub-sect
                    If cb$ = "PageErrors" Then cbo$ = "Errors" 'sub-sect
                    If cb$ = "PageUseWith" Then cbo$ = "Use with" 'sub-sect
                    If cb$ = "PageAvailability" Then cbo$ = "Availability:"
                    If cb$ = "PageExamples" Then cbo$ = "Examples:"
                    If cb$ = "PageSeeAlso" Then cbo$ = "See also:"
                    'Independent main page end sections (centered, no title)
                    If cb$ = "PageCopyright" Then cbo$ = "Copyright"
                    If cb$ = "PageNavigation" Then cbo$ = "" 'ignored for built-in help
                    'Internally used templates (not available in Wiki)
                    If cb$ = "PageInternalError" Then cbo$ = "Sorry, an error occurred:"
                    '----------
                    If cbo$ <> "" Then
                        If Right$(cbo$, 1) = ":" Then Help_Underline = Help_Col_Section
                        Help_AddTxt cbo$, Help_Col_Section, 0: Help_NewLine
                        If cbo$ = "Copyright" Then '_gl commands only
                            Help_NewLine: Help_AddTxt "1991-2006 Silicon Graphics, Inc.", 7, 0: Help_NewLine
                            Help_AddTxt "This document is licensed under the SGI Free Software B License.", 7, 0: Help_NewLine
                            Help_AddTxt "https://spdx.org/licenses/SGI-B-2.0.html https://spdx.org/licenses/SGI-B-2.0.html", 15, 0: Help_NewLine
                        End If
                    End If
                End If

                'Code Block
                If cb$ = "InlineCode" And Help_LockParse = 0 Then
                    Help_BG_Col = 1: Help_LockParse = 2
                End If
                If cb$ = "InlineCodeEnd" And Help_LockParse <> 0 Then
                    Help_BG_Col = 0: Help_LockParse = 0
                    Help_Bold = 0: Help_Italic = 0: col = Help_Col
                End If
                If cb$ = "CodeStart" And Help_LockParse = 0 Then
                    Help_CheckBlankLine
                    Help_BG_Col = 1: Help_LockParse = 2
                    Help_AddTxt String$(Help_ww - 15, 196) + " Code Block " + String$(3, 196), 15, 0: Help_NewLine
                    If c$(3) = "}}" + Chr$(10) Then i = i + 1
                End If
                If cb$ = "CodeEnd" And Help_LockParse <> 0 Then
                    Help_CheckFinishLine: Help_CheckRemoveBlankLine
                    Help_AddTxt String$(Help_ww, 196), 15, 0: Help_NewLine
                    Help_BG_Col = 0: Help_LockParse = 0
                    Help_Bold = 0: Help_Italic = 0: col = Help_Col
                End If
                'Output Block
                If Left$(cb$, 11) = "OutputStart" And Help_LockParse = 0 Then 'does also match new OutputStartBGn templates
                    Help_CheckBlankLine
                    Help_BG_Col = 2: Help_LockParse = 1
                    Help_AddTxt String$(Help_ww - 17, 196) + " Output Block " + String$(3, 196), 15, 0: Help_NewLine
                    If c$(3) = "}}" + Chr$(10) Then i = i + 1
                End If
                If cb$ = "OutputEnd" And Help_LockParse <> 0 Then
                    Help_CheckFinishLine: Help_CheckRemoveBlankLine
                    Help_AddTxt String$((Help_ww - 54) \ 2, 196), 15, 0
                    Help_AddTxt " This block does not reflect the actual output colors ", 15, 0
                    Help_AddTxt String$(Help_ww - Help_Pos + 1, 196), 15, 0: Help_NewLine
                    Help_BG_Col = 0: Help_LockParse = 0
                    Help_Bold = 0: Help_Italic = 0: col = Help_Col
                End If
                'Text Block
                If cb$ = "TextStart" And Help_LockParse = 0 Then
                    Help_CheckBlankLine
                    Help_BG_Col = 6: Help_LockParse = -1
                    Help_AddTxt String$(Help_ww - 15, 196) + " Text Block " + String$(3, 196), 15, 0: Help_NewLine
                    If c$(3) = "}}" + Chr$(10) Then i = i + 1
                End If
                If cb$ = "TextEnd" And Help_LockParse <> 0 Then
                    Help_CheckFinishLine: Help_CheckRemoveBlankLine
                    Help_AddTxt String$(Help_ww, 196), 15, 0: Help_NewLine
                    Help_BG_Col = 0: Help_LockParse = 0
                    Help_Bold = 0: Help_Italic = 0: col = Help_Col
                End If
                'Fixed Block
                If (cb$ = "FixedStart" Or cb$ = "WhiteStart") And Help_LockParse = 0 Then 'White is deprecated (but kept for existing pages)
                    Help_CheckBlankLine
                    Help_BG_Col = 6: Help_LockParse = -2
                    Help_AddTxt String$(Help_ww - 16, 196) + " Fixed Block " + String$(3, 196), 15, 0: Help_NewLine
                    If c$(3) = "}}" + Chr$(10) Then i = i + 1
                End If
                If (cb$ = "FixedEnd" Or cb$ = "WhiteEnd") And Help_LockParse <> 0 Then 'White is deprecated (but kept for existing pages)
                    Help_CheckFinishLine: Help_CheckRemoveBlankLine
                    Help_AddTxt String$(Help_ww, 196), 15, 0: Help_NewLine
                    Help_BG_Col = 0: Help_LockParse = 0
                    Help_Bold = 0: Help_Italic = 0: col = Help_Col
                End If

                'Template wrapped table
                If Right$(cb$, 5) = "Table" And Help_LockParse = 0 Then 'no table info in blocks
                    Help_AddTxt Space$((Help_ww - 52) \ 2) + "ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»", 8, 0: Help_NewLine
                    Help_AddTxt Space$((Help_ww - 52) \ 2) + "º ", 8, 0: Help_AddTxt "The original help page has a table here, please ", 15, 0: Help_AddTxt " º", 8, 0: Help_NewLine
                    Help_AddTxt Space$((Help_ww - 52) \ 2) + "º ", 8, 0: Help_AddTxt "use the ", 15, 0: ii = Help_BG_Col: Help_BG_Col = 3: Help_AddTxt " View on Wiki ", 15, 0: Help_BG_Col = ii: Help_AddTxt " button in the upper right", 15, 0: Help_AddTxt " º", 8, 0: Help_NewLine
                    Help_AddTxt Space$((Help_ww - 52) \ 2) + "º ", 8, 0: Help_AddTxt "corner to load the page into your browser.      ", 15, 0: Help_AddTxt " º", 8, 0: Help_NewLine
                    Help_AddTxt Space$((Help_ww - 52) \ 2) + "ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ", 8, 0
                End If

                'Small template text will be centered (maybe as block note)
                If LCase$(cb$) = "small" And Help_LockParse <= 0 Then 'keep as is in Code/Output blocks
                    wla$ = wikiLookAhead$(a$, i + 1, "}}")
                    Help_CIndent$ = wikiBuildCIndent$(wla$): iii = 0
                    If i > 31 And Asc(Help_CIndent$, 1) >= Help_ww / 4 Then
                        If InStr(Mid$(a$, i - 30, 30), "{{CodeEnd}}") > 0 Then iii = -1
                        If InStr(Mid$(a$, i - 30, 30), "{{TextEnd}}") > 0 Then iii = -6
                        If InStr(Mid$(a$, i - 31, 31), "{{FixedEnd}}") > 0 Then iii = -6
                        If InStr(Mid$(a$, i - 31, 31), "{{WhiteEnd}}") > 0 Then iii = -6
                    End If
                    If iii <> 0 Then
                        For ii = Help_Txt_Len - 3 To 1 Step -4
                            If Asc(Help_Txt$, ii) = 13 And iii < 0 Then
                                help_h = help_h - 1: Help_Line$ = Left$(Help_Line$, Len(Help_Line$) - 4)
                            ElseIf Asc(Help_Txt$, ii) = 196 And iii < 0 Then
                                iii = -iii
                            ElseIf Asc(Help_Txt$, ii) = 13 And iii > 0 Then
                                Help_Txt_Len = ii + 3: Exit For
                            End If
                        Next
                        Help_BG_Col = iii: cb$ = cb$ + Chr$(196) 'special signal byte
                        Help_AddTxt String$(Asc(Help_CIndent$, 1) - 1, 196) + " ", 15, 0
                        col = 15 'further text color until closing
                    Else
                        Help_Center = 1: cb$ = cb$ + Chr$(0) 'no special signal
                        Help_AddTxt Space$(Asc(Help_CIndent$, 1)), col, 0 'center content
                    End If
                    Help_CIndent$ = Mid$(Help_CIndent$, 2)
                End If

                GoTo charDone
            End If

            If cb = 1 Then cb$ = cb$ + c$ 'reading macro name
            If cb = 2 Then Help_AddTxt Chr$(c), col, 0 'copy macro'd text
            GoTo charDone
        End If

        'Wiki headings (==...==}) are not handled in blocks (soft- and hard lock), as it would
        'disrupt the block, also in code blocks it could be part of the code example itself
        If Help_LockParse = 0 Then
            'Custom section headings (current color, h3 w/o underline, h2 with underline)
            ii = 0
            If c$(5) = " === " Then ii = 4
            If c$(4) = "=== " Then ii = 3
            If c$(4) = " ===" Then ii = 3
            If c$(3) = "===" Then ii = 2
            If ii > 0 Then i = i + ii: GoTo charDone
            ii = 0
            If c$(4) = " == " Then ii = 3
            If c$(3) = "== " Then ii = 2
            If c$(3) = " ==" Then ii = 2
            If c$(2) = "==" Then ii = 1
            If ii > 0 Then i = i + ii: Help_Underline = col: GoTo charDone
        End If

        'Wiki/HTML rulers (----, <hr>) are not handled in blocks (soft- and hard lock), as it would
        'disrupt the block, also in code blocks it could be part of the code example itself
        If Help_LockParse = 0 Then
            'Rulers
            If c$(4) = "----" And nl = 1 Then
                i = i + 3
                Help_AddTxt String$(Help_ww, 196), 8, 0
                GoTo charDone
            End If
            If c$(4) = "<hr>" Or c$(6) = "<hr />" Then
                If c$(4) = "<hr>" Then i = i + 3
                If c$(6) = "<hr />" Then i = i + 5
                Help_CheckFinishLine
                Help_AddTxt String$(Help_ww, 196), 8, 0
                GoTo charDone
            End If
        End If

        'Wiki definition lists (;...:...) are not handled in blocks (soft- and hard lock), as it would
        'disrupt the block, also in code blocks it could be part of the code example itself
        If Help_LockParse = 0 Then
            'Definition lists
            If c$ = ";" And nl = 1 Then 'definition (new line only)
                If c$(2) = "; " Then i = i + 1
                Help_Bold = 1: col = Help_Col: Help_DList = 1
                If c$(3) = ";* " Then i = i + 2: Help_DList = 3 'list dot belongs to description
                If c$(2) = ";*" Then i = i + 1: Help_DList = 2 'list dot belongs to description
                GoTo charDone
            End If
            If c$ = ":" And Help_DList > 0 Then 'description (same or new line)
                If c$(2) = ": " Then i = i + 1
                Help_Bold = 0: col = Help_Col
                If nl = 0 Then Help_NewLine
                Help_AddTxt "   ", col, 0
                Help_NewLineIndent = Help_NewLineIndent + 3
                If Help_DList > 1 Then
                    Help_AddTxt Chr$(4) + " ", 14, 0
                    Help_NewLineIndent = Help_NewLineIndent + 2
                End If
                Help_DList = 0
                GoTo charDone
            End If
            If c$ = ":" And nl = 1 Then 'description w/o definition (new line only)
                If c$(2) = ": " Then i = i + 1
                Help_AddTxt "   ", col, 0
                Help_NewLineIndent = Help_NewLineIndent + 3
                GoTo charDoneKnl 'keep nl state for possible <UL> list bullets
            End If
        End If

        'Wiki lists (*, **) are not handled in blocks (soft- and hard lock), as it would
        'disrupt the block, also in code blocks it could be part of the code example itself
        If Help_LockParse = 0 Then
            'Unordered lists
            If nl = 1 Then
                If c$(2) = "**" Then
                    If c$(3) = "** " Then i = i + 2: Else i = i + 1
                    Help_AddTxt "   " + Chr$(4) + " ", 14, 0
                    Help_NewLineIndent = Help_NewLineIndent + 5
                    GoTo charDone
                End If
                If c$ = "*" Then
                    If c$(2) = "* " Then i = i + 1
                    Help_AddTxt Chr$(4) + " ", 14, 0
                    Help_NewLineIndent = Help_NewLineIndent + 2
                    GoTo charDone
                End If
            End If
        End If

        'Unicode handling (no restrictions)
        If ((c And &HE0~%%) = 192) And ((Asc(c$(2), 2) And &HC0~%%) = 128) Then '2-byte UTF-8
            i = i + 1
            For ii = 0 To wpUtfReplCnt
                If wpUtfRepl(ii).utf8 = c$(2) + MKI$(&H2020) Then
                    Help_AddTxt RTrim$(wpUtfRepl(ii).repl), col, 0: Exit For
                End If
            Next
            GoTo charDone
        End If
        If ((c And &HF0~%%) = 224) And ((Asc(c$(2), 2) And &HC0~%%) = 128) And ((Asc(c$(3), 3) And &HC0~%%) = 128) Then '3-byte UTF-8
            i = i + 2
            For ii = 0 To wpUtfReplCnt
                If wpUtfRepl(ii).utf8 = c$(3) + Chr$(0) Then
                    Help_AddTxt RTrim$(wpUtfRepl(ii).repl), col, 0: Exit For
                End If
            Next
            GoTo charDone
        End If
        If ((c And &HF8~%%) = 240) And ((Asc(c$(2), 2) And &HC0~%%) = 128) And ((Asc(c$(3), 3) And &HC0~%%) = 128) And ((Asc(c$(4), 4) And &HC0~%%) = 128) Then '4-byte UTF-8
            i = i + 3
            For ii = 0 To wpUtfReplCnt
                If wpUtfRepl(ii).utf8 = c$(4) Then
                    Help_AddTxt RTrim$(wpUtfRepl(ii).repl), col, 0: Exit For
                End If
            Next
            GoTo charDone
        End If

        'Line break handling (no restrictions)
        If c = 10 Or c$(4) = "<br>" Or c$(6) = "<br />" Then
            If c$(4) = "<br>" Then i = i + 3
            If c$(6) = "<br />" Then i = i + 5
            Help_NewLineIndent = 0

            If Help_LockParse > -2 Then 'everywhere except in fixed blocks
                If Help_Txt_Len >= 8 Then 'allow max. one blank line (ie. collapse multi blanks to just one)
                    If Asc(Help_Txt$, Help_Txt_Len - 3) = 13 And Asc(Help_Txt$, Help_Txt_Len - 7) = 13 Then
                        If Help_Center > 0 Then Help_CIndent$ = Mid$(Help_CIndent$, 2) 'drop respective center indent
                        GoTo skipMultiBlanks
                    End If
                End If
            End If
            Help_AddTxt Chr$(13), col, 0

            skipMultiBlanks:
            If Help_LockParse <> 0 Then 'in all blocks reset styles at EOL
                Help_Bold = 0: Help_Italic = 0: col = Help_Col
            Else
                If c = 10 Then Help_DList = 0: Help_Bold = 0: col = Help_Col 'def list incl. style ends after real new line
            End If
            nl = 1
            GoTo charDoneKnl 'keep just set nl state
        End If
        Help_AddTxt Chr$(c), col, 0

        charDone:
        nl = 0
        charDoneKnl: 'done, but keep nl state
        i = i + 1
    Loop
    'END_PARSE_LOOP

    'Trim Help_Txt$
    Help_Txt$ = Left$(Help_Txt$, Help_Txt_Len) + Chr$(13) 'chr13 stops reads past end of content
End Sub

Function wikiSafeName$ (page$) 'create a unique name for both case sensitive & insensitive systems
    ext$ = Space$(Len(page$))
    For i = 1 To Len(page$)
        c = Asc(page$, i)
        Select Case c
            Case 65 To 90: Asc(ext$, i) = 49 'upper = 1
            Case 97 To 122: Asc(ext$, i) = 48 'lower = 0
            Case Else: Asc(ext$, i) = c 'non-letter = take as is
        End Select
    Next
    wikiSafeName$ = page$ + "_" + ext$
End Function

Function wikiLookAhead$ (a$, i, token$) 'Prefetch further wiki text
    wikiLookAhead$ = "": If i >= Len(a$) Then Exit Function
    j = InStr(i, a$, token$)
    If j = 0 Then
        wikiLookAhead$ = Mid$(a$, i)
    Else
        wikiLookAhead$ = Mid$(a$, i, j - i)
    End If
End Function

Function wikiBuildCIndent$ (a$) 'Pre-calc center indentions
    wikiBuildCIndent$ = "": If a$ = "" Then Exit Function

    org$ = a$: b$ = "" 'eliminate internal links
    For i = 1 To Len(org$)
        If Mid$(org$, i, 2) = "[[" Then
            For ii = i + 2 To Len(org$)
                If Mid$(org$, ii, 1) = "|" Then i = ii + 1: Exit For
                If Mid$(org$, ii, 2) = "]]" Then i = i + 2: Exit For
            Next
        End If
        If Mid$(org$, i, 2) = "]]" Then i = i + 2
        b$ = b$ + Mid$(org$, i, 1)
    Next
    org$ = b$: b$ = "" 'eliminate external links
    For i = 1 To Len(org$)
        If Mid$(org$, i, 5) = "[http" Then
            For ii = i + 5 To Len(org$)
                If Mid$(org$, ii, 1) = " " Then i = ii + 1: Exit For
                If Mid$(org$, ii, 1) = "]" Then i = i + 1: Exit For
            Next
        End If
        If Mid$(org$, i, 1) = "]" Then i = i + 1
        b$ = b$ + Mid$(org$, i, 1)
    Next
    org$ = b$: b$ = "" 'eliminate templates
    For i = 1 To Len(org$)
        If Mid$(org$, i, 2) = "{{" Then
            For ii = i + 2 To Len(org$)
                If Mid$(org$, ii, 1) = "|" Then i = ii + 1: Exit For
                If Mid$(org$, ii, 2) = "}}" Then i = i + 2: Exit For
            Next
        End If
        If Mid$(org$, i, 1) = "|" Then
            For ii = i + 1 To Len(org$)
                If Mid$(org$, ii, 2) = "}}" Then i = ii: Exit For
            Next
        End If
        If Mid$(org$, i, 2) = "}}" Then i = i + 2
        b$ = b$ + Mid$(org$, i, 1)
    Next
    org$ = b$: b$ = "" 'eliminate text styles
    For i = 1 To Len(org$)
        If Mid$(org$, i, 3) = "'''" Then i = i + 3
        If Mid$(org$, i, 2) = "''" Then i = i + 2
        b$ = b$ + Mid$(org$, i, 1)
    Next
    b$ = StrReplace$(b$, "<br>", Chr$(10)) 'convert HTML line breaks
    b$ = StrReplace$(b$, "<br />", Chr$(10)) 'convert XHTML line breaks
    b$ = _Trim$(b$) + Chr$(10) 'safety fallback

    i = 1: st = 1: br = 0: res$ = ""
    While i <= Len(b$)
        ws = InStr(i, b$, " "): lb = InStr(i, b$, Chr$(10))
        If lb > 0 And (ws > lb Or lb - st <= Help_ww) Then Swap ws, lb
        If ws > 0 And ws - st <= Help_ww Then
            br = ws: i = ws + 1
            If Asc(b$, ws) <> 10 And i <= Len(b$) Then _Continue
        End If
        If br = 0 Then
            If lb < ws Then
                br = lb
            Else
                If ws > 0 Then br = ws: Else br = lb
            End If
        End If
        ci = (Help_ww - (br - st)) \ 2: If ci < 0 Then ci = 0
        res$ = res$ + Chr$(ci)
        i = br + 1: st = br + 1: br = 0
    Wend
    wikiBuildCIndent$ = res$
End Function



'===== Strings.bas
Function StrRemove$ (myString$, whatToRemove$) 'noncase sensitive
    Dim a$, b$
    Dim As Long i

    a$ = myString$
    b$ = LCase$(whatToRemove$)
    i = InStr(LCase$(a$), b$)
    Do While i
        a$ = Left$(a$, i - 1) + Right$(a$, Len(a$) - i - Len(b$) + 1)
        i = InStr(LCase$(a$), b$)
    Loop
    StrRemove$ = a$
End Function

Function StrReplace$ (myString$, find$, replaceWith$) 'noncase sensitive
    Dim a$, b$
    Dim As Long basei, i
    If Len(myString$) = 0 Then Exit Function
    a$ = myString$
    b$ = LCase$(find$)
    basei = 1
    i = InStr(basei, LCase$(a$), b$)
    Do While i
        a$ = Left$(a$, i - 1) + replaceWith$ + Right$(a$, Len(a$) - i - Len(b$) + 1)
        basei = i + Len(replaceWith$)
        i = InStr(basei, LCase$(a$), b$)
    Loop
    StrReplace$ = a$
End Function

Function AddQuotes$ (s$)
    AddQuotes$ = Chr$(34) + s$ + Chr$(34)
End Function


"So what is this, and what does it do," you ask?

It takes a look at our wiki and basically does the same thing externally that QB64.bas does internally with the Help menu -- it downloads our wiki in a simplified TEXT format.  

Now, one important caveat before you guys load this and run it:  Save this program in a directory by itself, as it *WILL* download about 870 files from the internet into that directory.  If you run this is your main QB64 folder, and come back later to complain about the mess it made of things, I *WILL* giggle at you and point at the big red warning here.   Remember -- make a directory for this program, save it inside that directory, and OUTPUT EXE TO SOURCE FOLDER.

Or not... And have a very cluttered directory which this download tons of junk off the web to...  The choice is yours.  Wink



I just figured this might be something nice which folks who code without using the IDE might want to use for offline reference from time to time, without having to grab the whole wiki itself.  

Note2: As is, this doesn't download any of the _gl keywords.  We almost never see programs which use _gl commands in them on the forums here, so I figured there wasn't a large demand to have those files downloaded from the wiki.  Why waste bandwidth and tie up the wiki with requests for something which folks don't generally use?  The files which are downloaded here are all the QB45 A-Z commands, and all the QB64 _A-_Z commands.  Other pages can be added later, if wanted/needed.  Smile

Note3: This is still a work in progress, hence the forum I posted it under.  Don't expect it to be 100% glitch free yet. Big Grin

Print this item

  Either 0.7.0 is bad, or I'm doing something wrong
Posted by: hanness - 05-23-2022, 04:05 AM - Forum: General Discussion - Replies (8)

I downloaded 0.7.0 this evening. I deleted all files from my 0.6.0 location and extracted 0.7.0 to this location.

Problem 1: If I go to Help / About it still reports that it is 0.6.0.

Problem 2: My program that compiled fine under 0.6.0 fails to compile on 0.7.0. Something odd about this as well. My program file is named "WordClock 1.0.1.9.bas" but when it compiles it, an EXE called "WordClock.EXE" is created.

If I rename the program to "WordClock.bas" it still compiles to "WordClock.exe", but I still get an error and the EXE file size is significantly larger than it was with 0.6.0 (5.53MB vs 3.54MB).

Error reported is: C++ Compilation failed (Check .\internal\temp\compilelog.txt)

The contents of that log:

internal\c\c_compiler\bin\c++.exe -w -DGLEW_STATIC -DFREEGLUT_STATIC -DDEPENDENCY_NO_SOCKETS -DDEPENDENCY_NO_PRINTER -DDEPENDENCY_ICON -DDEPENDENCY_NO_SCREENIMAGE -DDEPENDENCY_LOADFONT internal\c/qbx.cpp -c -o internal\c/qbx.o
internal\c\c_compiler\bin\windres.exe -i internal\temp\icon.rc -o internal\temp\icon.o
internal\c\c_compiler\bin\objcopy.exe -Ibinary -Oelf64-x86-64 -Bi386:x86-64 internal\temp/data.bin internal\temp/data.o
internal\c\c_compiler\bin\c++.exe -w -DGLEW_STATIC -DFREEGLUT_STATIC -DDEPENDENCY_NO_SOCKETS -DDEPENDENCY_NO_PRINTER -DDEPENDENCY_ICON -DDEPENDENCY_NO_SCREENIMAGE -DDEPENDENCY_LOADFONT internal\c/libqb/libqb_make_0000010100000.o  internal\c/qbx.o internal\temp\icon.o internal\temp/data.o -o C:\Users\hanness\Desktop\WordClock  internal\c/parts/video/font/ttf/src.a internal\c/parts/core/src.a  -static-libgcc -static-libstdc++ -mwindows -lopengl32 -lglu32 -lwinmm -lgdi32
internal\c\c_compiler\bin\objcopy.exe --only-keep-debug C:\Users\hanness\Desktop\WordClock internal\temp/C:\Users\hanness\Desktop\WordClock.sym
internal\c\c_compiler\bin\objcopy.exe: 'C:\Users\hanness\Desktop\WordClock': No such file
mingw32-make: *** [Makefile:346: C:\Users\hanness\Desktop\WordClock] Error 1


My questions:

1) Other than extracting the files, is there something else I should be doing?

2) I am running on what may possibly be the final build of Windows 11 22H2. This is as yet to be determined, but I thought that it was important that I mention this. Is it possible that this could be contributing to the problem?

One last piece of info: As a test, I disabled real time virus scanning to be sure that is not a contributing factor.

Print this item

  Map Movement Example
Posted by: SierraKen - 05-22-2022, 11:09 PM - Forum: Utilities - Replies (4)

A couple years ago I got this code from Felippe and made a cave shooter game with it as well as a gold hunting game. Today I decided to use Felippe's original example and add my own funny little game map to it. You use the arrow keys to move your guy around the map I drew. The map itself moves unless you are near an edge of the map. This is just an example but feel free to use any or all of the code as well as my map but please keep my "SierraKen" name on the bottom right corner of the map. I'm no artist as you can see, but I like it. Attached is the zip file called Map Movement Example.zip with the .bas and the .jpg files inside. Put both in the same directory. Tell me what you think, thanks.



Attached Files
.zip   Map Movement Example.zip (Size: 725.78 KB / Downloads: 61)
Print this item