Buchempfehlung
MySQL kurz & gut
MySQL kurz & gut
Das preiswerte Taschen- buch stellt MySQL-rele- vante Inhalte systematisch und knapp dar, sodass es sich optimal zum Nach- schlagen beim Pro- grammieren eignet. [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.4

Uploader:MitgliedThe_Muh
Datum/Zeit:25.07.2008 21:40:27

'MuhEdit, version 0.9.4
'programming and Idea by The_Muh
'Thanks to: MisterD, ThePuppetMaster for little pieces of code
'and Michael Tyca for Testing
'licence:
'Creative Commons:
'by-nc-sa
'subs und funktionen (declare):
declare sub laden(seite as string)
declare sub speichern()
declare function directory(FL as integer) as string
declare sub text(ByVal Maeh As Integer)
declare function conv(key as string) as string
declare sub anzeige(anzeigetext() as string, X as integer, Y as integer)
declare function eingabe(ByVal frage As String ,vorgabe As String, X as integer,Y as integer) as string
'Variablen:
dim shared as integer hoehe = 55, breite = 50
dim d as string
dim as string Li, Re
dim as integer ascL, ascR
dim shared as string tZeile()
dim shared as string seite
dim shared as integer zeile=3, spalte=1
dim as integer mzeile, mspalte, buttons
dim i as integer
dim L as integer
Dim as integer einf = 0
dim dirs as string
dim rest as string
dim shared a as integer
dim shared b as integer

REDIM tzeile(1) AS STRING
'Makros:
#macro datei (array2,endung,flag)
    K = DIR("*." & endung,flag)
    do
        if len(k) then                      ' alle anderen =)
        redim preserve array2(i)
        array2(i) = K
        K = DIR("")
        i += 1
        end if
    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(breite, asc("_"));
    locate 3, 1 : Print right(Curdir,50);
    locate hoehe,1 :Print "Switch between File / Directory = F1";
    text(5)

    for sh as integer = lbound(array) to hoehe-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
        if sh = 50 then exit for
    next sh

    do : sleep 1 : key = inkey : loop until key <> ""
    select case key
    case chr(255,59)
        if flag = &h10 then
            flag = &h00
        else
            flag = &h10
        end if
        exit do
    case chr(255,73):
        if A > 0 then
            A -= 1
        end if
    case chr(255,81)
        if c + a < ubound(array) then A += 1
    case chr(255,72)                      'oben
        if c > 0 then c -= 1
        if A > 0 and c = 0 then a -= 1
    case chr(255,80)                      'unten
        if c < hoehe -6 and c < ubound(array) then
            c += 1
        else
            if c + a < ubound(array) then A += 1
        end if
    case chr(27)
        if flag = &h10 then weiter = 0
        exit do
    case chr(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 angleichen()
    if ubound(tzeile) < zeile + A then redim preserve tzeile(zeile + A) as string
end sub

sub anzeige(anzeigetext() as string, X as integer,Y as integer)
    if X >= 0 then
        for sh as integer = 3 to (hoehe - 2)        'text anzeigen...
            if SH + X <= ubound(anzeigetext) then
                locate sh, 1
                print mid(anzeigetext(sh+X),Y +1,breite)
            else
                exit for
            end if
        next sh
    else
        for sh as integer = 3 to (hoehe -2)
            locate sh, 1
            print mid(anzeigetext(sh),Y +1,breite)
        next sh
    end if
    'text(1)
end sub

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)
    case else: con = chr(ascl)
    end select
    return con
end function

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 8,1
    print "Textlines:       "& code' - blank
    print "Blanklines:      "& blank
    print ""
    print "Gesamt:          "& code + blank
end sub

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)
    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 hoehe,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) 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
    locate x, 1
    print frage & Zeichenkette;
    spalte = len(zeichenkette)
    y = len(frage) +1
    do
        text(2)
        text(6)
        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
        end select

        if ascL <> 255 then
        select case ascL
        case 8                                            'backspace
            if L >= spalte then
                zeichenkette = left(zeichenkette,spalte-1) + right(zeichenkette,L -(spalte))
            else
                zeichenkette=left(zeichenkette,len(zeichenkette)-1)
            end if

            if spalte <> 1 then spalte -= 1
        case 13                                        'enter
            return zeichenkette
            locate 3,1
            exit function
        case 27
            return vorgabe
            locate 3,1
            exit function
        case 127                                        'entf
            if L >= spalte then
                zeichenkette = left(zeichenkette,spalte-1) + right(zeichenkette,L -(spalte))
            end if
        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

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
    filesize = filesize / 1024
    locate 3,1:print "Filename:        "& seite;
    locate 4,1:print "Letters:         "& zeichen;
    locate 5,1:print "Filesize:        "& filesize & " kB";
