 Rem File: Cmd155.bas
 Rem Sub: Scrnedit
 Rem $Include: 'dndbbs.inc'
 On Error Goto Main.Error
 If Chained=False Then
    Call Open.Arrays
    Call Get.Config
    Call Increase.Files
    Call Make.FileNames
    Call Open.Files
    Call Reset.Cursor
    Call Detect.Share
    Call Read.Rows(Var)
    Max.Row=Var
    Call Save.Screen2(0)
 Endif
 Call Scrnedit
Main.Resume:
 Call Clear.Status.Line
 If Chained Then
    Chain DND.Path+"DNDBBS.EXE"
 Endif
 Call Terminate.Program
 End
Main.Error:
 Resume Main.Resume

Sub Scrnedit
 ON LOCAL ERROR GOTO Error.Trap72
 DIM LineX As String
 DIM VarX AS STRING * 1
 DIM VarY AS STRING * 1
 Dim Linux As Integer
 Gosub Get.Config2
 Call Edit.Status.Line
 If Chained=0 Then
    If Command$<>Nul Then
       FileName$=Nul
       Command.Line$=Command$
       V=Instr(Command.Line$,"/LINUX")
       If V Then
          Linux=-1
          Command.Line$=Left$(Command.Line$,V-1)+Mid$(Command.Line$,V+7)
       Endif
       Var1$=Nul
       If Right$(Command.Line$,1)=Chr$(34) Then
          Command.Line$=Left$(Command.Line$,Len(Command.Line$)-1)
          If Instr(Command.Line$,Chr$(34)) Then
             Command.Line$=Mid$(Command.Line$,Instr(Command.Line$,Chr$(34))+1)
             Var1$=Ltrim$(Rtrim$(Command.Line$))
          Endif
       Endif
       If Len(Var1$) Then
          Filename$=Var1$
          If Instr(Filename$,"?") Or Instr(Filename$,"*") Then
             Call Boot.Usage
             Exit Sub
          Endif
          OutX$ = Ltrim$(Rtrim$(FileName$))
          For V=Len(OutX$) To 1 Step -1
             If Mid$(OutX$,V,1)="\" Then
                OutX$=MId$(OutX$,V+1)
                Exit For
             Endif
          Next
          If Mid$(OutX$,2,1)=":" Then
             OutX$=Mid$(OutX$,3)
          Endif
          Goto 102
       Endif
    Endif
 Endif
101
 DO WHILE Lost.Carrier = False
    DO WHILE Lost.Carrier = False
       'Call Edit.Status.Line
       OutX$ = Nul
       Locate Max.Row-1,1,1
       Graphics.Off = False
       Strng = "Screen editor utility:"
       CALL IO.O
       Graphics.Off = True
       If option1 Then
          Strng = "[1]Catalog"
       Else
          Strng = "[*]Catalog"
       Endif
       CALL IO.O
       If option2 Then
          Strng = "[2]Logoff"
       Else
          Strng = "[*]Logoff"
       Endif
       CALL IO.O
       If option3 Then
          Strng = "[3]Notice"
       Else
          Strng = "[*]Notice"
       Endif
       CALL IO.O
       If option4 Then
          Strng = "[4]Prelog"
       Else
          Strng = "[*]Prelog"
       Endif
       CALL IO.O
       If option5 Then
          Strng = "[5]Welcome"
       Else
          Strng = "[*]Welcome"
       Endif
       CALL IO.O
       If Local.Mode Or Sysop Then
          If option6 Then
             Strng = "[6]Other"
          Else
             Strng = "[*]Other"
          Endif
          Call IO.O
       Endif
       Graphics.Off = False
       No.Input.Out = "Q"
       If Local.Mode Or Sysop Then
          Strng = "Enter option(1-6, Q to Quit)? "
       Else
          Strng = "Enter option(1-5, Q to Quit)? "
       Endif

       CALL Modem.ANSI(4, 37, 0)
       CALL ScreenANSI(4, 37, 0)

       CALL Modem.ANSI(4, 40, 15)
       CALL ScreenANSI(4, 40, 15)

       CALL IO.I
       SELECT CASE UCASE$(Out2)
       CASE "1"
          If option1 Then
             FileName = Catalog.FileName
             OutX$ = "Catalog"
          Endif
       CASE "2"
          If option2 Then
             FileName = Logoff.FileName
             OutX$ = "Logoff"
          Endif
       CASE "3"
          If option3 Then
             FileName = Notice.FileName
             OutX$ = "Notice"
          Endif
       CASE "4"
          If option4 Then
             FileName = Prelog.FileName
             OutX$ = "Prelog"
          Endif
       CASE "5"
          If option5 Then
             FileName = Welcome.FileName
             OutX$ = "Welcome"
          Endif
       Case "6"
          If Local.Mode Or Sysop Then
             If option6 Then
                Strng = "Filename: "
                Call IO.I
                If Len(Out2) Then
                   FileName = Out2
                   OutX$ = FileName
                   For V=Len(OutX$) To 1 Step -1
                      If Mid$(OutX$,V,1)="\" Then
                         OutX$=MId$(OutX$,V+1)
                         Exit For
                      Endif
                   Next
                   If Mid$(OutX$,2,1)=":" Then
                      OutX$=Mid$(OutX$,3)
                   Endif
                Endif
             Endif
          Endif
       CASE "Q"
          OutX$=Nul
          EXIT DO
       END SELECT
102
       If Linux=0 Then
          Strng = "Load file in Linux form(y/n)?"
          No.Input.Out="N"
          CALL IO.I
          IF Yes THEN
             Linux=-1
          Endif
       Endif

       Max.Lines = False
       Max.File = 1024
       REDIM Temp.ArrayS(1024) AS STRING
       IF LEN(OutX$) THEN
	  CLOSE #TempFile1
          IF DIR$(FileName) = Nul Then ' create file
             OPEN FileName FOR OUTPUT AS #TempFile1
          ELSE
             OPEN FileName FOR BINARY AS #TempFile1 ' read file in binary
             Var! = 0!
             LineX = Nul
             DO
                Var! = Var! + 1!
                IF Var! > LOF(TempFile1) THEN
                   If Len(LineX) Then
                      Max.Lines = Max.Lines + 1
                      IF Max.Lines > Max.File THEN
                         Max.File = Max.File + 1
                         Redim Preserve Temp.ArrayS(Max.File) AS STRING
                      END IF
                      Temp.ArrayS(Max.Lines) = LineX
                   Endif
                   EXIT DO
                END IF
                GET #TempFile1, Var!, VarX
                LineFeed = 0
                If Linux Then
                   IF VarX = CHR$(10) THEN
                      LineFeed=-1
                   END IF
                Endif
                IF VarX = CHR$(13) THEN
                   IF Var! + 1! <= LOF(TempFile1) THEN
                      GET #TempFile1, Var! + 1!, VarY
                      IF VarY = CHR$(10) THEN
                         Var! = Var! + 1!
                         LineFeed=-1
                      END IF
                   END IF
                END IF
                IF LineFeed THEN
                   Max.Lines = Max.Lines + 1
                   IF Max.Lines > Max.File THEN
                      Max.File = Max.File + 1
                      Redim Preserve Temp.ArrayS(Max.File) AS STRING
                   END IF
                   Temp.ArrayS(Max.Lines) = LineX
                   LineX = Nul
                ELSE
                   LineX = LineX + VarX
                END IF
             LOOP
          Endif
          Exit Do
       END IF
    LOOP
    If OutX$=Nul Then
       Exit Do
    Endif
    Xcoor = 1
    Ycoor = 1
    Column = 1
    Row = 1
    If Max.Lines = 0 Then
       Line.Number = 0
    Else
       Line.Number = 1
    Endif
    OutX$ = LCASE$(OutX$)
    MID$(OutX$, 1, 1) = UCASE$(MID$(OutX$, 1, 1))
    Graphics.Off = True
    GOSUB Display.Screen
    DO WHILE Lost.Carrier = False
       CALL Modem.ANSI(4, 33, 0)
       CALL ScreenANSI(4, 33, 0)

       CALL Modem.ANSI(4, 44, 30)
       CALL ScreenANSI(4, 44, 30)

       CALL Modem.ANSI(2, 24, 1)
       CALL ScreenANSI(2, 24, 1)

       V = Column + Ycoor - 1
       Var# = Cdbl(Line.Number)
       If Var# = 0# Then
          Var$ = " 0"
       Else
          Call Amount(Var#,Var$)
       Endif

       If V = 0 Then
          Var2$ = " 0"
       Else
          Call Amount(Cdbl(V),Var2$)
       Endif

       Strng = "Row" + Var$ + " Column" + Var2$

       If V > 0 And V <= Len(Temp.ArrayS(Line.Number)) Then
          V2 = Asc(Mid$(Temp.ArrayS(Line.Number), V, 1))
          Strng = Strng + " Ascii" + Str$(V2)

          Select Case V2
          Case 0
             Strng = Strng + " (nul)"
          Case 1
             Strng = Strng + " (soh)"
          Case 2
             Strng = Strng + " (stx)"
          Case 3
             Strng = Strng + " (etx)"
          Case 4
             Strng = Strng + " (eot)"
          Case 5
             Strng = Strng + " (enq)"
          Case 6
             Strng = Strng + " (ack)"
          Case 7
             Strng = Strng + " (bel)"
          Case 8
             Strng = Strng + " (bs)"
          Case 9
             Strng = Strng + " (tab)"
          Case 10
             Strng = Strng + " (lf)"
          Case 11
             Strng = Strng + " (vt)"
          Case 12
             Strng = Strng + " (np)"
          Case 13
             Strng = Strng + " (cr)"
          Case 14
             Strng = Strng + " (so)"
          Case 15
             Strng = Strng + " (si)"
          Case 16
             Strng = Strng + " (dle)"
          Case 17
             Strng = Strng + " (dc1)"
          Case 18
             Strng = Strng + " (dc2)"
          Case 19
             Strng = Strng + " (dc3)"
          Case 20
             Strng = Strng + " (dc4)"
          Case 21
             Strng = Strng + " (nak)"
          Case 22
             Strng = Strng + " (syn)"
          Case 23
             Strng = Strng + " (etb)"
          Case 24
             Strng = Strng + " (can)"
          Case 25
             Strng = Strng + " (em)"
          Case 26
             Strng = Strng + " (eof)"
          Case 27
             Strng = Strng + " (esc)"
          Case 28
             Strng = Strng + " (fs)"
          Case 29
             Strng = Strng + " (gs)"
          Case 30
             Strng = Strng + " (rs)"
          Case 31
             Strng = Strng + " (us)"
          Case 32
             Strng = Strng + " (spc)"
          Case 255
             Strng = Strng + " (?)"
          Case Else
             Strng = Strng + " (" + Chr$(V2) + ")"
          End Select
       Endif

       Strng = Left$(Strng, 41)
       Strng = Strng + SPACE$(41 - LEN(Strng))
       CALL Scrn.Output(Strng)

       CALL Modem.ANSI(4, 37, 0)
       CALL ScreenANSI(4, 37, 0)

       CALL Modem.ANSI(4, 40, 15)
       CALL ScreenANSI(4, 40, 15)

       CALL Modem.ANSI(2, Xcoor, Ycoor)
       CALL ScreenANSI(2, Xcoor, Ycoor)

       TempX$ = Nul
       StartTime2#=Timeit!
       DO WHILE TempX$ = Nul
	  IF Lost.Carrier THEN
             EXIT DO
          END IF
          RunTime2# = Timeit! - StartTime2#
          IF RunTime2# < 0# THEN RunTime2# = RunTime2# + 86400#
          IF RunTime2# >= 1# THEN
             StartTime2# = Timeit!
             Call Get.Cursor.Row(Var1)
             Call Get.Cursor(Var2)
             Call Edit.Status.Line
             Locate Var1,Var2,1
             Call Modem.ANSI(4,37,15)
             Call ScreenANSI(4,37,15)
          END IF
          CALL Read.ANSI.Input
          If TempX$ = Chr$(0) + Chr$(0) Then ' Control-Break
             Lost.Carrier=True
             Exit Do
          Endif
          If Len(TempX$)=1 Then
             Select Case TempX$
             Case Chr$(4) ' ^D = control-right
                TempX$ = Chr$(0) + Chr$(116)
             Case Chr$(6) ' ^F = control-left
                TempX$ = Chr$(0) + Chr$(115)
             Case Chr$(19) ' ^S = control-home
                TempX$ = Chr$(0) + Chr$(119)
             Case Chr$(24) ' ^X = control-end
                TempX$ = Chr$(0) + Chr$(117)
             Case Chr$(21) ' ^U = pageup
                TempX$ = Chr$(0) + Chr$(73)
             Case Chr$(14) ' ^N = pagedown
                TempX$ = Chr$(0) + Chr$(81)
             Case Chr$(22) ' ^V = insert
                TempX$ = Chr$(0) + Chr$(82)
             End Select
          Endif
       LOOP
       SELECT CASE LEN(TempX$)
       CASE 1
	  SELECT CASE TempX$
          CASE CHR$(13) ' insert line
             If Max.Lines = 0 Then
                Line.Number = 1
                Temp.ArrayS(1) = Nul
                Max.Lines = 1
             Else
                IF Max.Lines + 1 > Max.File THEN
                   Max.File = Max.File + 1
                   Redim Preserve Temp.ArrayS(Max.File) AS STRING
                END IF
                IF Max.Lines < Max.File THEN
                   ' above
                   IF Column + Ycoor - 1 = 1 THEN
                      FOR Temp1 = Max.Lines TO Line.Number STEP -1
                         Temp.ArrayS(Temp1 + 1) = Temp.ArrayS(Temp1)
                      NEXT
                      Temp.ArrayS(Line.Number) = Nul
                      Max.Lines = Max.Lines + 1
                      Line.Number = Line.Number + 1
                      IF Xcoor < 23 THEN
                         Xcoor = Xcoor + 1
                      END IF
                   ELSE
                      ' below
                      IF Column + Ycoor - 1 > LEN(Temp.ArrayS(Line.Number)) THEN
                         Line.Number = Line.Number + 1 ' below
                         FOR Temp1 = Max.Lines TO Line.Number STEP -1
                            Temp.ArrayS(Temp1 + 1) = Temp.ArrayS(Temp1)
                         NEXT
                         Temp.ArrayS(Line.Number) = Nul
                         Max.Lines = Max.Lines + 1
                         IF Xcoor < 23 THEN
                            Xcoor = Xcoor + 1
                         END IF
                      ELSE
                         ' split line
                         FOR Temp1 = Max.Lines TO Line.Number + 1 STEP -1
                            Temp.ArrayS(Temp1 + 1) = Temp.ArrayS(Temp1)
                         NEXT
                         T$ = Temp.ArrayS(Line.Number)
                         U$ = MID$(T$, Column + Ycoor - 1)
                         T$ = LEFT$(T$, Column + Ycoor - 2)
                         Temp.ArrayS(Line.Number) = T$
                         Line.Number = Line.Number + 1 ' below
                         Temp.ArrayS(Line.Number) = U$
                         Max.Lines = Max.Lines + 1
                         IF Xcoor < 23 THEN
                            Xcoor = Xcoor + 1
                         END IF
                      END IF
                   END IF
                END IF
             Endif
             Column = 1
             Ycoor = 1
             GOSUB Display.Screen
	  CASE CHR$(8) ' backspace
	     Q = Column + Ycoor - 1
             IF Line.Number <= 1 AND Q <= 1 THEN ' no backspace at 1,1
                Eat$ = Nul
	     ELSE
                ' remove current line
                IF Temp.ArrayS(Line.Number) = Nul THEN
                   ' pack array
                   FOR Temp1 = Line.Number TO Max.Lines - 1
                      Temp.ArrayS(Temp1) = Temp.ArrayS(Temp1 + 1)
                   NEXT
                   IF Xcoor > 1 THEN
                      Xcoor = Xcoor - 1
                   END IF
                   Line.Number = Line.Number - 1
                   Max.Lines = Max.Lines - 1
                   ' position at eol
                   End.Line = LEN(Temp.ArrayS(Line.Number))
                   IF End.Line >= 80 THEN
                      Column = End.Line - 78
                      Ycoor = End.Line - Column + 2
                   ELSE
                      Ycoor = End.Line - Column + 2
                   END IF
                   GOSUB Display.Screen
                ELSE
                   ' concatenate previous line
                   IF Column + Ycoor - 1 <= 1 THEN
                      IF Line.Number > 1 THEN
                         IF Line.Number <= Max.Lines THEN
                            Var=0
                            If Temp.ArrayS(Line.Number-1)=Nul Then
                               If Ycoor=1 Then
                                  Var=-1
                               Endif
                            Endif

                            ' position at eol
                            If Var=0 Then
                               End.Line = LEN(Temp.ArrayS(Line.Number-1))
                            Endif

                            Temp.ArrayS(Line.Number - 1) = Temp.ArrayS(Line.Number - 1) + Temp.ArrayS(Line.Number)
                            FOR Temp1 = Line.Number TO Max.Lines - 1
                               Temp.ArrayS(Temp1) = Temp.ArrayS(Temp1 + 1)
                            NEXT
                            If Xcoor > 1 Then
                               Xcoor = Xcoor - 1
                            Endif
                            Line.Number = Line.Number - 1
                            Max.Lines = Max.Lines - 1
                            Column = 1
                            Ycoor = 1

                            ' position at eol
                            If Var=0 Then
                               IF End.Line >= 80 THEN
                                  Column = End.Line - 78
                                  Ycoor = End.Line - Column + 2
                               ELSE
                                  Ycoor = End.Line - Column + 2
                               END IF
                            Endif

                            GOSUB Display.Screen
                         END IF
                     END IF
                  ELSE
                      ' backspace 1 character
                      IF Column + Ycoor - 2 > False THEN
                         T$ = Temp.ArrayS(Line.Number)
                         T$ = LEFT$(T$, Column + Ycoor - 3) + MID$(T$, Column + Ycoor - 1)
                         Temp.ArrayS(Line.Number) = T$
                         ' move cursor 1 left
                         IF Ycoor > 1 THEN
                            Ycoor = Ycoor - 1
                            GOSUB Display.Screen
                         ELSE
                            IF Column > 1 THEN
                               Column = Column - 1
                               GOSUB Display.Screen
                            END IF
                         END IF
                      END IF
                   END IF
                END IF
             END IF
	  CASE CHR$(9) ' tab
	     IF Column + Ycoor + 7 <= LEN(Temp.ArrayS(Line.Number)) THEN
                IF Ycoor + 8 < 80 THEN
		   Ycoor = Ycoor + 8
		ELSE
		   Column = Column + 8
		   GOSUB Display.Screen
		END IF
	     ELSE ' end
		End.Line = LEN(Temp.ArrayS(Line.Number))
                IF End.Line >= 80 THEN
                   Column = End.Line - 78
                   Ycoor = End.Line - Column + 2
                   GOSUB Display.Screen
                ELSE
                   Ycoor = End.Line - Column + 2
                END IF
	     END IF
	  CASE CHR$(27) ' escape, exit editor
	     EXIT DO
	  CASE ELSE ' insert character
             SELECT CASE ASC(TempX$)
             CASE 12, 32 TO 126
                If Line.Number > 0 Then
                   T$ = Temp.ArrayS(Line.Number)
                   T$ = LEFT$(T$, Column + Ycoor - 2) + TempX$ + MID$(T$, Column + Ycoor - 1)
                   Temp.ArrayS(Line.Number) = T$
                   IF Column + Ycoor - 1 <= LEN(Temp.ArrayS(Line.Number)) THEN
                      IF Ycoor < 80 THEN
                         Ycoor = Ycoor + 1
                         GOSUB Display.Screen
                      ELSE
                         Column = Column + 1
                         GOSUB Display.Screen
                      END IF
                   END IF
                Endif
             END SELECT
	  END SELECT
       CASE 2
	  Temp = ASC(MID$(TempX$, 2, 1))
	  SELECT CASE Temp
          CASE 0 ' ctrl-break, exit editor
	     EXIT DO
	  CASE 15 ' shift-tab
	     IF Column + Ycoor - 8 > False THEN
		IF Column + Ycoor - 7 > 1 THEN
		   Ycoor = Ycoor - 7
		ELSE
		   IF Column > 8 THEN
		      Column = Column - 7
		      GOSUB Display.Screen
		   END IF
		END IF
	     ELSE ' home
		IF Column > 1 THEN
		   Column = 1
		   Ycoor = 1
		   GOSUB Display.Screen
		ELSE
		   Column = 1
		   Ycoor = 1
		END IF
	     END IF
          CASE 83, 147 ' delete/control-delete
	     Q = Column + Ycoor - 1
             ' no delete at 1,1
             IF (Line.Number <= 1 AND Q < 1) OR Max.Lines < 1 THEN
                Eat$ = Nul
	     ELSE
                ' remove line
                IF Temp.ArrayS(Line.Number) = Nul THEN
                   IF Line.Number = 1 AND Max.Lines = 1 THEN ' 1,1
                      Eat$ = Nul
                   ELSE
                      ' pack array
                      FOR Temp1 = Line.Number TO Max.Lines - 1
                         Temp.ArrayS(Temp1) = Temp.ArrayS(Temp1 + 1)
                      NEXT
                      IF Line.Number = Max.Lines THEN
                         Line.Number = Line.Number - 1
                         IF Xcoor > 1 THEN
                            Xcoor = Xcoor - 1
                         END IF
                      END IF
                      Max.Lines = Max.Lines - 1
                      Column = 1
                      Ycoor = 1
                      GOSUB Display.Screen
                   END IF
                ELSE
                   ' delete line
                   IF LEN(Temp.ArrayS(Line.Number))<1 THEN
                      Temp.ArrayS(Line.Number) = Nul
                      GOSUB Display.Screen
                   ELSE
                      ' concatenate line
                      IF Column + Ycoor - 1 > LEN(Temp.ArrayS(Line.Number)) THEN
                         If Line.Number + 1 <= Max.Lines Then
                            T$ = Temp.ArrayS(Line.Number)
                            T$ = T$ + Temp.ArrayS(Line.Number + 1)
                            Temp.ArrayS(Line.Number) = T$

                            ' pack array
                            FOR Temp1 = Line.Number + 1 TO Max.Lines - 1
                               Temp.ArrayS(Temp1) = Temp.ArrayS(Temp1 + 1)
                            NEXT
                            Max.Lines = Max.Lines - 1

                            GOSUB Display.SCreen
                         Endif
                      ELSE
                         ' delete character
                         T$ = Temp.ArrayS(Line.Number)
                         T$ = LEFT$(T$, Column + Ycoor - 2) + MID$(T$, Column + Ycoor)
                         Temp.ArrayS(Line.Number) = T$
                         GOSUB Display.Screen
                      END IF
                   END IF
                END IF
             END IF
	  CASE 71 ' home
	     IF Column > 1 THEN
		Column = 1
		Ycoor = 1
		GOSUB Display.Screen
	     ELSE
		Column = 1
		Ycoor = 1
	     END IF
	  CASE 79 ' end
	     End.Line = LEN(Temp.ArrayS(Line.Number))
             IF End.Line >= 80 THEN
                Column = End.Line - 78
                Ycoor = End.Line - Column + 2
                GOSUB Display.Screen
             ELSE
                Ycoor = End.Line - Column + 2
             END IF
          CASE 75, 155 ' left/alt-left
	     IF Ycoor > 1 THEN
		Ycoor = Ycoor - 1
	     ELSE
		IF Column > 1 THEN
		   Column = Column - 1
		   GOSUB Display.Screen
		END IF
	     END IF
          CASE 77, 157 ' right/alt-right
	     IF Column + Ycoor - 1 <= LEN(Temp.ArrayS(Line.Number)) THEN
                IF Ycoor < 80 THEN
		   Ycoor = Ycoor + 1
		ELSE
		   Column = Column + 1
		   GOSUB Display.Screen
		END IF
	     END IF
          CASE 72, 141, 152 ' up/ctrl-up/alt-up
	     Var = False
	     IF Line.Number > 1 THEN
		Line.Number = Line.Number - 1
		IF Xcoor = 1 THEN
		   Var = True
		ELSE
		   Xcoor = Xcoor - 1
		END IF
		End.Line = LEN(Temp.ArrayS(Line.Number)) + 1
		IF Column + Ycoor - 1 > End.Line THEN
		   Ycoor = End.Line - Column + 1
		   IF Ycoor <= 0 THEN
		      Ycoor = End.Line
		      IF Column > 1 THEN
			 Var = True
		      END IF
		      Column = 1
		   END IF
		END IF
		IF Var THEN
		   GOSUB Display.Screen
		END IF
	     END IF
          CASE 80, 145, 160 ' down/ctrl-dn/alt-dn
             Var = False
             IF Line.Number < Max.Lines THEN
		Line.Number = Line.Number + 1
                IF Xcoor >= 23 THEN
                   Var = True
		ELSE
		   Xcoor = Xcoor + 1
		END IF
		End.Line = LEN(Temp.ArrayS(Line.Number)) + 1
		IF Column + Ycoor - 1 > End.Line THEN
		   Ycoor = End.Line - Column + 1
		   IF Ycoor <= 0 THEN
		      Ycoor = End.Line
		      IF Column > 1 THEN
			 Var = True
		      END IF
		      Column = 1
		   END IF
		END IF
		IF Var THEN
		   GOSUB Display.Screen
		END IF
	     END IF
          CASE 73, 132 ' ^U, pageup/ctrl-pageup
	     IF Line.Number > 1 THEN
                IF Line.Number - 22 > 1 THEN
                   Line.Number = Line.Number - 22
		ELSE
		   Line.Number = 1
		END IF
		Xcoor = 1
		End.Line = LEN(Temp.ArrayS(Line.Number)) + 1
		IF Column + Ycoor - 1 > End.Line THEN
		   Ycoor = End.Line - Column + 1
		   IF Ycoor <= 0 THEN
		      Ycoor = End.Line
		      IF Column > 1 THEN
			 Var = True
		      END IF
		      Column = 1
		   END IF
		END IF
		GOSUB Display.Screen
	     END IF
          CASE 81, 118 ' ^N, pagedown/ctrl-pagedn
	     IF Line.Number < Max.Lines THEN
		IF Line.Number + 22 < Max.Lines THEN
		   Line.Number = Line.Number + 22
                   Xcoor = 1
		ELSE
		   Line.Number = Max.Lines
                   IF Max.Lines < 22 THEN
                      Xcoor = Max.Lines
                   ELSE
                      Xcoor = 22
                   END IF
		END IF
		End.Line = LEN(Temp.ArrayS(Line.Number)) + 1
		IF Column + Ycoor - 1 > End.Line THEN
		   Ycoor = End.Line - Column + 1
		   IF Ycoor <= 0 THEN
		      Ycoor = End.Line
		      IF Column > 1 THEN
			 Var = True
		      END IF
		      Column = 1
		   END IF
		END IF
		GOSUB Display.Screen
	     END IF
          CASE 82 ' ^V, insert
             If Line.Number > 0 Then
                ' row 24
                CALL Modem.ANSI(4, 33, 0)
                CALL ScreenANSI(4, 33, 0)
                CALL Modem.ANSI(4, 44, 30)
                CALL ScreenANSI(4, 44, 30)
                CALL Modem.ANSI(2, 24, 1)
                CALL ScreenANSI(2, 24, 1)
                Strng = SPACE$(41)
                CALL Scrn.Output(Strng)
                CALL Modem.ANSI(2, 24, 1)
                CALL ScreenANSI(2, 24, 1)
                Strng = "Enter 3-digit ascii code: "
                CALL Scrn.Output(Strng)
                Var = False
                Ascii$ = Nul
                DO While Lost.Carrier=False
                   Var$ = Nul
                   StartTime2#=Timeit!
                   DO While Lost.Carrier=False
                      RunTime2# = Timeit! - StartTime2#
                      IF RunTime2# < 0# THEN RunTime2# = RunTime2# + 86400#
                      IF RunTime2# >= 1# THEN
                         StartTime2# = Timeit!
                         Call Get.Cursor.Row(Var1)
                         Call Get.Cursor(Var2)
                         Call Edit.Status.Line
                         Locate Var1,Var2,1
                         Call Modem.ANSI(4,37,15)
                         Call ScreenANSI(4,37,15)
                      END IF
                      CALL Read.ANSI.Input
                      Var$=TempX$
                      If Len(Var$) Then
                         Exit Do
                      Endif
                      Call Check.Carrier
                   LOOP
                   If Len(Var$) = 1 Then
                      If Var$=Chr$(8) Then
                         If Len(Ascii$)>0 Then
                            Ascii$=Left$(Ascii$,Len(Ascii$)-1)
                            Gosub Display.Ascii.Line
                            Var=Var-1
                            CALL Modem.ANSI(2, 24, 26)
                            CALL ScreenANSI(2, 24, 26)
                            Strng = Ascii$ + " "
                            CALL Scrn.Output(Strng)
                            CALL Modem.ANSI(2, 24, 26)
                            CALL ScreenANSI(2, 24, 26)
                            Strng = Ascii$
                            CALL Scrn.Output(Strng)
                         Endif
                      Endif
                      If Var$=Chr$(13) Then
                         Exit Do
                      Endif
                      If Lcase$(Var$) = "x" Or Lcase$(Var$)="o" Or Lcase$(Var$)="b" Then
                         If Var=0 Then
                            Ascii$ = Ascii$ + Lcase$(Var$)
                            Gosub Display.Ascii.Line
                            Var = Var + 1
                            CALL Modem.ANSI(2, 24, 26 + Var)
                            CALL ScreenANSI(2, 24, 26 + Var)
                            Strng = Lcase$(Var$)
                            CALL Scrn.Output(Strng)
                         Endif
                      Endif
                      If Lcase$(Var$) >= "a" And Lcase$(Var$) <= "f" Then
                         If Var>=1 And Var<3 Then
                            If Left$(Ascii$,1)="x" Then
                               Var = Var + 1
                               CALL Modem.ANSI(2, 24, 26 + Var)
                               CALL ScreenANSI(2, 24, 26 + Var)
                               Strng = Var$
                               CALL Scrn.Output(Strng)
                               Ascii$ = Ascii$ + Var$
                            Endif
                         Endif
                      Endif
                      If Left$(Ascii$,1)="o" Then
                         If Var$ >= "0" And Var$ <= "7" Then
                            If Var<4 Then
                               Var = Var + 1
                               CALL Modem.ANSI(2, 24, 26 + Var)
                               CALL ScreenANSI(2, 24, 26 + Var)
                               Strng = Var$
                               CALL Scrn.Output(Strng)
                               Ascii$ = Ascii$ + Var$
                            Endif
                         Endif
                      Else
                         If Left$(Ascii$,1)="b" Then
                            If Var$ = "0" Or Var$ = "1" Then
                               If Var<9 Then
                                  Var = Var + 1
                                  CALL Modem.ANSI(2, 24, 26 + Var)
                                  CALL ScreenANSI(2, 24, 26 + Var)
                                  Strng = Var$
                                  CALL Scrn.Output(Strng)
                                  Ascii$ = Ascii$ + Var$
                               Endif
                            Endif
                         Else
                            If Var$ >= "0" And Var$ <= "9" Then
                                If Var<3 Then
                                   Var = Var + 1
                                   CALL Modem.ANSI(2, 24, 26 + Var)
                                   CALL ScreenANSI(2, 24, 26 + Var)
                                   Strng = Var$
                                   CALL Scrn.Output(Strng)
                                   Ascii$ = Ascii$ + Var$
                               Endif
                            Endif
                         Endif
                      Endif
                   Endif
                LOOP

                ' reset color
                CALL Modem.ANSI(1, 37, 7)
                CALL ScreenANSI(1, 37, 7)
                CALL Modem.ANSI(4, 37, 15)
                CALL ScreenANSI(4, 37, 15)

                ' insert ascii character
                If Left$(Ascii$,1)="x" Then
                   Ascii.Value=Int(Val("&H"+Mid$(Ascii$,2))+.5)
                Else
                   If Left$(Ascii$,1)="o" Then
                      Ascii.Value=Int(Val("&O"+Mid$(Ascii$,2))+.5)
                   Else
                      If Left$(Ascii$,1)="b" Then
                         Ascii$=Mid$(Ascii$,2)
                         Gosub Binary.String
                      Else
                         Ascii.Value = Int(Val(Ascii$)+.5)
                      Endif
                   Endif
                Endif
                If Ascii.Value >= 0 And Ascii.Value <= 255 Then
                   TempX$ = Chr$(Ascii.Value)
                   T$ = Temp.ArrayS(Line.Number)
                   T$ = LEFT$(T$, Column + Ycoor - 2) + TempX$ + MID$(T$, Column + Ycoor - 1)
                   Temp.ArrayS(Line.Number) = T$

                   IF Column + Ycoor - 1 <= LEN(Temp.ArrayS(Line.Number)) THEN
                      IF Ycoor < 80 THEN
                         Ycoor = Ycoor + 1
                         GOSUB Display.Screen
                      ELSE
                         Column = Column + 1
                         GOSUB Display.Screen
                      END IF
                   END IF
                Endif
             Endif
	  CASE 116 ' control-right
             IF Column + Ycoor - 1 > LEN(Temp.ArrayS(Line.Number)) THEN ' eol
                If Line.Number + 1 <= Max.Lines Then
                   Line.Number = Line.Number + 1
                   IF Xcoor = 22 THEN
                      Var = True
                   ELSE
                      Xcoor = Xcoor + 1
                   END IF
                   Ycoor = 1
                   Column = 1
                   GOSUB Display.Screen
                Endif
             Else
                P = 0
                FOR Temp2 = Column + Ycoor - 1 TO LEN(Temp.ArrayS(Line.Number))
                   P = P + 1
                   IF MID$(Temp.ArrayS(Line.Number), Temp2, 1) = " " THEN
                      IF MID$(Temp.ArrayS(Line.Number), Temp2 + 1, 1) <> " " THEN
                         EXIT FOR
                      END IF
                   END IF
                NEXT
                'shift right
                FOR Var3 = 1 TO P
                   IF Ycoor < 80 THEN
                      Ycoor = Ycoor + 1
                   ELSE
                      Column = Column + 1
                   END IF
                NEXT
                GOSUB Display.Screen
             Endif
	  CASE 115 ' control-left
             If Column + Ycoor - 1 <= 1 Then
                If Line.Number > 1 Then
                   Line.Number = Line.Number - 1
                   IF Xcoor = 1 THEN
                      Var = True
                   ELSE
                      Xcoor = Xcoor - 1
                   END IF
                   End.Line = LEN(Temp.ArrayS(Line.Number))
                   IF End.Line >= 80 THEN
                      Column = End.Line - 78
                      Ycoor = End.Line - Column + 2
                   ELSE
                      Ycoor = End.Line - Column + 2
                   END IF
                   GOSUB Display.Screen
                Endif
             Else
                P = 0
                V = 0
                FOR Temp2 = Column + Ycoor - 3 TO 1 STEP -1
                   P = P + 1
                   IF MID$(Temp.ArrayS(Line.Number), Temp2, 1) = " " THEN
                      IF MID$(Temp.ArrayS(Line.Number), Temp2 + 1, 1) <> " " THEN
                         V = -1
                         EXIT FOR
                      END IF
                   END IF
                NEXT
                IF V = 0 THEN
                   P = P + 1
                END IF
                ' shift left
                FOR Var3 = 1 TO P
                   IF Ycoor > 1 THEN
                      Ycoor = Ycoor - 1
                   ELSE
                      IF Column > 1 THEN
                         Column = Column - 1
                      END IF
                   END IF
                NEXT
                GOSUB Display.Screen
             Endif
	  CASE 119 ' control-home
             If Max.Lines > 0 Then
                Line.Number = 1
                Xcoor = 1
                Ycoor = 1
                Column = 1
                GOSUB Display.Screen
             Endif
	  CASE 117 ' control-end
             If Max.Lines > 0 Then
                Line.Number = Max.Lines
                IF Max.Lines < 22 THEN
                   Xcoor = Max.Lines
                ELSE
                   Xcoor = 22
                END IF
                Ycoor = 1
                Column = 1
                GOSUB Display.Screen
             Endif
	  END SELECT
       END SELECT
    LOOP
    CALL Modem.ANSI(1, 37, 7)
    CALL ScreenANSI(1, 37, 7)

    CALL Modem.ANSI(3, 0, 0)
    CALL ScreenANSI(3, 0, 0)

    Call Edit.Status.Line

    CALL Modem.ANSI(2, 24, 1)
    CALL ScreenANSI(2, 24, 1)

    Locate Max.Row-1,1,1
    Strng = "Store '" + OutX$ + "' to disk(y/n)? "
    No.Input.Out="Y"
    CALL IO.I
    IF Yes THEN
       Strng = "Store file in Linux form(y/n)?"
       No.Input.Out="N"
       CALL IO.I
       Store.Linux=Yes
       CLOSE #TempFile1
       If Dir$(FileName)<>"" Then
          Kill FileName
       Endif
       OPEN FileName FOR BINARY AS #TempFile1
       Var!=0!
       FOR Count = 1 TO Max.Lines
          FOR Count2=1 TO LEN(Temp.ArrayS(Count))
             VarX=Mid$(Temp.ArrayS(Count),Count2,1)
             Var!=Var!+1!
             Put TempFile1,Var!,VarX
          NEXT
          If Store.Linux=0 Then
             Var!=Var!+1!
             VarX=Chr$(13)
             Put TempFile1,Var!,VarX
          Endif
          Var!=Var!+1!
          VarX=Chr$(10)
          Put TempFile1,Var!,VarX
          'PRINT #TempFile1, Temp.ArrayS(Count)
       NEXT
       Strng = "File '" + OutX$ + "' stored to disk"
       If Linux Then Strng=Strng+" in linux form"
       Strng=Strng+"."
       CALL IO.O
    END IF
    ERASE Temp.ArrayS
 LOOP
 EXIT SUB

Display.Ascii.Line:
 CALL Modem.ANSI(4, 33, 0)
 CALL ScreenANSI(4, 33, 0)
 CALL Modem.ANSI(4, 44, 30)
 CALL ScreenANSI(4, 44, 30)
 CALL Modem.ANSI(2, 24, 1)
 CALL ScreenANSI(2, 24, 1)
 Strng = SPACE$(41)
 CALL Scrn.Output(Strng)
 CALL Modem.ANSI(2, 24, 1)
 CALL ScreenANSI(2, 24, 1)
  If Left$(Ascii$,1)="x" Then
     Var2$ = "Enter 2-digit ascii code: " 
  Else
     If Left$(Ascii$,1)="o" Then
        Var2$ = "Enter 3-digit ascii code: "
     Else
        If Left$(Ascii$,1)="b" Then
           Var2$ = "Enter 8-digit ascii code: "
        Else
           Var2$ = "Enter 3-digit ascii code: " 
        Endif
     Endif
  Endif
 CALL Scrn.Output(Var2$)
RETURN

Binary.String:
  Ascii.Value = False
  Binary.Power = False
  FOR Binary.Digit = LEN(Ascii$) TO 1 STEP -1
      Out2X$ = MID$(Ascii$, Binary.Digit, 1)
      SELECT CASE OutX2$
          CASE "0"
              ' nul
          CASE "1"
              Ascii.Value = Ascii.Value + 2 ^ Binary.Power
      END SELECT
      Binary.Power = Binary.Power + 1
  NEXT
RETURN

' display current edit screen
Display.Screen:
 CALL Modem.ANSI(1, 37, 7)
 CALL ScreenANSI(1, 37, 7)

 CALL Modem.ANSI(3, 0, 0)
 CALL ScreenANSI(3, 0, 0)

 CALL Modem.ANSI(2, 1, 1)
 CALL ScreenANSI(2, 1, 1)

 CALL Modem.ANSI(4, 37, 15)
 CALL ScreenANSI(4, 37, 15)

 ' store teletype state
 VarQ=IO.Upper.Case
 IO.Upper.Case=0

 ' display edit lines
 Count = 0
 If Max.Lines = 0 Then
    Count = 1
 Endif
 If Max.Lines > 0 Then
    DO
       Count = Count + 1
       IF Count = 24 THEN
          EXIT DO
       END IF
       IF Count + Line.Number - Xcoor > Max.Lines THEN
          EXIT DO
       END IF
       CALL Modem.ANSI(2, Count, 1)
       CALL ScreenANSI(2, Count, 1)
       Strng = MID$(Temp.ArrayS(Count + Line.Number - Xcoor), Column)
       IF LEN(Strng) > 80 THEN
          Strng = LEFT$(Strng, 80)
       END IF
       CALL Scrn.Output(Strng)
    LOOP
 Endif

 ' eof marker
 IF Count < 24 THEN
    CALL Modem.ANSI(2, Count, 1)
    CALL ScreenANSI(2, Count, 1)
    Strng = "<end of file>"
    CALL Scrn.Output(Strng)
 END IF

 ' row 24
 CALL Modem.ANSI(4, 33, 0)
 CALL ScreenANSI(4, 33, 0)

 CALL Modem.ANSI(4, 44, 30)
 CALL ScreenANSI(4, 44, 30)

 CALL Modem.ANSI(2, 24, 1)
 CALL ScreenANSI(2, 24, 1)

 Strng = SPACE$(79)
 CALL Scrn.Output(Strng)

 ' eol char
 Color 0, 1
 Locate 24,80,0
 Print " ";
 Locate 23,1,1

 ' row 24 filename
 CALL Modem.ANSI(2, 24, 42)
 CALL ScreenANSI(2, 24, 42)

 ' restore teletype state
 IO.Upper.Case=VarQ

 ' filename
 Strng = "File: " + OutX$
 CALL Scrn.Output(Strng)

 ' reset color
 CALL Modem.ANSI(4, 37, 15)
 CALL ScreenANSI(4, 37, 15)

 ' row 25 (local)
 Call Edit.Status.Line
 Locate ,,1
 RETURN
Error.Resume72:
 Erase Temp.ArrayS
Error.Resume72a:
 Goto 101
 EXIT SUB

Error.Trap72:
 Select Case Err
 Case 7
    Strng="Out of memory."
    Call IO.O
    Resume Error.Resume72
 Case 9
    Strng="Subscript out of range."
    Call IO.O
    Resume Error.Resume72
 Case 14
    Strng="Out of string space."
    Call IO.O
    Resume Error.Resume72
 Case Else
    Strng="Error loading file."
    Call IO.O
    Resume Error.Resume72a
 End Select
 Exit Sub
Get.Config2:
 option1=-1
 option2=-1
 option3=-1
 option4=-1
 option5=-1
 option6=-1
 VarX2=0
 Do
    VarX2=VarX2+1
    If VarX2>Options.Lines Then
       Exit Do
    Endif
    Var$=Ltrim$(Rtrim$(Options.Array(VarX2)))
    If Ucase$(Var$)="[CMD155]" Then
       Do
          VarX2=VarX2+1
          If VarX2>Options.Lines Then
             Return
          Endif
          Var$=Ltrim$(Rtrim$(Options.Array(VarX2)))
          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)))
             Select Case Lcase$(Var2$)
             Case "allow.catalog"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   option1=0
                End Select
             Case "allow.logoff"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   option2=0
                End Select
             Case "allow.notice"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   option3=0
                End Select
             Case "allow.prelog"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   option4=0
                End Select
             Case "allow.welcome"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   option5=0
                End Select
             Case "allow.other"
                Select Case Lcase$(Var3$)
                Case "0", "false", "off"
                   option6=0
                End Select
             End Select
          Endif
       Loop
    Endif
 Loop
 Return
End Sub

Sub Boot.Usage
 Call Clear.Status.Line
 Call Save.Screen2(-1)
 Print
 Color 15
 Print "Cmd155 - full screen editor."
 Color 14
 Print "Usage:"
 Color 15
 Print " Cmd155 [/n][/linux] "+Chr$(34)+"filename"+Chr$(34)
 Color 14
 Print "Where:"
 Color 15
 Print " /n is node from <nul>,0-9,A-Z,10-99"
 Print " /linux reads binary file."
 Print " Filename is the file in quotes to load."
 Color 7
 End
End Sub

Sub Amount(Var#,Var$)
 If Instr(Str$(Var#),"D") Then
    Var$=Str$(Var#)
 Else
    Var$=" "+Form$(Var#)
 Endif
End Sub
