Re: EBCDIC Formatted File (Help Needed)
- Posted by cklester <cklester at yahoo.com> Oct 13, 2004
- 475 views
Tommy Carlier wrote: > > 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 think it's better if you convert it in chunks: > read a chunk of bytes, convert it, write it to file, > rinse and repeat. Yeah, you're right. :) Final proggie:
include ebcdic.e include get.e include wildcard.e include graphics.e integer fn_in, fn_out sequence fname_in, fname_out, chunk fname_in = "orf850" fname_out = "orf850a" clear_screen() fn_in = open(fname_in, "rb") fn_out = open(fname_out, "wb") chunk = get_bytes(fn_in, 1000) while length(chunk) do position(1,1) printf(1,"%d",{numchunks}) puts(fn_out, ebcdic_to_ascii(chunk)) chunk = get_bytes(fn_in, 1000) end while close(fn_in) close(fn_out)
Worked great! Hayden, regarding your ebcdic_to_ascii() function, I had to change it to the following to account for zeroes... Is this proper/correct?
-- Encodes an EBCDIC formatted string to ASCII. global function ebcdic_to_ascii(sequence string) sequence ascii ascii = {} for i = 1 to length(string) do if string[i] = 0 then -- because EBCDIC[0] is bad ascii &= 0 else if string[i] < 64 then ascii &= find(EBCDIC[string[i]], ASCII) else ascii &= EBCDIC[string[i]] end if end if end for return ascii end function
-=ck "Programming in a state of EUPHORIA." http://www.cklester.com/euphoria/