Intrest.Bas 3/

 BBS: Inland Empire Archive
Date: 02-23-93 (22:26)             Number: 397
From: QUINN TYLER JACKSON          Refer#: NONE
  To: ALL                           Recvd: NO  
Subj: Intrest.Bas           3/       Conf: (2) Quik_Bas
>>> Continued from previous message
DO WHILE Offset > 0
    Limit = MaxRow - Offset
        Switch = FALSE
        FOR Row = Start TO Limit
            IF Array$(Row) > Array$(Row + Offset) THEN
                SWAP Array$(Row), Array$(Row + Offset)
                Switch = Row
            END IF
        NEXT Row
        Limit = Switch - Offset
    LOOP WHILE Switch
    Offset = Offset \ 2


SUB sqjTableInit (CustomTableFile$)

' This SUB initializes the global array HundredTable$(), which contains
' a list of 100 words that comprise 50% of English language usage.  It
' also accepts a file spec in the parameter CustomTableFile$, which it
' then opens and scans into CustomTable$().  Words in the custom file
' that are in [] or {} are flagged to be avoided.  That is to say,
' every occurance of an AvoidTable$() word decreases the interest factor
' of a given string in the same way that every occurance of a WordTable$()
' word increases the interest factor.  ObsceneTable$() is used to flag
' when a given string contains predefined obscenities.  I leave it to
' each programmer's idea of decency to add words to the ObsceneWordData
' DATA statements.  User defined obscenities can be in the CustomTableFile
' in angle brackets <>.

' The CustomTableFile is in the format:
' programming
' compiler
' [C Language]
' <crap>
' think

' This means that 'programming' 'compiler' and 'think' and added to the
' custom list, whereas 'C Language' is a phrase to avoid, and 'crap' is
' an obscenity you'd rather not contend with.

' First, we initialize BlankSpace$

BlankSpace$ = " :/,.()[]<>{}!?" + CHR$(13) + CHR$(9) + CHR$(10) + CHR$(32)

' Then, we deal with the 100 most used English words.

RESTORE EnglishWordData

FOR i = 1 TO 100
    READ Temp$
    HundredTable$(i) = UCASE$(Temp$)

sqjShellSort HundredTable$()

' Then, we deal with the obscenities.  The logic is to scan the data until
' the word MOUTH_WITH_SOAP is encountered in the DATA stream.

RESTORE ObsceneWordData

    ObPtr = ObPtr + 1
    READ Temp$
    ObsceneTable$(ObPtr) = UCASE$(Temp$)

ObPtr = ObPtr - 1   ' Subtract one to cover over MOUTH_WITH_SOAP

sqjShellSort ObsceneTable$()

' Finally, we read in the CustomTableFile if there is one.

IF CustomTableFile$ <> "" THEN
    CustBound = UBOUND(CustomTable$)
    AvBound = UBOUND(AvoidTable$)
    CussBound = UBOUND(ObsceneTable$)

    CustomHandle = FREEFILE
    OPEN CustomTableFile$ FOR INPUT AS CustomHandle

        LINE INPUT #CustomHandle, Buffer$

        Buffer$ = UCASE$(RTRIM$(LTRIM$(Buffer$)))

        SELECT CASE LEFT$(Buffer$, 1)
            CASE "[", "{"   ' Word to be avoided
                AvoidPtr = AvoidPtr + 1
                AvoidTable$(AvoidPtr) = MID$(Buffer$, 2, LEN(Buffer$) - 2)
                IF AvoidPtr = AvBound THEN
                    AvBound = AvBound + 25
                    REDIM PRESERVE AvoidTable$(AvBound)
                    '     ^^^^^^^^
                    ' See the comment below about my use of PRESERVE in this
                    ' program.  QuickBASIC 4.5 users will have to program a
                    ' way around this handy PDS/VBDOS feature.
                END IF

            CASE "<"        ' User defined obscenity
                ObsceneTable$(ObPtr) = MID$(Buffer$, 2, LEN(Buffer$) - 2)
                IF ObPtr = CussBound THEN
                    CussBound = CussBound + 25
                    REDIM PRESERVE ObsceneTable$(CussBound)
                END IF
                ObPtr = ObPtr + 1

            CASE ELSE       ' Word that makes reading interesting
                CustPtr = CustPtr + 1
                CustomTable$(CustPtr) = Buffer$
                IF CustPtr = CustBound THEN
                    CustBound = CustBound + 25
                    REDIM PRESERVE CustomTable$(CustBound)
                END IF
        END SELECT
    LOOP UNTIL EOF(CustomHandle)

    CLOSE CustomHandle

    IF AvPtr THEN
        REDIM PRESERVE AvoidTable$(AvPtr)
    END IF

    REDIM PRESERVE CustomTable$(CustPtr)
    '     ^^^^^^^^
    ' This is a PDS or VBDOS extension!  QuickBASIC 4.5 won't like
    ' this.  You'll have to find a work around.  This is the most
    ' efficient means of reading into the array without knowing in
    ' advance how many custom words will be in the CustomTableFile.
    ' There are other methods that use pointers, but the arrays that
    ' result are kind of difficult to work with.

    sqjShellSort CustomTable$()
    sqjShellSort AvoidTable$()


    REDIM AvoidTable$(1)
    REDIM CustomTable$(1)
    ' If there is no CustomTableFile, the above statement grabs back
    ' most of the memory that the array would have used.  Now, isn't that
    ' a nifty way to grab back some of DGROUP and the far heap?

Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET