Simple line editor. This is a work in progress, so there may be some issues.

DECLARE FUNCTION Acquire.Command$ (Maxlen!)
DECLARE FUNCTION Acquire.text$ (Maxlen!, Tsize!, Flag.sound%)
COMMON SHARED In.line$, In.line1$, Zend
CONST Page.width = 75
CONST Wsize = 50
    '**
    '* Lizzyword
    '**
        'SCREEN 2, 1
    ' vga required
    REM CLEAR 80000
    DEFINT A-Z
    DIM T$(1000), FP(1000)
    Tsize! = 5
    Fs% = 1
    WIDTH Page.width + 5, Wsize
    CL = 0
    HL = 0
    CLS
    PRINT "Lizzyword (V.: -1) [Cmd: H (for help)] Computoman"
    PRINT STRING$(79, "=")
    VIEW PRINT 3 TO Wsize

    '--
    ' give directions
    '--
    'GOSUB Help
    'PRINT "Current line number is"; CL; ".  To append text ";
    'PRINT "at line #1 respond: "
    'PRINT "Cmd: A  After: 0"

    '--
    ' initialize a linked list
    '--
    AV = 2
    Amount.tab = 0
    FP(1) = 0
    FOR I = 2 TO 999
     FP(I) = I + 1
    NEXT I
    FP(1000) = 0
true = -1
WHILE true
    '--
    ' input command
    '--
    'PRINT "-------------------------------------------------"
    PRINT "Cmd: ";
    L$ = Acquire.Command$(Page.width)
    L$ = UCASE$(L$)
    L1 = CL
    L2 = CL
    '--
    ' interpret commands
    '--
    L2$ = LEFT$(L$, 2)
    SELECT CASE L2$
        CASE "C/"
            IF LEN(L$) < 3 THEN
                PRINT "type in form of c/old/new"
            ELSEIF RIGHT$(L$, 1)  "/" THEN
                PRINT "You need a slash at the end!"
            ELSEIF RIGHT$(L$, 2) = "//" THEN
                PRINT "Need text between last two slashes!"
            ELSE
                GOSUB Changeit
            END IF
        CASE "F/"
            IF (LEN(L$) - 3) >= 0 THEN
                GOSUB findit
            ELSE
                PRINT "No text to find."
            END IF
        CASE "L/"
            Pageplus = LEN(L$)
            SELECT CASE Pageplus
                CASE 3
                    IF RIGHT$(L$, 1) = "-" OR RIGHT$(L$, 1) = "+" THEN
                        GOSUB Pageit
                    END IF
                CASE 2
                    PRINT "No direction found."
            END SELECT
        CASE ELSE
            REM
    END SELECT
    SELECT CASE L$
        CASE "A", "R"
            V$ = "After"
        CASE "G"
            V$ = "Where"
        CASE ELSE
            V$ = "From"
    END SELECT
    SELECT CASE L$
        CASE "N"
            INPUT "How many spaces over: ", Nudge.factor
    END SELECT
    SELECT CASE L$
        CASE "A", "C", "D", "G", "L", "P", "T", "R", "S", "M", "B", "N"
                PRINT V$;
                INPUT ": ", L1
                L2 = L1
    END SELECT
    SELECT CASE L$
        CASE "C", "D", "L", "P", "T", "S", "M", "B", "N"
            INPUT "To: ", L2A
            IF L2A = 0 THEN
                L2 = L1 + (Wsize - 3)
            ELSE
                L2 = L2A
            END IF
    END SELECT
    SELECT CASE L$
        CASE "I"
            GOSUB Information
        CASE "E"
            Fs% = -Fs%
        CASE "H", "?"
            GOSUB Help
        CASE "X"
            GOSUB Help.print
        CASE "N"
            GOSUB Nudge.text
        CASE "O"
            GOSUB Screendump
        CASE "Q"
            CLS
            PRINT
            PRINT "Thank you for using Lizzyword."
            PRINT
            PRINT "      computoman"
            PRINT
            A$ = ""
            WHILE A$ = ""
                A$ = INPUT$(1)
            WEND
            END
        CASE "V"
            PRINT USING "###:"; CL;
            PRINT T$(CP)
        CASE "A"
            GOSUB Lineappend
        CASE "R"
            GOSUB Readfile:
        CASE "G"
            CL = L1
        CASE "W"
            INPUT "Enter tab size: ", Tsize!
            IF Tsize! = 0 THEN
                Tsize! = 5
            END IF
        CASE "L"
            GOSUB Listtext
        CASE "D"
            GOSUB Delete
        CASE "C"
            GOSUB Change
        CASE "P"
            GOSUB Printtext
        CASE "S"
            GOSUB Savetext
        CASE "T"
            GOSUB LtrimText
        CASE "M"
            GOSUB MiddleText
        CASE "B"
            GOSUB BankRightText
        CASE "Z"
            CLS
    END SELECT
WEND
Help:
    '
    '..........help routine ....................
    PRINT "Would you like a long help list (Y/N): ";
    TT$ = ""
    WHILE TT$  "Y" AND TT$  "N"
        TT$ = UCASE$(INPUT$(1))
    WEND
    PRINT TT$
    IF UCASE$(TT$) = "Y" THEN
        '..........extended help routine ....................
        PRINT "(A)ppend lines of text from keyboard."
        PRINT "(B)ank text to the right."
        PRINT "(C(/))hange one or more lines or within a line."
        PRINT "(D)elete one or more existing lines."
        PRINT "(F/)ind first display of text within a line or lines."
        PRINT "(G)o to a particular line."
        PRINT "(H)elp."
        PRINT "(I)nfo to find current line number."
        PRINT "(L)ist one or more lines. (L/+ = +20 lines L/- = -20 lines"
        PRINT "(M)iddle text on one or more lines."
        PRINT "(N)udge over so many spaces on specific lines."
        PRINT "(O)utput the screen to printer help."
        PRINT "(P)rint one or more lines to the printer."
        PRINT "(Q)uit this program without saving."
        PRINT "(R)ead lines of text from a disk into the current file."
        PRINT "(S)ave one or more lines of text of the current file to disk."
        PRINT "(T)rim blanks from left side of line."
        PRINT "(V)erify a line. (W)iden tab."
        PRINT "(X)tra help for print commands. (Z)ero screen."
        PRINT " Respond to other ':' prompts with a line number. Otherwise"
        PRINT " pressing 'Enter' defaults to the current line number."
    ELSE
        PRINT "After 'Cmd: ' type (A)ppend, (B)ank, (C/)hange, (D)elete, (F/)ind,"
        PRINT "(G)o to, (H)elp, (I)nfo, (L(/))ist, (M)iddle, (N)udge, (O)utput,"
        PRINT "(P)rint, (Q)uit, (R)ead, (S)ave, (T)rim, (V)erify, (W)iden,"
        PRINT "(X)tra, or (Z)ero."
        PRINT "Respond to other ':' prompts with a line number. Otherwise"
        PRINT "responding with 'Enter' defaults to the current line number."
    END IF
    RETURN
Information:
     '--
     ' (I)nformation command
     '--
     PRINT "Current line is: "; CL; " highest line is: "; HL; "."
     RETURN
Lineappend:
     '--
     ' line (A)ppend command
     '--
     B$ = ""
     DO WHILE B$  "." AND AV  0
        PRINT USING "###> "; L1 + 1;
        B$ = Acquire.text$(Page.width + 5, Tsize!, Fs%)
        IF B$ = "." THEN
            EXIT DO
        END IF
        IF LEN(B$) = 0 THEN
            B$ = " "
        END IF
        CL = L1 + 1
        I = 1
        K = 1
        DO UNTIL FP(I) = 0 OR K = CL
            I = FP(I)
            K = K + 1
        LOOP
        J = AV
        AV = FP(J)
        FP(J) = FP(I)
        FP(I) = J
        T$(J) = B$
        CP = J
        HL = HL + 1
        IF CL = HL THEN
            HP = CP
        END IF
        L1 = CL
     LOOP
     IF AV = 0 THEN
      PRINT "Buffer is full"
     END IF
     RETURN
