 Rem File: Share5.bas .lib file. for edit*.bas
 Rem $Include: 'edit.inc'

Sub Write.Record(Var,Var!)
 On Local Error Goto Write.Record.Error
 Dim Locked As Integer
 Dim Lock.Count As Single
 Locked=False
 Lock.Count=Timeit!
Write.Record.Resume1:
 If Share.Installed Then
    Select Case Var
    Case BankFile
       Lock TempFile1,Var!
    Case ObjDescFile
       Lock TempFile1,Var!
    Case Else
       Lock Var,Var!
       Locked=True
    End Select
 Endif
Write.Record.Resume2:
 Select Case Var
 Case SicFile
    Put SicFile,Var!,UserProfile
 Case AutomateFile
    Put AutomateFile,Var!,AutomateRecord
 Case TempFile1
    Put TempFile1,Var!,AutomateRecord
 Case BankFile
    Put TempFile1,Var!,BankRecord
 Case ObjDescFile
    Put TempFile1,Var!,BufferRecord
 Case RoomFile
    Put RoomFile,Var!,RoomRecord
 Case RoomDescFile
    Put RoomDescFile,Var!,BufferRecord
 Case ActionFile
    Put ActionFile,Var!,ActionRecord
 Case MonClassFile
    Put MonClassFile,Var!,MonClassRecord
 Case NonPlayerFile
    Put NonPlayerFile,Var!,MonsterRecord
 Case MonsterFile
    Put MonsterFile,Var!,MonsterRecord
 Case UserFile
    Put UserFile,Var!,UserRecord
 Case UserFile2
    Put UserFile2,Var!,UserRecord2
 Case SpellFile
    Put SpellFile,Var!,SpellRecord
 Case ObjectFile
    Put ObjectFile,Var!,ObjectRecord
 Case TreasureFile
    Put TreasureFile,Var!,TreasureRecord
 Case MessWorkFile1
    Put MessWorkFile1,Var!,MessWorkRecord1
 Case MessWorkFile2
    Put MessWorkFile2,Var!,MessWorkRecord2
 Case MessWorkFile3
    Put MessWorkFile3,Var!,MessWorkRecord3
 Case MessWorkFile4
    Put MessWorkFile4,Var!,MessWorkRecord4
 Case MessWorkFile5
    Put MessWorkFile5,Var!,MessWorkRecord5
 Case MessWorkFile6
    Put MessWorkFile6,Var!,MessWorkRecord6
 Case MonClassFile
    Put MonClassFile,Var!,MonClassRecord
 Case MonTalkFile
    Put MonTalkFile,Var!,BufferRecord
 Case ContainerFile
    Put ContainerFile,Var!,ContainerRecord
 Case TeamInvFile
    Put TeamInvFile,Var!,MessWorkRecord6
 Case UserInvFile
    Put UserInvFile,Var!,MessWorkRecord6
 Case CtnInvFile
    Put CtnInvFile,Var!,MessWorkRecord6
 Case RoomInvFile
    Put RoomInvFile,Var!,MessWorkRecord6
 Case MonInvFile
    Put MonInvFile,Var!,MessWorkRecord6
 Case MessBaseFile
    Put MessBaseFile,Var!,MessageBaseRecord
 Case MessageFile
    Put MessageFile,Var!,BufferRecord
 Case NewFile
    Put NewFile,Var!,NewMessages
 Case TableFile
    Put TableFile,Var!,TableRecord
 Case TeamFile
    Put TeamFile,Var!,TeamRecord
 Case DayFile1
    Put DayFile1,Var!,BufferRecord
 Case LogFile
    Put LogFile,Var!,LogRecord
 Case TemplateFile
    Put TemplateFile,Var!,EditCommands
 End Select
 If Share.Installed Then
    Select Case Var
    Case BankFile
       Unlock TempFile1,Var!
    Case ObjDescFile
       Unlock TempFile1,Var!
    Case Else
       UnLock Var,Var!
    End Select
 Endif
Write.Record.Exit:
 Exit Sub
Write.Record.Error:
 Data.Error=Err
 If Share.Installed Then
    If Data.Error=70 Then
       If Time.Elapsed(Lock.Count,10!)=False Then
          If Locked=False Then
             Resume Write.Record.Resume1
          Else
             Resume Write.Record.Resume2
          Endif
       Endif
    Endif
 Endif
 If Debug.Mode Then
    Call Display.Share.Error("Write lock",Var,Var!)
 Endif
 Resume Write.Record.Exit
End Sub

Sub Write.Message.Record(Var,Var2)
 On Local Error Goto Write.Message.Error
 Dim Locked As Integer
 Dim Lock.Count As Single
 Locked=False
 Lock.Count=Timeit!
Write.Message.Resume1:
 If Share.Installed Then
    Lock Var,Var2
    Locked=True
 Endif
Write.Message.Resume2:
 Select Case Var
 Case MessWorkFile1
    Put MessWorkFile1,Var2,MessWorkRecord1
 Case MessWorkFile7
    Put MessWorkFile7,Var2,MessWorkRecord7
 Case MessWorkFile8
    Put MessWorkFile8,Var2,UserCommandRecord
 Case MessWorkFile9
    Put MessWorkFile9,Var2,UserConfigRecord
 End Select
 If Share.Installed Then
    UnLock Var,Var2
 Endif
Write.Message.Exit:
 Exit Sub
Write.Message.Error:
 Data.Error=Err
 If Share.Installed Then
    If Data.Error=70 Then
       If Time.Elapsed(Lock.Count,10!)=False Then
          If Locked=False Then
             Resume Write.Message.Resume1
          Else
             Resume Write.Message.Resume2
          Endif
       Endif
    Endif
 Endif
 If Debug.Mode Then
    Call Display.Share.Error2("Message write lock",Var,Var2)
 Endif
 Resume Write.Message.Exit
End Sub

Sub Read.Record(Var,Var!)
 On Local Error Goto Read.Record.Error
 Dim Lock.Count As Single
 Lock.Count=Timeit!
Read.Record.Resume:
 Select Case Var
 Case SicFile
    Get SicFile,Var!,UserProfile
 Case BankFile
    Get TempFile1,Var!,BankRecord
 Case ObjDescFile
    Get TempFile1,Var!,BufferRecord
 Case AutomateFile
    Get AutomateFile,Var!,AutomateRecord
 Case TempFile1
    Get TempFile1,Var!,AutomateRecord
 Case RoomFile
    Get RoomFile,Var!,RoomRecord
 Case RoomDescFile
    Get RoomDescFile,Var!,BufferRecord
 Case ActionFile
    Get ActionFile,Var!,ActionRecord
 Case MonClassFile
    Get MonClassFile,Var!,MonClassRecord
 Case NonPlayerFile
    Get NonPlayerFile,Var!,MonsterRecord
 Case MonsterFile
    Get MonsterFile,Var!,MonsterRecord
 Case UserFile
    Get UserFile,Var!,UserRecord
 Case UserFile2
    Get UserFile2,Var!,UserRecord2
 Case SpellFile
    Get SpellFile,Var!,SpellRecord
 Case ObjectFile
    Get ObjectFile,Var!,ObjectRecord
 Case TreasureFile
    Get TreasureFile,Var!,TreasureRecord
 Case MessWorkFile1
    Get MessWorkFile1,Var!,MessWorkRecord1
 Case MessWorkFile2
    Get MessWorkFile2,Var!,MessWorkRecord2
 Case MessWorkFile3
    Get MessWorkFile3,Var!,MessWorkRecord3
 Case MessWorkFile4
    Get MessWorkFile4,Var!,MessWorkRecord4
 Case MessWorkFile5
    Get MessWorkFile5,Var!,MessWorkRecord5
 Case MessWorkFile6
    Get MessWorkFile6,Var!,MessWorkRecord6
 Case MonClassFile
    Get MonClassFile,Var!,MonClassRecord
 Case MonTalkFile
    Get MonTalkFile,Var!,BufferRecord
 Case ContainerFile
    Get ContainerFile,Var!,ContainerRecord
 Case TeamInvFile
    Get TeamInvFile,Var!,MessWorkRecord6
 Case UserInvFile
    Get UserInvFile,Var!,MessWorkRecord6
 Case CtnInvFile
    Get CtnInvFile,Var!,MessWorkRecord6
 Case RoomInvFile
    Get RoomInvFile,Var!,MessWorkRecord6
 Case MonInvFile
    Get MonInvFile,Var!,MessWorkRecord6
 Case MessBaseFile
    Get MessBaseFile,Var!,MessageBaseRecord
 Case MessageFile
    Get MessageFile,Var!,BufferRecord
 Case NewFile
    Get NewFile,Var!,NewMessages
 Case TableFile
    Get TableFile,Var!,TableRecord
 Case TeamFile
    Get TeamFile,Var!,TeamRecord
 Case DayFile1
    Get DayFile1,Var!,BufferRecord
 Case LogFile
    Get LogFile,Var!,LogRecord
 Case TemplateFile
    Get TemplateFile,Var!,EditCommands
 End Select
Read.Record.Exit:
 Exit Sub
Read.Record.Error:
 Data.Error=Err
 If Share.Installed Then
    If Data.Error=70 Then
       If Time.Elapsed(Lock.Count,10!)=False Then
          Resume Read.Record.Resume
       Endif
    Endif
 Endif
 If Debug.Mode Then
    Call Display.Share.Error("Read lock",Var,Var!)
 Endif
 Resume Read.Record.Exit
End Sub

Sub Read.Message.Record(Var,Var2)
 On Local Error Goto Read.Message.Error
 Dim Lock.Count As Single
 Lock.Count=Timeit!
Read.Message.Resume:
 Select Case Var
 Case MessWorkFile1
    Get MessWorkFile1,Var2,MessWorkRecord1
 Case MessWorkFile7
    Get MessWorkFile7,Var2,MessWorkRecord7
 Case MessWorkFile8
    Get MessWorkFile8,Var2,UserCommandRecord
 Case MessWorkFile9
    Get MessWorkFile9,Var2,UserConfigRecord
 Case TempFile1
    Get TempFile1,Var2,BufferRecord.Buffer
 End Select
Read.Message.Exit:
 Exit Sub
Read.Message.Error:
 Data.Error=Err
 If Share.Installed Then
    If Data.Error=70 Then
       If Time.Elapsed(Lock.Count,10!)=False Then
          Resume Read.Message.Resume
       Endif
    Endif
 Endif
 If Debug.Mode Then
    Call Display.Share.Error2("Message read lock",Var,Var2)
 Endif
 Resume Read.Message.Exit
End Sub

Sub Read.Helpfile(Var,Var2)
 On Local Error Goto Read.Help.Error
 Dim Lock.Count As Single
 Lock.Count=Timeit!
Read.Help.Resume:
 Select Case Var
 Case HelpFile1
    Get HelpFile1,Var2,HelpRecord1
 Case HelpFile2
    Get HelpFile2,Var2,HelpRecord2
 Case HelpFile3
    Get HelpFile3,Var2,HelpRecord3
 Case HelpFile4
    Get HelpFile4,Var2,HelpRecord3
 End Select
Read.Help.Exit:
 Exit Sub
Read.Help.Error:
 Data.Error=Err
 If Share.Installed Then
    If Data.Error=70 Then
       If Time.Elapsed(Lock.Count,10!)=False Then
          Resume Read.Help.Resume
       Endif
    Endif
 Endif
 If Debug.Mode Then
    Call Display.Share.Error2("Help read lock",Var,Var2)
 Endif
 Resume Read.Help.Exit
End Sub

