[comp.lang.postscript] Run length decoder eexec

rick@ut-emx.UUCP (Rick Watson) (08/08/90)

Ok, here's my run length decoder eexec.
 
I originally decided not to post this since it is not portable and
will probably be misused, but it is useful and I might as well save
others the trouble of duplicating the effort.  Thanks to Carsten Wiethoff 
for posting the original eexec code upon which some of this
code is based (Hi Carsten!).

Some reasons NOT to use this decode eexec:

- It contains very non-portable code that won't run on a lot of 
  PostScript interpreters; maybe even Adobe interpreters 
  (according to a source at Adobe).
- It probably won't be compatible with whatever Adobe does to 
  address compressed data.

Please don't embed this in some application without any way to turn it
off.  In fact, don't make it the default mode.  Any application that
uses this should default to a mode that either can decode the
run-length data with normal PostScript or that doesn't put out
compressed data in the first place.  You shouldn't include the eexec
in generated PostScript unless you intend to use it.  If you ignore
this, your application won't produce portable PostScript and will fail
to run on some printers.
 
Anyway, here's some notes on how to use it:

|
| <input encoded string> (output string buffer) decode (output substring)
| (input hex digits string) (output string buffer) decodel (output substring)
|
| errors: rangecheck if output buffer too small or input string ends
|                       before input string count (malformed run-length entry)
|  
|  decode is used for 8-bit data such as read from readhexstring.
|  decodel is used for 8-bit data represented by ascii hex digits
|    such as read by readline
|
|  The problem with using readhexstring and decode is that readhexstring
|  always attemps to fill its input buffer.  This would make it 
|  more difficult to block the data appropriately for decode.  Decodel
|  allows you to use readline to block the data although this is
|  more sensitive to input problems.
|
| Run length encoding:
|
| A series of:
|      positive (1 byte) count followed by count+1 bytes to copy
|   or negative (1 byte) count followed by byte to repeat -count +1 times
|
|  Examples:
|	/buffer 100 string def
|	<02616263F764> buffer decode --> (abcdddddddddd)
|       (f741ed42) buffer decodel --> (AAAAAAAAAABBBBBBBBBBBBBBBBBBBB)
|
|       <00> buffer decode --> "rangecheck error" (missing byte of data)
|

Feel free to send me mail if it doesn't work but I make no claim that
anything will get fixed. Sorry, sources are not available.

Here it is:

%!
%
% Copyright 1990, The University of Texas at Austin
%
% Permission to use, copy, modify, and distribute this software and its
% documentation for any purpose and without fee is hereby granted,
% provided that the above copyright notice and this permission notice 
% appear in all copies and that the name of The University of Texas
% not be used in advertising or publicity pertaining to distribution of
% the software without specific, written prior permission.  The
% University of Texas makes no representations about the suitability of
% this software for any purpose.  It is provided "as is" without express
% or implied warranty.
% 
% THE UNIVERSITY OF TEXAS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
% SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
% FITNESS, IN NO EVENT SHALL THE UNIVERSITY OF TEXAS BE LIABLE FOR ANY
% SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
% RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
% CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
% CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
%
% Author: 
% Rick Watson 
%   The University of Texas Computation Center
%   internet: rick@digate.cc.utexas.edu       bitnet: watson@utadnx
%   uucp:     ...!cs.utexas.edu!ut-emx!rick   span:   utspan::utadnx::watson
%
% This eexec installs 2 operators: decode and decodel
%
% usage: encoded-data output-buffer decode output-buffer-substring
%        encoded-hex-data output-buffer decodel output-buffer-substring
%
currentfile eexec
d8054da8129fbd456df2d8893886c610b655364c71b35e236ea7e941f850de64
982395c233a19de6f6729acc799f20e6dd39953be75db7617b5277009b7cbbda
af3b5e06b4f6d1993d41f60279e61795bc1616d64c8d9ce6ff6a3c843b4e5d01
fcb5ec4bc9f7a476feb267ac6ac800c5e2d35476e120291432d0f5bb8b9f6405
4825975fc9fa1faf608b9844c3126c93ac0e9a391d7a41a7f1ce9fb03661b805
554a7fc2011d012fa1894ddb24affd5eadb616c5f27f4841957e4d99e4b90af3
a243a64ef020c66c79d75a1c26e535e1eee1c18b2de5f6fa377b8f477aea79fa
dcbd2374f504893bb0b60734827d2a4002e8a1be3eea60c62cbb320b37dd89ad
a685b1e08fc437c9b0158b5d3a438b5162084862585cdb8b6bca42711454e1bc
acc21cd9a82956343f5c429f44306c045b1a4b25d0b50b6ebf1bbfa4d1702f86
8bd12bd0b6e77a7540ede6095872187d1c41b216a9cc0062caef89c10d6f48eb
4b47cf9b135e8708a066e8dab4435c11a35a41ba5ae08d393023e9588ad246f8
f0a8d67a88c7fb7d9012be290a60bf6b5f6c58fb99700878d171514517bde698
8939ccc4d93eb11040cdcd1ef3d41d3987e50c6f6a4b3a9e1ee680f7da71fd36
92e868d1559a3c115316e5ed53ed5733575ec9fc1abbab1bbd040a225e14dd7a
775eca4414ac52bb3f03f1ebc323af9a40dbb15a887d80cb909205f18584c5e4
06da5e1b788f16ae3f5a3aa796a8700a1aadd4d66b5450adfce0509c463ddb01
8c78109c8442f9066129c92d9cd0a06086b3e6b8bf836cab54af072cd769348e
14c19a15963821469ac79e013faf519dc57fac2cad63432087ca7985cfa7f623
5004e2e11b216f0a708806be9d40b694bbdbfe0ff8064854f96c075cca0dac92
b8e4271d0451e9645b9c63400600d97ecbd894e0ed2a1492e417c787794aec2e
cdf0ab04a106888749ae7c5c0fd5dce22b3ddb6d8f3cbda3b81f04b68848d012
0499caeeec70d69fe3003b8b584e42b0bc6e402fc40da851f3b9afd8c102aa4f
745b77e62ecbe8ff83aed906edfb01d5ebd9c24a8151accba84eb77916f3fbca
46f15e519450593b49

Rick Watson 
The University of Texas Computation Center
   internet: rick@digate.cc.utexas.edu       bitnet: watson@utadnx
   uucp:     ...!cs.utexas.edu!ut-emx!rick   span:   utspan::utadnx::watson