"Fossies" - the Fresh Open Source Software Archive 
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 /* Copyright (C) 1996-2001 Ghostgum Software Pty Ltd. 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: iapi.h,v 1.2 2002/06/16 22:03:21 ghostgum Exp $ */
18
19 /*
20 * Public API for Ghostscript interpreter
21 * for use both as DLL and for static linking.
22 *
23 * Should work for Windows, OS/2, Linux, Mac.
24 *
25 * DLL exported functions should be as similar as possible to imain.c
26 * You will need to include "errors.h".
27 *
28 * Current problems:
29 * 1. Ghostscript does not support multiple instances.
30 * 2. Global variables in gs_main_instance_default()
31 * and gsapi_instance_counter
32 */
33
34 /* Exported functions may need different prefix
35 * GSDLLEXPORT marks functions as exported
36 * GSDLLAPI is the calling convention used on functions exported
37 * by Ghostscript
38 * GSDLLCALL is used on callback functions called by Ghostscript
39 * When you include this header file in the caller, you may
40 * need to change the definitions by defining these
41 * before including this header file.
42 * Make sure you get the calling convention correct, otherwise your
43 * program will crash either during callbacks or soon after returning
44 * due to stack corruption.
45 */
46
47 #ifndef iapi_INCLUDED
48 # define iapi_INCLUDED
49
50 #ifdef __WINDOWS__
51 # define _Windows
52 #endif
53
54 #ifdef _Windows
55 # ifndef GSDLLEXPORT
56 # define GSDLLEXPORT __declspec(dllexport)
57 # endif
58 # ifndef GSDLLAPI
59 # define GSDLLAPI __stdcall
60 # endif
61 # ifndef GSDLLCALL
62 # define GSDLLCALL __stdcall
63 # endif
64 #endif /* _Windows */
65
66 #if defined(OS2) && defined(__IBMC__)
67 # ifndef GSDLLAPI
68 # define GSDLLAPI _System
69 # endif
70 # ifndef GSDLLCALL
71 # define GSDLLCALL _System
72 # endif
73 #endif /* OS2 && __IBMC */
74
75 #ifdef __MACINTOSH__
76 # pragma export on
77 #endif
78
79 #ifndef GSDLLEXPORT
80 # define GSDLLEXPORT
81 #endif
82 #ifndef GSDLLAPI
83 # define GSDLLAPI
84 #endif
85 #ifndef GSDLLCALL
86 # define GSDLLCALL
87 #endif
88
89 #if defined(__IBMC__)
90 # define GSDLLAPIPTR * GSDLLAPI
91 # define GSDLLCALLPTR * GSDLLCALL
92 #else
93 # define GSDLLAPIPTR GSDLLAPI *
94 # define GSDLLCALLPTR GSDLLCALL *
95 #endif
96
97 #ifndef gs_main_instance_DEFINED
98 # define gs_main_instance_DEFINED
99 typedef struct gs_main_instance_s gs_main_instance;
100 #endif
101 #ifndef display_callback_DEFINED
102 # define display_callback_DEFINED
103 typedef struct display_callback_s display_callback;
104 #endif
105
106 typedef struct gsapi_revision_s {
107 const char *product;
108 const char *copyright;
109 long revision;
110 long revisiondate;
111 } gsapi_revision_t;
112
113
114 /* Get version numbers and strings.
115 * This is safe to call at any time.
116 * You should call this first to make sure that the correct version
117 * of the Ghostscript is being used.
118 * pr is a pointer to a revision structure.
119 * len is the size of this structure in bytes.
120 * Returns 0 if OK, or if len too small (additional parameters
121 * have been added to the structure) it will return the required
122 * size of the structure.
123 */
124 GSDLLEXPORT int GSDLLAPI
125 gsapi_revision(gsapi_revision_t *pr, int len);
126
127 /*
128 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
129 * Ghostscript supports only one instance.
130 * The current implementation uses a global static instance
131 * counter to make sure that only a single instance is used.
132 * If you try to create two instances, the second attempt
133 * will return < 0 and set pinstance to NULL.
134 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
135 */
136 /* Create a new instance of Ghostscript.
137 * This instance is passed to most other API functions.
138 * The caller_handle will be provided to callback functions.
139 */
140
141 GSDLLEXPORT int GSDLLAPI
142 gsapi_new_instance(gs_main_instance **pinstance, void *caller_handle);
143
144 /*
145 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
146 * Ghostscript supports only one instance.
147 * The current implementation uses a global static instance
148 * counter to make sure that only a single instance is used.
149 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
150 */
151 /* Destroy an instance of Ghostscript
152 * Before you call this, Ghostscript must have finished.
153 * If Ghostscript has been initialised, you must call gsapi_exit()
154 * before gsapi_delete_instance.
155 */
156 GSDLLEXPORT void GSDLLAPI
157 gsapi_delete_instance(gs_main_instance *instance);
158
159 /* Set the callback functions for stdio
160 * The stdin callback function should return the number of
161 * characters read, 0 for EOF, or -1 for error.
162 * The stdout and stderr callback functions should return
163 * the number of characters written.
164 * If a callback address is NULL, the real stdio will be used.
165 */
166 GSDLLEXPORT int GSDLLAPI
167 gsapi_set_stdio(gs_main_instance *instance,
168 int (GSDLLCALLPTR stdin_fn)(void *caller_handle, char *buf, int len),
169 int (GSDLLCALLPTR stdout_fn)(void *caller_handle, const char *str, int len),
170 int (GSDLLCALLPTR stderr_fn)(void *caller_handle, const char *str, int len));
171
172 /* Set the callback function for polling.
173 * This is used for handling window events or cooperative
174 * multitasking. This function will only be called if
175 * Ghostscript was compiled with CHECK_INTERRUPTS
176 * as described in gpcheck.h.
177 */
178 GSDLLEXPORT int GSDLLAPI gsapi_set_poll(gs_main_instance *instance,
179 int (GSDLLCALLPTR poll_fn)(void *caller_handle));
180
181 /* Set the display device callback structure.
182 * If the display device is used, this must be called
183 * after gsapi_new_instance() and before gsapi_init_with_args().
184 * See gdevdisp.h for more details.
185 */
186 GSDLLEXPORT int GSDLLAPI gsapi_set_display_callback(
187 gs_main_instance *instance, display_callback *callback);
188
189
190 /* Initialise the interpreter.
191 * This calls gs_main_init_with_args() in imainarg.c
192 * 1. If quit or EOF occur during gsapi_init_with_args(),
193 * the return value will be e_Quit. This is not an error.
194 * You must call gsapi_exit() and must not call any other
195 * gsapi_XXX functions.
196 * 2. If usage info should be displayed, the return value will be e_Info
197 * which is not an error. Do not call gsapi_exit().
198 * 3. Under normal conditions this returns 0. You would then
199 * call one or more gsapi_run_*() functions and then finish
200 * with gsapi_exit().
201 */
202 GSDLLEXPORT int GSDLLAPI gsapi_init_with_args(gs_main_instance *instance,
203 int argc, char **argv);
204
205 /*
206 * The gsapi_run_* functions are like gs_main_run_* except
207 * that the error_object is omitted.
208 * If these functions return <= -100, either quit or a fatal
209 * error has occured. You then call gsapi_exit() next.
210 * The only exception is gsapi_run_string_continue()
211 * which will return e_NeedInput if all is well.
212 */
213
214 GSDLLEXPORT int GSDLLAPI
215 gsapi_run_string_begin(gs_main_instance *instance,
216 int user_errors, int *pexit_code);
217
218 GSDLLEXPORT int GSDLLAPI
219 gsapi_run_string_continue(gs_main_instance *instance,
220 const char *str, unsigned int length, int user_errors, int *pexit_code);
221
222 GSDLLEXPORT int GSDLLAPI
223 gsapi_run_string_end(gs_main_instance *instance,
224 int user_errors, int *pexit_code);
225
226 GSDLLEXPORT int GSDLLAPI
227 gsapi_run_string_with_length(gs_main_instance *instance,
228 const char *str, unsigned int length, int user_errors, int *pexit_code);
229
230 GSDLLEXPORT int GSDLLAPI
231 gsapi_run_string(gs_main_instance *instance,
232 const char *str, int user_errors, int *pexit_code);
233
234 GSDLLEXPORT int GSDLLAPI
235 gsapi_run_file(gs_main_instance *instance,
236 const char *file_name, int user_errors, int *pexit_code);
237
238
239 /* Exit the interpreter.
240 * This must be called on shutdown if gsapi_init_with_args()
241 * has been called, and just before gsapi_delete_instance().
242 */
243 GSDLLEXPORT int GSDLLAPI
244 gsapi_exit(gs_main_instance *instance);
245
246
247 /* function prototypes */
248 typedef int (GSDLLAPIPTR PFN_gsapi_revision)(
249 gsapi_revision_t *pr, int len);
250 typedef int (GSDLLAPIPTR PFN_gsapi_new_instance)(
251 gs_main_instance **pinstance, void *caller_handle);
252 typedef void (GSDLLAPIPTR PFN_gsapi_delete_instance)(
253 gs_main_instance *instance);
254 typedef int (GSDLLAPIPTR PFN_gsapi_set_stdio)(gs_main_instance *instance,
255 int (GSDLLCALLPTR stdin_fn)(void *caller_handle, char *buf, int len),
256 int (GSDLLCALLPTR stdout_fn)(void *caller_handle, const char *str, int len),
257 int (GSDLLCALLPTR stderr_fn)(void *caller_handle, const char *str, int len));
258 typedef int (GSDLLAPIPTR PFN_gsapi_set_poll)(gs_main_instance *instance,
259 int(GSDLLCALLPTR poll_fn)(void *caller_handle));
260 typedef int (GSDLLAPIPTR PFN_gsapi_set_display_callback)(
261 gs_main_instance *instance, display_callback *callback);
262 typedef int (GSDLLAPIPTR PFN_gsapi_init_with_args)(
263 gs_main_instance *instance, int argc, char **argv);
264 typedef int (GSDLLAPIPTR PFN_gsapi_run_string_begin)(
265 gs_main_instance *instance, int user_errors, int *pexit_code);
266 typedef int (GSDLLAPIPTR PFN_gsapi_run_string_continue)(
267 gs_main_instance *instance, const char *str, unsigned int length,
268 int user_errors, int *pexit_code);
269 typedef int (GSDLLAPIPTR PFN_gsapi_run_string_end)(
270 gs_main_instance *instance, int user_errors, int *pexit_code);
271 typedef int (GSDLLAPIPTR PFN_gsapi_run_string_with_length)(
272 gs_main_instance *instance, const char *str, unsigned int length,
273 int user_errors, int *pexit_code);
274 typedef int (GSDLLAPIPTR PFN_gsapi_run_string)(
275 gs_main_instance *instance, const char *str,
276 int user_errors, int *pexit_code);
277 typedef int (GSDLLAPIPTR PFN_gsapi_run_file)(gs_main_instance *instance,
278 const char *file_name, int user_errors, int *pexit_code);
279 typedef int (GSDLLAPIPTR PFN_gsapi_exit)(gs_main_instance *instance);
280
281
282 #ifdef __MACINTOSH__
283 #pragma export off
284 #endif
285
286 #endif /* iapi_INCLUDED */