Sub Write.TempFile(Var,Var2!)
 On Local Error Goto write.TempFile.Error
 Dim Locked As Integer
 Dim Lock.Count As Single
 Locked=False
 Lock.Count=Timeit!
Write.TempFile.Resume1:
 If Share.Installed Then
    Select Case Var
    Case 2, 9
       Lock TempFile2,Var2!
       Locked=True
    Case Else
       Lock TempFile1,Var2!
       Locked=True
    End Select
 Endif
Write.TempFile.Resume2:
 Select Case Var
 Case 1
    Put TempFile1,Var2!,TableRecord
 Case 2
    Put TempFile2,Var2!,BufferRecord
 Case 3
    Put TempFile1,Var2!,TeamRecord
 Case 4
    Put TempFile1,Var2!,UserRecord2
 Case 5
    Put TempFile1,Var2!,ContainerRecord
 Case 6
    Put TempFile1,Var2!,MessageBaseRecord
 Case 7
    Put TempFile1,Var2!,MessWorkRecord6
 Case 8
    Put TempFile1,Var2!,BufferRecord
 Case 9
    Put TempFile2,Var2!,MessWorkRecord6
 Case 10
    Put TempFile1,Var2!,UserProfile
 End Select
 If Share.Installed Then
    Select Case Var
    Case 2, 9
       UnLock TempFile2,Var2!
    Case Else
       UnLock TempFile1,Var2!
    End Select
 Endif
Write.TempFile.Exit:
 Exit Sub
Write.TempFile.Error:
 Data.Error=Err
 If Share.Installed Then
    If Data.Error=70 Then
       If Time.Elapsed(Lock.Count,10!)=False Then
          If Locked=False Then
             Resume Write.TempFile.Resume1
          Else
             Resume Write.TempFile.Resume2
          Endif
       Endif
    Endif
 Endif
 If Debug.Mode Then
    Call Display.Share.Error("Tempfile write lock",Var,Var2!)
 Endif
 Resume Write.TempFile.Exit
End Sub

Sub Read.TempFile(Var,Var2!)
 On Local Error Goto Read.TempFile.Error
 Dim Lock.Count As Single
 Lock.Count=Timeit!
Read.TempFile.Resume:
 Select Case Var
 Case 1
    Get TempFile1,Var2!,TableRecord
 Case 2
    Get TempFile2,Var2!,BufferRecord
 Case 3
    Get TempFile1,Var2!,TeamRecord
 Case 4
    Get TempFile1,Var2!,UserRecord2
 Case 5
    Get TempFile1,Var2!,ContainerRecord
 Case 6
    Get TempFile1,Var2!,MessageBaseRecord
 Case 7
    Get TempFile1,Var2!,MessWorkRecord6
 Case 8
    Get TempFile1,Var2!,BufferRecord
 Case 9
    Get TempFile2,Var2!,MessWorkRecord6
 End Select
Read.TempFile.Exit:
 Exit Sub
Read.TempFile.Error:
 Data.Error=Err
 If Share.Installed Then
    If Data.Error=70 Then
       If Time.Elapsed(Lock.Count,10!)=False Then
          Resume Read.TempFile.Resume
       Endif
    Endif
 Endif
 If Debug.Mode Then
    Call Display.Share.Error("Tempfile read lock",Var,Var2!)
 Endif
 Resume Read.TempFile.Exit
End Sub

Sub Display.Share.Error(Var2$,Var,Var!)
 On Local Error Goto Display.Record.Error1
 If Var=24 Then
    If Data.Error=52 Then
       exit sub
    Endif
 Endif
 Color 15
 Var$=Nul
 Var$=Var$+Var2$+" error:"+Str$(Data.Error)
 Var$=Var$+" file#"+Str$(Var)+" record#"+Str$(Var!)
 Var$=Chr$(13)+Chr$(10)+Var$+Chr$(13)+Chr$(10)
 Call Scrn(Var$)
Display.Record.Exit1:
 Exit Sub
Display.Record.Error1:
 Resume Display.Record.Exit1
End Sub

Sub Display.Share.Error2(Var2$,Var,Var2)
 On Local Error Goto Display.Record.Error2
 If Var=24 Then
    If Data.Error=52 Then
       exit sub
    Endif
 Endif
 Color 15
 Var$=Nul
 Var$=Var$+Var2$+" error:"+Str$(Data.Error)
 Var$=Var$+" file#"+Str$(Var)+" record#"+Str$(Var2)
 Var$=Chr$(13)+Chr$(10)+Var$+Chr$(13)+Chr$(10)
 Call Scrn(Var$)
Display.Record.Exit2:
 Exit Sub
Display.Record.Error2:
 Resume Display.Record.Exit2
End Sub

Sub Detect.Local.ANSI
 Call Plex.Function(26)
 If (OutregsX.AX And &HFF)=&HFF Then
    Local.ANSI.Color=True
 Else
    Local.ANSI.Color=False
 Endif
 Local.Avatar.Color=False
 Call Plex.Function(27)
 If (OutregsX.AX And &HFF)=&HFF Then
    If (OutregsX.DX And &HFF)=&H16 Then
       Local.Avatar.Color=True
    Endif
 Endif
End Sub

Sub VideoInt(Var,Var1)
 Select Case Var
 Case 2 ' set cursor
    InregsX.AX=&H0200
    InregsX.BX=Video.Page
    InregsX.DX=Var1
 Case 3 ' get cursor
    InregsX.AX=&H0300
    InregsX.BX=Video.Page
 Case 6 ' scroll
    InregsX.AX=&H0601
    InregsX.BX=&H0700
    InregsX.CX=&H0000
    InregsX.DX=Var1
 Case 15 ' get mode
    InregsX.AX=&H0F00
 End Select
 Call InterruptX(&H10,InregsX,OutregsX)
End Sub

Sub StdinInt(Var,VarY)
 Select Case Var
 Case 6 ' output
    InregsX.AX=&H0600
    InregsX.DX=VarY
 Case 7 ' input
    InregsX.AX=&H0600
    InregsX.DX=&H00FF
 Case 48 ' get os version
    InregsX.AX=&H3001
 Case 54 ' get disk space
    InregsX.AX=&H3600
    InregsX.DX=&H0000
 Case 62 ' get psp segment
    InregsX.AX=&H6200
 Case 68 ' ioctl
    InregsX.AX=&H4400+VarY
    InregsX.BX=&H01
 End Select
 Call InterruptX(&H21,InregsX,OutregsX)
End Sub

Sub Mouse.Function(Var1,Var2)
 InregsX.AX=Var1
 InregsX.BX=Var2
 Call InterruptX(&H33,InregsX,OutregsX)
End Sub

Sub Mouse.Function2(Var1,Var2,Var3,Var4)
 InregsX.AX=Var1
 InregsX.BX=Var2
 InregsX.CX=Var3
 InregsX.DX=Var4
 Call InterruptX(&H33,InregsX,OutregsX)
End Sub

Sub Slice.Function
 InregsX.AX=&H1680
 InregsX.BX=&H0000
 Call InterruptX(&H2F,InregsX,OutregsX)
End Sub

Sub Plex.Function(Var1)
 Select Case Var1
 Case 16 ' detect share
    InregsX.AX=&H1000
 Case 22 ' detect windows
    InregsX.AX=&H160A
 Case 26 ' detect ansi
    InregsX.AX=&H1A00
 Case 27 ' detect avatar
    InregsX.AX=&H1A00
    InregsX.BX=&H4156
    InregsX.CX=&H4154
    InregsX.DX=&H4152
 Case 74 ' detect dos
    InregsX.AX=&H4A33
 End Select
 Call InterruptX(&H2F,InregsX,OutregsX)
End Sub

Sub Clear.Container
 On Local Error Goto ErrResume116b
 ContainerRecord.ContainerName=Nul
 ContainerRecord.ContainerShort=Nul
 ContainerRecord.NamePrefix="in it"
 ContainerRecord.ContainerMax=False
 ContainerRecord.Closed=False
 ContainerRecord.Locked=False
 ContainerRecord.KeyNumber=SFalse
 ContainerRecord.UserNumber=SFalse
 ContainerRecord.RoomNumber=SFalse
 ContainerRecord.DeletedContainer=False
 ContainerRecord.InvisibleContainer=False
 ContainerRecord.Weight=False
 ContainerRecord.WithinContainer=SFalse
 ContainerRecord.Disappears=SFalse
 ContainerRecord.ContainerIndex=SFalse
 ContainerRecord.Size=False
 ContainerRecord.Material=False
 ContainerRecord.Permanent=False
 ContainerRecord.SelfImplodes=False
 ContainerRecord.RestrictItem(1)=SFalse
 ContainerRecord.RestrictItem(2)=SFalse
 ContainerRecord.RestrictItem(3)=SFalse
 ContainerRecord.TrapType=False
 ContainerRecord.TrapHits=False
 ContainerRecord.TrapItem=SFalse
 ContainerRecord.First2=SFalse
 ContainerRecord.Last2=SFalse
 ContainerRecord.First=SFalse
 ContainerRecord.Last=SFalse
 ContainerRecord.Prev=SFalse
 ContainerRecord.Next=SFalse
 ContainerRecord.Prefix1=""
 ContainerRecord.Damaged=False
 ContainerRecord.Scanned=False
ErrExit116b:
 Exit Sub
ErrResume116b:
 Resume ErrExit116b
End Sub

Sub Clear.List.Node
 On Local Error Goto ErrorTrp32b
 MessWorkRecord6.User=SFalse
 MessWorkRecord6.Room=SFalse
 MessWorkRecord6.Index=SFalse
 MessWorkRecord6.Charges=False
 MessWorkRecord6.Plus=False
 MessWorkRecord6.Prev=SFalse
 MessWorkRecord6.Next=SFalse
 For Var=1 To 4
    MessWorkRecord6.Desc(Var)=0!
 Next
ErrorRsm32b:
 Exit Sub
ErrorTrp32b:
 Resume ErrorRsm32b
End Sub

Sub Find.Object
 On Local Error Goto ErrResume105
 TempD!=SFalse
 Strng="Object name, or number"
 Strng=Strng+"(1-"+Mid$(Str$(Lof(ObjectFile)/ObjectRecLen),2)+")? "
 No.Input.Out="1"
 Call IO.I
 If Out2=Nul Then
    Exit Sub
 Endif
 Out2=Lcase$(Out2)
 Temp7!=SFalse
 If Instr(Out2,"#") Then
    Temp7!=Val(Mid$(Out2,Instr(Out2,"#")+1))
    Out2=Left$(Out2,Instr(Out2,"#")-1)
 Endif
 TempQ!=SFalse
 No.Input=False
 For Var2!=1! To Lof(ObjectFile)/ObjectRecLen
    Call Read.Record(ObjectFile,Var2!)
    If Left$(ObjectRecord.ObjectName,Len(Out2))=Out2 Then
       TempQ!=TempQ!+1!
       If Temp7!=SFalse Or TempQ!=Temp7! Then
          No.Input=True
          Exit For
       Endif
    Endif
 Next
 If No.Input=False Then
    Var2!=Int(Val(Out2)+.5)
    If Var2!>SFalse And Var2!<=Lof(ObjectFile)/ObjectRecLen Then
       Call Read.Record(ObjectFile,Var2!)
       No.Input=True
    Endif
 Endif
 If No.Input=False Then
    Var2!=SFalse
 Endif
 TempD!=Var2!
ErrExit105:
 Exit Sub
ErrResume105:
 Resume ErrExit105
End Sub

Sub Find.Spell(Var)
 On Local Error Goto ErrResume104
 If Var=False Then
    Temp!=SFalse
 Else
    TempD!=SFalse
 Endif
 Strng="Spell name, or number"
 Strng=Strng+"(1-"+Mid$(Str$(Lof(SpellFile)/SpellRecLen),2)+")? "
 No.Input.Out="1"
 Call IO.I
 If Out2=Nul Then
    Exit Sub
 Endif
 Temp7!=SFalse
 Out2=Lcase$(Out2)
 If Instr(Out2,"#") Then
    Temp7!=Val(Mid$(Out2,Instr(Out2,"#")+1))
    Out2=Left$(Out2,Instr(Out2,"#")-1)
 Endif
 TempQ!=SFalse
 No.Input=False
 For Var2!=1! To Lof(SpellFile)/SpellRecLen
    Call Read.Record(SpellFile,Var2!)
    If Left$(SpellRecord.SpellName,Len(Out2))=Out2 Then
       TempQ!=TempQ!+1!
       If Temp7!=SFalse Or TempQ!=Temp7! Then
          No.Input=True
          Exit For
       Endif
    Endif
 Next
 If No.Input=False Then
    Var2!=Int(Val(Out2)+.5)
    If Var2!>SFalse And Var2!<=Lof(SpellFile)/SpellRecLen Then
       Call Read.Record(SpellFile,Var2!)
       No.Input=True
    Endif
 Endif
 If No.Input=False Then
    Var2!=SFalse
 Endif
 If Var=False Then
    Temp!=Var2!
 Else
    TempD!=Var2!
 Endif
ErrExit104:
 Exit Sub
ErrResume104:
 Resume ErrExit104
End Sub

Sub Find.Treasure
 On Local Error Goto ErrResume103
 TempC!=SFalse
 Strng="Treasure name, or number"
 Strng=Strng+"(1-"+Mid$(Str$(Lof(TreasureFile)/TreasureRecLen),2)+")? "
 No.Input.Out="0"
 Call IO.I
 If Out2=Nul Then
    Exit Sub
 Endif
 Temp7!=SFalse
 Out2=Lcase$(Out2)
 If Instr(Out2,"#") Then
    Temp7!=Val(Mid$(Out2,Instr(Out2,"#")+1))
    Out2=Left$(Out2,Instr(Out2,"#")-1)
 Endif
 TempQ!=SFalse
 No.Input=False
 For Var2!=1! To Lof(TreasureFile)/TreasureRecLen
    Call Read.Record(TreasureFile,Var2!)
    If Left$(TreasureRecord.TreasureName,Len(Out2))=Out2 Then
       TempQ!=TempQ!+1!
       If Temp7!=SFalse Or TempQ!=Temp7! Then
          No.Input=True
          Exit For
       Endif
    Endif
 Next
 If No.Input=False Then
    Var2!=Int(Val(Out2)+.5)
    If Var2!>SFalse And Var2!<=Lof(TreasureFile)/TreasureRecLen Then
       Call Read.Record(TreasureFile,Var2!)
       No.Input=True
    Endif
 Endif
 If No.Input=False Then
    Var2!=SFalse
 Endif
 TempC!=Var2!
ErrExit103:
 Exit Sub
ErrResume103:
 Resume ErrExit103
End Sub

Sub Find.User(Var)
 On Local Error Goto ErrResume3
 If Var=False Then
    Temp5!=SFalse
 Else
    TempD!=SFalse
 Endif
 Graphics.Off=False
 Strng="User name, or number"
 Strng=Strng+"(1-"+Mid$(Str$(Lof(UserFile2)/UserRecLen),2)+")? "
 No.Input.Out="1"
 Call IO.I
 Temp7!=SFalse
 Out2=Ucase$(Out2)
 If Instr(Out2,"#") Then
    Temp7!=Int(Val(Mid$(Out2,Instr(Out2,"#")+1))+.5)
    Out2=Left$(Out2,Instr(Out2,"#")-1)
 Endif
 TempQ!=SFalse
 No.Input=False
 For Var2!=1! To Lof(UserFile2)/UserRecLen
    Call Read.Record(UserFile2,Var2!)
    Out3=UserRecord2.CodeName
    If Left$(Out3,Len(Out2))=Out2 Then
       TempQ!=TempQ!+1!
       If Temp7!=SFalse Or TempQ!=Temp7! Then
	  No.Input=True
	  Exit For
       Endif
    Endif
 Next
 If No.Input=False Then
    Var2!=Int(Val(Out2)+.5)
    If Var2!>SFalse And Var2!<=Lof(UserFile2)/UserRecLen Then
       Call Read.Record(UserFile2,Var2!)
       No.Input=True
    Endif
 Endif
 If No.Input=False Then
    Var2!=SFalse
    Strng="User name not found."
    Call IO.O
 Endif
 If Var=False Then
    Temp5!=Var2!
 Else
    TempD!=Var2!
 Endif
ErrExit3:
 Exit Sub
ErrResume3:
 Resume ErrExit3
End Sub

Sub Find.Monster(Var)
 On Local Error Goto ErrResume102
 If Var=False Then
    Temp5!=SFalse
 Else
    TempD!=SFalse
 Endif
 Strng="Monster name, or number"
 Strng=Strng+"(1-"+Mid$(Str$(Lof(MonsterFile)/MonsterRecLen),2)+")? "
 No.Input.Out="0"
 Call IO.I
 If Out2=Nul Then
    Exit Sub
 Endif
 Temp7!=SFalse
 Out2=Lcase$(Out2)
 If Instr(Out2,"#") Then
    Temp7!=Val(Mid$(Out2,Instr(Out2,"#")+1))
    Out2=Left$(Out2,Instr(Out2,"#")-1)
 Endif
 TempQ!=SFalse
 No.Input=False
 For Var2!=1! To Lof(MonsterFile)/MonsterRecLen
    Call Read.Record(MonsterFile,Var2!)
    If Left$(MonsterRecord.MonsterName,Len(Out2))=Out2 Then
       TempQ!=TempQ!+1!
       If Temp7!=SFalse Or TempQ!=Temp7! Then
          No.Input=True
          Exit For
       Endif
    Endif
 Next
 If No.Input=False Then
    Var2!=Int(Val(Out2)+.5)
    If Var2!>SFalse And Var2!<=Lof(MonsterFile)/MonsterRecLen Then
       Call Read.Record(MonsterFile,Var2!)
       No.Input=True
    Endif
 Endif
 If No.Input=False Then
    Var2!=SFalse
 Endif
 If Var=False Then
    Temp5!=Var2!
 Else
    TempD!=Var2!
 Endif
ErrExit102:
 Exit Sub
ErrResume102:
 Resume ErrExit102
End Sub

Sub Get.Range(Var1,Var2,VarX)
 On Local Error Goto ErrResume134
 Strng="Enter range:"
 Call IO.O
 Var$=Mid$(Str$(VarX),2)
 If VarX=False Then
    Strng="From(0-"+Var$+")? "
 Else
    Strng="From(1-"+Var$+")? "
 Endif
 No.Input.Out="1"
 Call IO.I
 Var1=Int(Val(Out2)+.5)
 If Var1<1 Then
    Var1=1
 Endif
 If Var1>VarX Then
    Var1=VarX
 Endif
 Strng="To("+Mid$(Str$(Var1),2)+"-"+Var$+")? "
 No.Input.Out=Var$
 Call IO.I
 Var2=Int(Val(Out2)+.5)
 If Var2<Var1 Then
    Var2=Var1
 Endif
 If Var2>VarX Then
    Var2=VarX
 Endif
ErrExit134:
 Exit Sub
ErrResume134:
 Resume ErrExit134
End Sub

Sub Get.Range2(Var1,Var2,VarX)
 On Local Error Goto ErrResume135
 Var1$=Mid$(Str$(Var1),2)
 Var2$=Mid$(Str$(Var2),2)
 Strng=Strng+"("+Var1$+"-"+Var2$+")? "
 No.Input.Out=Var1$
 Call IO.I
 VarX=Int(Val(Out2)+.5)
 If VarX<Var1 Then
    VarX=Var1
 Endif
 If VarX>Var2 Then
    VarX=Var2
 Endif
ErrExit135:
 Exit Sub
ErrResume135:
 Resume ErrExit135
End Sub

Sub Get.Record.Range(Var1!,Var2!,VarX!)
 On Local Error Goto ErrResume136
 Strng="Enter range:"
 Call IO.O
 Var$=Mid$(Str$(VarX!),2)
 Strng="From(1-"+Var$+")? "
 No.Input.Out="1"
 Call IO.I
 Var1!=Int(Val(Out2)+.5)
 If Var1!<1 Then
    Var1!=1
 Endif
 If Var1!>VarX! Then
    Var1!=VarX!
 Endif
 Strng="To("+Mid$(Str$(Var1!),2)+"-"+Var$+")? "
 No.Input.Out=Var$
 Call IO.I
 Var2!=Int(Val(Out2)+.5)
 If Var2!<Var1! Then
    Var2!=Var1!
 Endif
 If Var2!>VarX! Then
    Var2!=VarX!
 Endif
ErrExit136:
 Exit Sub
ErrResume136:
 Resume ErrExit136
End Sub

Sub Get.Record.Range2(Var1!,Var2!,VarX!)
 On Local Error Goto ErrResume137
 Var1$=Mid$(Str$(Var1!),2)
 Var2$=Mid$(Str$(Var2!),2)
 Strng=Strng+"("+Var1$+"-"+Var2$+")? "
 No.Input.Out=Var1$
 Call IO.I
 VarX!=Int(Val(Out2)+.5)
 If VarX!<Var1! Then
    VarX!=Var1!
 Endif
 If VarX!>Var2! Then
    VarX!=Var2!
 Endif
ErrExit137:
 Exit Sub
ErrResume137:
 Resume ErrExit137
End Sub

Sub Get.Record.Range3(Var1!,Var2!,VarX!)
 On Local Error Goto ErrResume137a
 Var1$=Mid$(Str$(Var1!),2)
 Var2$=Mid$(Str$(Var2!),2)
 Strng=Strng+"("+Var1$+"-"+Var2$+")?"
 Call IO.I
 VarX!=Int(Val(Out2)+.5)
 If VarX!<Var1! Then
    VarX!=Var1!
 Endif
 If VarX!>Var2! Then
    VarX!=Var2!
 Endif
ErrExit137a:
 Exit Sub
ErrResume137a:
 Resume ErrExit137a
End Sub

Sub Edit.Message(Var)
 On Local Error Goto ErrResume76
 Do While Lost.Carrier=False
    Graphics.Off=True
    If TempC=False Then
       Strng="[A]bort"
       Call IO.O
       Strng="[C]ontinue"
       Call IO.O
       Strng="[D]elete"
       Call IO.O
       Strng="[E]dit"
       Call IO.O
       Strng="[H]elp"
       Call IO.O
       Strng="[I]nsert"
       Call IO.O
       Strng="[L]ist"
       Call IO.O
       If ANSIPrefixChar<>Nul Then
          Strng="[P]refixes"
          Call IO.O
       Endif
       Strng="[R]eplace"
       Call IO.O
       Strng="[S]tore"
       Call IO.O
       Strng="[T]ext search"
       Call IO.O
       Graphics.Off=False
    Endif
    Line.Length=TempD
    Graphics.Off=False
    Strng="Edit option? "
    No.Input.Out="?"
    Call IO.I
    Out2=Ucase$(Out2)
    Select Case Out2
    Case "A"
       Strng="Abort. Are you sure(y/n)? "
       No.Input.Out="N"
       Line.Length=TempD
       Call IO.I
       If Yes Then
          Var=False
          Exit Do
       Endif
    Case "C"
       Var=True
       Exit Do
    Case "D"
       If Message.Length=False Then
          Strng="Message buffer empty."
          Call IO.O
       Else
          Call Delete.Line
       Endif
    Case "E"
       If Message.Length=False Then
          Strng="Message buffer empty."
          Call IO.O
       Else
          Call Edit.Line
       Endif
    Case "H"
       Stored.Parsed.Command1="MAILEDIT"
       Call Read.Help
    Case "I"
       If Message.Length=False Then
          Strng="Message buffer empty."
          Call IO.O
       Else
          Call Insert.Lines
       Endif
    Case "L"
       If Message.Length=False Then
          Strng="Message buffer empty."
          Call IO.O
       Else
          Call List.Lines
       Endif
    Case "P"
       Graphics.Off=True
       Call Display.ANSI.Prefixes
    Case "R"
       If Message.Length=False Then
          Strng="Message buffer empty."
          Call IO.O
       Else
          Call Replace.Line
       Endif
    Case "S"
       Var=1
       Exit Do
    Case "T"
       If Message.Length=False Then
          Strng="Message buffer empty."
          Call IO.O
       Else
          Call Search.Mess.Text
       Endif
    End Select
 Loop
