 Rem File: Cmd999.bas
 Rem Sub: Main.Loop.Update
 Rem $Include: 'dndbbs.inc'
 On Error Goto Main.Error
 If Chained=0 Then
    Color 15,0
    Print "DNDBBS Command 999 -- Main.Loop.Update. (Sub 1)."
    Color 7,0
    End
 Endif

 ' chain to subprogram
 If Chained=-3 Then
    Eat$=Nul
 Else
    Chained=-3
    Gosub Get.Config2
    FileName=Option1$+"CMD998.EXE"
    If Dir$(FileName)<>"" Then
       Chain FileName
    Endif
 Endif
 Chained=-2

 ' get config settings
 Gosub Get.Config

 ' update system
 If (New.Mail.Count Mod Option0) = 0 Then
    Call Main.Loop.Update
 Endif

Main.Resume:
 Chain DND.Path+"DNDBBS.EXE"
 End

Main.Error:
 Resume Main.Resume

Get.Config2:
 VarX$="CMD998"
 Option1$=DND.Path
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[RAMDRIVE]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          If Ucase$(Var$)="[END]" Then
             Return
          Endif
          VarZ=Instr(Var$,"=")
          If VarZ Then
             Var2$=Ltrim$(Rtrim$(Left$(Var$,VarZ-1)))
             Var3$=Ltrim$(Rtrim$(Mid$(Var$,VarZ+1)))
             If Ucase$(Var2$)=VarX$ Or Ucase$(Var2$)="CMD*" Then
                ' force cmd module to ramdrive
                If Var3$="-1" Then
                   Option1$=Data.Path3
                Else
                   Var3$=Ucase$(Var3$)
                   If Len(Var3$) Then
                      If Left$(Var3$,1)>="A" And Left$(Var3$,1)<="Z" Then
                         Select Case Len(Var3$)
                         Case 1
                            Option1$=Var3$+":\"
                         Case 2
                            If Right$(Var3$,1)=":" Then
                               Option1$=Var3$+"\"
                            Endif
                         Case 3
                            If Right$(Var3$,2)=":\" Then
                               Option1$=Var3$
                            Endif
                         End Select
                      Endif
                   Endif
                Endif
             Endif
          Endif
       Loop
    Endif
 Loop
 Return

Get.Config:
 option0=4
 VarX=0
 Do
    VarX=VarX+1
    If VarX>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
    If Ucase$(Var$)="[CMD999]" Then
       Do
          VarX=VarX+1
          If VarX>Options.Lines Then
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX)))
          If Ucase$(Var$)="[END]" Then
             Return
          Endif
          Var=Instr(Var$,"=")
          If Var Then
             Var2$=Ltrim$(Rtrim$(Left$(Var$,Var-1)))
             Var3$=Ltrim$(Rtrim$(Mid$(Var$,Var+1)))
             VarQ=Int(Val(Var3$)+.5)
             Select Case VarQ
             Case 1,2,4,8,16,32,64
                Select Case Lcase$(Var2$)
                Case "main.loop.update"
                   option0=VarQ
                End Select
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
