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