ErrExit76:
 Exit Sub
ErrResume76:
 Resume ErrExit76
End Sub

Sub List.Lines
 On Local Error Goto ErrResume77
 Line.Length=1
 No.Input.Out="Y"
 Strng="Display line numbers(y/n)? "
 Call IO.I
 TempX=Yes
 Graphics.Off=True
 Allow.Break=True
 Break=False
 For Temp=1 To Message.Length
    Strng=Nul
    If TempX Then
       Strng=Mid$(Str$(Temp),2)+":"
    Endif
    Strng=Strng+Temp.ArrayS(Temp)
    Strng=Left$(Strng,79)
    Call IO.O
    If Break Then
       Exit For
    Endif
 Next
 Allow.Break=False
 Break=False
 Call More.Prompt
ErrExit77:
 Exit Sub
ErrResume77:
 Resume ErrExit77
End Sub

Sub Search.Mess.Text
 On Local Error Goto ErrResume77a
 Strng="Enter search text(?, * allowed): "
 Call IO.I
 If Out2=Nul Then
    Exit Sub
 Endif
 Var3$=Out2
 Strng="Case sensitive(y/n)? "
 Call IO.I
 TmpS=Yes
 Strng=Rtrim$(RoomRecord.ShortDesc)
 If Len(Strng) Then
    Call InstrSUB4(VarX,Var3$,TmpS)
    If VarX Then
       Strng="Text found in short description."
       Call IO.O
    Endif
 Endif
 TempX=False
 Graphics.Off=True
 For Temp=1 To Message.Length
    Strng=Rtrim$(Temp.ArrayS(Temp))
    If Len(Strng) Then
       Call InstrSUB4(VarX,Var3$,TmpS)
       If VarX>0 Then
          Strng2="Text found in line"+Str$(Temp)+" in position"+Str$(VarX)+"."
       Endif
       If VarX=-1 Then
          Strng2="Text found in line"+Str$(Temp)+"."
       Endif
       If VarX Then
          If TempX=False Then
             Strng="Long description:"
             Call IO.O
          Endif
          Strng=Strng2
          TempX=True
          Call IO.O
       Endif
    Endif
 Next
 If TempX=False Then
    Strng="Text not found."
    Call IO.O
 Endif
 Call More.Prompt
ErrExit77a:
 Exit Sub
ErrResume77a:
 Resume ErrExit77a
End Sub

' function to match case-sensitive substring with ?, * characters in substring
SUB InstrSUB4(Var,Var$,VarQ)

' see if Var$ matches in Strng
On Local Error Goto ErrorTrap24x5

' store case-sensitive string match variables
If VarQ Then
   S2$ = Var$
   S3$ = Strng
Else
   S2$ = Lcase$(Var$)
   S3$ = Lcase$(Strng)
Endif

' check default instr
IF INSTR(S2$, "*") = 0 THEN
   IF INSTR(S2$, "?") = 0 THEN
      Var = INSTR(S3$, S2$)
      EXIT SUB
   END IF
END IF

Var = -1 ' assume match

' see if S2$ matches in S3$ with substrings
FOR S3 = 1 TO LEN(S3$)
   S1$ = MID$(S3$, S3)
   P1 = 1 ' pointer to S1$
   P2 = 1 ' pointer to S2$
   P3 = S3 ' position match
   DO
      ' check match
      IF P2 > LEN(S2$) THEN
         Var = P3
         EXIT SUB
      END IF

      ' check character in S2$ at P2
      V$ = MID$(S2$, P2, 1)
      SELECT CASE V$
      CASE "*" ' global character
         ' scan to next char
         IF P2 > LEN(S2$) THEN
            EXIT DO
         END IF
         S4$ = MID$(S2$, P2 + 1, 1)
         SELECT CASE S4$
         CASE "*", "?"
            P2 = P2 + 1
         CASE ELSE
            DO
               IF MID$(S1$, P1, 1) = S4$ THEN
                  EXIT DO
               END IF
               IF P1 >= LEN(S1$) THEN
                  EXIT DO
               END IF
               P1 = P1 + 1
            LOOP
            P3 = P1
            P2 = P2 + 1
         END SELECT
      CASE "?" ' wildcard character
         P1 = P1 + 1
         P2 = P2 + 1
      CASE ELSE ' ascii character
         IF MID$(S1$, P1, 1) <> V$ THEN ' no match
            EXIT DO
         END IF
         P1 = P1 + 1
         P2 = P2 + 1
      END SELECT
   LOOP
NEXT
Var = 0 ' no match
EXIT SUB
ErrorResume24x5:
 Exit Sub
ErrorTrap24x5:
 Resume ErrorResume24x5
End Sub

