Aly-Gator Compression/Decompression Utility


'** 8/16/2003 7:07:53 AM
'** Aly-Gator
'** very simple compression for plain text files
'** no characters above 127 may be contained in files to be compressed
'** uses array of 127 most recently used English words longer than two letters
'** replaces words with characters 128-255 for compression
'** appends "c" to filename to save compressed file
'** appends "d" to filename to save decompressed file, and opens it in Notepad
'** reports compression percentage
'** compression varies, ranges from 5% to 20% on files tested
 
    True = 1 : False = 0

gosub [fillArray]

[WindowSetup]
    NOMAINWIN
    WindowWidth = 370 : WindowHeight = 180
    UpperLeftX = INT((DisplayWidth-WindowWidth)/2)
    UpperLeftY = INT((DisplayHeight-WindowHeight)/2)

[ControlSetup]

statictext  #main.s, "Status of Operation", 20, 55, 320, 90
button      #main.compress, "Compress",[compress],UL, 15, 15, 105, 25
button      #main.decompress, "Decompress",[decompress],UL, 125, 15, 105, 25
button      #main.quit, "Exit",[quit],UL, 235, 15, 105, 25

Open "Aly-Gator" for Dialog as #main
    #main "trapclose [quit]"
    #main "font ms_sans_serif 10"

[loop]
    Wait

[quit]
    close #main : END

[compress]
    filedialog "Compress File","*.txt",cfile$
    if cfile$="" then wait
    #main.s "PLEASE WAIT -  Compressing ";cfile$
    cursor hourglass
    
    open cfile$ for input as #f
    origLen=lof(#f)
    c$=""   'new string
    
    while not(eof(#f))
        line input #f, s$
        for i = 1 to 127
            wx=1
            while wx>0
                wx=instr(s$,a$(i))
                if wx>0 then
                    s$=left$(s$,wx-1)+chr$(i+127)+mid$(s$,wx+len(a$(i)))
                end if
            wend
        next
        c$=c$+s$+chr$(13)+chr$(10) 'add back the crlf
    wend
    close #f
    
[doneCompress]
    open cfile$+"c" for output as #g
    print #g, c$
    close #g   
    cursor normal   
    compLen=len(c$)
    compPercent=(origLen-compLen)/origLen
    cp$=using("##.##",compPercent*100)+"%"
    #main.s "Compressed file saved as "+cfile$+"c"+chr$(13)+"Compression:  "+cp$
    wait

[decompress]
    filedialog "Decompress File","*.txtc",dfile$
    if dfile$="" then wait
    #main.s "Decompressing ";dfile$
    cursor hourglass
    open dfile$ for input as #f
    s$=input$(#f, lof(#f))
    close #f
    
    j=1     'word counter
    d$=""   'new string
    
    for i = 1 to len(s$)
        x$=mid$(s$,i,1)
        ax=asc(x$)
        if ax >127 then
            x$=a$(ax-127)
        end if
        d$=d$+x$
    next
    
[doneDecompress]
    open dfile$+"d" for output as #g
    print #g, d$
    close #g   
    #main.s "Decompressed file saved as ";dfile$+"d"  
    run "Notepad " + chr$(34)+dfile$+"d"+chr$(34) 
    cursor normal  
    wait

[fillArray]
    DIM a$(127)
    a$(1) = "the"
    a$(2) = "and"
    a$(3) = "you"
    a$(4) = "that"
    a$(5) = "was"
    a$(6) = "for"
    a$(7) = "are"
    a$(8) = "with"
    a$(9) = "his"
    a$(10) = "they"
    a$(11) = "one"
    a$(12) = "have"
    a$(13) = "this"
    a$(14) = "from"
    a$(15) = "had"
    a$(16) = "hot"
    a$(17) = "word"
    a$(18) = "but"
    a$(19) = "what"
    a$(20) = "some"
    a$(21) = "can"
    a$(22) = "out"
    a$(23) = "other"
    a$(24) = "were"
    a$(25) = "all"
    a$(26) = "there"
    a$(27) = "when"
    a$(28) = "use"
    a$(29) = "your"
    a$(30) = "how"
    a$(31) = "said"
    a$(32) = "each"
    a$(33) = "she"
    a$(34) = "which"
    a$(35) = "their"
    a$(36) = "time"
    a$(37) = "will"
    a$(38) = "way"
    a$(39) = "about"
    a$(40) = "many"
    a$(41) = "then"
    a$(42) = "them"
    a$(43) = "write"
    a$(44) = "would"
    a$(45) = "like"
    a$(46) = "these"
    a$(47) = "long"
    a$(48) = "make"
    a$(49) = "thing"
    a$(50) = "see"
    a$(51) = "him"
    a$(52) = "two"
    a$(53) = "has"
    a$(54) = "look"
    a$(55) = "more"
    a$(56) = "day"
    a$(57) = "could"
    a$(58) = "come"
    a$(59) = "did"
    a$(60) = "number"
    a$(61) = "sound"
    a$(62) = "most"
    a$(63) = "people"
    a$(64) = "over"
    a$(65) = "know"
    a$(66) = "water"
    a$(67) = "than"
    a$(68) = "call"
    a$(69) = "first"
    a$(70) = "who"
    a$(71) = "may"
    a$(72) = "down"
    a$(73) = "side"
    a$(74) = "been"
    a$(75) = "now"
    a$(76) = "find"
    a$(77) = "any"
    a$(78) = "new"
    a$(79) = "work"
    a$(80) = "part"
    a$(81) = "take"
    a$(82) = "get"
    a$(83) = "place"
    a$(84) = "made"
    a$(85) = "live"
    a$(86) = "where"
    a$(87) = "after"
    a$(88) = "back"
    a$(89) = "little"
    a$(90) = "only"
    a$(91) = "round"
    a$(92) = "man"
    a$(93) = "year"
    a$(94) = "came"
    a$(95) = "show"
    a$(96) = "every"
    a$(97) = "good"
    a$(98) = "give"
    a$(99) = "our"
    a$(100) = "under"
    a$(101) = "name"
    a$(102) = "very"
    a$(103) = "through"
    a$(104) = "just"
    a$(105) = "form"
    a$(106) = "sentence"
    a$(107) = "great"
    a$(108) = "think"
    a$(109) = "say"
    a$(110) = "help"
    a$(111) = "low"
    a$(112) = "line"
    a$(113) = "differ"
    a$(114) = "turn"
    a$(115) = "cause"
    a$(116) = "much"
    a$(117) = "mean"
    a$(118) = "before"
    a$(119) = "move"
    a$(120) = "right"
    a$(121) = "boy"
    a$(122) = "old"
    a$(123) = "tool"
    a$(124) = "same"
    a$(125) = "tell"
    a$(126) = "does"
    a$(127) = "set"
    return

Home

Source Code

Utilities

Internet

Games

Graphics

Media Demos

Snippets

DLL's

API Resources

Freeware

LB 4 Companion

Mastering LB 3

LB Workshop

Game Workshop

Links

Index