🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.postscript
Article #4130

Version of concatenate which does use VM

#4130
From: Rob Bradlee
Date: Mon, 12 Oct 1992 17:34
52 lines
2369 bytes
I was using Glenn Reid's concatenate routine (from "Thinking in PostScript")
in some system PostScript (outside the server loop).  However, each 
invocation consumes some VM, so I wrote a version that takes the destination
string or array as a passed in parameter.  This way, if you don't want to
bracket the code in a save/restore pair, you can use a predeclared string
to store the result (and reuse the same string later).  Any comments or
corrections welcome.

------------------------- cut here ------------------------------------
%!
%%*****************************************************************************
%% concatenate
%%*****************************************************************************
% concatenate
% concats either two strings or two arrays.
% Modified from Glenn Reid's "Thinking in PostScript".  Caller now
% passes in the destination string or array so that the routine itself
% does not allocate any VM.
% Result is string3 = string1 + string2
%
/concatenate  % (string1) (string2) (string3) concatenate string3
	      % [array1] [array2] [array3] concatenate array3
{
dup type 2 index type 2 copy ne 		% chech that both inputs are same
	{
	pop pop
	errordict begin (concatenate) typecheck end
	}
	{
	/stringtype ne exch /arraytype ne and	% must be string or array
		{
		errordict begin (concatenate) typecheck end
		} if
	} ifelse
3 1 roll
dup length 2 index length 			% st: str3 str1 str2 len2 len1
add 	 		  			% st: str3 str1 str2 len1+2 
3 index length exch lt	  			% Make sure there is enough room in dest
	{
	errordict begin (concatenate) rangecheck end
	} if
3 -1 roll					% st: str1 str2 str3
dup 0 4 index putinterval 			% str1 str2 str3(w/str1)
dup 4 -1 roll length 4 -1 roll putinterval
} def % concatenate


-- 
Rob Bradlee  w:(508)-658-5600 X5153 
Agfa Corporation.                      ...!{decvax}!cg-atla!bradlee
200 Ballardvale St.                        bradlee@cg-atla.agfa.com
Wilmington, Mass. 01887 
Technical Details
Message-ID: <10136@cg-atla.UUCP>
Path: arc1-ca.pugleaf.net!sparky!uunet!ulowell!swlvx2!cg-atla!bradlee

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ulowell!swlvx2!cg-atla!bradlee
From: bradlee@cg-atla.UUCP (Rob Bradlee)
Newsgroups: comp.lang.postscript
Subject: Version of concatenate which does use VM
Keywords: strings
Message-ID: <10136@cg-atla.UUCP>
Date: 12 Oct 92 17:34:19 GMT
Distribution: comp
Organization: Agfa Compugraphic Division, Wilmington, Mass. USA
Lines: 52