Re: EBCDIC Formatted File (Help Needed)

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

cklester wrote:
> I've got a file from a government agency that is in EBCDIC format (shoot
> me now). It is almost 140MB in size. I'm trying to use Hayden McKay's
> EBCDIC converter, and I'm sure it will work, but I can't even get the
> raw file loaded up! I tried using "rb" and gets() but that was taking
> a million years to load the file and I couldn't interrupt it nicely. Then
> I tried using "rb" and getc(), but that will obviously take a million years
> also, but at least I could put a tracking counter on screen and use SPACE
> to stop it. Am I just going to have to be patient loading this big boy into
> a variable so I can txt = ebcdic_to_ascii( txt ) it? AAARRRRRRRGGGHH!!!
> 
> Here's my program, in case anybody wants to revise/advise/contemplize.
> 
> ---start
> -- EBCDIC file converter
> 
> include ebcdic.e
> include get.e
> include graphics.e
> include wildcard.e
> 
> object fn, line, junk
> sequence txt, fname
> 
> txt = ""
> fname = "orf850"
> 
> puts(1,"Opening " & fname & "...")
> fn = open(fname,"rb")
> clear_screen()
> 
> line = getc(fn)
> while line != -1 do
> 	txt &= line
> 	position(1,1)
> 	?length(txt)
> 	line = getc(fn)
> 	junk = get_key()
> 	if junk = ' ' then
> 		line = -1
> 	end if
> end while
> close(fn)
> 
> puts(1,"Convert? (Y/N) ")
> junk = wait_key()
> if upper(junk) = 'Y' then
> 	txt = ebcdic_to_ascii( txt )
> 	fn = open("orf850a","wb")
> 	puts(fn,txt)
> 	close(fn)
> end if
> 
> puts(1,"\nFinished.")
> junk = wait_key()
> ---end

I think it's better if you convert it in chunks:
read a chunk of bytes, convert it, write it to file,
rinse and repeat.

Something like this (untested code):
include ebcdic.e
include get.e
include wildcard.e

integer fn_in, fn_out
sequence fname_in, fname_out, chunk

fname_in = "orf850"
fname_out = "orf850a"

fn_in = open(fname_in, "rb")
fn_out = open(fname_out, "wb")

chunk = get_bytes(fn_out, 1000)
while length(chunk) do
	puts(fn_out, ebcdic_to_ascii(chunk))
	chunk = get_bytes(fn_in, 1000)
end while
close(fn_in)
close(fn_out)


--
tommy online: http://users.telenet.be/tommycarlier
tommy.blog: http://tommycarlier.blogspot.com
Euphoria Message Board: http://uboard.proboards32.com
Empire for Euphoria: http://empire.iwireweb.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu