1 /* Copyright (C) 2001-2006 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied, modified
8    or distributed except as expressly authorized under the terms of that
9    license.  Refer to licensing information at http://www.artifex.com/
10    or contact Artifex Software, Inc.,  7 Mt. Lassen Drive - Suite A-134,
11    San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12 */
13 
14 /* $Id: ifilter.h 9043 2008-08-28 22:48:19Z giles $ */
15 /* Interpreter filter support */
16 /* Requires oper.h, stream.h, strimpl.h */
17 
18 #ifndef ifilter_INCLUDED
19 #  define ifilter_INCLUDED
20 
21 #include "istream.h"
22 #include "ivmspace.h"
23 
24 /*
25  * Define the utility procedures for creating filters.
26  * Note that a filter will be allocated in global VM iff the source/target
27  * and all relevant parameters (if any) are in global VM.
28  */
29 int filter_read(
30 	/* Operator arguments that were passed to zfxxx operator */
31 		i_ctx_t *i_ctx_p,
32 	/* # of parameters to pop off o-stack, */
33 	/* not counting the source/target and also not counting any */
34 	/* top dictionary operand (both of which will always be popped) */
35 		int npop,
36 	/* Template for stream */
37 		const stream_template * template,
38 	/* Initialized s_xxx_state, 0 if no separate state */
39 		stream_state * st,
40 	/* Max of space attributes of all parameters referenced by */
41 	/* the state, 0 if no such parameters */
42 		uint space
43 		);
44 int filter_write(i_ctx_t *i_ctx_p, int npop,
45 		 const stream_template * template,
46 		 stream_state * st, uint space);
47 
48 /*
49  * Define a simplified interface for streams with no parameters (except
50  * an optional dictionary) or state.
51  */
52 int filter_read_simple(i_ctx_t *i_ctx_p,
53 		       const stream_template * template);
54 int filter_write_simple(i_ctx_t *i_ctx_p,
55 			const stream_template * template);
56 
57 /* Mark a filter stream as temporary. */
58 /* See stream.h for the meaning of is_temp. */
59 void filter_mark_temp(const ref * fop, int is_temp);
60 
61 /* Mark the source or target of a filter as temporary, and propagate */
62 /* close_strm from the temporary stream to the filter. */
63 void filter_mark_strm_temp(const ref * fop, int is_temp);
64 
65 /* Define a standard report_error procedure for filters, */
66 /* that records the error message in $error.errorinfo. */
67 stream_proc_report_error(filter_report_error);
68 
69 /*
70  * Define the state of a procedure-based stream.
71  * Note that procedure-based streams are defined at the Ghostscript
72  * interpreter level, unlike all other stream types which depend only
73  * on the stream package and the memory manager.
74  */
75 typedef struct stream_proc_state_s {
76     stream_state_common;
77     bool eof;
78     uint index;			/* current index within data */
79     ref proc;
80     ref data;
81 } stream_proc_state;
82 
83 #define private_st_stream_proc_state() /* in zfproc.c */\
84   gs_private_st_complex_only(st_sproc_state, stream_proc_state,\
85     "procedure stream state", sproc_clear_marks, sproc_enum_ptrs, sproc_reloc_ptrs, 0)
86 
87 /* Test whether a stream is procedure-based. */
88 bool s_is_proc(const stream *s);
89 
90 #endif /* ifilter_INCLUDED */
91