Loopey Revisited
- Posted by Euman <euman at BELLSOUTH.NET> Dec 13, 2000
- 415 views
------=_NextPart_000_0021_01C06515.F19B9DC0 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hiya A.R.S. Alvin >Yes I'm playing with test >loops using length() to read a series of characters (less the > you = get in >forwards) in to a sequence until it gets 80 characters long then add a >return and pass it to another sequence until the end of file=20 In my prior example I thought you might be looking (based on you code) for a particular character '>' and read 79 bytes past that point but, in light of you most previous post I see that you dont seem to care = about the character and that you just want to read 80 bytes at a time up to = the end=20 of your file. If I'm right, you probably will find that my last example minus looking for the char will work but, with an addition to the code = snippet to find the last n bytes of the file if the file were to exceed 79 bytes = past the last x number generated by the for loop. Sounds complicated but, = NOT. eg: -- begin code -- include get.e include file.e object junk atom ad integer fn, file_length, last_n_bytes sequence seq seq =3D {} fn =3D open(file_name , "rb") junk=3Dseek(fn,-1) =20 file_length=3Dwhere(fn) junk=3Dseek(fn,0) ad =3D floor(file_length / 80 ) last_n_bytes =3D file_length - (ad * 80) for x =3D 1 to ad do seq =3D append(seq, get_bytes(fn, 79)) end for seq =3D append(seq, get_bytes(fn, last_n_bytes)) -- end code -- As far as passing the sequence to another and adding those sequences to another file, I'll let you have some fun. I hope you'll study this and find that my method is not the best but certainly very fast. euman at bellsouth.net ------=_NextPart_000_0021_01C06515.F19B9DC0 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Hiya A.R.S. Alvin</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>>Yes I'm playing with = test<BR>>loops using=20 length() to read a series of characters (less the > you get=20 in<BR>>forwards) in to a sequence until it gets 80 characters long = then add=20 a<BR>>return and pass it to another sequence until the end of file=20 </FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>In my prior example I thought you might = be looking=20 (based on you code)</FONT></DIV> <DIV><FONT face=3DArial size=3D2>for a particular character '>' and = read 79 bytes=20 past that point but,</FONT></DIV> <DIV><FONT face=3DArial size=3D2>in light of you most previous post I = see that you=20 dont seem to care about</FONT></DIV> <DIV><FONT face=3DArial size=3D2>the character and that you just want to = read 80=20 bytes at a time up to the end </FONT></DIV> <DIV><FONT face=3DArial size=3D2>of your file. If I'm right, you = probably will find=20 that my last example</FONT></DIV> <DIV><FONT face=3DArial size=3D2>minus looking for the char will work = but, with an=20 addition to the code snippet</FONT></DIV> <DIV><FONT face=3DArial size=3D2>to find the last n bytes of the file if = the file=20 were to exceed 79 bytes past</FONT></DIV> <DIV><FONT face=3DArial size=3D2>the last x number generated by the for = loop. Sounds=20 complicated but, NOT.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>eg:</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>-- begin code --</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>include get.e<BR>include = file.e</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>object junk<BR>atom ad<BR>integer fn, = file_length,=20 last_n_bytes<BR>sequence seq<BR>seq =3D {}</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> fn =3D open(file_name ,=20 <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> ad =3D floor(file_length / 80=20 )<BR> last_n_bytes =3D file_length - (ad * 80)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> for x =3D 1 to ad=20 do<BR> seq =3D append(seq, get_bytes(fn, = 79))<BR> end=20 for</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> seq =3D append(seq, get_bytes(fn, = last_n_bytes))</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>-- end code --</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>As far as passing the sequence to = another and=20 adding those</FONT></DIV> <DIV><FONT face=3DArial size=3D2>sequences to another file, I'll let you = have some=20 fun.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>I hope you'll study this and find that = my method is=20 not the best</FONT></DIV> <DIV><FONT face=3DArial size=3D2>but certainly very fast.</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2><A=20 ------=_NextPart_000_0021_01C06515.F19B9DC0--