Change:
     '--
     '(C)hange command
     '--
     CL = L1
     IF L2 > HL THEN
        PRINT "Last line number does not exist!"
     ELSE
        DO
            I = 1
            K = 1
            WHILE NOT (FP(I) = 0 OR K = CL)
                I = FP(I)
                K = K + 1
            WEND
            CP = FP(I)
            PRINT USING "###:"; CL;
            PRINT T$(CP)
            PRINT USING "###>"; CL;
            T$(CP) = Acquire.text$(Page.width + 5, Tsize!, Fs%)
            IF CL  L2
     END IF
     RETURN
Delete:
     '--
     '(D)elete command
     '--
     CL = L1
     IF L2 > HL THEN
        L2 = HL
     END IF
     FOR C = 0 TO L2 - L1
        I = 1
        K = 1
        DO
            IF FP(I) = 0 OR K = CL THEN
                IF FP(I) = 0 THEN
                    PRINT "There is no text to delete!"
                    EXIT FOR
                ELSE
                    J = FP(I)
                    FP(I) = FP(J)
                    FP(J) = AV
                    AV = J
                    HL = HL - 1
                    CP = I
                    IF HL = CL THEN
                        HP = CP
                    END IF
                    EXIT DO
                END IF
            END IF
            I = FP(I)
            K = K + 1
        LOOP
     NEXT C
     CL = CL - 1
     IF CL  HL THEN
        L2 = HL
     END IF
     IF I = 0 THEN
        PRINT "Buffer empty"
     ELSE
        DO
            IF NOT (K  L2
        CL = K - 1
     END IF
     RETURN
Printtext:
    '--
    '(P)rint text
    '--
    I = FP(1)
    K = 1
    IF L2 > HL THEN
        L2 = HL
    END IF
    IF I = 0 THEN
        PRINT "Buffer empty"
    ELSE
        PRINT "Enter name of file to print ('prn' for printer): ";
        Out.to.file$ = Acquire.Command$(Page.width + 5)
        IF Out.to.file$ = "" THEN
            Out.to.file$ = "con"
        END IF
        PRINT "Please ready device to handle input. When ready press .";
        A$ = ""
        WHILE A$ = ""
            A$ = INPUT$(1)
        WEND
        OPEN Out.to.file$ FOR OUTPUT AS #2
        DO
            IF NOT (K  L2
    CL = K - 1
    END IF
    CLOSE #2
RETURN
Savetext:
     '--
     '(S)ave text
     '--
     I = FP(1)
     K = 1
     IF L2 > HL THEN
        L2 = HL
     END IF
     IF I > 0 THEN
        PRINT "Enter a Lizzyword filename to save: ";
        z$ = Acquire.Command$(Page.width + 5)
        OPEN z$ FOR OUTPUT AS #1
        DO
            IF NOT (K  L2 + 1
        CL = K - 1
        CLOSE #1
    ELSE
        PRINT "Buffer empty"
    END IF
    RETURN
Readfile:
     '--
     '(R)ead file
     '--
     PRINT "Enter Lizzyword file to read: ";
     Q$ = Acquire.Command$(Page.width + 5)
     Zend = 0
     OPEN Q$ FOR INPUT AS #1
     DO WHILE NOT (EOF(1) OR AV = 0)
        LINE INPUT #1, B$
        PRINT USING "###>"; L1 + 1;
        PRINT B$
        IF LEN(B$) = 0 THEN
            B$ = " "
        END IF
        CL = L1 + 1
        I = 1
        K = 1
        DO UNTIL FP(I) = 0 OR K = CL
            I = FP(I)
            K = K + 1
        LOOP
        J = AV
        AV = FP(J)
        FP(J) = FP(I)
        FP(I) = J
        T$(J) = B$
        CP = J
        HL = HL + 1
        IF CL = HL THEN
            HP = CP
        END IF
        L1 = CL
    LOOP
    IF AV = 0 THEN
        PRINT "buffer is full"
    END IF
    CLOSE #1
    RETURN

findit:
     '--
     ' (F)ind command f/text/
     '--
     LP = LEN(L$) - 3
     P$ = MID$(L$, 3, LP)
     IF LP = 0 THEN
        P$ = " "
     END IF
     I = 1
     K = 1
     DO
        I = FP(I)
        IF I = 0 THEN
            PRINT "Text not found"
            EXIT DO
        ELSE
            FOR Q = 1 TO LEN(T$(I))
                IF MID$(T$(I), Q, LP) = P$ THEN
                    CP = I
                    CL = K
                    PRINT USING "###:"; CL;
                    PRINT T$(CP)
                    EXIT DO
                END IF
            NEXT Q
            K = K + 1
        END IF
     LOOP
RETURN

Changeit:
     '--
     ' c/ change text       c/old/new/
     '--
     r$ = ""
     P = 3
     DO
        X$ = MID$(L$, P, 1)
        IF X$ = "/" THEN
            EXIT DO
        END IF
        r$ = r$ + X$
        P = P + 1
     LOOP
     N$ = ""
     FOR Q = P + 1 TO LEN(L$) - 1
        N$ = N$ + MID$(L$, Q, 1)
     NEXT Q
     lT = LEN(T$(CP)): lR = P - 3
     FOR Q = 1 TO lT
        IF MID$(T$(CP), Q, lR) = r$ THEN
            EXIT FOR
        END IF
     NEXT Q
     IF Q > lT THEN
        PRINT r$; " not found"
     ELSE
        T$(CP) = LEFT$(T$(CP), Q - 1) + N$ + RIGHT$(T$(CP), lT - Q - lR + 1)
        PRINT USING "###:"; CL;
        PRINT T$(CP)
     END IF
 RETURN
Screendump:
      '--
      ' transfer screen to printer
      '--
      PRINT "Press (shift) (print-screen) at any time to get a screen dump."
      RETURN
LtrimText:
'--
     'l(T)rim text
     '--
     I = FP(1)
     K = 1
     IF L2 > HL THEN
        L2 = HL
     END IF
     IF I = 0 THEN
         PRINT "Buffer empty"
     ELSE
        DO
            IF NOT (K  L2
        CL = K - 1
     END IF
RETURN

MiddleText:
'--
     '(M)iddle text
     '--
     I = FP(1)
     K = 1
     IF L2 > HL THEN
        L2 = HL
     END IF
     IF I = 0 THEN
         PRINT "Buffer empty"
     ELSE
        DO
            IF NOT (K  L2
        CL = K - 1
     END IF
RETURN

Pageit:
    Marker$ = MID$(L$, 3, 1)
    SELECT CASE Marker$
        CASE "+"
            IF CL > HL THEN
                CL = CL - (Wsize - 3)
            END IF
        CASE "-"
            CL = CL - ((Wsize - 3) * 2)
            IF CL  HL THEN
        L2 = HL
     END IF
     IF I = 0 THEN
         PRINT "Buffer empty"
     ELSE
        DO
            IF NOT (K  L2
        CL = K - 1
     END IF
RETURN

Nudge.text:
'--
     '(N)udge text
     '--
     I = FP(1)
     K = 1
     IF L2 > HL THEN
        L2 = HL
     END IF
     IF I = 0 THEN
         PRINT "Buffer empty"
     ELSE
        DO
            IF NOT (K  L2
        CL = K - 1
     END IF
RETURN

Help.print:
    PRINT
    PRINT "Printer help commands."
    PRINT
    PRINT "P = page foreward               (øP                        )"
    PRINT "I = italics                     (øI1 for on and øI0 for off)"
    PRINT "L = large print                 (øL1            øL0        )"
    PRINT "S = condensed print             (øS1            øS0        )"
    PRINT "T = tab size if needed.         (øTsize to set size        )"
    PRINT "Q = near letter quality         (øQ1            øQ0        )"
    PRINT "U = underlining                 (øU1            øU0        )"
    PRINT "F = insert file into print job  (øFfilename                )"
RETURN

DEFSNG A-Z
'=================================================
FUNCTION Acquire.Command$ (Maxlen!)
    Crow = CSRLIN
    Ccol = POS(0)
    LOCATE Crow, Ccol
    GOSUB Gline11
    'PRINT
    Acquire.Command$ = Com.line$
    PRINT
EXIT FUNCTION

' ------------------------------------------------
' gchar - get a character
Gchar11:
    Clizzy$ = INPUT$(1)
    C = ASC(Clizzy$)
    IF C  8 THEN
        IF C  &HD THEN
            PRINT CHR$(C);
        END IF
    ELSE
        IF LEN(Com.line$) > 0 THEN
            PRINT "  ";
        END IF
    END IF
RETURN
' ----------------------------------------------------
' gline - get a line
Gline11:
  Com.line$ = ""
  DO
    GOSUB Gchar11
    SELECT CASE C
        CASE &HD
           PRINT " ";
        CASE 29, 8
           IF LEN(Com.line$) > 0 THEN
                Com.line$ = LEFT$(Com.line$, LEN(Com.line$) - 1)
           END IF
        CASE ELSE
           Com.line$ = Com.line$ + CHR$(C)
    END SELECT
  LOOP UNTIL LEN(Com.line$) >= Maxlen OR (C = &HD AND LEN(Com.line$) >= Zero)
RETURN
END FUNCTION

'=================================================
FUNCTION Acquire.text$ (Maxlen!, Tab.size!, Flag.sound%)
    PRINT In.line$;
    GOSUB Gline1
    Newb$ = ""
    IF LEN(In.line$) >= Page.width THEN
        WHILE RIGHT$(In.line$, 1)  " " OR LEN(In.line$) >= Page.width
            Newb$ = RIGHT$(In.line$, 1) + Newb$
            IF LEN(In.line$) > 0 THEN
                In.line$ = LEFT$(In.line$, LEN(In.line$) - 1)
            END IF
            PRINT " ";
        WEND
    END IF
    Acquire.text$ = In.line$
    In.line$ = Newb$
    PRINT
EXIT FUNCTION

' ------------------------------------------------
' gchar - get a character
Gchar1:
    Clizzy$ = INPUT$(1)
    IF Flag.sound% = 1 THEN
        REM 	SOUND 55, .5
    END IF
    C = ASC(Clizzy$)
    IF C  8 THEN
        SELECT CASE C
            CASE &HD
                REM
            CASE 14
                Flag.sound% = -Flag.sound%
            CASE 9
                Lim = (Tab.size - 1) - (LEN(In.line$) MOD Tab.size)
                IF Lim  0 THEN
            PRINT  "  ";
        END IF
    END IF
RETURN
' ----------------------------------------------------
' gline - get a line
Gline1:
  DO
    GOSUB Gchar1
    SELECT CASE C
        CASE &HD
           PRINT " ";
        CASE 9
           In.line$ = In.line$ + SPACE$(Lim)
        CASE 29, 8
           IF LEN(In.line$) > 0 THEN
                In.line$ = LEFT$(In.line$, LEN(In.line$) - 1)
           END IF
        CASE 14
            REM
        CASE ELSE
           In.line$ = In.line$ + CHR$(C)
    END SELECT
    z = POS(0)
    y = CSRLIN
    VIEW PRINT
    LOCATE 1, 75
    PRINT USING "C:###"; LEN(In.line$) + 1;
    VIEW PRINT 3 TO Wsize
    LOCATE y, z
  LOOP UNTIL LEN(In.line$) >= Maxlen OR (C = &HD AND LEN(In.line$) >= Zero)
RETURN

END FUNCTION
Advertisements