Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.postscript > #996

Re: What's the correct interpretation of readline?

From "luser.droog" <luser.droog@gmail.com>
Newsgroups comp.lang.postscript
Subject Re: What's the correct interpretation of readline?
Date 2012-10-12 21:35 -0500
Organization unorganized
Message-ID <k5ak2b$d81$1@dont-email.me> (permalink)
References <k585al$j4i$1@dont-email.me>

Show all headers | View raw


luser.droog wrote:

> I've spent the past few days porting my Mandelbrot Explorer to run on
> xpost. And I've run into a bizarre snag. Here's a typescript that
> illustrates the problem. [I've inserted '[^D]' to indicate where I hit
> ctrl-D.]
> 
> 515(1)10:56 PM:ps 0> cat interact.ps
> 
> {
>     { (%lineedit) (r) file }
>     stopped { clear exit } if
>     dup bytesavailable
>     string readline pop
>     print (\n) print
> } loop
> 
> 516(1)10:59 PM:ps 0> gsnd interact.ps
> GPL Ghostscript 8.62 (2008-02-29)
> Copyright (C) 2008 Artifex Software, Inc.  All rights reserved.
> This software comes with NO WARRANTY: see the file PUBLIC for details.
> a
> b
> c
> [^D]a
> b
> c
> GS>[^D]517(1)11:00 PM:ps 0> xpost -nd interact.ps
> 197 opcodes
> 227 definitions in systemdict
> mcp interact.ps
> a
> %%[ Error: rangecheck; OffendingCommand: readline ]%%
> Stack:
> -filestream-
> (a)
> Exec Stack:
> --quit--
> { { handleerror } --if----quit--}
> false
> -filestream-
> --loop--
> --cvx--
> [ { (%lineedit)(r)file } stopped { clear exit } if dup bytesavailable
> string readline pop print (
> )print ]
> { pop print (
> )print }
> stop
> mcp launching executive
> Xpost Version x2vG
> PS<FS>[^D]518(1)11:00 PM:ps 0>
> 
> But here's the description from the PLRM 1ed.
> 
> readline
> 
> reads a line of characters (terminated by newline character) from file
> and stores them into successive elements of string. readline then
> returns the substring of string that was actually filled and a boolean
> indicating the outcome (true normally, false if end-of-file was encoun-
> tered before a newline character was read).
> 
> The terminating newline character is not stored into string or included
> at the end of the returned substring. If readline completely fills string
> before encountering a newline character, it executes the error
> rangecheck.
> 
> So I've implemented this in xpost with the following C function.
> 
> 
> OPFN_ void FSreadline(state *st, object f, object s) {
>     if (!f_status(st, f)) error(st,ioerror);
>     int n, c = 0;
>     if (!f.flags.read) error(st,invalidaccess);
>     for (n = 0; n < s.u.c.n; n++) {
>         c = getc( *(FILE **)VM(f.u.c.a));
>         if (c == EOF || c == '\n') break;
>         STR(s)[n] = c;
>     }
>     //if (c != EOF)
>     if (n == s.u.c.n && c != '\n') error(st,rangecheck);
>     s.u.c.n = n;
>     push(s);
>     push(consbool(c != EOF));
> }
> 
> So it seems I'm doing *what it says*. But I much prefer
> ghostscript's behavior of not signaling this error here.
> 
> I toyed with adding the 'if (c != EOF)' part to suppress
> the error, but I'm not sure I'm following the standard
> by doing that.
> 
> Any thoughts?

But it won't fix the problem anyway. Since the string *is*
filled, there's no cause to read that last char to discover
the EOF condition. 

I found ghostscript's code for %lineedit
http://git.ghostscript.com/?p=ghostpdl.git;a=blob;f=gs/psi/ziodev.c;h=9099475afb1439d95905d6f8e787b85f7310d0ca;hb=HEAD

and readline:
http://git.ghostscript.com/?p=ghostpdl.git;a=blob;f=gs/psi/zfileio.c;h=aea01345874b95436cc9cad39a3afcd4febfc756;hb=HEAD

But I haven't found the answer yet. The whole approach is
much more involved, looping with callbacks on the execstack.


Back to comp.lang.postscript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

What's the correct interpretation of readline? "luser.droog" <luser.droog@gmail.com> - 2012-10-11 23:11 -0500
  Re: What's the correct interpretation of readline? "luser.droog" <luser.droog@gmail.com> - 2012-10-12 21:35 -0500
  Re: What's the correct interpretation of readline? sjprouty3765@gmail.com - 2012-10-15 12:01 -0700
    Re: What's the correct interpretation of readline? "luser.droog" <luser.droog@gmail.com> - 2012-10-15 22:34 -0500
      Re: What's the correct interpretation of readline? sjprouty3765@gmail.com - 2012-10-16 12:43 -0700
        Re: What's the correct interpretation of readline? "luser.droog" <luser.droog@gmail.com> - 2012-10-16 20:22 -0500
          Re: What's the correct interpretation of readline? sjprouty3765@gmail.com - 2012-10-17 12:06 -0700
            Re: What's the correct interpretation of readline? "luser.droog" <luser.droog@gmail.com> - 2012-10-17 23:43 -0500

csiph-web