Buchempfehlung
Mikrocomputertechnik mit Controllern der Atmel AVR-RISC-Familie
Mikrocomputertechnik mit Controllern der Atmel AVR-RISC-Familie
Umfassend, aber leicht verständlich führt dieses Buch in die Programmierung von ATMEL AVR Mikrocontrollern ein. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

MuhEdit 0.9.X.3 (RC3)

Uploader:MitgliedThe_Muh
Datum/Zeit:14.01.2009 21:17:37

'--------------Credits--------------'
'   MuhEdit, version 0.9.X.3 Final

'   Erklärung: .X = finale version des 0.9er stammes

'   Alle nachfolgenden änderungen sind automatisch in

'   die nachfolgende versionsziffer einzuordnen und

'   gehören nicht in den eigentlichen Release-plan.

'   (Zählung nach Release, beginn der letzten ziffer bei 1)

'   Nach 1.0.0.0 wird das alte versions-system fortgesetzt

'   Einführung dieser Sonderversionsbezeichnung dient der

'   größtmöglichen Bugfreiheit bei 1.0
'   Programming and idea by The_Muh.
'--------------License--------------'
'   This program is free software; you can redistribute it and/or modify
'   it under the terms of the GNU General Public License as published by
'   the Free Software Foundation; either version 2 of the License, or
'   (at your option) any later version.
'
'   This program is distributed in the hope that it will be useful,
'   but WITHOUT ANY WARRANTY; without even the implied warranty of
'   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'   GNU General Public License for more details.
'
'   You should have received a copy of the GNU General Public License
'   along with this program; if not, write to the Free Software
'   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
'   MA 02110-1301, USA.
'-----------------------------------'
'-Tabulator Gefixt
'-Eingabe() gefixt
'-Markieren + RowNum gefixt
'declares:

declare sub set_mark(key as integer)
declare function search() as integer
declare sub cut(flag as integer = 0)
declare sub correct_curs()
declare sub laden(seite as string)
declare sub speichern(file as string = "")
declare sub text(ByVal wahl As Integer, title as string = "")
declare sub anzeige(anzeigetext() as string, X as integer, Y as integer)
declare sub tab_correct(old_width as integer)
declare sub menu()
declare function decoder(txt as string, key as string) as string
declare function encoder (txt_crypt as string, key as string) as string
declare function byte_2_x(B as ulongint) as string
declare function new_file() as string
declare function conv(key as string) as string
declare function directory(FL as integer) as string
declare function gen_row(number as integer, biggest as integer) as string
declare function exist(BYREF DateiName AS STRING, Attr AS INTEGER=&h27)AS INTEGER
declare function eingabe(ByVal frage As String ,vorgabe As String, X as integer,Y as integer, title as string = "") as string
declare function max(array() as string, p as integer = 3) as integer
declare Function str_replace(ByVal V_Data As String, ByVal V_Expression As String, ByVal V_ReplaceBy As String) As String
#ifdef __fb_linux__
    DECLARE FUNCTION GetFromClipboard() AS INTEGER
    DECLARE SUB SendToClipboard(ClipStr() AS STRING)
    dim clip as integer
#else
    #include "windows.bi"
    Declare Sub WriteClipboard(Text As String)
    Declare Function ReadClipboard() As String
    declare sub s_t_a(text as string)
#endif
'variablen:
Dim as integer einf = 1
dim as string Li, Re
dim as integer ascL, ascR
dim as integer mzeile, mspalte, buttons, wheel, wheel_old, mdummy
dim d as string
dim i as integer
dim L as integer
dim rest as string
dim shared crypt_key as string
dim shared dirs as string
dim shared a as integer
dim shared b as integer
dim shared ba as integer = 0
dim shared pot_spalte as integer = 1
dim shared as string tZeile()
dim shared as string seite
dim shared as integer zeile=3, spalte=1
REDIM tzeile(1) AS STRING   'Der Text


type mark_type

    x as integer

    y as integer

end type


dim test1 as mark_type
dim test2 as mark_type

dim shared m_start as mark_type

dim shared m_akt as mark_type

dim shared mark as integer


'Options-variablen:
type options
    nam as string
    value as integer
    min as integer
    max as integer
end type

dim shared opt(1 to 5) as options

opt(1).nam = "Tab width:"
opt(1).value = 4
opt(1).min = 4
opt(1).max = 12

opt(2).nam = "Print row-numbers?"
opt(2).value = 0
opt(2).min = 0
opt(2).max = 1

opt(3).nam = "Print all row-numbers?"
opt(3).value = 0
opt(3).min = 0
opt(3).max = 1

opt(4).nam = "Window-height:"
opt(4).value = 40
opt(4).min = 22
opt(4).max = 100

opt(5).nam = "Window-width:"
opt(5).value = 55
opt(5).min = 55
opt(5).max = 120
'ende der options-variablen

'makros:
#macro datei (array2,endung,flag)
    K = DIR("*." & endung,flag)
    do
        if len(k) > 0 and k <> "." and k <> ".." then
         redim preserve array2(i)
        array2(i) = K
        i += 1
        end if
        K = DIR("")
    LOOP until LEN(K) = 0' solange noch ein nicht gelistetes Verzeichnis existiert
#endmacro

#macro blubb(array)
dim key as string
c = 0
do
    cls
    locate 1, 1 : PRINT "MuhEdit Directory";
    if flag = &h10 then print " | Set Directory = ESC";
    locate 2, 1 : Print String(opt(5).value, asc("_"));
    locate 3, 1 : Print right(Curdir,50);
    locate opt(4).value,1 :Print "Switch between File / Directory = F2 or F4 ";
    text(5)

    for sh as integer = lbound(array) to opt(4).value-6     'text anzeigen...
           if SH + A <= ubound(array) then
                  locate sh+4 ,1
        if sh = c then
                print "X "& sh + A &") /"& array(sh+A);
        else
                print "  "& sh + A &") /"& array(sh+A);
            end if
        else
            exit for
        end if
    next sh

    do : sleep 1 : key = inkey : loop until key <> ""
    select case asc(right(key,1))
    case 60, 62
        if flag = &h10 then
            flag = &h00
        else
            flag = &h10
        end if
        exit do
    case 73
        if A > 0 then
            A -= 1
        end if
    case 81
        if c + a < ubound(array) then A += 1
    case 72                   'oben
        if c > 0 then c -= 1
        if A > 0 and c = 0 then a -= 1
    case 80                   'unten
        if c < opt(4).value -6 and c < ubound(array) then
            c += 1
        else
            if c + a < ubound(array) then A += 1
        end if
    end select
    select case asc(left(key,1))
    case 27
        if flag = &h10 then
            weiter = 0
        else
            C = -1
            weiter = 0
        end if
        exit do
    case 14
        redim preserve array(ubound(array) +1)
        array(ubound(array)) = new_file
        cls
    case 13
        if flag = &h10 then
            if c = 0 then
                dirs = ".."
              else
                dirs = dirname(c)
            end if
            chdir(dirs)
        else
            seite = filename(c)
            weiter = 0
        end if
        exit do
    end select
loop
#endmacro

'subs und funktionen:
sub help()
    cls
    text (6,"MuhEdit - Help")
    locate 3,1
    print "Browse files / directorys : F2"
    print "Save file : F3"
    print "Open menu : F4"
    print "Show file-infos: F5"
    print "Mark text: use shift + arrowkeys or your mouse"
    print "Cut marked text: ctrl+x"
    print "Paste: ctrl+v (marked text will replaced)"
    print "Copy: ctrl+c"
    print "create new file: ctrl+n"
    print "show row-numbers : ctrl+r"
    print "Search in the text: ctrl+f"
    sleep
    while len(inkey) :wend
end sub
sub angleichen()
    if ubound(tzeile) < zeile + A then redim preserve tzeile(zeile + A) as string
end sub

sub cut(flag as integer = 0)
    dim old_line as string
    dim dummy() as string
    dim text_dummy as string
    dim count as integer
    dim m_t_ende as mark_type
    dim m_t_start as mark_type
    Dim leer as byte
    dim posi as integer
    dim debug as string
    old_line = tzeile(m_start.x)

    m_t_start = m_start
    m_t_ende = m_akt
    if m_t_start.y = 0 and m_t_start.x = 0 then exit sub
    if m_start.x > m_akt.x then
        swap m_t_start, m_t_ende.x
    elseif m_start.y > m_akt.y and m_start.x = m_akt.x then
        swap m_t_start, m_t_ende
    end if
    for sh as integer = m_t_start.x to m_t_ende.x
        if mark = 1 and m_t_start.x <= sh and m_t_ende.x >= sh then
            count += 1
            redim preserve dummy(count)
            if m_t_ende.x = m_t_start.x then
                dummy(count) = mid(tzeile(sh), m_t_start.y,  m_t_ende.y - m_t_start.y)
                if flag <> 2 then tzeile(sh) = left(tzeile(sh), m_t_start.y-1) + right(tzeile(sh),len(tzeile(sh)) -m_t_ende.y+1)
            elseif m_t_start.x < sh and m_t_ende.x > sh then
                dummy(count) = tzeile(sh)
                if flag <> 2 then tzeile(sh) = ""
            elseif m_t_start.x < sh and m_t_ende.x = sh then
                dummy(count) = left(tzeile(sh),m_t_ende.y-1)
                if flag <> 2 then tzeile(m_t_start.x) += right(tzeile(sh),len(tzeile(sh)) - m_t_ende.y+1)
                if flag <> 2 then tzeile(sh) = ""
            elseif m_t_start.x = sh and m_t_ende.x > sh then
                dummy(count) = right(tzeile(sh),len(tzeile(sh)) - m_t_start.y+1)
                if flag <> 2 then tzeile(sh) = left(tzeile(sh),  m_t_start.y-1)
            end if
        end if
    next
    do
        leer = 0
        for sh as integer = m_t_start.x to m_t_ende.x
            if tzeile(sh) = "" and sh < ubound(tzeile)  then
                for x as integer = sh to ubound(tzeile)-1
                    tzeile(x) = tzeile(x+1)
                next
                leer = 1
                posi += 1
            elseif tzeile(sh) = "" and sh = ubound(tzeile) then
                redim preserve tzeile(sh-1)
                exit do
            end if
        next
    loop until leer = 0
    if posi <> 0 then redim preserve tzeile(ubound(tzeile)-posi)
    for i as integer = 1 to ubound(dummy)
        debug += dummy(i) + chr(13,10)
    next
    mark = 0
    if flag = 1 or flag = 3 or flag = 0 then
        spalte = m_t_start.y
        b = 0
        pot_spalte = spalte
        zeile = m_t_start.x
        correct_curs
    end if
    if flag = 1 or flag = 2 then
        #ifdef __fb_linux__
        sendtoclipboard(dummy())
        #else
        writeClipboard(debug)
        #endif
    end if
end sub

function gen_row(number as integer, biggest as integer) as string
    dim l_num as integer
    dim l_big as integer
    dim row as string
    l_num = len(str(number))
    l_big = len(str(biggest-2))
    row = string( (l_big - l_num), " ")  & str(number) & "|"
    return row
end function

sub anzeige(anzeigetext() as string, X as integer,Y as integer)

    dim text_dummy as string

    dim m_t_ende as mark_type

    dim m_t_start as mark_type

    for sh as integer = 3 to (opt(4).value - 2)     'text anzeigen...
        if SH + X <= ubound(anzeigetext) then

            locate sh, 1
            if mark = 0 then
                if opt(2).value = 1 then
                    if ubound(anzeigetext) < opt(4).value -2  and opt(3).value = 1 then
                        print gen_row(sh + x -2, opt(4).value -2)  & mid(anzeigetext(sh+X),Y +1,opt(5).value)
                        ba = len(gen_row(0,opt(4).value -2))
                    else
                        print gen_row(sh + x -2, ubound(anzeigetext))  & mid(anzeigetext(sh+X),Y +1,opt(5).value)
                        ba = len(gen_row(0,ubound(anzeigetext)))
                    end if
                else
                    print mid(anzeigetext(sh+X),Y +1,opt(5).value)
                end if
            else

                m_t_start = m_start

                m_t_ende = m_akt
                if m_start.x > m_akt.x then
                    swap m_t_start, m_t_ende.x
                elseif m_start.y > m_akt.y and m_start.x = m_akt.x then
                    swap m_t_start, m_t_ende
                end if

                if opt(2).value = 1 then
                    color 0,15
                    if ubound(anzeigetext) < opt(4).value -2  and opt(3).value = 1 then
                        print gen_row(sh + x -2, opt(4).value -2);
                        ba = len(gen_row(0,opt(4).value -2))
                    else
                        print gen_row(sh + x -2, ubound(anzeigetext));
                        ba = len(gen_row(0,ubound(anzeigetext)))
                    end if
                    if sh <= m_t_ende.x -x and sh > m_t_start.x -x then color 15,1
                end if

                if mark = 1 and m_t_start.x -x <= sh and m_t_ende.x -x >= sh then

                    text_dummy = mid(anzeigetext(sh+X),Y +1,opt(5).value)
                    for i as integer = 1 to len(text_dummy)

                        'if m_t_ende.x = m_akt.x then
                            if i >= m_t_start.y -y and sh >= m_t_start.x -x then color 15,1

                            if i >= m_t_ende.y -y and sh >= m_t_ende.x -x then color 0,15

                        'end if

                        print mid(text_dummy,i,1);

                    next
                    if m_t_start.y  = len(text_dummy)+1 and m_t_start.x -x = sh  then color 15,1

                    if m_t_ende.x -x = sh then color 0,15

                elseif mark = 0 or m_t_start.x -x < sh or m_t_ende.x -x > sh then

                   print mid(anzeigetext(sh+X),Y +1,opt(5).value)

                end if
            end if
        else
            exit for
        end if
    next sh

    color 0,15
    if ubound(anzeigetext) < opt(4).value -2 and opt(2).value = 1 and opt(3).value = 1 then
        for i as integer = ubound(anzeigetext) +1 to opt(4).value -2
            print gen_row(i -2, opt(4).value -2)
        next
    end if
end sub

function byte_2_x(B as ulongint) as string
    dim KiB as ulongint
    dim MiB as ulongint
    dim biggest as string
    dim stamp as string

    if B >= 1024 then
        KiB = int(B / 1024)
        B -= KiB * 1024
        Biggest = "KiB"
    end if
    if KiB >= 1024 then
        MiB = int(KiB / 1024)
        KiB -= MiB * 1024
        Biggest = "MiB"
    end if

    select case biggest
    case "KiB":
        stamp = Kib & " KiB, " & B & " Byte"
    case "MiB":
        stamp = Mib & "MiB, " & KiB & " KiB"
    end select
    return stamp
end function

function conv(key as string) as string
    dim con as string
    dim ascl as integer
    ascL = asc(left(key,1))
    select case ascL
    'case 167 : con = chr(245) '§
    case 228 : con = chr(132) 'ä
    case 196 : con = chr(142)
    case 246 : con = chr(148) 'ö
    case 214 : con = chr(153)
    case 252 : con = chr(129) 'ü
    case 220 : con = chr(154)
    case 223 : con = chr(225) 'Ã&#159;
    case else: con = chr(ascl)
    end select
    return con
end function

sub correct_curs()
    angleichen()
    if len(tzeile(zeile + A)) >= pot_spalte  and len(tzeile(zeile + a)) > 1 then
           spalte = pot_spalte
    end if
    if len(tzeile(zeile + A)) < pot_spalte then
        spalte = len(tzeile(zeile + A)) + 1
        if len(tzeile(zeile + A)) = 0  then spalte = 1
    end if
    if spalte + ba > opt(5).value then
        B = spalte - (opt(5).value + ba)
        spalte -= B
    else
        b = 0
    end if
end sub

sub counter()
    dim code as integer
    dim blank as integer
    dim i as integer
    for i = 1 to ubound(tzeile)-1
        if len(ltrim(tzeile(i))) = 0 or len(ltrim(tzeile(i),chr(9))) = 0 then blank += 1
        if len(ltrim(tzeile(i),chr(9))) <> 0 and len(ltrim(tzeile(i))) <> 0 then code += 1
    next i

    locate 5,1
    print "Textlines:       "& code
    print "Blanklines:      "& blank
    print "Lines total:     "& code + blank
end sub

function encoder (txt_crypt as string, key as string) as string
    dim txt as string
    dim txt_dummy() as integer
    dim key_int as integer
    dim dummy as integer
    dim fail as integer
    dim i2 as integer = 1

    for i as integer = 1 to len(key)
        dummy = asc(mid(key,i,1))
        dummy = dummy + (val(right(str(dummy),2))+ i)
        key_int += dummy
    next

    for i as integer = 1 to len(txt_crypt) step +3
        i2 += len(key)
        if i2 >= len(key) + 33 then
            i2 = 1
        end if
        redim preserve txt_dummy(i)
        txt_dummy(i) = val("&h" & mid(txt_crypt,i,3))
        txt = txt & chr(txt_dummy(i) - key_int - i2)
    next
    return txt
end function

function decoder(txt as string, key as string) as string
    dim txt_dummy() as integer
    dim txt_crypt as string
    dim key_int as integer
    dim dummy as integer
    dim fail as integer
    dim i2 as integer = 1

    for i as integer = 1 to len(key)
        dummy = asc(mid(key,i,1))
        dummy = dummy + (val(right(str(dummy),2))+ i)
        key_int += dummy
    next
    for i as integer = 1 to len(txt)
        i2 += len(key)
        if i2 >= len(key) +33 then
            i2 = 1
        end if
        dummy = asc(mid(txt,i,1))
        redim preserve txt_dummy(i)
        txt_dummy(i) += dummy + key_int + i2
    next
    for i as integer = 1 to ubound(txt_dummy)
        if len(str(hex(txt_dummy(i)))) <> 3 then
            print "alert"
            fail = 1
            exit for
        end if
        txt_crypt += str(hex(txt_dummy(i)))
    next

    if fail <> 1 then
        return txt_crypt
        Print "Text Crypted."
    else
        print "Crypt Failure"
    end if
end function

function directory(FL as integer) as string
    dim dirs as string
    DIM AS STRING dirname()
    dim filename() as string
    dim as integer i = 1
    dim c as integer
    dim K as string
    dim key as string
    dim flag as integer
    dim weiter as integer
    weiter = 1
    Locate 4,1
    flag = fl

    do
        if flag = &h10 then
            i = 1
            redim dirname(1)
            dirname(0) = ".."
            datei(dirname,"*",flag)
        else
            i = 0
            redim filename(1)
            datei(filename,"txt",&h00)
            datei(filename,"*ml",&h00)
            datei(filename,"bas",&h00)
            datei(filename,"mct",&h00)
        end if

        text(5) 'linie
        if flag = &h10 then
               blubb(dirname)
               if c > ubound(dirname) then continue do
           else
               blubb(filename)
            if c > ubound(filename) then continue do
        end if
    loop until weiter = 0
    if flag = &h00 then laden(seite)
    if flag = &h10 then
        text 2
        locate opt(4).value,1 : print "Accepted";
        getkey
    end if
    return dirs
end function

function eingabe(ByVal frage As String ,vorgabe As String, X as integer,Y as integer, title as string = "") as string
    dim zeichen as string
    dim zeichenkette as string
    dim L as integer
    dim Li as string
    dim Re as string
    dim ascR as integer
    dim ascL as integer
    dim einf as integer
    dim spalte as integer
    dim rest as string
    einf = 1
    zeichenkette = vorgabe
    spalte = len(zeichenkette) +1
    y = len(frage) +1
    do
        text(2)
        text(6, title)
        locate x,1: print frage;
        locate x,len(frage) + 1: print Zeichenkette;
        DRAW STRING ((y + spalte-2)*8 , (x-1)*8), "_"  'Cursor anzeigen
        do : sleep 1 : zeichen = inkey : loop while zeichen = ""

        Li = mid(zeichen, 1,1)
        Re = mid(zeichen, 2.1)
        ascL = asc(Li)
        ascR = asc(Re)

        L = len(zeichenkette)
        select case ascR
        case 82                             'testen ob "einf" gedrückt wurde
            if einf = 1 then                             'der umschalter
                einf = 0
            else
                einf = 1
            end if
        case 75:                         'links
            if spalte > 1 then spalte -= 1
        case 77:                           'rechts
            if spalte <= L then spalte += 1
        #ifndef __fb_linux__
        case 83                                    'entf
            if L >= spalte then
                zeichenkette = left(zeichenkette,spalte-1) + right(zeichenkette,L -(spalte))
            end if
        #endif
        end select

        if ascL <> 255 then
        select case ascL
        case 8                                          'backspace
            if L >= spalte then
                zeichenkette = left(zeichenkette,spalte-2) + right(zeichenkette,L -(spalte-1))
            else
                zeichenkette = left(zeichenkette,len(zeichenkette)-1)
            end if
            if spalte <> 1 then spalte -= 1
            pot_spalte = spalte
        case 13                                     'enter
            return zeichenkette
            locate 3,1
            exit function
        case 27
            return vorgabe
            locate 3,1
            exit function
        #ifdef __fb_linux__
        case 127                                       'entf
            if L >= spalte then
                zeichenkette = left(zeichenkette,spalte-1) + right(zeichenkette,L -(spalte))
            end if
        #endif
        case else
            if L >= spalte then
                if einf = 0 then
                    MID(zeichenkette, spalte, 1) = zeichen
                else
                    zeichenkette = left(zeichenkette, spalte-1) + zeichen + right(zeichenkette, (L - spalte +1) )
                end if
            else
                zeichenkette = zeichenkette + zeichen
            end if
            spalte += 1
        end select
        end if
    loop until zeichen = chr(13)
end function

FUNCTION exist(BYREF DateiName AS STRING, Attr AS INTEGER=&h27)AS INTEGER
    RETURN DIR(DateiName, Attr)<>""
END FUNCTION

sub info()
    cls
    text(1)
    dim array as integer
    dim zeilen as integer
    dim zeichen as integer
    dim filesize as integer

    OPEN seite FOR BINARY AS #1
        filesize = LOF(1)
    CLOSE #1

    array = ubound(tzeile)
    for i1 as integer = 1 to array
        if len(tzeile(i1)) > 0 then
            zeilen += 1
        end if
    next i1

    for i2 as integer = 1 to array
        zeichen += len(tzeile(i2))
    next

    if len(seite) > 1 then
        locate 3,1:print "Filename:     "& seite;
        locate 4,1:print "Letters:      "& zeichen;
        locate 8,1:print "Filesize:     "& byte_2_x(filesize)
    else
        Locate 3,1:print "No File loaded / File not saved"
        locate 4,1:print "Letters:       "& zeichen;
    end if
    counter()
end sub

#ifdef __fb_Linux__
if shell("xclip -version") = 0 then
    clip = 1
end if
cls

SUB sendtoclipboard(ClipStr() AS STRING)
    DIM AS INTEGER i,ff
    DIM AS STRING helper, file
    file=EXEPATH+"/xcliptmp"
    ff=FREEFILE

    OPEN file FOR OUTPUT AS #ff

    for i as integer = 1 to max(clipstr(),0)
        PRINT #ff,ClipStr(i)
    Next
    CLOSE #ff

    helper="less "+file+" | xclip -sel clip"
    SHELL helper
END SUB

FUNCTION getfromclipboard() AS INTEGER
    DIM AS STRING helper,file,dummy
    DIM AS INTEGER i,j,ff
    dim paste() as string
    dim l as integer
    file=EXEPATH+"/xcliptmp"

    helper="xclip -o -sel clip > "+file
    SHELL helper

    IF exist(file) THEN
        ff=FREEFILE
        OPEN file FOR INPUT AS #ff
        WHILE NOT EOF(ff)
            i+=1
            LINE INPUT #ff,dummy
            redim preserve paste(i)
            paste(i)=dummy
        Wend
        CLOSE #ff
    ELSE
        i=0
    END IF
    if len(paste(i)) > 0 then
    redim preserve tzeile(ubound(tzeile) + ubound(paste)-1)
    for x as integer = max(tzeile()) to zeile + 1 step -1
        tzeile(x + ubound(paste) -1) = tzeile(x)
    next
    L = Len(tzeile(zeile + a))
    tzeile(zeile +A) = left(tzeile(zeile +A), spalte +B-1) + paste(1) + right(tzeile(zeile +A), (L - spalte -B +1))

    for x as integer = lbound(paste) +2 to ubound(paste)
        tzeile(x+zeile-1) =  paste(x)
    next
    end if
    if ubound(paste) > 0 then
        zeile += ubound(paste) -1
    end if
    if zeile > opt(4).value - 2 then
        A += (zeile - opt(4).value - 2)
        zeile -= (zeile - opt(4).value -2)
    end if
    if ubound(paste) >= 1 then
        spalte = len(tzeile(zeile)) +1
        if spalte > opt(5).value then
            b = spalte - opt(5).value
            spalte -= b
        end if
        pot_spalte = spalte
    end if
    kill file
    RETURN i
END FUNCTION
#endif

sub laden(filename as string)
    dim as integer i = 2
    dim dummy as string

    dim pw_dummy as string
    redim tzeile(1) as string

    OPEN filename FOR INPUT AS #1
        if right(filename,3) = "mct" then

            crypt_key = eingabe("Password:","",opt(4).value,1)
            line INPUT #1, dummy
            pw_dummy = encoder(dummy,crypt_key)



            while not pw_dummy = crypt_key

            crypt_key = eingabe("Password:","",opt(4).value,1)

            pw_dummy = encoder(dummy,crypt_key)

            if dummy = crypt_key then

                print "Accepted";

            else

                print "Wrong!";

            end if

        wend

        end if
    while not EOF(1)
        i += 1
        REDIM Preserve tzeile(i) AS STRING
        line INPUT #1, dummy
        if right(filename,3) = "mct" then
            dummy = encoder(dummy,crypt_key)
        end if
        tzeile(i) = rtrim(str_replace(dummy, chr(9), string(opt(1).value," ")))
    wend
    CLOSE #1
    redim preserve tzeile(max(tzeile())) 'leere zeilen am ende der datei "abschneiden"
end sub