end sub

sub laden(seite as string)
    dim as integer i = 2
    'seite = file()

    redim tzeile(0) as string
    OPEN seite FOR INPUT AS #1
    while not EOF(1)
        i += 1
        REDIM Preserve tzeile(i) AS STRING
        line INPUT #1, tzeile(i)
    wend
    CLOSE #1
    cls
end sub

sub speichern()
    cls
    dim x as integer
    dim as integer i = 3
    dim max as integer
    dim K as string
    for i as integer = 1 to ubound(tzeile)
        if len(ltrim(tzeile(i))) >= 1 then
            max = i
        end if
    next
    dim filename() as string
    redim filename(i)
    'datei("txt"):datei("*ml"):datei("bas")
    anzeige(filename(), 0, 0)

    text 6 'linie
    if len(seite) > 0 then
        seite = eingabe("Filename:",seite,hoehe,1)
    else
        seite = eingabe("Filename:","example.txt",hoehe,1)
    end if

    OPEN seite FOR OUTPUT AS #1
    For x = 3 to max
        PRINT #1, rtrim(tzeile(x))
    next
    CLOSE #1
    text(3) 'accepted
    getkey
end sub

sub text(ByVal Maeh As Integer)
    select case maeh
    case 1:
        locate 1, 1 : PRINT "Load = F2 / Save = F3 / Directory = F4 / Quit = ESC":
        locate 2, 1 : Print String(breite , asc("_"));
        Locate (hoehe-1),1 : Print String(breite , asc("_"));
        Locate (hoehe),1 : Print "File: "& seite &" / Line: "& Zeile+A-2 &" / Row:"& spalte+b;
    case 2:
        locate (hoehe    ), 1 : Print String(breite, asc(" "));
    case 3:
        locate (hoehe), 1 : Print String(breite, asc(" "));
        Locate (hoehe), 1 : Print "Accepted";
        locate 3,1
    case 4:
        locate (hoehe), 1 : Print String(breite, asc(" "));
        Locate (hoehe), 1 : Print "False";
        locate 3,1
    case 5:
        Locate (hoehe-1),1 : Print String(breite, asc("_"));
    case 6:
        locate 1, 1           : PRINT "MuhEdit Saver" ;
        locate 2, 1           : Print String(breite, asc("_"));
        Locate (hoehe-1),1 : Print String(breite, asc("_"));
    case 7:
        locate 1, 1           : PRINT "MuhEdit Fileinfo";
        locate 2, 1           : Print String(breite, asc("_"));
        Locate (hoehe-1),1 : Print String(breite, asc("_"));
        Locate (hoehe),1 : Print String(breite, asc(" "));
    case else
        exit sub
    end select
end sub

'------------------------hauptprogramm----------------------'
if command(1) = "-S" then
    hoehe = HIWORD(WIDTH)
    breite = LOWORD(WIDTH)

    if command(2) <> "" then
        seite = command(2)
        laden(seite)
    end if
elseif command(1) <> "-S" then
    seite = command(1)
    laden(seite)
    screenres breite*8, hoehe * 8
    COLOR 0, 15
end if

CLS
dirs = curdir
locate 3, 0
DO
    angleichen()
    L = len(tzeile(zeile + A))
    if L < spalte + B then
        for i = 1 to spalte + b
            tzeile(zeile + A) += " "
        next i
    end if
    anzeige(tzeile(), A, B)
    text 1
    locate zeile ,spalte,1
    DRAW STRING ((spalte-1)*8 , (zeile -1)*8), "_",  'Cursor anzeigen
    'auf eingabe warten:
    do : sleep 1
        d = inkey
        getmouse mspalte, mzeile,,buttons
        mzeile = mzeile / 8
        mspalte =  mspalte / 8
        if buttons = 1 and mzeile <= (hoehe - 2) and mzeile > 3 then
            zeile = mzeile
            spalte = mspalte
            d = ""
            exit do
        end if
    loop until d<>""
    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)

    SELECT CASE ascR
    case 72:                      'oben
        if zeile > 3 then
            zeile -= 1
        else
            if A > 0 then A -= 1
        end if
    case 80:                         'unten
        if zeile < (hoehe - 2) then
            zeile += 1
        else
            A += 1
        end if
    case 75:                         'links
        if spalte > 1 then                        'nicht am zeilenanfang
            spalte-=1
        else                                'am zeilenanfang
            if zeile > 3 and zeile < (hoehe - 2) then
                if B = 0 then
                    zeile -= 1
                    spalte = 1
                else
                    B -= 1
                end if
            elseif zeile = 3 or zeile = (hoehe-2) then
                if B <> 0 then
                    B -= 1
                elseif B = 0 then
                    if zeile = hoehe-2 then zeile -= 1
                    if A > 0 then A -= 1
                end if
            end if
        end if
    case 77:                           'rechts
        if spalte < breite then
            tzeile(zeile +A) += chr(32)
            spalte += 1
        elseif spalte = breite then
            b += 1
        end if
    case 107:                        'das X oben
        exit do
    case 63:                            'F5, hohe und breite
        if command(1) <> "-S" then
        CLS
        text(1)
        locate 3,1 : print "The width must be 55 or higher"
        locate 4,1 : print "The Heigth must be 20 or higher"
        locate 5,1 : Input "Heigth: ", Hoehe
        Locate 6,1 : Input "Width: ", Breite
        if breite < 55 then breite = 55
        if hoehe < 20 then hoehe = 20
        screenres breite *8, hoehe * 8
        if zeile > hoehe then
            A += zeile-hoehe+2
            zeile = 3
        end if
        if command(1) <> "-S" then COLOR 0, 15
        end if
    case 64:                        'f5 (dateiinfo)
        info()
        counter()
        getkey
    case 62:                            'F4 (verzeichnis wechseln)
        dirs = directory(&h10)
        text(1)
    case 61:                          'seite speichern(F3)
        speichern()
        text(1)
    case 60:                          'Laden (F2)
        dirs = directory(&h00)
        text(1)
    case 82:                            'einfügen
        if einf = 1 then
            einf = 0
        else
            einf = 1
        end if
    case 73:
        if A > 0 then
            A -= 1
        end if
    case 81
        a += 1
    end select

    'Zweiter case-block
    if ascL <> 255 then
    select case ascL
        case 8:                               'backspace
        if spalte > 1 then                        'nicht am zeilenanfang
            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 > 3 then
                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
                zeile -= 1
                spalte = len(rtrim(tzeile(zeile)))+1
            else
                if A > 0 then A -= 1
            end if
        end if
    case 26:
        cls
        locate 3,1 : print"         \__/"
        locate 4,1 : print"         (oo)"
        locate 5,1 : print"  /-------\/"
        locate 6,1 : print" / |     ||"
        locate 7,1 : print"*  ||----||"
        locate 8,1 : print"   ~~    ~~"
        getkey
    case 13:                              'enter
        if L > (spalte + b) then
            for i as integer = ubound(tzeile) + 1 to (zeile + a +1) step -1
                if i >= ubound(tzeile) then redim preserve tzeile(i+1)
                if i <> 3 then tzeile(i+1) = tzeile(i)
            next i
            rest = right(tzeile(zeile +A), (L - (spalte + B))+1)
            tzeile(zeile+A) = left(tzeile(zeile+A), (Spalte +B) -1)
            tzeile(Zeile+A+1) = rest
        end if
        if zeile < (hoehe - 2) then
            zeile += 1
            spalte = 1
            B = 0
        else
            spalte = 1
            B = 0
            A += 1
        end if
    case 127:
        if L >= spalte then
            tzeile(zeile+A) = left(tzeile(zeile+A),B + spalte-1) + right(tzeile(zeile+A),L -(spalte+B))
        end if
    case 19:
        speichern()
        text(1)
    case 27:                              'escape
        exit do
    case 32 to 127,9,245, 132,142,148,153,129,154,225
        if D = chr(9) then
            D = "    "
            if spalte <= breite -4 then
                spalte +=4
            else
                B += 4 - (breite - spalte)
            end if
        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) = mid(tzeile(zeile +A),1,(spalte +B)) + d + mid(tzeile(zeile +A),spalte + b + 1,(L -spalte +1))
            end if
        else
            tzeile(zeile +A) = tzeile(zeile +A) + d
        end if

        if spalte = breite then
            b += 1
        else
            spalte += 1
        end if
    end select
    end if
    cls
loop

cls
locate 1, 1
PRINT "TextEditor by The_Muh | Press any key to quit   ";
locate 2, 1 : Print String(breite, asc("_"));

text(5)
Locate (hoehe),1
Print "Programming and Idea:                   The_Muh";
getkey
'color 15,0
cls
end
'---------------------------------------------------------------
'bis 1.0:
'- Fertigstellung und bugfreiheit aller, für Textbearbeitung notwendiger features
'Danach:
'eventuell mehrere Builds um auch globales Copy'n'Paste zu unterstützen.
'---------------------------------------------------------------