'************************************************************** 
'*****                                                    ***** 
'***           Fast Indexed Help   November 1991            *** 
'*                   Program: HELP.BAS                        * 
'*                                                            * 
'*      Copyright (C) 1990, 1991  George R. Toft              * 
'*                                92-902 Welo St, #94         * 
'*                                Makakilo, HI 96707          * 
'*          Original creation date:   March 1990              * 
'*          Reduced to minimum size:  November 1991           * 
'***                                                        *** 
'*****                                                    ***** 
'************************************************************** 
 
'============== Type Declaration Section ============== 
DEFINT A-Z 
    
'============== Procedure Declaration Section ========= 
DECLARE SUB Display (MasterHelpText$, RecordNum AS INTEGER) 
DECLARE SUB GetEnter () 
DECLARE SUB GetMasterHelpText (Record AS INTEGER, MasterHelpText
AS STRING) 
DECLARE SUB HelpMain (MasterHelpText$, Index AS INTEGER) 
DECLARE SUB IINC (Argument AS INTEGER) 
    
'============== Execution Section ===================== 
' This is the minimum program to retrieve help records. 
' There is minimal processing performed on the data, it is 
' simply retrieved and displayed. 
 
FOR RecordToGet = 10 TO 1 STEP -1 
    HelpMain MasterHelpText$, RecordToGet 
    Display MasterHelpText$, RecordToGet 
NEXT RecordToGet 
CLS 
END 

SUB Display (MasterHelpText$, RecordNum AS INTEGER) 
    CLS 
    PRINT "Help record number"; RecordNum 
    PRINT " 
    PRINT MasterHelpText$ 
    GetEnter 
END SUB' Display 

SUB GetEnter 
    PRINT 
    PRINT TAB(34); "Press [Enter]"; 
    DO WHILE INKEY$ <> CHR$(13): LOOP 
END SUB' GetEnter 

DEFSNG H 
SUB GetMasterHelpText (Record AS INTEGER, MasterHelpText AS
STRING) 
'  This routine looks up the location of MasterHelpText in
'  HELP.IDX, then retrieves it from HELP.TXT. 
 
' use index to look up help location 
OPEN "HELP.IDX" FOR RANDOM AS 1 LEN = 5 
FIELD #1, 5 AS CountField$ 
    GET #1, Record 
    HelpStart = CVS(CountField$) 
    GET #1, Record + 1 
    HelpEnd = CVS(CountField$) - 2' Remove CR+LF at end 
CLOSE 1 
 
' Retrieve the MasterHelpText 
SELECT CASE HelpStart 
    CASE IS = 1 
        OPEN "HELP.TXT" FOR RANDOM AS 1 LEN = HelpEnd 
        FIELD #1, (HelpEnd - HelpStart) AS FieldLine$ 
            GET #1, 1 
            MasterHelpText = FieldLine$ 
        CLOSE 1 
    CASE IS <= 1000 
        OPEN "HELP.TXT" FOR RANDOM AS 1 LEN = HelpEnd 
        FIELD #1, HelpStart AS Trash$, (HelpEnd - HelpStart) AS
FieldLine$ 
            GET #1, 1 
            MasterHelpText = FieldLine$ 
        CLOSE 1 
    CASE ELSE 
        RecordToGet = HelpStart \ 1000 + 1 
        HelpStart = HelpStart - (RecordToGet - 1) * 1000! 
        HelpEnd = HelpEnd - (RecordToGet - 1) * 1000! 
        IF HelpEnd > 1000 THEN '  Text crosses record boundary 
            OPEN "HELP.TXT" FOR RANDOM AS 1 LEN = 1000 
            ' get first piece of MasterHelpText 
            FIELD #1, HelpStart AS Trash$, (1000! - HelpStart)
AS FieldLine$ 
                GET #1, RecordToGet 
                MasterHelpText = FieldLine$ 
                ' get middle pieces 
                FIELD #1, 1000 AS FieldLine$ 
                FOR i = 1 TO HelpEnd \ 1000 - 1 
                    IINC RecordToGet 
                    GET #1, RecordToGet 
                    MasterHelpText = MasterHelpText + FieldLine$ 
                NEXT i 
                ' get last piece 
                FIELD #1, (HelpEnd MOD 1000) AS FieldLine$ 
                GET #1, RecordToGet + 1 
                MasterHelpText = MasterHelpText + FieldLine$ 
            CLOSE 1 
        ELSE 
            OPEN "HELP.TXT" FOR RANDOM AS 1 LEN = 1000 
            FIELD #1, HelpStart AS Trash$, (HelpEnd - HelpStart)
AS FieldLine$ 

                GET #1, RecordToGet 
                MasterHelpText = FieldLine$ 
            CLOSE 1 
        END IF 
END SELECT 
END SUB' GetMasterHelpText 

DEFINT H 
SUB HelpMain (MasterHelpText$, Index AS INTEGER) 
' load in help pages 
' A sequential file is used to allow for a variable
' length record. The record is terminated with a <CR>. 
 
GetMasterHelpText Index, MasterHelpText$ 
 
' clear up free string space 
Temp! = FRE("") 
END SUB' HelpMain 
 
SUB IINC (Argument AS INTEGER) 
    Argument = Argument + 1 
END SUB' IINC 
