xref: /plan9/sys/src/cmd/gs/src/idparam.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1992, 2000 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: idparam.h,v 1.7 2004/08/04 19:36:12 stefan Exp $ */
18 /* Interface to idparam.c */
19 
20 #ifndef idparam_INCLUDED
21 #  define idparam_INCLUDED
22 
23 #ifndef gs_matrix_DEFINED
24 #  define gs_matrix_DEFINED
25 typedef struct gs_matrix_s gs_matrix;
26 #endif
27 
28 #ifndef gs_uid_DEFINED
29 #  define gs_uid_DEFINED
30 typedef struct gs_uid_s gs_uid;
31 #endif
32 
33 /*
34  * Unless otherwise noted, all the following routines return 0 for
35  * a valid parameter, 1 for a defaulted parameter, or <0 on error.
36  *
37  * Note that all the dictionary parameter routines take a C string,
38  * not a t_name ref *.  Even though this is slower, it means that
39  * the GC doesn't have to worry about finding statically declared
40  * name refs, and we have that many fewer static variables.
41  *
42  * All these routines allow pdict == NULL, which they treat the same as
43  * pdict referring to an empty dictionary.  Routines with "null" in their
44  * name return 2 if the parameter is null, without setting *pvalue.
45  */
46 int dict_bool_param(const ref * pdict, const char *kstr,
47 		    bool defaultval, bool * pvalue);
48 int dict_int_param(const ref * pdict, const char *kstr,
49 		   int minval, int maxval, int defaultval, int *pvalue);
50 int dict_int_null_param(const ref * pdict, const char *kstr,
51 			int minval, int maxval, int defaultval,
52 			int *pvalue);
53 int dict_uint_param(const ref * pdict, const char *kstr,
54 		    uint minval, uint maxval, uint defaultval,
55 		    uint * pvalue);
56 int dict_float_param(const ref * pdict, const char *kstr,
57 		     floatp defaultval, float *pvalue);
58 /*
59  * There are 3 variants of the procedures for getting array parameters.
60  * All return the element count if the parameter is present and of the
61  * correct size, 0 if the key is missing.
62  *	_xxx_check_param return over_error if the array size > len,
63  *	  (under_error < 0 ? under_error : the element count) if the array
64  *	  size < len.
65  *	_xxx_param return limitcheck if the array size > maxlen.
66  *	  Equivalent to _xxx_check_param(..., 0, limitcheck).
67  *	_xxxs return rangecheck if the array size != len.
68  *	  Equivalent to _xxx_check_param(..., rangecheck, rangecheck).
69  * All can return other error codes (e.g., typecheck).
70  */
71 int dict_int_array_check_param(const ref * pdict, const char *kstr,
72 			       uint len, int *ivec,
73 			       int under_error, int over_error);
74 int dict_int_array_param(const ref * pdict, const char *kstr,
75 			 uint maxlen, int *ivec);
76 int dict_ints_param(const ref * pdict, const char *kstr,
77 		    uint len, int *ivec);
78 /*
79  * For _float_array_param, if the parameter is missing and defaultvec is
80  * not NULL, copy (max)len elements from defaultvec to fvec and return
81  * (max)len.
82  */
83 int dict_float_array_check_param(const gs_memory_t *mem,
84 				 const ref * pdict, const char *kstr,
85 				 uint len, float *fvec,
86 				 const float *defaultvec,
87 				 int under_error, int over_error);
88 int dict_float_array_param(const gs_memory_t *mem,
89 			   const ref * pdict, const char *kstr,
90 			   uint maxlen, float *fvec,
91 			   const float *defaultvec);
92 int dict_floats_param(const gs_memory_t *mem,
93 		      const ref * pdict, const char *kstr,
94 		      uint len, float *fvec,
95 		      const float *defaultvec);
96 
97 /*
98  * For dict_proc_param,
99  *      defaultval = false means substitute t__invalid;
100  *      defaultval = true means substitute an empty procedure.
101  * In either case, return 1.
102  */
103 int dict_proc_param(const ref * pdict, const char *kstr, ref * pproc,
104 		    bool defaultval);
105 int dict_matrix_param(const gs_memory_t *mem,
106 		      const ref * pdict, const char *kstr,
107 		      gs_matrix * pmat);
108 int dict_uid_param(const ref * pdict, gs_uid * puid, int defaultval,
109 		   gs_memory_t * mem, const i_ctx_t *i_ctx_p);
110 
111 /* Check that a UID in a dictionary is equal to an existing, valid UID. */
112 bool dict_check_uid_param(const ref * pdict, const gs_uid * puid);
113 
114 #endif /* idparam_INCLUDED */
115