xref: /plan9/sys/src/cmd/gs/src/iapi.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
13ff48bf5SDavid du Colombier /* Copyright (C) 1996-2001 Ghostgum Software Pty Ltd.  All rights reserved.
23ff48bf5SDavid du Colombier 
3*593dc095SDavid du Colombier   This software is provided AS-IS with no warranty, either express or
4*593dc095SDavid du Colombier   implied.
53ff48bf5SDavid du Colombier 
6*593dc095SDavid du Colombier   This software is distributed under license and may not be copied,
7*593dc095SDavid du Colombier   modified or distributed except as expressly authorized under the terms
8*593dc095SDavid du Colombier   of the license contained in the file LICENSE in this distribution.
93ff48bf5SDavid du Colombier 
10*593dc095SDavid du Colombier   For more information about licensing, please refer to
11*593dc095SDavid du Colombier   http://www.ghostscript.com/licensing/. For information on
12*593dc095SDavid du Colombier   commercial licensing, go to http://www.artifex.com/licensing/ or
13*593dc095SDavid du Colombier   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14*593dc095SDavid du Colombier   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
153ff48bf5SDavid du Colombier */
163ff48bf5SDavid du Colombier 
17*593dc095SDavid du Colombier /* $Id: iapi.h,v 1.13 2004/08/19 19:33:09 stefan Exp $ */
183ff48bf5SDavid du Colombier 
193ff48bf5SDavid du Colombier /*
203ff48bf5SDavid du Colombier  * Public API for Ghostscript interpreter
213ff48bf5SDavid du Colombier  * for use both as DLL and for static linking.
223ff48bf5SDavid du Colombier  *
233ff48bf5SDavid du Colombier  * Should work for Windows, OS/2, Linux, Mac.
243ff48bf5SDavid du Colombier  *
253ff48bf5SDavid du Colombier  * DLL exported functions should be as similar as possible to imain.c
26*593dc095SDavid du Colombier  * You will need to include "ierrors.h".
273ff48bf5SDavid du Colombier  *
283ff48bf5SDavid du Colombier  * Current problems:
293ff48bf5SDavid du Colombier  * 1. Ghostscript does not support multiple instances.
303ff48bf5SDavid du Colombier  * 2. Global variables in gs_main_instance_default()
313ff48bf5SDavid du Colombier  *    and gsapi_instance_counter
323ff48bf5SDavid du Colombier  */
333ff48bf5SDavid du Colombier 
343ff48bf5SDavid du Colombier /* Exported functions may need different prefix
353ff48bf5SDavid du Colombier  *  GSDLLEXPORT marks functions as exported
363ff48bf5SDavid du Colombier  *  GSDLLAPI is the calling convention used on functions exported
373ff48bf5SDavid du Colombier  *   by Ghostscript
383ff48bf5SDavid du Colombier  *  GSDLLCALL is used on callback functions called by Ghostscript
393ff48bf5SDavid du Colombier  * When you include this header file in the caller, you may
403ff48bf5SDavid du Colombier  * need to change the definitions by defining these
413ff48bf5SDavid du Colombier  * before including this header file.
423ff48bf5SDavid du Colombier  * Make sure you get the calling convention correct, otherwise your
433ff48bf5SDavid du Colombier  * program will crash either during callbacks or soon after returning
443ff48bf5SDavid du Colombier  * due to stack corruption.
453ff48bf5SDavid du Colombier  */
463ff48bf5SDavid du Colombier 
473ff48bf5SDavid du Colombier #ifndef iapi_INCLUDED
483ff48bf5SDavid du Colombier #  define iapi_INCLUDED
493ff48bf5SDavid du Colombier 
50*593dc095SDavid du Colombier #ifdef __cplusplus
51*593dc095SDavid du Colombier extern "C" {
52*593dc095SDavid du Colombier #endif
53*593dc095SDavid du Colombier 
54*593dc095SDavid du Colombier #if defined(_WINDOWS_) || defined(__WINDOWS__)
55*593dc095SDavid du Colombier # ifndef _Windows
563ff48bf5SDavid du Colombier #  define _Windows
573ff48bf5SDavid du Colombier # endif
58*593dc095SDavid du Colombier #endif
593ff48bf5SDavid du Colombier 
603ff48bf5SDavid du Colombier #ifdef _Windows
613ff48bf5SDavid du Colombier # ifndef GSDLLEXPORT
623ff48bf5SDavid du Colombier #  define GSDLLEXPORT __declspec(dllexport)
633ff48bf5SDavid du Colombier # endif
643ff48bf5SDavid du Colombier # ifndef GSDLLAPI
653ff48bf5SDavid du Colombier #  define GSDLLAPI __stdcall
663ff48bf5SDavid du Colombier # endif
673ff48bf5SDavid du Colombier # ifndef GSDLLCALL
683ff48bf5SDavid du Colombier #  define GSDLLCALL __stdcall
693ff48bf5SDavid du Colombier # endif
703ff48bf5SDavid du Colombier #endif  /* _Windows */
713ff48bf5SDavid du Colombier 
723ff48bf5SDavid du Colombier #if defined(OS2) && defined(__IBMC__)
733ff48bf5SDavid du Colombier # ifndef GSDLLAPI
743ff48bf5SDavid du Colombier #  define GSDLLAPI _System
753ff48bf5SDavid du Colombier # endif
763ff48bf5SDavid du Colombier # ifndef GSDLLCALL
773ff48bf5SDavid du Colombier #  define GSDLLCALL _System
783ff48bf5SDavid du Colombier # endif
793ff48bf5SDavid du Colombier #endif	/* OS2 && __IBMC */
803ff48bf5SDavid du Colombier 
81*593dc095SDavid du Colombier #ifdef __MACOS__
823ff48bf5SDavid du Colombier # pragma export on
833ff48bf5SDavid du Colombier #endif
843ff48bf5SDavid du Colombier 
853ff48bf5SDavid du Colombier #ifndef GSDLLEXPORT
863ff48bf5SDavid du Colombier # define GSDLLEXPORT
873ff48bf5SDavid du Colombier #endif
883ff48bf5SDavid du Colombier #ifndef GSDLLAPI
893ff48bf5SDavid du Colombier # define GSDLLAPI
903ff48bf5SDavid du Colombier #endif
913ff48bf5SDavid du Colombier #ifndef GSDLLCALL
923ff48bf5SDavid du Colombier # define GSDLLCALL
933ff48bf5SDavid du Colombier #endif
943ff48bf5SDavid du Colombier 
953ff48bf5SDavid du Colombier #if defined(__IBMC__)
963ff48bf5SDavid du Colombier # define GSDLLAPIPTR * GSDLLAPI
973ff48bf5SDavid du Colombier # define GSDLLCALLPTR * GSDLLCALL
983ff48bf5SDavid du Colombier #else
993ff48bf5SDavid du Colombier # define GSDLLAPIPTR GSDLLAPI *
1003ff48bf5SDavid du Colombier # define GSDLLCALLPTR GSDLLCALL *
1013ff48bf5SDavid du Colombier #endif
1023ff48bf5SDavid du Colombier 
1033ff48bf5SDavid du Colombier #ifndef display_callback_DEFINED
1043ff48bf5SDavid du Colombier # define display_callback_DEFINED
1053ff48bf5SDavid du Colombier typedef struct display_callback_s display_callback;
1063ff48bf5SDavid du Colombier #endif
1073ff48bf5SDavid du Colombier 
1083ff48bf5SDavid du Colombier typedef struct gsapi_revision_s {
1093ff48bf5SDavid du Colombier     const char *product;
1103ff48bf5SDavid du Colombier     const char *copyright;
1113ff48bf5SDavid du Colombier     long revision;
1123ff48bf5SDavid du Colombier     long revisiondate;
1133ff48bf5SDavid du Colombier } gsapi_revision_t;
1143ff48bf5SDavid du Colombier 
1153ff48bf5SDavid du Colombier 
1163ff48bf5SDavid du Colombier /* Get version numbers and strings.
1173ff48bf5SDavid du Colombier  * This is safe to call at any time.
1183ff48bf5SDavid du Colombier  * You should call this first to make sure that the correct version
1193ff48bf5SDavid du Colombier  * of the Ghostscript is being used.
1203ff48bf5SDavid du Colombier  * pr is a pointer to a revision structure.
1213ff48bf5SDavid du Colombier  * len is the size of this structure in bytes.
1223ff48bf5SDavid du Colombier  * Returns 0 if OK, or if len too small (additional parameters
1233ff48bf5SDavid du Colombier  * have been added to the structure) it will return the required
1243ff48bf5SDavid du Colombier  * size of the structure.
1253ff48bf5SDavid du Colombier  */
1263ff48bf5SDavid du Colombier GSDLLEXPORT int GSDLLAPI
127*593dc095SDavid du Colombier gsapi_revision(gsapi_revision_t *pr, int len);
1283ff48bf5SDavid du Colombier 
1293ff48bf5SDavid du Colombier /*
1303ff48bf5SDavid du Colombier  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
1313ff48bf5SDavid du Colombier  *  Ghostscript supports only one instance.
1323ff48bf5SDavid du Colombier  *  The current implementation uses a global static instance
1333ff48bf5SDavid du Colombier  *  counter to make sure that only a single instance is used.
1343ff48bf5SDavid du Colombier  *  If you try to create two instances, the second attempt
1353ff48bf5SDavid du Colombier  *  will return < 0 and set pinstance to NULL.
1363ff48bf5SDavid du Colombier  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
1373ff48bf5SDavid du Colombier  */
1383ff48bf5SDavid du Colombier /* Create a new instance of Ghostscript.
1393ff48bf5SDavid du Colombier  * This instance is passed to most other API functions.
1403ff48bf5SDavid du Colombier  * The caller_handle will be provided to callback functions.
1413ff48bf5SDavid du Colombier  */
1423ff48bf5SDavid du Colombier 
1433ff48bf5SDavid du Colombier GSDLLEXPORT int GSDLLAPI
144*593dc095SDavid du Colombier gsapi_new_instance(void **pinstance, void *caller_handle);
1453ff48bf5SDavid du Colombier 
1463ff48bf5SDavid du Colombier /*
1473ff48bf5SDavid du Colombier  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
1483ff48bf5SDavid du Colombier  *  Ghostscript supports only one instance.
1493ff48bf5SDavid du Colombier  *  The current implementation uses a global static instance
1503ff48bf5SDavid du Colombier  *  counter to make sure that only a single instance is used.
1513ff48bf5SDavid du Colombier  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
1523ff48bf5SDavid du Colombier  */
1533ff48bf5SDavid du Colombier /* Destroy an instance of Ghostscript
1543ff48bf5SDavid du Colombier  * Before you call this, Ghostscript must have finished.
1553ff48bf5SDavid du Colombier  * If Ghostscript has been initialised, you must call gsapi_exit()
1563ff48bf5SDavid du Colombier  * before gsapi_delete_instance.
1573ff48bf5SDavid du Colombier  */
1583ff48bf5SDavid du Colombier GSDLLEXPORT void GSDLLAPI
159*593dc095SDavid du Colombier gsapi_delete_instance(void *instance);
1603ff48bf5SDavid du Colombier 
1613ff48bf5SDavid du Colombier /* Set the callback functions for stdio
1623ff48bf5SDavid du Colombier  * The stdin callback function should return the number of
1633ff48bf5SDavid du Colombier  * characters read, 0 for EOF, or -1 for error.
1643ff48bf5SDavid du Colombier  * The stdout and stderr callback functions should return
1653ff48bf5SDavid du Colombier  * the number of characters written.
1663ff48bf5SDavid du Colombier  * If a callback address is NULL, the real stdio will be used.
1673ff48bf5SDavid du Colombier  */
1683ff48bf5SDavid du Colombier GSDLLEXPORT int GSDLLAPI
169*593dc095SDavid du Colombier gsapi_set_stdio(void *instance,
1703ff48bf5SDavid du Colombier     int (GSDLLCALLPTR stdin_fn)(void *caller_handle, char *buf, int len),
1713ff48bf5SDavid du Colombier     int (GSDLLCALLPTR stdout_fn)(void *caller_handle, const char *str, int len),
172*593dc095SDavid du Colombier     int (GSDLLCALLPTR stderr_fn)(void *caller_handle, const char *str, int len));
1733ff48bf5SDavid du Colombier 
1743ff48bf5SDavid du Colombier /* Set the callback function for polling.
1753ff48bf5SDavid du Colombier  * This is used for handling window events or cooperative
1763ff48bf5SDavid du Colombier  * multitasking.  This function will only be called if
1773ff48bf5SDavid du Colombier  * Ghostscript was compiled with CHECK_INTERRUPTS
1783ff48bf5SDavid du Colombier  * as described in gpcheck.h.
179*593dc095SDavid du Colombier  * The polling function should return 0 if all is well,
180*593dc095SDavid du Colombier  * and negative if it wants ghostscript to abort.
181*593dc095SDavid du Colombier  * The polling function must be fast.
1823ff48bf5SDavid du Colombier  */
183*593dc095SDavid du Colombier GSDLLEXPORT int GSDLLAPI gsapi_set_poll(void *instance,
184*593dc095SDavid du Colombier     int (GSDLLCALLPTR poll_fn)(void *caller_handle));
1853ff48bf5SDavid du Colombier 
1863ff48bf5SDavid du Colombier /* Set the display device callback structure.
1873ff48bf5SDavid du Colombier  * If the display device is used, this must be called
1883ff48bf5SDavid du Colombier  * after gsapi_new_instance() and before gsapi_init_with_args().
1893ff48bf5SDavid du Colombier  * See gdevdisp.h for more details.
1903ff48bf5SDavid du Colombier  */
1913ff48bf5SDavid du Colombier GSDLLEXPORT int GSDLLAPI gsapi_set_display_callback(
192*593dc095SDavid du Colombier    void *instance, display_callback *callback);
1933ff48bf5SDavid du Colombier 
1943ff48bf5SDavid du Colombier 
1953ff48bf5SDavid du Colombier /* Initialise the interpreter.
1963ff48bf5SDavid du Colombier  * This calls gs_main_init_with_args() in imainarg.c
1973ff48bf5SDavid du Colombier  * 1. If quit or EOF occur during gsapi_init_with_args(),
1983ff48bf5SDavid du Colombier  *    the return value will be e_Quit.  This is not an error.
1993ff48bf5SDavid du Colombier  *    You must call gsapi_exit() and must not call any other
2003ff48bf5SDavid du Colombier  *    gsapi_XXX functions.
2013ff48bf5SDavid du Colombier  * 2. If usage info should be displayed, the return value will be e_Info
2023ff48bf5SDavid du Colombier  *    which is not an error.  Do not call gsapi_exit().
2033ff48bf5SDavid du Colombier  * 3. Under normal conditions this returns 0.  You would then
2043ff48bf5SDavid du Colombier  *    call one or more gsapi_run_*() functions and then finish
2053ff48bf5SDavid du Colombier  *    with gsapi_exit().
2063ff48bf5SDavid du Colombier  */
207*593dc095SDavid du Colombier GSDLLEXPORT int GSDLLAPI gsapi_init_with_args(void *instance,
208*593dc095SDavid du Colombier     int argc, char **argv);
2093ff48bf5SDavid du Colombier 
2103ff48bf5SDavid du Colombier /*
2113ff48bf5SDavid du Colombier  * The gsapi_run_* functions are like gs_main_run_* except
2123ff48bf5SDavid du Colombier  * that the error_object is omitted.
2133ff48bf5SDavid du Colombier  * If these functions return <= -100, either quit or a fatal
2143ff48bf5SDavid du Colombier  * error has occured.  You then call gsapi_exit() next.
2153ff48bf5SDavid du Colombier  * The only exception is gsapi_run_string_continue()
2163ff48bf5SDavid du Colombier  * which will return e_NeedInput if all is well.
2173ff48bf5SDavid du Colombier  */
2183ff48bf5SDavid du Colombier 
2193ff48bf5SDavid du Colombier GSDLLEXPORT int GSDLLAPI
220*593dc095SDavid du Colombier gsapi_run_string_begin(void *instance,
221*593dc095SDavid du Colombier     int user_errors, int *pexit_code);
2223ff48bf5SDavid du Colombier 
2233ff48bf5SDavid du Colombier GSDLLEXPORT int GSDLLAPI
224*593dc095SDavid du Colombier gsapi_run_string_continue(void *instance,
225*593dc095SDavid du Colombier     const char *str, unsigned int length, int user_errors, int *pexit_code);
2263ff48bf5SDavid du Colombier 
2273ff48bf5SDavid du Colombier GSDLLEXPORT int GSDLLAPI
228*593dc095SDavid du Colombier gsapi_run_string_end(void *instance,
229*593dc095SDavid du Colombier     int user_errors, int *pexit_code);
2303ff48bf5SDavid du Colombier 
2313ff48bf5SDavid du Colombier GSDLLEXPORT int GSDLLAPI
232*593dc095SDavid du Colombier gsapi_run_string_with_length(void *instance,
233*593dc095SDavid du Colombier     const char *str, unsigned int length, int user_errors, int *pexit_code);
2343ff48bf5SDavid du Colombier 
2353ff48bf5SDavid du Colombier GSDLLEXPORT int GSDLLAPI
236*593dc095SDavid du Colombier gsapi_run_string(void *instance,
237*593dc095SDavid du Colombier     const char *str, int user_errors, int *pexit_code);
2383ff48bf5SDavid du Colombier 
2393ff48bf5SDavid du Colombier GSDLLEXPORT int GSDLLAPI
240*593dc095SDavid du Colombier gsapi_run_file(void *instance,
241*593dc095SDavid du Colombier     const char *file_name, int user_errors, int *pexit_code);
2423ff48bf5SDavid du Colombier 
2433ff48bf5SDavid du Colombier 
2443ff48bf5SDavid du Colombier /* Exit the interpreter.
2453ff48bf5SDavid du Colombier  * This must be called on shutdown if gsapi_init_with_args()
2463ff48bf5SDavid du Colombier  * has been called, and just before gsapi_delete_instance().
2473ff48bf5SDavid du Colombier  */
2483ff48bf5SDavid du Colombier GSDLLEXPORT int GSDLLAPI
249*593dc095SDavid du Colombier gsapi_exit(void *instance);
250*593dc095SDavid du Colombier 
251*593dc095SDavid du Colombier /* Visual Tracer */
252*593dc095SDavid du Colombier /* This function is only for debug purpose clients */
253*593dc095SDavid du Colombier struct vd_trace_interface_s;
254*593dc095SDavid du Colombier GSDLLEXPORT void GSDLLAPI
255*593dc095SDavid du Colombier gsapi_set_visual_tracer(struct vd_trace_interface_s *I);
2563ff48bf5SDavid du Colombier 
2573ff48bf5SDavid du Colombier 
2583ff48bf5SDavid du Colombier /* function prototypes */
2593ff48bf5SDavid du Colombier typedef int (GSDLLAPIPTR PFN_gsapi_revision)(
260*593dc095SDavid du Colombier     gsapi_revision_t *pr, int len);
2613ff48bf5SDavid du Colombier typedef int (GSDLLAPIPTR PFN_gsapi_new_instance)(
262*593dc095SDavid du Colombier     void **pinstance, void *caller_handle);
2633ff48bf5SDavid du Colombier typedef void (GSDLLAPIPTR PFN_gsapi_delete_instance)(
264*593dc095SDavid du Colombier     void *instance);
265*593dc095SDavid du Colombier typedef int (GSDLLAPIPTR PFN_gsapi_set_stdio)(void *instance,
2663ff48bf5SDavid du Colombier     int (GSDLLCALLPTR stdin_fn)(void *caller_handle, char *buf, int len),
2673ff48bf5SDavid du Colombier     int (GSDLLCALLPTR stdout_fn)(void *caller_handle, const char *str, int len),
268*593dc095SDavid du Colombier     int (GSDLLCALLPTR stderr_fn)(void *caller_handle, const char *str, int len));
269*593dc095SDavid du Colombier typedef int (GSDLLAPIPTR PFN_gsapi_set_poll)(void *instance,
270*593dc095SDavid du Colombier     int(GSDLLCALLPTR poll_fn)(void *caller_handle));
2713ff48bf5SDavid du Colombier typedef int (GSDLLAPIPTR PFN_gsapi_set_display_callback)(
272*593dc095SDavid du Colombier     void *instance, display_callback *callback);
2733ff48bf5SDavid du Colombier typedef int (GSDLLAPIPTR PFN_gsapi_init_with_args)(
274*593dc095SDavid du Colombier     void *instance, int argc, char **argv);
2753ff48bf5SDavid du Colombier typedef int (GSDLLAPIPTR PFN_gsapi_run_string_begin)(
276*593dc095SDavid du Colombier     void *instance, int user_errors, int *pexit_code);
2773ff48bf5SDavid du Colombier typedef int (GSDLLAPIPTR PFN_gsapi_run_string_continue)(
278*593dc095SDavid du Colombier     void *instance, const char *str, unsigned int length,
279*593dc095SDavid du Colombier     int user_errors, int *pexit_code);
2803ff48bf5SDavid du Colombier typedef int (GSDLLAPIPTR PFN_gsapi_run_string_end)(
281*593dc095SDavid du Colombier     void *instance, int user_errors, int *pexit_code);
2823ff48bf5SDavid du Colombier typedef int (GSDLLAPIPTR PFN_gsapi_run_string_with_length)(
283*593dc095SDavid du Colombier     void *instance, const char *str, unsigned int length,
284*593dc095SDavid du Colombier     int user_errors, int *pexit_code);
2853ff48bf5SDavid du Colombier typedef int (GSDLLAPIPTR PFN_gsapi_run_string)(
286*593dc095SDavid du Colombier     void *instance, const char *str,
287*593dc095SDavid du Colombier     int user_errors, int *pexit_code);
288*593dc095SDavid du Colombier typedef int (GSDLLAPIPTR PFN_gsapi_run_file)(void *instance,
289*593dc095SDavid du Colombier     const char *file_name, int user_errors, int *pexit_code);
290*593dc095SDavid du Colombier typedef int (GSDLLAPIPTR PFN_gsapi_exit)(void *instance);
291*593dc095SDavid du Colombier typedef void (GSDLLAPIPTR PFN_gsapi_set_visual_tracer)
292*593dc095SDavid du Colombier     (struct vd_trace_interface_s *I);
2933ff48bf5SDavid du Colombier 
2943ff48bf5SDavid du Colombier 
295*593dc095SDavid du Colombier #ifdef __MACOS__
2963ff48bf5SDavid du Colombier #pragma export off
2973ff48bf5SDavid du Colombier #endif
2983ff48bf5SDavid du Colombier 
299*593dc095SDavid du Colombier #ifdef __cplusplus
300*593dc095SDavid du Colombier } /* extern 'C' protection */
301*593dc095SDavid du Colombier #endif
302*593dc095SDavid du Colombier 
3033ff48bf5SDavid du Colombier #endif /* iapi_INCLUDED */
304