sub menu
    dim key as string
    dim c as integer = 1

    dim as integer old_tw = opt(1).value
    dim as integer old_w = opt(5).value, old_h = opt(4).value

    Locate old_h,1  : Print String(old_w, " ");
    do
        cls

        locate 1, 1     : PRINT "Use the Arrow-keys to change the values";

        locate 2, 1     : Print String(old_w, "_");

        Locate old_h-1,1: Print String(old_w, "_");

        Locate old_h,1  : Print "Press Enter or ESC to confirm";


        for sh as integer = 1 to ubound(opt)        'text anzeigen...
           if SH <= ubound(opt) then
                  locate sh+2 ,1
        if sh = c then
                print "X "& opt(sh).nam & string(49 - len(opt(sh).nam), " ") & opt(sh).value
        else
                print "  "& opt(sh).nam & string(49 - len(opt(sh).nam), " ") & opt(sh).value
            end if
        else
            exit for
        end if
        if sh = 50 then exit for
    next sh

    do : sleep 1 : key = inkey : loop until key <> ""
    select case key
    case chr(255,77) ' rechts
        if opt(c).value < opt(c).max then
            opt(c).value += 1
        end if
    case chr(255,75) 'links
        if opt(c).value > opt(c).min then
            opt(c).value -= 1
        end if
    case chr(255,72)                      'oben
        if c = 1 then
            c = ubound(opt)
        else
            c -= 1
        end if
    case chr(255,80)                      'unten
        if c < ubound(opt) then
            c += 1
        else
             c = 1
            end if
    case chr(27), chr(13)
        exit do
    end select
    loop

    if old_w <> opt(5).value or old_h <> opt(4).value then
        screenres opt(5).value *8, opt(4).value * 8
        COLOR 0, 15
    end if
    if old_tw <> opt(1).value then tab_correct(old_tw)

end sub

function max(array() as string, p as integer = 3) as integer
    dim m as integer
    for i as integer = 1 to ubound(array)
        if len(ltrim(array(i))) <> 0 then
            m = i
        end if
    next
    return m
end function


sub set_mark(key as integer)
    select case key
    case 72, 75, 77,80

        if multikey(&h2A) then

            if mark = 0 then

                m_start.x = zeile +A

                m_start.y = spalte +B

                mark = 1

            else

                m_akt.x = zeile +A

                m_akt.y = spalte +B

            end if

        else

            mark = 0

        end if
    case 71
        if multikey(&h2A) then
            if mark = 0 then
                m_start.x = zeile +A
                m_start.y = spalte +B
                m_akt.x = zeile +A
                m_akt.y = len(tzeile(zeile+A))+1
                mark = 1
            else
                m_akt.x = zeile +A
                m_akt.y = spalte +B
            end if
        else
            mark = 0
        end if
    case 79
        if multikey(&h2A) then
            if mark = 0 then
                m_start.x = zeile +A
                m_start.y = spalte +B
                m_akt.x = zeile +A
                m_akt.y = 1
                mark = 1
            else
                m_akt.x = zeile +A
                m_akt.y = spalte +B
            end if
        else
            mark = 0
        end if
    case else
        mark = 0
    end select

end sub


function new_file() as string
    dim filename as string
    dim key as string
    cls
    text (6,"Create a new File")
    if seite <> "" then
        locate opt(4).value, 1 : print "Save old file? (J/N)";
        do : sleep 1 : key = inkey: loop until key <> ""
        if lcase(key) = "j" then
            speichern(seite)
           end if
    end if

    filename = eingabe("New Filename: ", "new.txt", opt(4).value, 1, "Create a new File")
    if exist(filename) then
        locate opt(4).value, 1 : print "File already exists, overwrite? (J/N)";
        do : sleep 1 : key = inkey: loop until lcase(key) = "j" or lcase(key) = "n"
        if lcase(key) = "j" then
            open filename for output as #1
            close #1
            redim tzeile(0)
        elseif lcase(key) = "n" then
            exit function
        end if
    elseif len(filename) <> 0 then
        open filename for output as #1
        close #1
        redim tzeile(0)
    end if
    return filename
end function

Function str_replace(ByVal V_Data As String, ByVal V_Expression As String, ByVal V_ReplaceBy As String) As String
    Dim X As Long
    Dim SL As Long
    Dim D as String
    D = V_Data
    SL = Len(V_Expression)
    X = 0
    Do
        X = X + 1
        If X > Len(D) - SL + 1 Then Exit Do
        If Mid(D, X, SL) = V_Expression Then
            D = Mid(D, 1, X - 1) & V_ReplaceBy & Mid(D, X + SL)
            X = X - (SL  - 1)
            If X < 0 then X = 0
        End If
    Loop
    Return D
End Function

sub replace()
    dim keyword as string
    dim positionX(1 to 46) as integer
    dim positionY(1 to 46) as integer
    dim repl as string
    dim hit as integer

    locate 1,1 : print "Replace";
    locate 2, 1 : Print String(opt(5).value , asc("_"));
    text 5
    keyword = eingabe("Keyword:","",opt(4).value,1)
    repl = eingabe("Replace with:","",opt(4).value,1)
    locate 3,1
    for i as integer = zeile+a to ubound(tzeile)
        hit = instr(spalte,tzeile(i),keyword)
        if hit > 0 then
            tzeile(i) = left(tzeile(i),hit-1) + repl + right(tzeile(i), len(tzeile(i)) - hit -len(keyword) +1 )
        end if
    next
end sub

function search() as integer

    dim keyword as string
    dim key as string
    dim suchpos as integer
    dim as integer hit = 1
    locate 1,1 :Print String(opt(5).value , asc(" "));
    locate 1,1 : print "MuhEdit - Search";
    locate 2, 1 : Print String(opt(5).value , asc("_"));
    text 5
    keyword = eingabe("Keyword:","",opt(4).value,1)
    suchpos = spalte +B
    do
        for i as integer = zeile + A +hit to ubound(tzeile)
            do
                hit = instr(suchpos+1,lcase(tzeile(i)),lcase(keyword))
                if hit > 0 then
                    zeile = i
                    if zeile >= opt(4).value then
                        A = (zeile - opt(4).value) +4
                        zeile = zeile - A
                    end if
                    pot_spalte = hit
                    mark = 1
                    m_start.x = i
                    m_akt.x = i
                    m_start.y = hit
                    m_akt.y = hit + len(keyword)
                    correct_curs
                    exit for
                end if
                suchpos = hit + len(keyword) -1
            loop until hit = 0
            suchpos = 0
        next
        cls
        locate 1,1 :Print String(opt(5).value , asc(" "));
        locate 1,1 : print "Search";
        locate 2, 1 : Print String(opt(5).value , asc("_"));

        anzeige(tzeile(),A, B)
        text 5
        if hit = 0 then
            print "Last result in File, start new?";
        else
            print "Continue search?";
        end if
        print " Y/N";
        do : sleep 1 : key = inkey : loop until key <> ""
        if lcase(key) = "y" or key = chr(13) then
            if hit = 0 then
                zeile = 3
                A = 0
                hit = 0
            end if
        else
            exit do
        end if
    loop

    if mark = 1 then
        return -1
    else
        return 0
    end if