Sub Replace.Line
 On Local Error Goto ErrResume78
 Strng="Line number"
 Call Get.Range2(1,Message.Length,Temp)
 If Temp Then
    Strng="Replacement line:"
    Call IO.O
    Strng="?"
    Call IO.I
    Var$=Out2
    If Var$=Nul Then
       Strng="Erase line(y/n)? "
       No.Input.Out="N"
       Call IO.I
       If No Then
          Exit Sub
       Endif
    Endif
    Temp.ArrayS(Temp)=Var$
    If Var$=Nul Then
       Strng="Line number"+Str$(Temp)+" erased."
    Else
       Strng="Line number"+Str$(Temp)+" replaced."
    Endif
    Call IO.O
 Endif
ErrExit78:
 Exit Sub
ErrResume78:
 Resume ErrExit78
End Sub

Sub Edit.Line
 On Local Error Goto ErrResume79
 Strng="Line number"
 Call Get.Range2(1,Message.Length,Temp)
 If Temp=0 Then
    Exit Sub
 Endif
 Strng="Replace what word? "
 Call IO.I
 Temp$=Out2
 If No.Input Then
    Strng="No changes made."
    Call IO.O
    Exit Sub
 Endif
 Strng="Replace with what word? "
 Call IO.I
 Temp2$=Out2
 If Temp$=Nul Or Temp$=Temp2$ Then
    Strng="No changes made."
    Call IO.O
    Exit Sub
 Endif
 Strng="Replace all occurences(y/n)? "
 No.Input.Out="Y"
 Call IO.I
 Var$=Temp.ArrayS(Temp)
 Var$=Rtrim$(Var$)
 Temp1=1
 Temp2=False
 Temp3=Yes
 Do While Lost.Carrier=False
    If Var$=Nul Then
       Exit Do
    Endif
    Var1=Instr(Temp1,Var$,Temp$)
    If Var1=False Then
       Exit Do
    Endif
    Var$=Left$(Var$,Var1-1)+Temp2$+Mid$(Var$,Var1+Len(Temp$))
    Var$=Left$(Var$,80)
    Temp1=Temp1+Len(Temp2$)
    Temp2=Temp2+1
    If Temp2=1 Then
       If Temp3=False Then
          Exit Do
       Endif
    Endif
 Loop
 Temp.ArrayS(Temp)=Var$
 If Temp2 Then
    If Temp2=1 Then
       Strng=Mid$(Str$(Temp2),2)+" change made."
    Else
       Strng=Mid$(Str$(Temp2),2)+" changes made."
    Endif
 Else
    Strng="No changes made."
 Endif
 Call IO.O
ErrExit79:
 Exit Sub
ErrResume79:
 Resume ErrExit79
End Sub

Sub Delete.Line
 On Local Error Goto ErrResume80
 Call Get.Range(Temp,Temp2,Message.Length)
 For Temp3=1 To Temp2-Temp+1
    Message.Length=Message.Length-1
    For Temp1=Temp To Message.Length
       Temp.ArrayS(Temp1)=Temp.ArrayS(Temp1+1)
    Next
 Next
 If Message.Length=False Then
    Strng="No message left."
    Call IO.O
    Exit Sub
 Endif
 Strng="Line numbers"+Str$(Temp)+" to"+Str$(Temp2)+" deleted."
 Call IO.O
ErrExit80:
 Exit Sub
ErrResume80:
 Resume ErrExit80
End Sub

Sub Insert.Lines
 On Local Error Goto ErrResume81
 If Message.Length>18 Then
    Strng="Message buffer full."
    Call IO.O
    Exit Sub
 Endif
 Strng="Before line number"
 Call Get.Range2(1,Message.Length,Temp)
 Graphics.Off=True
 Do While Message.Length<19 And Lost.Carrier=False
    Strng="?"
    Call IO.I
    If No.Input Then
       Exit Do
    Endif
    For Temp1=Message.Length To Temp Step -1
       Temp.ArrayS(Temp1+1)=Temp.ArrayS(Temp1)
    Next
    Temp.ArrayS(Temp)=Out2
    Temp=Temp+1
    Message.Length=Message.Length+1
 Loop
 Graphics.Off=False
 If Message.Length=19 Then
    Strng="Message buffer full."
    Call IO.O
 Endif
 Call More.Prompt
ErrExit81:
 Exit Sub
ErrResume81:
 Resume ErrExit81
End Sub

Sub Read.Help
 On Local Error Goto Error.Trap30a
 Graphics.Off=True
 Var$=Stored.Parsed.Command1
 Var$=Left$(Var$,8)
 Var$=Rtrim$(Var$)
 Var$=Ucase$(Var$)
 Close #HelpFile2
 Open Help.FileName2 For Random Shared As #HelpFile2 Len=Len(HelpRecord2)
 Var=1
 Temp5=False
 Allow.Break=True
 Break=False
 Continuous=False
 Do While Lost.Carrier=False
    Var=Var+1
    Call Read.Helpfile(HelpFile2,Var)
    Var2$=HelpRecord2.CommandName
    Var2$=Ucase$(Rtrim$(Var2$))
    If Left$(Var2$,Len(Var$))=Var$ Then
       Strng=Rtrim$(HelpRecord2.Text)
       Call IO.O
       If Break Then
          Exit Do
       Endif
       Temp5=Temp5+1
       If Temp5>=User.Pagelength-2 Then
          Temp5=False
          If Continuous=False Then
             Call More.Prompt
             If No Or Quit Then
                Exit Do
             Endif
          Endif
       Endif
    Endif
    If Var>Lof(HelpFile2)/HelpRecLen2 Then
       Exit Do
    Endif
 Loop
 If Temp5 Then
    Call More.Prompt
 Endif
 Allow.Break=False
 Break=False
 Graphics.Off=False
Error.Resume30a:
 Exit Sub
Error.Trap30a:
 Resume Error.Resume30a
End Sub
