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

 On Error Goto ErrMain0
 Stack 4096
 Call Stdin(Var)
 If Chained=False Then
    If Chained2=False Then
       Call Open.Arrays
       Call Get.Config
       Call Increase.Files
       Call Make.FileNames
       Call Reset.Cursor
       Call Detect.Share
       Call Save.Screen(0)
    Endif
 Endif
 Call Open.Files
 If Chained2=False Then
    Call Passwrd6(Var)
    If Var=False Then
       Call Terminate.Program2
       End
    Endif
 Endif
 Call Edit.Status.Line
 Chained2=False
 No.Echo=False
 Carriage.Input=False
 Carriage.Return=False
 If Shell.Type Then
    Shell.Type=False
    If Local.Mode Then
       Call Console
    Endif
 Endif
 Do While Lost.Carrier=False
    Graphics.Off=False
    If TempC=False Then
       Strng="Edit utility v"+Left$(Version$,4)+" menu:"
       Call IO.O
    Endif
    Graphics.Off=True
    If TempC=False Then
       If Dir$(DND.Path+"editcmd1.exe")=Nul Then
          Strng="[*]ction"
       Else
          Strng=RT$(1,"[A]")+"ction"
       Endif
       If Dir$(DND.Path+"editcmd8.exe")=Nul Then
          Strng=Strng+"           [*]bject"
       Else
          Strng=Strng+"           "+RT$(10,"[O]")+"bject"
       Endif
       Call IO.O
       If Dir$(DND.Path+"editcmd2.exe")=Nul Then
          Strng="[*]ontainer"
       Else
          Strng=RT$(2,"[C]")+"ontainer"
       Endif
       If Dir$(DND.Path+"editcmd9.exe")=Nul Then
          Strng=Strng+"        [*]layer"
       Else
          Strng=Strng+"        "+RT$(11,"[P]")+"layer"
       Endif
       Call IO.O
       If Dir$(DND.Path+"editcmd3.exe")=Nul Then
          Strng=RT$(3,"[*]")+"mail"
       Else
          Strng=RT$(3,"[E]")+"mail"
       Endif
       Strng=Strng+"            [Q]uit"
       Call IO.O
       Temp1=True
       If Dir$(DND.Path+"editcmdg.exe")=Nul Then
          Temp1=False
       Endif
       Temp2=False
       If Local.Mode Then
          Temp2=True
          FileName=Rtrim$(Inline.FileName1)
          If FileName="" Then
             Temp2=False
          Else
             If Dir$(FileName)=Nul Then
                Temp2=False
             Endif
          Endif
       Endif
       If Temp1 Or Temp2 Then
          Strng=RT$(4,"[F]")+"ile editor"
       Else
          Strng="[*]ile editor"
       Endif
       If Dir$(DND.Path+"editcmd4.exe")=Nul Then
          Strng=Strng+"      [*]oom"
       Else
          Strng=Strng+"      "+RT$(13,"[R]")+"oom"
       Endif
       Call IO.O
       If Dir$(DND.Path+"editcmdd.exe")=Nul Then
          Strng="[*]elp"
       Else
          Strng=RT$(5,"[H]")+"elp"
       Endif
       If Dir$(DND.Path+"editcmdb.exe")=Nul Then
          Strng=Strng+"             [*]pell"
       Else
          Strng=Strng+"             "+RT$(14,"[S]")+"pell"
       Endif
       Call IO.O
       Temp1=True
       If Dir$(DND.Path+"dndsic.exe")=Nul Then
          Temp1=False
       Endif
       Temp2=False
       If Local.Mode Then
          Temp2=True
          FileName=Rtrim$(Inline.FileName2)
          If FileName="" Then
             Temp2=False
          Else
             If Dir$(FileName)=Nul Then
                Temp2=False
             Endif
          Endif
       Endif
       If Temp1 Or Temp2 Then
          Strng=RT$(6,"[I]")+"nterpreter"
       Else
          Strng="[*]nterpreter"
       Endif
       If Dir$(DND.Path+"editcmdc.exe")=Nul Then
          Strng=Strng+"      [*]reasure"
       Else
          Strng=Strng+"      "+RT$(15,"[T]")+"reasure"
       Endif
       Call IO.O
       If Dir$(DND.Path+"editcmd5.exe")=Nul Then
          Strng="[*]ink"
       Else
          Strng=RT$(7,"[L]")+"ink"
       Endif
       If Dir$(DND.Path+"editcmda.exe")=Nul Then
          Strng=Strng+"             [*]ser"
       Else
          Strng=Strng+"             "+RT$(16,"[U]")+"ser"
       Endif
       Call IO.O
       If Dir$(DND.Path+"editcmd6.exe")=Nul Then
          Strng="[*]onster"
       Else
          Strng=RT$(8,"[M]")+"onster"
       Endif
       Strng=Strng+"          "+RT$(17,"[1]")+"Utilities"
       Call IO.O
       If Dir$(DND.Path+"editcmd7.exe")=Nul Then
          Strng="[*]onplayer"
       Else
          Strng=RT$(9,"[N]")+"onplayer"
       Endif
       If Local.Mode Then
          Strng=Strng+"        "+RT$(18,"[2]")+"Console"
       Else
          Strng=Strng+"        [*]Console"
       Endif
       Call IO.O
       Graphics.Off=False
    Endif
    Strng="Edit option(q to quit)? "
    Allow.Break=True
    Break=False
    Line.Length=TempD
    No.Input.Out="Q"
    Call IO.I
    Allow.Break=False
    If Break Then
       Break=False
       Call IO.O
       Exit Do
    Endif
    Select Case Ucase$(Out2)
    Case "A"
       If RT$(1,"[A]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Chain.Program("EDITCMD1.EXE")
       Endif
    Case "C"
       If RT$(2,"[C]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Chain.Program("EDITCMD2.EXE")
       Endif
    Case "E"
       If RT$(3,"[E]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Chain.Program("EDITCMD3.EXE")
       Endif
    Case "F"
       If RT$(4,"[F]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Temp1=False ' editcmdg.exe exists
          Temp2=False ' edit.com exists
          If Dir$(DND.Path+"editcmdg.exe")<>Nul Then
             Temp1=True
          Endif
          FileName=Rtrim$(Inline.FileName1)
          If FileName<>"" Then
             If Dir$(FileName)<>Nul Then
                Temp2=True
             Endif
          Endif
          VarX=0
          If Local.Mode Then
             If Temp1 Then
                Line.Length=TempD
                Strng="Use inline editor(y/n)? "
                Call IO.I
                If Yes Then
                   Call Chain.Program("EDITCMDG.EXE")
                   VarX=-1
                Endif
             Endif
             If Temp2 Then
                Close
                Shell FileName
                Call Open.Files
                VarX=-1
             Endif
          Else
             If Temp1 Then
                Call Chain.Program("EDITCMDG.EXE")
                VarX=-1
             Endif
          Endif
          If VarX=0 Then
             Strng="Utility not called."
             Call IO.O
          Endif
       Endif
    Case "H"
       If RT$(5,"[H]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Chain.Program("EDITCMDD.EXE")
       Endif
    Case "I"
       If RT$(6,"[I]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Temp1=False ' dndsic.exe exists
          Temp2=False ' qbasic.exe exists
          If Dir$(DND.Path+"dndsic.exe")<>Nul Then
             Temp1=True
          Endif
          FileName=Rtrim$(Inline.FileName2)
          If FileName<>"" Then
             If Dir$(FileName)<>Nul Then
                Temp2=True
             Endif
          Endif
          VarX=0
          If Local.Mode Then
             If Temp1 Then
                Line.Length=TempD
                Strng="Use inline interpreter(y/n)? "
                Call IO.I
                If Yes Then
                   TempX$=Nul
                   Gosub Get.Account
                   Call Chain.Program("DNDSIC.EXE")
                   VarX=-1
                Endif
             Endif
             If Temp2 Then
                Close
                Shell FileName
                Call Open.Files
                VarX=-1
             Endif
          Else
             If Temp1 Then
                TempX$=Nul
                Gosub Get.Account
                Call Chain.Program("DNDSIC.EXE")
                VarX=-1
             Endif
          Endif
          If VarX=0 Then
             Strng="Utility not called."
             Call IO.O
          Endif
       Endif
    Case "L"
       If RT$(7,"[L]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Chain.Program("EDITCMD5.EXE")
       Endif
    Case "M"
       If RT$(8,"[M]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Chain.Program("EDITCMD6.EXE")
       Endif
    Case "N"
       If RT$(9,"[N]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Chain.Program("EDITCMD7.EXE")
       Endif
    Case "O"
       If RT$(10,"[O]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Chain.Program("EDITCMD8.EXE")
       Endif
    Case "P"
       If RT$(11,"[P]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Chain.Program("EDITCMD9.EXE")
       Endif
    Case "R"
       If RT$(13,"[R]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Chain.Program("EDITCMD4.EXE")
       Endif
    Case "S"
       If RT$(14,"[S]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Chain.Program("EDITCMDB.EXE")
       Endif
    Case "T"
       If RT$(15,"[T]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Chain.Program("EDITCMDC.EXE")
       Endif
    Case "U"
       If RT$(16,"[U]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Chain.Program("EDITCMDA.EXE")
       Endif
    Case "1"
       If RT$(17,"[1]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Utilities
       Endif
    Case "2"
       If Local.Mode Then
          If RT$(18,"[2]")="[*]" Then
             Strng="Command restricted.."
             Call IO.O
          Else
             Call Console
          Endif
       Else
          Strng="Console utilities only!"
          Call IO.O
       Endif
    Case "Q"
       Exit Do
    End Select
 Loop
 Call Terminate.Program2
 End
Get.Account:
 TempX$=Nul
 If Sysop Or Local.Mode Then
    No.Input.Out="N"
    Strng="Override sic account(y/n)?"
    Call IO.I
    If Yes Then
       Do While Lost.Carrier=0
          Strng="Enter account:"
          Call IO.I
          Out2=Ltrim$(Rtrim$(Out2))
          If Out2=Nul Then Exit Do
          If Len(Out2)=8 Then
             TempX$=Ucase$(Out2)
             Exit Do
          Else
             Strng="Account must be 8 chars.."
             Call IO.O
          Endif
       Loop
    Endif
 Endif
 Return
MainExit0:
 End
ErrMain0:
 Resume MainExit0

Sub Utilities
 On Local Error Goto ErrMain0a
 Do While Lost.Carrier=False
    Graphics.Off=False
    Strng="Edit utility menu:"
    Call IO.O
    Graphics.Off=True
    If TempC=False Then
       Strng=RT$(555,"[H]")+"otkeys"
       Call IO.O
       Strng=RT$(556,"[P]")+"references"
       Call IO.O
       Strng=RT$(557,"[S]")+"hort menus"
       Call IO.O
    Endif
    Graphics.Off=False
    Line.Length=TempD
    No.Input.Out="Q"
    Strng="Enter utility option(q to quit)? "
    Allow.Break=True
    Break=False
    Call IO.I
    Allow.Break=False
    If Break Then
       Break=False
       Call IO.O
       Exit Do
    Endif
    Out3=Out2
    Select Case Ucase$(Out2)
    Case "H"
       If RT$(555,"[H]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          No.Input.Out="N"
          Line.Length=TempD
          Strng="Use hotkeys(y/n)? "
          Call IO.I
          TempD=Abs(Yes)
          If Yes Then
             Strng="Hotkeys more than 1 char(y/n)? "
             No.Input.Out="N"
             Line.Length=TempD
             Call IO.I
             If Yes Then
                Strng="Length of hotkey? "
                Call IO.I
                If Int(Val(Out2)+.5)>1 Then
                   TempD=Int(Val(Out2)+.5)
                   Strng="Hotkey length set to"+Str$(TempD)+" chars."
                   Call IO.O
                Endif
             Endif
          Endif
       Endif
    Case "S"
       If RT$(557,"[S]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          No.Input.Out="N"
          Line.Length=TempD
          Strng="Short menus(y/n)? "
          Call IO.I
          TempC=Yes
       Endif
    Case "P"
       If RT$(556,"[P]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Do While Lost.Carrier=False
             If TempC=False Then
                Graphics.Off=False
                Strng="Preference menu:"
                Call IO.O
                Graphics.Off=True
                Strng=RT$(558,"[1]")+"Ansi"
                If Local.Mode Then
                   If Local.ANSI.Color Then
                      Strng=Strng+" (on)"
                   Else
                      Strng=Strng+" (off)"
                   Endif
                Else
                   If Remote.ANSI.Color Then
                      Strng=Strng+" (on)"
                   Else
                      Strng=Strng+" (off)"
                   Endif
                Endif
                Call IO.O
                Strng=RT$(559,"[2]")+"Avatar"
                If Local.Mode Then
                   If Local.Avatar.Color Then
                      Strng=Strng+" (on)"
                   Else
                      Strng=Strng+" (off)"
                   Endif
                Else
                   If Remote.Avatar.Color Then
                      Strng=Strng+" (on)"
                   Else
                      Strng=Strng+" (off)"
                   Endif
                Endif
                Call IO.O
                Strng=RT$(560,"[3]")+"Echo"
                If User.Echo=False Then
                   Strng=Strng+" (on)"
                Else
                   Strng=Strng+" (off)"
                Endif
                Call IO.O
                Strng=RT$(561,"[4]")+"Linefeeds"
                If User.Linefeeds=False Then
                   Strng=Strng+" (on)"
                Else
                   Strng=Strng+" (off)"
                Endif
                Call IO.O
                Strng=RT$(562,"[5]")+"Linelength
                Strng=Strng+" ("+Mid$(Str$(User.Linelength),2)+")"
                Call IO.O
                Strng=RT$(563,"[6]")+"Pagelength"
                Strng=Strng+" ("+Mid$(Str$(User.Pagelength),2)+")"
                Call IO.O
                Strng=RT$(564,"[7]")+"Wordwrap"
                If User.WordWrap=False Then
                   Strng=Strng+" (on)"
                Else
                   Strng=Strng+" (off)"
                Endif
                Call IO.O
             Endif
             Graphics.Off=False
             Line.Length=TempD
             No.Input.Out="Q"
             Strng="Enter preference selection(1-7, Q to quit)? "
             Allow.Break=True
             Break=False
             Call IO.I
             Allow.Break=False
             If Break Then
                Break=False
                Call IO.O
                Exit Do
             Endif
             Var$=Nul
             Temp=Int(Val(Out2)+.5)
             If Ucase$(Out2)="Q" Then
                Exit Do
             Endif
             Select Case Temp
             Case 1
                If RT$(558,"[1]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   Do While Lost.Carrier=False
                      Strng="Use ANSI color(y/n/h)? "
                      No.Input.Out="H"
                      Line.Length=TempD
                      Call IO.I
                      Select Case Ucase$(Out2)
                      Case "H"
                         Call Logon.Help(1)
                      Case "Y"
                         If Local.Mode Then
                            Local.ANSI.Color=True
                         Else
                            Remote.ANSI.Color=True
                         Endif
                         Strng="ANSI codes enabled."
                         Exit Do
                      Case "N"
                         If Local.Mode Then
                            If Local.ANSI.Color Then
                               Call ScreenANSI(1,37,0)
                               Local.ANSI.Color=False
                            Endif
                         Else
                            If Remote.ANSI.Color Then
                               Call Modem.ANSI(1,37,0)
                               Remote.ANSI.Color=False
                            Endif
                         Endif
                         Strng="ANSI codes disabled."
                         Exit Do
                      End Select
                   Loop
                   Call IO.O
                Endif
             Case 2
                If RT$(559,"[2]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   Do While Lost.Carrier=False
                      Strng="Use Avatar codes(y/n/h)? "
                      No.Input.Out="H"
                      Line.Length=TempD
                      Call IO.I
                      Select Case Ucase$(Out2)
                      Case "H"
                         Call Logon.Help(2)
                      Case "Y"
                         If Local.Mode Then
                            Local.Avatar.Color=True
                         Else
                            Remote.Avatar.Color=True
                         Endif
                         Strng="Avatar codes enabled."
                         Exit Do
                      Case "N"
                         If Local.Mode Then
                            If Local.Avatar.Color Then
                               Call ScreenANSI(1,37,0)
                               Local.Avatar.Color=False
                            Endif
                         Else
                            If Remote.Avatar.Color Then
                               Call Modem.ANSI(1,37,0)
                               Remote.Avatar.Color=False
                            Endif
                         Endif
                         Strng="Avatar codes disabled."
                         Exit Do
                      End Select
                   Loop
                   Call IO.O
                Endif
             Case 3
                If RT$(560,"[3]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   User.Echo=Not User.Echo
                Endif
             Case 4
                If RT$(561,"[4]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   User.Linefeeds=Not User.Linefeeds
                Endif
             Case 5
                If RT$(562,"[5]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   Strng="Linelength(40, 80)? "
                   Call IO.I
                   Var=Int(Val(Out2)+.5)
                   Select Case Var
                   Case 40
                      User.Linelength=40
                   Case 80
                      User.Linelength=80
                   End Select
                Endif
             Case 6
                If RT$(563,"[6]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   Strng="Pagelength(25, 43, 50)? "
                   Call IO.I
                   Var=Int(Val(Out2)+.5)
                   Select Case Var
                   Case 25
                      User.Pagelength=25
                   Case 43 
                      User.Pagelength=43
                   Case 50
                      User.Pagelength=50
                   End Select
                Endif
             Case 7
                If RT$(564,"[7]")="[*]" Then
                   Strng="Command restricted.."
                   Call IO.O
                Else
                   User.WordWrap=Not User.WordWrap
                Endif
             End Select
          Loop
       Endif
    Case "Q"
       Exit Do
    End Select
 Loop
MainExit0a:
 Exit Sub
ErrMain0a:
 Resume MainExit0a
End Sub

Sub Console
 On Local Error Goto ErrMain0b
 Do While Lost.Carrier=False
    Graphics.Off=False
    Strng="Console utility menu:"
    Call IO.O
    Graphics.Off=True
    If TempC=False Then
       If Dir$(DND.Path+"dndpack.exe")=Nul Then
          Strng="[*]ack files"
       Else
          Strng=RT$(565,"[P]")+"ack files"
       Endif
       Call IO.O
       If Dir$(DND.Path+"dndutil.exe")=Nul Then
          Strng="[*]un utility program"
       Else
          Strng=RT$(566,"[R]")+"un utility program"
       Endif
       Call IO.O
       If Dir$(DND.Path+"editcmde.exe")=Nul Then
          Strng="[*]ic edit"
       Else
          Strng=RT$(567,"[S]")+"ic edit"
       Endif
       Call IO.O
       If Dir$(DND.Path+"editcmdf.exe")=Nul Then
          Strng="[*]sage counter"
       Else
          Strng=RT$(568,"[U]")+"sage counter"
       Endif
       Call IO.O
       Strng=RT$(569,"[V]")+"iew text file"
       Call IO.O
       Strng=RT$(570,"[1]")+"Dos shell"
       Call IO.O
       Strng=RT$(571,"[2]")+"Dos command"
       Call IO.O
       Strng=RT$(572,"[3]")+"Spawn process"
       Call IO.O
    Endif
    Graphics.Off=False
    Line.Length=TempD
    No.Input.Out="Q"
    Strng="Enter utility option(q to quit)? "
    Allow.Break=True
    Break=False
    Call IO.I
    Allow.Break=False
    If Break Then
       Break=False
       Call IO.O
       Exit Do
    Endif
    Out3=Out2
    Select Case Ucase$(Out2)
    Case "1"
       If RT$(570,"[1]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Clear.Status.Line
          Graphics.Off=True
          Strng="Type 'EXIT' to return to Edit.."
          Call IO.O
          Call Shell.Program("")
          Call Edit.Status.Line
       Endif
    Case "2"
       If RT$(571,"[2]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Call Clear.Status.Line
          Graphics.Off=True
          Strng="Enter DOS command: "
          Call IO.I
          Var$=Out2
          Close #TempFile1
          Open DOS.Exit For Output Shared As #TempFile1
          Print #TempFile1,Var$
          Print #TempFile1,"PAUSE"
          Print #TempFile1,"EXIT"
          Close #TempFile1
          Call Shell.Program(DOS.Exit)
          Call Edit.Status.Line
       Endif
    Case "3"
       If RT$(572,"[3]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Var=True
          If Var Then
             Var$=Nul
             Var2$=Nul
             Do While Lost.Carrier=False
                Graphics.Off=False
                Strng="Enter program/data file to spawn:"
                Call IO.O
                Graphics.Off=True
                If TempC=False Then
                   Strng=RT$(573,"[1]")+"Calc"
                   Call IO.O
                   Strng=RT$(574,"[2]")+"Notepad"
                   Call IO.O
                   Strng=RT$(575,"[3]")+"Other file"
                   Call IO.O
                   Strng=RT$(576,"[P]")+"Path for file: "
                   If Var2$=Nul Then
                      Strng=Strng+"<path>"
                   Else
                      Strng=Strng+Var2$
                   Endif
                   Call IO.O
                Endif
                Graphics.Off=False
                No.Input.Out="Q"
                Line.Length=TempD
                Strng="Selection(1,2,3,P=Path,Q=Quit)? "
                Call IO.I
                Select Case Lcase$(Out2)
                Case "1"
                   If RT$(573,"[1]")="[*]" Then
                      Strng="Command restricted.."
                      Call IO.O
                   Else
                      Var$="calc.exe"
                      Gosub Start.Program
                   Endif
                Case "2"
                   If RT$(574,"[2]")="[*]" Then
                      Strng="Command restricted.."
                      Call IO.O
                   Else
                      Var$="notepad.exe"
                      Gosub Start.Program
                   Endif
                Case "3"
                   If RT$(575,"[3]")="[*]" Then
                      Strng="Command restricted.."
                      Call IO.O
                   Else
                      Strng="Enter filename:"
                      Call IO.I
                      Var$=Out2
                      Gosub Start.Program
                   Endif
                Case "p"
                   If RT$(576,"[P]")="[*]" Then
                      Strng="Command restricted.."
                      Call IO.O
                   Else
                      Strng="Enter path:"
                      Call IO.I
                      Var2$=Out2
                   Endif
                Case "q"
                   Var$=Nul
                   Exit Do
                End Select
             Loop
          Endif
       Endif
    Case "P"
       If RT$(565,"[P]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          If Dir$(DND.Path+"dndpack.exe")<>Nul Then
             Call Clear.Status.Line
             Call Shell.Program("DNDPACK.EXE")
             Call Edit.Status.Line
             Strng="Files packed."
             Call IO.O
          Endif
       Endif
    Case "R"
       If RT$(566,"[R]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          If Dir$(DND.Path+"dndutil.exe")<>Nul Then
             Call Clear.Status.Line
             Call Shell.Program("DNDUTIL.EXE /L")
             Call Edit.Status.Line
             Strng="Files written."
             Call IO.O
          Endif
       Endif
    Case "S"
       If RT$(567,"[S]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Shell.Type=True
          Call Chain.Program("EDITCMDE.EXE")
       Endif
    Case "U"
       If RT$(568,"[U]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Shell.Type=True
          Call Chain.Program("EDITCMDF.EXE")
       Endif
    Case "V"
       If RT$(569,"[V]")="[*]" Then
          Strng="Command restricted.."
          Call IO.O
       Else
          Strng="Enter text filename: "
          Call IO.I
          If Len(Out2) Then
             Call Out.File(Out2)
          Endif
       Endif
    Case "Q"
       Exit Do
    End Select
 Loop
 Exit Sub
Start.Program:
 If Var$<>Nul Then
    If Var2$<>Nul Then
       If Right$(Var2$,1)<>"\" Then
          Var2$=Var2$+"\"
       Endif
    Endif
    Var3$="start.exe "+Var2$+Var$
    Strng="Starting: "+Chr$(34)+Var3$+Chr$(34)
    Call IO.O
    Call Shell.Program(Var3$)
 Endif
 Return
MainExit0b:
 Exit Sub
ErrMain0b:
 Resume MainExit0b
End Sub

Sub Logon.Help(VarY)
 On Local Error Goto ErrMain43
 Close #HelpFile3
 FileName=Logon.Help.FileName
 Open FileName For Random Shared As #HelpFile3 Len=HelpRecLen3
 Graphics.Off=True
 Strng=Nul
 Call IO.O
 Select Case VarY
 Case 1
    VarA=2
    VarB=4
 Case 2
    VarA=39
    VarB=42
 End Select
 For VarC=VarA To VarB
    If VarC<=Lof(HelpFile3)/HelpRecLen3 Then
       Call Read.Helpfile(HelpFile3,VarC)
       Strng=Space$(3)+Rtrim$(HelpRecord3.Text)
       Call IO.O
    Endif
 Next
 Call IO.O
 Call More.Prompt
 Graphics.Off=False
MainExit43:
 Exit Sub
ErrMain43:
 Resume MainExit43
End Sub

Sub Shell.Program(Var$)
 On Local Error Goto Shell.Error
 Call Clear.Status.Line
 Var2$=Curdir$
 Close
 Color 7,0
 Call ScreenANSI(1,37,7)
 If Var$=Nul Then
    Shell
 Else
    Shell Var$
 Endif
Shell.Return:
 Chdrive Var2$
 Chdir Var2$
 Call Reset.Cursor
 If Chained=False Then
    If Chained2=False Then
       Call Get.Config
       Call Make.FileNames
    Endif
 Endif
 Call Open.Files
 Call Edit.Status.Line
 Exit Sub
Shell.Error:
 Color 14,0
 Print
 Print "Error shelling to "+Lcase$(FileName)
 Print "Increase files= in config.sys or config.nt, or run Dndcnfg."
 Resume Shell.Return
End Sub

Sub Terminate.Program2
 On Local Error Goto ErrMain42
 Call Clear.Status.Line
 If Chained Then
    Chain DND.Path+"DNDBBS.EXE"
 Endif
 Color 15,0
 Call ScreenANSI(1,37,7)
 Cls
 Call ScreenANSI(3,0,0)
 Call Save.Screen(-1)
' Locate Max.Row,1,1
 If TempX=0 Then TempX=1
 Locate TempX,1,1
 If Local.Mode Then
    Color 15,0
    Print
    Print "Now exiting the Dndbbs Menu Editor.."
    Color 7,0
 Endif
 Call Decrease.Files
MainExit42:
 End 0
ErrMain42:
 Resume MainExit42
End Sub

Sub Chain.Program(Var$)
 On Local Error Goto ErrMain44
 Var2$=DND.Path+Var$
 If Dir$(Var2$)<>Nul Then
    Chained2=True
    Chain Var2$
 Endif
MainExit44:
 Exit Sub
ErrMain44:
 Strng="Error chaining to: "+Var2$
 Call IO.O
 Resume MainExit44
End Sub

Sub Save.Screen(Var)
 On Local Error Goto Error.Trap62
 If Var=False Then
    VarX3=(Max.Row-1)*80+80
    Redim Temp.ArrayY(VarX3) As Long
    Redim Temp.ArrayZ(VarX3) As Double
    For Var1=1 To Max.Row
       For Var2=1 To 80
          TempZ1=Screen(Var1,Var2)
          TempZ2=Screen(Var1,Var2,1)
          VarX2=(Var1-1)*80+Var2
          Temp.ArrayY(VarX2)=TempZ1
          Temp.ArrayZ(VarX2)=TempZ2
       Next
    Next
 Else
    Cls
    For VarX=Max.Row To 1 Step -1
       For VarY=1 To 80
          VarX2=(VarX-1)*80+VarY
          If Temp.ArrayY(VarX2)<>32 Then
             Goto Next.Line
          Endif
       Next
    Next
Next.Line:
    TempX=VarX
    For Var1=1 To VarX ' Max.Row
       For Var2=1 To 80
          VarX2=(Var1-1)*80+Var2
          VarB=Int(Temp.ArrayZ(VarX2)/16)
          VarF=Temp.ArrayZ(VarX2) Mod 16
          TempZ1=Temp.ArrayY(VarX2)
          Locate Var1,Var2,0
          Color VarF,VarB
          Print Chr$(TempZ1);
       Next
    Next
 Endif
Error.Resume62:
 Exit Sub
Error.Trap62:
 Resume Error.Resume62
End Sub
