xref: /plan9/sys/src/cmd/gs/src/ibnum.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1990, 1996, 1997, 2001 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: ibnum.h,v 1.8 2004/08/04 19:36:12 stefan Exp $ */
18 /* Encoded number definitions and support */
19 /* Requires stream.h */
20 
21 #ifndef ibnum_INCLUDED
22 #  define ibnum_INCLUDED
23 
24 /*
25  * There is a bug in all Adobe interpreters that causes them to byte-swap
26  * native reals in binary object sequences iff the native real format is
27  * IEEE.  We emulate this bug (it will be added to the PLRM errata at some
28  * point), but under a conditional so that it is clear where this is being
29  * done.
30  */
31 #define BYTE_SWAP_IEEE_NATIVE_REALS 1
32 
33 /*
34  * Define the byte that begins an encoded number string.
35  * (This is the same as the value of bt_num_array in btoken.h.)
36  */
37 #define bt_num_array_value 149
38 
39 /*
40  * Define the homogenous number array formats.  The default for numbers is
41  * big-endian.  Note that these values are defined by the PostScript
42  * Language Reference Manual: they are not arbitrary.
43  */
44 #define num_int32 0		/* [0..31] */
45 #define num_int16 32		/* [32..47] */
46 #define num_float 48
47 #define num_float_IEEE num_float
48 /* Note that num_msb / num_lsb is ignored for num_float_native. */
49 #define num_float_native (num_float + 1)
50 #define num_msb 0
51 #define num_lsb 128
52 #define num_is_lsb(format) ((format) >= num_lsb)
53 #define num_is_valid(format) (((format) & 127) <= 49)
54 /*
55  * Special "format" for reading from an array.
56  * num_msb/lsb is not used in this case.
57  */
58 #define num_array 256
59 /* Define the number of bytes for a given format of encoded number. */
60 extern const byte enc_num_bytes[];	/* in ibnum.c */
61 
62 #define enc_num_bytes_values\
63   4, 4, 2, 4, 0, 0, 0, 0,\
64   4, 4, 2, 4, 0, 0, 0, 0,\
65   sizeof(ref)
66 #define encoded_number_bytes(format)\
67   (enc_num_bytes[(format) >> 4])
68 
69 /* Read from an array or encoded number string. */
70 int num_array_format(const ref *);	/* returns format or error */
71 uint num_array_size(const ref *, int);
72 int num_array_get(const gs_memory_t *mem, const ref *, int, uint, ref *);
73 
74 /* Decode a number from a string with appropriate byte swapping. */
75 int sdecode_number(const byte *, int, ref *);
76 int sdecodeshort(const byte *, int);
77 uint sdecodeushort(const byte *, int);
78 long sdecodelong(const byte *, int);
79 float sdecodefloat(const byte *, int);
80 
81 #endif /* ibnum_INCLUDED */
82