Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsfeed.datemas.de!feeder.erje.net!eu.feeder.erje.net!feed.xsnews.nl!border-3.ams.xsnews.nl!feeder.xennanews.com!feeder3!nf40.xennanews.com!not-for-mail From: Cecil Westerhof Newsgroups: comp.lang.postscript Subject: Re: Putting lines from a file into an array Organization: Decebal Computing References: <87624kp6hc.fsf@Compaq.site.inet> <87r4n8nd8x.fsf@Compaq.site.inet> X-Homepage: http://www.decebal.nl/ Date: Mon, 03 Dec 2012 10:01:07 +0100 Message-ID: <87fw3no6gc.fsf@Compaq.site.inet> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:AIHRbac6JgqhE+bKgRVyhyObl+w= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@xennanews.com Lines: 39 NNTP-Posting-Host: 84.53.123.169 (84.53.123.169) NNTP-Posting-Date: Mon, 03 Dec 2012 10:14:30 +0100 Xref: csiph.com comp.lang.postscript:1136 Op maandag 3 dec 2012 06:28 CET schreef luser droog: >>> Chris's response is totally correct. But here's another way to do it. >>> You can slurp the whole file into one string (assuming the file size is >>> less than 65535 bytes), and then use `search` to chop it up. >>> >>> %! >>> %farr.ps File into Array >>> /infile (farr.ps)(r)file def >>> infile dup bytesavailable string readstring pop >>> (\n){ search { 3 1 roll }{ exit } ifelse }loop >>> count array astore == >>> >>> gs output: >>> >>> [(%!) (%farr.ps File into Array) (/infile \(farr.ps\)\(r\)file def) >>> [(infile >>> dup bytesavailable string readstring pop) (\(\\n\){ search { 3 1 roll }{ >>> exit } ifelse }loop) (count array astore ==) ()] >> >> I already implemented Chris's way, but I'll look into this one also. >> > > No worries. Some caveats are you usually can't rely on `bytesavailable` for > terminal input or pipes, so you can only slurp a file where the size can be > discovered by the interpreter. And my use of `search` above left an empty > string. Adding `pop` just before `exit` will discard it. I only use real files, so I can use bytesavailable. I already implemented it. I now added the pop. It was a lot of work. But I now have a better implementation as I had with Image Magick (the graphic is always the right width), so it was worth it. And I can implement other effects also. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof