🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #8023

Re: How long can a PostScript name be?

#8023
From: Glenn Reid
Date: Wed, 22 Feb 1989 19:32
63 lines
3293 bytes
In article <9FE19B2A625D3620@UK.AC.CAM.PHX> CET1@phoenix.cambridge.ac.UK writes:
   Sometimes, when converting a name to a string with "cvs", one needs
   to know how long the result might be (to avoid a "rangecheck"). This
   happens in particular when handling the `object being executed' after
   an error ("command" in "$error"). (I am assuming that if one prepares
   a string big enough to receive the longest possible name, then one is
   not going to have any trouble with mere integers, reals, and booleans!)
   
   The red book tells me in Appendix B that the longest allowed name on
   a LaserWriter is 128 bytes, but this is presented merely as being a
   feature of a particular implementation: it might be different on other
   PostScript printers, or even in later versions of the PostScript
   interpreter for the LaserWriter.
   
   The way that Adobe's ehandler.ps deals with this problem is to use
   the useful scratch string stored under the name `=string' in systemdict.
   This string (also used by the = procedure, hence its name) is 128 bytes
   long on the LaserWriter, and this would presumably be changed if the
   limit on the length of a name were changed.
   
   However, =string is not documented in the red book (or elsewhere, as
   far as I know), so using it may be just as chancy as assuming that the
   limit of 128 will stay the same. Is there any way of determining the
   upper limit on the length of a name relying only on documented features
   of PostScript? If not, what method entails the least risk?

This is a very good question.  Particularly in an error handler, it is
good to be as safe as possible about this kind of thing.

You are correct in that the 128 byte limit mentioned is an
implementation limit.  I believe that it is consistent across all
existing implementations.  However, to be on the safe side, you might
consider this technique:

% before:
	/buff 128 string def
	buff cvs

% after:
	/buff 128 string def
	dup type /nametype eq {
	    dup length 128 gt { dup length string }{ buff } ifelse
	}{ buff } ifelse
	cvs

You will allocate a new temporary string if the object you are trying
to "cvs" is a name and is larger than 128 bytes, but the likelihood of
the code ever getting executed is practically nil.  One thing you have
to be careful about is if the error happened to be a VMerror, you get
into trouble trying to allocate more of it :-)

As an aside, if the type of the does not lend itself to being converted
to a string, you will get back a string (--nostringval--), which is a
little less than helpful (for example, arrays and dictionaries do not
have string values).

Note: I haven't actually tested this code, but it looks OK.

Good luck.

Glenn Reid
Adobe Systems
Developer Tools & Strategies
Technical Details
Message-ID: <515@adobe.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!adobe!greid
References: <9FE19B2A625D3620@UK.AC.CAM.PHX>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!adobe!greid
From: greid@adobe.com (Glenn Reid)
Newsgroups: comp.lang.postscript
Subject: Re: How long can a PostScript name be?
Message-ID: <515@adobe.UUCP>
Date: 22 Feb 89 19:32:00 GMT
References: <9FE19B2A625D3620@UK.AC.CAM.PHX>
Sender: news@adobe.COM
Reply-To: greid@adobe.COM (Glenn Reid)
Organization: Adobe Systems Incorporated, Mountain View
Lines: 63