end function

sub speichern(file as string = "")
    cls
    dim x as integer
    dim as integer i = 3
    dim K as string
    dim filename() as string
    dim dummy as string
    text (6,"MuhEdit Saver")
    if file = "" then
        redim filename(i)
        anzeige(filename(), 0, 0)
        if len(seite) > 0 then
            seite = eingabe("Filename:",seite,opt(4).value,1)
        else
            seite = eingabe("Filename:","example.txt",opt(4).value,1)
        end if
    else
        seite = file
    end if

    if lcase(right(seite,3)) <> "mct" then
        text 5
        print "Do you want to Crypt the file? (Y/N)";
        do : sleep 1 : k = inkey : k = lcase(k) : loop until k = "y" or k = "n"
        if k = "y" then
            seite = left(seite, len(seite)-3) & "mct"
        end if
    else
        k = "y"
    end if
    if k = "y" then
        crypt_key = eingabe("Password:","",opt(4).value,1)
        OPEN seite FOR OUTPUT AS #1
        print #1, decoder(crypt_key, crypt_key)
        close #1
        OPEN seite FOR APPEND AS #1
    else
        OPEN seite FOR OUTPUT AS #1
    end if
    For x = 3 to max(tzeile())
        dummy = str_replace(tzeile(x), string(opt(1).value, " "), chr(9))
        if k = "y" then
            dummy = decoder(dummy,crypt_key)
        end if
        PRINT #1, rtrim(dummy)
    next
    CLOSE #1
       if file = "" then text(3) : getkey
end sub

sub tab_correct(old_width as integer)
    for i as integer = 1 to ubound(tzeile)
        tzeile(i) = str_replace(tzeile(i), string(old_width, " "), chr(9))
        tzeile(i) = str_replace(tzeile(i), chr(9), string(opt(1).value, " "))
    next
end sub

sub text(ByVal wahl As Integer, title as string = "")
    select case wahl
    case 1
        locate 1, 1 : PRINT " Browse = F2 / Save = F3 / Menu = F5 / Quit = ESC";
        locate 2, 1 : Print String(opt(5).value ,"_");
        Locate (opt(4).value-1),1 : Print String(opt(5).value ,"_");
        Locate (opt(4).value),1 : Print String(opt(5).value ," ");
        Locate (opt(4).value),1 : Print "File: "& right(seite,26) &" / Line: "& Zeile + A - 2 &" / Row:"& spalte+b;
        case 2
        locate (opt(4).value),1 : Print String(opt(5).value," ");
    case 3
        locate (opt(4).value),1 : Print String(opt(5).value," ");
        Locate (opt(4).value),1 : Print "Accepted";
        locate 3,1
    case 4
        locate (opt(4).value), 1 : Print String(opt(5).value," ");
        Locate (opt(4).value), 1 : Print "False";
        locate 3,1
    case 5
        Locate (opt(4).value-1),1 : Print String(opt(5).value,"_");
    case 6
        locate 1, 1        : PRINT title;
        locate 2, 1        : Print String(opt(5).value,"_");
        Locate (opt(4).value-1),1 : Print String(opt(5).value,"_");
        Locate (opt(4).value),1 : Print String(opt(5).value, " ");
    case else
        exit sub
    end select
end sub

'------WIndows-Spezifisch:------'
#ifndef __fb_linux__
#include "windows.bi"
Declare Sub WriteClipboard(Text As String)
Declare Function ReadClipboard() As String
declare sub s_t_a(text as string)
dim text2 as string

sub s_t_a(text2 as string)
    dim paste() as string
    dim suchpos as integer
    dim n_zeile as integer
    dim count as integer
    dim old as integer
    dim L as integer
    dim as integer hit = 0
    do
    hit = instr(suchpos+1,text2,chr(13,10))
        if hit > 0 then
                count += 1
            redim preserve paste(count)
            if old > 0 then
                paste(count) = mid(text2,old+2,hit - old -1 )
            else
                paste(count) = left(text2,hit)
            end if
            old = hit
        end if
        suchpos = hit + 1
    loop until hit = 0
    redim preserve paste(count+1)
    if old = 0 then
        paste(count+1) =  mid(text2,old+1,hit - old -1)
    else
        paste(count+1) =  mid(text2,old+2,hit - old -1)
    end if
    print "-----"
    print "test" + paste(count+1)
    redim preserve tzeile(ubound(tzeile) + ubound(paste))
    for x as integer = max(tzeile()) to zeile + 1 step -1
        tzeile(x + ubound(paste) -1) = tzeile(x)
    next

    L = Len(tzeile(zeile + a))

    tzeile(zeile +A) = left(tzeile(zeile +A), spalte +B-1) + paste(1) + right(tzeile(zeile +A), (L - spalte -B +1))

    for x as integer = lbound(paste) +2 to ubound(paste)
        tzeile(x+zeile-1) =  paste(x)
    next

    n_zeile += ubound(paste) -1
    if n_zeile > opt(4).value - 4 then
        A += n_zeile - opt(4).value -4
        zeile = n_zeile - opt(4).value -4
    end if
    if zeile > opt(4).value - 2 then
        A += (zeile - opt(4).value - 2)
        zeile -= A
    end if
    if ubound(paste) = 1 then
        spalte = len(tzeile(zeile)) +1
        if spalte > opt(5).value then
            b =  spalte - opt(5).value
            spalte -= b
        end if
        pot_spalte = spalte
    end if
end sub

Function readClipboard() As String
      Dim As Any Ptr hGlobal, pGlobal
      Dim As String txt

    OpenClipboard(0)
      hGlobal=GetClipboardData(1)
      If hGlobal then
        pGlobal=GlobalLock(hGlobal)
        txt=Space(lstrlen(pGlobal)) ' txt auf die Länge des Clipboards bringen
         lstrcpy(strptr(txt), pGlobal)
         ReadClipboard=txt
     End If
     CloseClipboard()
End Function

Sub writeClipboard(Txt As String)
    Dim As Any Ptr lpMem, hGlobalClip

    hGlobalClip=GlobalAlloc(GMEM_MOVEABLE Or GMEM_SHARE, Len(Txt)+1)
    OpenClipboard(0)
    EmptyClipboard()
    lpMem=GlobalLock(hGlobalClip)
    lstrcpy(lpMem, strptr(Txt))
    GlobalUnlock(lpMem)
    SetClipboardData(CF_TEXT, hGlobalClip)
    CloseClipboard()
End Sub
#endif
'----Ende Windows-teil----'

'------------------Aufruf-flags auswerten------------------'
dim s as integer
if command(1) = "-S" then
    opt(4).value = HIWORD(WIDTH)
    opt(5).value = LOWORD(WIDTH)

    if command(2) <> "" then
        seite = command(2)
        laden(seite)
    end if
    COLOR 0, 15
    CLS
elseif command(1) <> "-S" then

    screenres opt(5).value*8, opt(4).value * 8

    COLOR 0, 15

    CLS
    seite = command(1)
    laden(seite)
end if
'Dateinamen korrigieren:
seite = right(seite,len(seite) -InstrRev(seite, "/"))
'------------------------hauptprogramm----------------------'
dirs = curdir
locate 3, 0
DO
    '------ verwaltung + anzeige ------'
    angleichen()
    L = len(tzeile(zeile + A))
    anzeige(tzeile(), A, B)
    text 1
    locate zeile ,spalte,1
    DRAW STRING ((spalte-1 + ba)*8 , (zeile -1)*8), "_",  'Cursor anzeigen
    '------ Eingabe ------':
    do : sleep 1 'auf eingabe warten
        d = inkey

        getmouse mspalte, mzeile,wheel,buttons

        if mzeile = -1 and mspalte = -1 then continue do
        mzeile = mzeile / 8
        mspalte =  (mspalte+4) / 8 - BA

        if mspalte <= 0 then mspalte = 1
        if buttons = 1 and mzeile <= (opt(4).value - 2) and mzeile > 2 then
            if mzeile <= ubound(tzeile) and mzeile >= 3 then
                m_start.x = mzeile +A
                m_start.y = mspalte +B
            end if
            while buttons <> 0
                getmouse mspalte, mzeile,wheel,buttons
                if mzeile = -1 and mspalte = -1 then continue while
                mzeile = mzeile / 8
                mspalte =  (mspalte+4) / 8 - BA
                if mzeile <= ubound(tzeile) and mzeile > 2 then
                    m_akt.x = mzeile+A
                    if mspalte > 0 then
                        m_akt.y = mspalte+B
                    else
                        m_akt.y = 1+B
                    end if
                    mark = 1

                    if zeile <> mzeile or spalte <> mspalte  then
                        DRAW STRING ((spalte-1 + ba)*8 , (zeile -1)*8), "_",15
                    end if
                    zeile = mzeile
                    spalte = mspalte
                    'Begin Mouse-Check Code
                    if ubound(tZeile) < zeile + A then
                        if ubound(tzeile) > opt(4).value -4 then
                            A = (ubound(tzeile) -opt(4).value +4)
                            zeile = (ubound(tzeile) - A)
                        else
                            zeile = (ubound(tzeile))
                        end if
                    end if
                    tZeile(zeile + A) = rtrim(tZeile(zeile + A))
                    if mspalte > len(tZeile(zeile + A)) then
                        spalte = len(tZeile(zeile + A)) + 1
                    else
                        spalte = mspalte

                    end if
                    'End Mouse-Check Code
                    pot_spalte = spalte
                    d = ""
                    anzeige(tzeile(),A,B)
                end if
            wend
            exit do
        end if

        'mausrad-code:

        mdummy = wheel - wheel_old

        if mdummy > 0 then 'hoch

            if A-3 > 0 then

                A -= 3

            else

                A = 0

            end if

        end if

        if mdummy < 0 and ubound(tzeile) > opt(4).value then 'runter

            if zeile + A +3 < ubound(tzeile) then

                A += 3

            else

                A = ubound(tzeile) - zeile

            end if

        end if

        wheel_old = wheel

        if mdummy <> 0 then exit do

        'set_mark()

        'ende Mausrad-code
    loop until d<>""


    if mdummy <> 0 then cls : correct_curs :continue do
    locate zeile ,spalte,1
    if d = "" then continue do
    Re = mid(d, 2,1)
    ascR = asc(Re)
    if command(1) <> "-S" then D = conv(D)
    Li = mid(d, 1,1)
    ascL = asc(Li)
    '------ Verarbeitung teil 1 ------':
    SELECT CASE ascR
    case 72                   'oben

        set_mark(ascR)
        if zeile > 3 then
            zeile -= 1
        else
            if A > 0 then A -= 1
        end if
        if zeile <> 2 then
            correct_curs
        end if
    case 80                      'unten

        set_mark(ascR)
        if zeile + a < ubound(tzeile) then
            if zeile < (opt(4).value - 2) then
                zeile += 1
            else
                A += 1
            end if
            correct_curs
        end if
    case 75                      'links

        set_mark(ascR)
        if spalte > 1 then                       'nicht am zeilenanfang
            spalte-=1
            pot_spalte = spalte + b
        else                                'am zeilenanfang
            if zeile > 3 and zeile < (opt(4).value - 2) then
                if B = 0 then
                    zeile -= 1
                    pot_spalte = len(tzeile(zeile +A)) +1

                    if spalte > opt(5).value then

                        B = pot_spalte - opt(5).value

                        pot_spalte -= B

                    end if

                    correct_curs
                else
                    B -= 1
                end if
            elseif zeile = 3 or zeile = (opt(4).value-2) then
                if B <> 0 then
                    B -= 1
                elseif B = 0 then
                    if zeile = opt(4).value-2 then zeile -= 1
                    if A > 0 then A -= 1
                end if
            end if
        end if
    case 77                       'rechts

        set_mark(ascR)
        if spalte + b < L + 2 and spalte + b < L +1 orelse zeile + a < ubound(tzeile) then
            if spalte < opt(5).value then
                spalte += 1
                pot_spalte = spalte + b
            elseif spalte = opt(5).value then
                b += 1
            end if
        end if
        if spalte + b >= l +2 then

            spalte = 1

            B = 0
            if zeile < (opt(4).value - 2) then
                zeile += 1
            else
                A += 1
            end if
        end if
    case 107                        'das X oben
        exit do
    case 59                         'F1
        Help

    case 60                         'F2 - laden

        dirs = directory(&h10)

        text(1)

        spalte =1

        zeile = 3

    case 61                         'F3 - Speichern

        speichern()

        text(1)
    case 62                         'F4 - fileinfos
        info()

        sleep

    case 63                      'F5 - Menü

        menu
        if opt(2).value  = 0 then ba = 0
    case 82                         'einfügen
        if einf = 1 then
            einf = 0
        else
            einf = 1
        end if
    case 73                         'bild hoch
        set_mark(ascR)
        if A-2 > 0 then
            A -= 3

        else

            A = 0
        end if
        correct_curs
    case 81                         'bild runter

        if ubound(tzeile) > (zeile + A)+2 then
            a += 3

        else

            A = ubound(tzeile) - zeile
        end if

        correct_curs
    case 71                      'Pos1
        set_mark(ascR)
        pot_spalte = 1
        b = 0
        correct_curs
    case 79                      'Ende
        set_mark(ascR)
        pot_spalte = len(tzeile(zeile +A)) +1
        if spalte > opt(5).value then
            B = pot_spalte - opt(5).value
            pot_spalte -= B
        end if
        correct_curs
    #ifndef __fb_linux__
    case 83          'entf
        if mark = 1 then
            cut()
        else
            if L >= spalte + B  then
                tzeile(zeile+A) = left(tzeile(zeile+A),B + spalte-1) + right(tzeile(zeile+A),L -(spalte+B))
            elseif L < spalte + B then
                redim preserve tzeile(ubound(tzeile) + 1)
                rest = tzeile(zeile + a +1)
                tzeile(zeile +a ) = tzeile(zeile + a) + rest
                for x as integer = zeile + a +1 TO max(tzeile())
                    tzeile(x) = tzeile(x+1)
                next
                redim preserve tzeile(ubound(tzeile) -1)
            end if
        end if
    #endif
    end select
    '------ Verarbeitung teil 2 ------':
    if ascL <> 255 then
    select case ascL
    case 6
        if search() then
            if zeile > 46 then
                A = zeile - 46
                zeile -= A
            end if
            cls
            'mark = 1
            continue do
        end if
    case 8
        if mark = 1 then
            cut()
        else
            if spalte > 1 then
                if B = 0 then
                    spalte-=1
                else
                    b -= 1
                end if
                locate zeile,spalte
                L = len(tzeile(zeile +A))
                if L >= spalte+B then
                    tzeile(zeile+A) = left(tzeile(zeile+A),B + spalte-1) + right(tzeile(zeile+A),L -(spalte+B))
                else
                    tzeile(zeile +A)=left(tzeile(zeile +A),len(tzeile(zeile +A))-1)
                end if
            else                                    'am zeilenanfang
                if zeile + A <= max(tzeile()) and zeile + A  > 3 then
                    spalte = len(tzeile(zeile +A -1)) +1
                    redim preserve tzeile(ubound(tzeile) + 1)
                    rest = tzeile(zeile + A)
                    tzeile(zeile + A -1) = tzeile(zeile + A -1) + rest
                    for x as integer = (zeile + A) TO max(tzeile())
                        tzeile(x) = tzeile(x+1)
                    next
                    redim preserve tzeile(ubound(tzeile) -1)
                    zeile -= 1
                   end if
                   if zeile +a  > max(tzeile()) and zeile > 3 then
                    zeile -= 1
                    spalte = len(rtrim(tzeile(zeile + A)))+1
                end if
                   if zeile = 3 and a > 0 then
                       if A > 0 then A -= 1
                       spalte = len(rtrim(tzeile(zeile+a)))+1
                end if
                pot_spalte = spalte

                if max(tzeile()) < ubound(tzeile) then redim preserve tzeile(max(tzeile()))
            end if
        end if
    case 13                           'enter
        if L >= (spalte + b)-1 and zeile + a <= max(tzeile()) then
            redim preserve tzeile(ubound(tzeile) + 1)
            for x as integer = ubound(tzeile) to (zeile +a +1) step -1
                tzeile(x) = tzeile(x-1)
            next
            rest = right(tzeile(zeile +A), (L - (spalte + B))+1)
            tzeile(zeile+A) = left(tzeile(zeile+A), (Spalte +B) -1)
            tzeile(Zeile+A+1) = rest
        elseif zeile + a <= max(tzeile()) and L = 0 then
            redim preserve tzeile(ubound(tzeile) + 1)

            for x as integer = ubound(tzeile)-1 to (zeile + a) step -1
                tzeile(x+1) = tzeile(x)
            next
        end if


        if zeile < (opt(4).value - 2) then
            zeile += 1
            spalte = 1
            B = 0
        else
            spalte = 1
            B = 0
            A += 1
        end if
        pot_spalte = spalte
    #IFdef __fb_linux__
    case 127                    'ENTF
        'set_mark()
        if mark = 1 then
            cut()
        else
            if L >= spalte + B  then

                tzeile(zeile+A) = left(tzeile(zeile+A),B + spalte-1) + right(tzeile(zeile+A),L -(spalte+B))

            elseif L < spalte + B then

                redim preserve tzeile(ubound(tzeile) + 1)

                rest = tzeile(zeile + a +1)

                tzeile(zeile +a ) = tzeile(zeile + a) + rest

                for x as integer = zeile + a +1 TO max(tzeile())

                    tzeile(x) = tzeile(x+1)

                next

                redim preserve tzeile(ubound(tzeile) -1)

            end if
        end if
    #endif
    '------ Copy und Paste ------':
    case 3
        if mark = 1 then
            cut(2)
        end if
    case 22
        #ifdef __fb_linux__
        if clip  = 1 then
            if mark = 1 then
                cut(3)
            end if
            getfromclipboard()
        end if

        #else
            text2 = ReadClipboard
            s_t_a(text2)
        #endif
    '-----------------------------'
    case 19
        speichern()
        text(1)
    case 27                         'escape
        exit do
    case 32 to 127,9,245,21, 132,142,148,153,129,154,225
        if mark = 1 then cut(3)
        if D = chr(9) then
            D = string(opt(1).value, " ")
        end if
        L = len(tzeile(zeile +A))
        if L >= spalte + B then
            if einf = 0 then
                MID(tzeile(zeile + A), spalte +B, 1) = d
            else
                tzeile(zeile +A) = left(tzeile(zeile +A), spalte +B-1) + d + right(tzeile(zeile +A), (L - spalte -B +1))
            end if
        else
            tzeile(zeile +A) = tzeile(zeile +A) + d
        end if
        if spalte = opt(5).value then
            b += 1
        else
            spalte += 1
        end if
        if ascL = 9 then
            if spalte <= opt(5).value -4 then
                spalte += len(D) -1
            else
                B += len(D) -1 - (opt(5).value - spalte)
            end if
        end if
        pot_spalte = spalte + b
    case else
        if multikey(&h1D) then
            if multikey(&h13) then 'Strg+R
                if opt(2).value = 1 then
                    opt(2).value = 0
                    ba = 0
                else
                    opt(2).value = 1
                end if
            elseif multikey(&h1E) then 'STRG+A
                mark = 1
                m_start.x = 3
                m_start.y = 1
                m_akt.x = ubound(tzeile)
                m_akt.y = len(tzeile(m_akt.x))+1 + B
                cls
                continue do
            elseif multikey(&h18) then 'STRG+O
                dirs = directory(&h00)
                text(1)
                spalte =1
                zeile = 3
            elseif multikey(&h31) then 'STRG+N
                seite = new_file
                cls
            elseif multikey(&h2D) and mark = 1 then
                cut(1)
            end if
        end if
    end select
    end if
    cls
    set_mark(ascR)
loop
end