Re: Equal Distribution

new topic     » goto parent     » topic index » view thread      » older message » newer message

Well, my code had a bug in it, so here's a tested version:

-- span.ex
include file.e

integer
    at,             -- position of current byte
    disk,           -- current disk number
    handle,         -- handle of file being written
    fat,            -- handle to 'fat' file
    bytesPerDisk    -- bytes per disk

sequence
    files,          -- list of files to write
    data            -- data from current file

-- your files go here...
files = {
    "wininet.h",
    "webshelp.hlp",
    "webshelp.cnt",
    "shepherd.exw",
    "http.ew",
    "test.ex" }

function read_file( sequence filename )
    -- read a file, return sequence containing data
    integer handle
    sequence data
    object result

    -- open the file
    handle = open( filename, "r" )
    data = ""
    while 1 do
        result = getc( handle )
        if result = -1 then
            exit
        else
            data &= result
        end if
    end while
    close( handle )
    return data
end function

-- fat table
fat = open( "fat.dat", "w" )

-- fat header
printf( fat, "files=%d\n", length( files ) )

-- set size of disk
bytesPerDisk = 1000

-- output file
disk = 1
at = 0
handle = open( sprintf( "disk%d.dat", {disk} ), "w" )
for i = 1 to length( files ) do
    data = read_file( files[i] )
    printf( fat, "name=%s,disk=%d,at=%d,bytes=%d\n",
            {files[i],disk,at,length(data)} )
    for j = 1 to length( data ) do
        at += 1
        if at > bytesPerDisk then
            close( handle )
            disk += 1
            handle = open( sprintf( "disk%d.dat", {disk} ), "w" )
            at = 1
        end if
        puts( handle, data[j] )
    end for
end for

-- fat footer
printf( fat, "disks=%d\n", disk )

-- close the files
close( handle )
close( fat )


this only writes the file. to recreate the datafile, all you need to do is
build all the data files into a large data file. the fat contains the names
and position of the data. Actual position of the data is:

   ((disk-1)*bytesPerDisk)+(at-1)

I've left that portion as an exercise to the reader (since it involves
prompting the user to enter the proper disk, and so on), but here's a
routine that can be used to get the parameters from the fat data file:

function get_parm( sequence parm, sequence string )
    integer at
    at = match( parm & "=", string )
    at += length( parm ) + 1
    string = string[at..length(string)]
    at = find( ',', string )
    if at then
        string = string[1..at-1]
    end if
    return string
end function

For example:

   s = get_parm( "name", parms )

will return the "name" parameter.

Also, I'd leave a bit of room on each disk; quite often diskettes go bad,
and the disk repair routines that Windows has can only repair sectors if
there is space on the floppy to move the repaired data to. sad

I hope this helps! If you really want the decompression routine, I can throw
that together, too.

-- David Cuny

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu