 Rem File: EditcmdD for Dndbbs Version v5.0a Release r2.0
 Rem $Include: 'edit.inc'

 On Error Goto ErrMain0
 If Chained2=False Then
    Call Open.Arrays
    Call Get.Config
    Call Increase.Files
    Call Make.FileNames
    Call Open.Files
    Call Reset.Cursor
    Call Detect.Share
    Call Save.Screen2(0)
    Call Passwrd9(Var,"d")
    If Var=False Then
       Call Terminate.Program
       End
    Endif
 Endif
 Call Edit.Help
MainExit0:
 End
ErrMain0:
 Resume MainExit0
 End

Sub Edit.Help
 On Local Error Goto ErrResume140
 Call Edit.Status.Line
 Do While Lost.Carrier=False
    If TempC=False Then
       Graphics.Off=False
       Strng="Edit Help utility v"+Left$(Version$,4)+" menu:"
       Call IO.O
       Graphics.Off=True
       Strng=RT$(602,"[C]")+"ontents"
       Call IO.O
       If Local.Mode Then
          Strng=RT$(603,"[P]")+"rint"
          Call IO.O
       Endif
       Strng=RT$(604,"[S]")+"earch"
       Call IO.O
       Strng=RT$(605,"[T]")+"opic"
       Call IO.O
    Endif
    Graphics.Off=False
    No.Input.Out="Q"
    Line.Length=TempD
    Strng="Enter help option(q to quit)? "
    Call IO.I
    Allow.Break=True
    Break=False
    Select Case Ucase$(Out2)
    Case "C"
       If RT$(602,"[C]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Stored.Parsed.Command1="contents"
          Continuous=False
          Call Read.Help2
       Endif
    Case "S"
       If RT$(604,"[S]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Enter help search string? "
          Call IO.I
          Continuous=False
          Call Search.Help
       Endif
    Case "T"
       If RT$(605,"[T]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Enter help topic number sequence? "
          Call IO.I
          Stored.Parsed.Command1=Out2
          Continuous=False
          Call Read.Help2
       Endif
    Case "P"
       If Local.Mode Then
          If RT$(603,"[P]")="[*]" Then
             Strng="Command restricted.."
             Call IO.O
          Else
             Strng="Enter help search string? "
             Call IO.I
             Call Print.Help
          Endif
       Endif
    Case "Q"
       Exit Do
    End Select
    Allow.Break=False
    Break=False
 Loop
 Close
 Call Clear.Status.Line
 If Chained2 Then
    Chain DND.Path+"EDIT.EXE"
 Endif
 Call Terminate.Program
ErrExit140:
 Exit Sub
ErrResume140:
 Resume ErrExit140
End Sub

Sub Read.Help2
 On Local Error Goto ErrResume141
 Var$=Stored.Parsed.Command1
 Var$=Rtrim$(Var$)
 Var$=Ucase$(Var$)
 If Left$(Var$,8)<>"CONTENTS" Then
    For Var2=2 To Lof(HelpFile1)/HelpRecLen1
       Call Read.Helpfile(HelpFile1,Var2)
       Var2$=HelpRecord1.CName
       Var2$=Rtrim$(Var2$)
       Var2$=Ucase$(Var2$)
       If Left$(Var2$,8)<>"CONTENTS" Then
	  Exit For
       Endif
       Var2$=HelpRecord1.Text
       Var2$=Rtrim$(Var2$)
       If Left$(Var2$,Len(Var$))=Var$ Then
          Strng="Topic: "+Var2$
	  Call IO.O
	  Exit For
       Endif
    Next
 Endif
 Var=1
 Var1=False
 Graphics.Off=True
 Allow.Break=True
 Break=False
 For Var2=2 To Lof(HelpFile1)/HelpRecLen1
    Call Read.Helpfile(HelpFile1,Var2)
    Var2$=HelpRecord1.CName
    Var2$=Rtrim$(Var2$)
    Var2$=Ucase$(Var2$)
    If Var2$=Var$ Then
       Strng=HelpRecord1.Text
       Strng=Rtrim$(Strng)
       If Lost.Carrier Then
	  Exit For
       Endif
       Call IO.O
       Var1=True
       If Break Then
	  Exit For
       Endif
       If Continuous=False Then
          Var=Var+1
          If Var>=User.Pagelength-2 Then
             Var=False
             Call More.Prompt
             Select Case Ucase$(Left$(Out2,1))
             Case "C"
                Continuous=True
             Case "N", "Q"
                Exit For
             End Select
          Endif
       Endif
    Endif
 Next
 Allow.Break=False
 Graphics.Off=False
 If Var1=False Then
    Strng="No help found on '"+Lcase$(Var$)+"'."
    Call IO.O
 Else
    If Var Then
       If Continuous=0 Then
          Call More.Prompt
       Endif
    Endif
 Endif
ErrExit141:
 Exit Sub
ErrResume141:
 Resume ErrExit141
End Sub

Sub Print.Item
 On Local Error Goto ErrResume141a
 Var$=Stored.Parsed.Command1
 Var$=Rtrim$(Var$)
 Var$=Ucase$(Var$)
 If Left$(Var$,8)<>"CONTENTS" Then
    For Var2=2 To Lof(HelpFile1)/HelpRecLen1
       Call Read.Helpfile(HelpFile1,Var2)
       Var2$=HelpRecord1.CName
       Var2$=Rtrim$(Var2$)
       Var2$=Ucase$(Var2$)
       If Left$(Var2$,8)<>"CONTENTS" Then
	  Exit For
       Endif
       Var2$=HelpRecord1.Text
       Var2$=Rtrim$(Var2$)
       If Left$(Var2$,Len(Var$))=Var$ Then
          Strng="Topic: "+Var2$
          Print #TempFile1,Strng
	  Exit For
       Endif
    Next
 Endif
 Var=False
 For Var2=2 To Lof(HelpFile1)/HelpRecLen1
    Call Read.Helpfile(HelpFile1,Var2)
    Var2$=HelpRecord1.CName
    Var2$=Rtrim$(Var2$)
    Var2$=Ucase$(Var2$)
    If Var2$=Var$ Then
       Strng=HelpRecord1.Text
       Strng=Rtrim$(Strng)
       Print #TempFile1,Strng
       Var=Var+1
       If Var=23 Then
	  Var=False
          Print #TempFile1,Chr$(12);
       Endif
    Endif
 Next
 If Var Then
    Print #TempFile1,Chr$(12);
 Endif
ErrExit141a:
 Exit Sub
ErrResume141a:
 Resume ErrExit141a
End Sub

Sub Search.Help
 On Local Error Goto ErrResume98
 Var$=Out2
 Var$=Rtrim$(Var$)
 Var$=Ucase$(Var$)
 Var1=False
 Var3$=Nul
 Allow.Break=True
 Break=False
 VarZ1!=0!
 VarZ2!=0!
 If Var$<>Nul Then
    VarZ=Instr(Var$,"#")
    If VarZ Then
       VarZ2!=Int(Val(Mid$(Var$,VarZ+1)))
       Var$=Left$(Var$,VarZ-1)
    Endif
 Endif
 For Var2=2 To Lof(HelpFile1)/HelpRecLen1
    TempX=False
    Call Read.Helpfile(HelpFile1,Var2)
    Var2$=HelpRecord1.CName
    Var2$=Rtrim$(Var2$)
    Var2$=Ucase$(Var2$)
    Strng=HelpRecord1.Text
    Strng=Rtrim$(Strng)
    Strng=Ltrim$(Strng)
    Strng=Ucase$(Strng)
    If Lost.Carrier Then
       Exit For
    Endif
    If Break Then
       Exit For
    Endif
    Call InstrSUB(VarX,Strng,Var$)
    If VarX Then
       VarZ1!=VarZ1!+1!
       If VarZ2!=0! Or VarZ1!=VarZ2! Then
          TempX=True
       Endif
    Endif
    If TempX Then
       If Var2$<>Var3$ Then
          If Left$(Var2$,8)<>"CONTENTS" Then
             Var3$=Var2$
             Stored.Parsed.Command1=Var2$
             Call Read.Help2
	     Var1=True
             If No Or Quit Then
                Exit For
             Endif
	  Endif
       Endif
    Endif
 Next
 Graphics.Off=False
 If Var1=False Then
    Strng="No help found for '"+Lcase$(Var$)+"'."
    Call IO.O
 Endif
 Allow.Break=False
ErrExit98:
 Exit Sub
ErrResume98:
 Resume ErrExit98
End Sub

Sub Print.Help
 On Local Error Goto ErrResume98a
 Var$=Out2
 Var$=Rtrim$(Var$)
 Var$=Ucase$(Var$)
 Strng="Printer port(1-3)? "
 Call IO.I
 VarP=Int(Val(Out2))
 If VarP>=1 And VarP<=3 Then
    Close #TempFile1
    VarP$="LPT"+Mid$(Str$(VarP),2)+":"
    Open VarP$ For Output As #TempFile1
    Var1=False
    Var3$=Nul
    VarZ1!=0!
    VarZ2!=0!
    If Var$<>Nul Then
       VarZ=Instr(Var$,"#")
       If VarZ Then
          VarZ2!=Int(Val(Mid$(Var$,VarZ+1)))
          Var$=Left$(Var$,VarZ-1)
       Endif
    Endif
    For Var2=2 To Lof(HelpFile1)/HelpRecLen1
       Call Read.Helpfile(HelpFile1,Var2)
       Var2$=HelpRecord1.CName
       Var2$=Rtrim$(Var2$)
       Var2$=Ucase$(Var2$)
       Strng=HelpRecord1.Text
       Strng=Rtrim$(Strng)
       Strng=Ltrim$(Strng)
       Strng=Ucase$(Strng)
       Call InstrSUB(VarX,Strng,Var$)
       If VarX Then
          VarZ1!=VarZ1!+1!
          If VarZ2!=0! Or VarZ1!=VarZ2! Then
             TempX=True
          Endif
       Endif
       If TempX Then
          If Var2$<>Var3$ Then
             If Left$(Var2$,8)<>"CONTENTS" Then
                Var3$=Var2$
                Stored.Parsed.Command1=Var2$
                Call Print.Item
                Var1=True
             Endif
          Endif
       Endif
    Next
    Graphics.Off=False
    If Var1=False Then
       Strng="No help found for '"+Lcase$(Var$)+"'."
       Call IO.O
    Endif
 Endif
ErrExit98a:
 Close #TempFile1
 Exit Sub
ErrResume98a:
 Resume ErrExit98a
End Sub
