iapi.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. /* Copyright (C) 1996-2001 Ghostgum Software Pty Ltd. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: iapi.h,v 1.13 2004/08/19 19:33:09 stefan Exp $ */
  14. /*
  15. * Public API for Ghostscript interpreter
  16. * for use both as DLL and for static linking.
  17. *
  18. * Should work for Windows, OS/2, Linux, Mac.
  19. *
  20. * DLL exported functions should be as similar as possible to imain.c
  21. * You will need to include "ierrors.h".
  22. *
  23. * Current problems:
  24. * 1. Ghostscript does not support multiple instances.
  25. * 2. Global variables in gs_main_instance_default()
  26. * and gsapi_instance_counter
  27. */
  28. /* Exported functions may need different prefix
  29. * GSDLLEXPORT marks functions as exported
  30. * GSDLLAPI is the calling convention used on functions exported
  31. * by Ghostscript
  32. * GSDLLCALL is used on callback functions called by Ghostscript
  33. * When you include this header file in the caller, you may
  34. * need to change the definitions by defining these
  35. * before including this header file.
  36. * Make sure you get the calling convention correct, otherwise your
  37. * program will crash either during callbacks or soon after returning
  38. * due to stack corruption.
  39. */
  40. #ifndef iapi_INCLUDED
  41. # define iapi_INCLUDED
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. #if defined(_WINDOWS_) || defined(__WINDOWS__)
  46. # ifndef _Windows
  47. # define _Windows
  48. # endif
  49. #endif
  50. #ifdef _Windows
  51. # ifndef GSDLLEXPORT
  52. # define GSDLLEXPORT __declspec(dllexport)
  53. # endif
  54. # ifndef GSDLLAPI
  55. # define GSDLLAPI __stdcall
  56. # endif
  57. # ifndef GSDLLCALL
  58. # define GSDLLCALL __stdcall
  59. # endif
  60. #endif /* _Windows */
  61. #if defined(OS2) && defined(__IBMC__)
  62. # ifndef GSDLLAPI
  63. # define GSDLLAPI _System
  64. # endif
  65. # ifndef GSDLLCALL
  66. # define GSDLLCALL _System
  67. # endif
  68. #endif /* OS2 && __IBMC */
  69. #ifdef __MACOS__
  70. # pragma export on
  71. #endif
  72. #ifndef GSDLLEXPORT
  73. # define GSDLLEXPORT
  74. #endif
  75. #ifndef GSDLLAPI
  76. # define GSDLLAPI
  77. #endif
  78. #ifndef GSDLLCALL
  79. # define GSDLLCALL
  80. #endif
  81. #if defined(__IBMC__)
  82. # define GSDLLAPIPTR * GSDLLAPI
  83. # define GSDLLCALLPTR * GSDLLCALL
  84. #else
  85. # define GSDLLAPIPTR GSDLLAPI *
  86. # define GSDLLCALLPTR GSDLLCALL *
  87. #endif
  88. #ifndef display_callback_DEFINED
  89. # define display_callback_DEFINED
  90. typedef struct display_callback_s display_callback;
  91. #endif
  92. typedef struct gsapi_revision_s {
  93. const char *product;
  94. const char *copyright;
  95. long revision;
  96. long revisiondate;
  97. } gsapi_revision_t;
  98. /* Get version numbers and strings.
  99. * This is safe to call at any time.
  100. * You should call this first to make sure that the correct version
  101. * of the Ghostscript is being used.
  102. * pr is a pointer to a revision structure.
  103. * len is the size of this structure in bytes.
  104. * Returns 0 if OK, or if len too small (additional parameters
  105. * have been added to the structure) it will return the required
  106. * size of the structure.
  107. */
  108. GSDLLEXPORT int GSDLLAPI
  109. gsapi_revision(gsapi_revision_t *pr, int len);
  110. /*
  111. * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  112. * Ghostscript supports only one instance.
  113. * The current implementation uses a global static instance
  114. * counter to make sure that only a single instance is used.
  115. * If you try to create two instances, the second attempt
  116. * will return < 0 and set pinstance to NULL.
  117. * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  118. */
  119. /* Create a new instance of Ghostscript.
  120. * This instance is passed to most other API functions.
  121. * The caller_handle will be provided to callback functions.
  122. */
  123. GSDLLEXPORT int GSDLLAPI
  124. gsapi_new_instance(void **pinstance, void *caller_handle);
  125. /*
  126. * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  127. * Ghostscript supports only one instance.
  128. * The current implementation uses a global static instance
  129. * counter to make sure that only a single instance is used.
  130. * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  131. */
  132. /* Destroy an instance of Ghostscript
  133. * Before you call this, Ghostscript must have finished.
  134. * If Ghostscript has been initialised, you must call gsapi_exit()
  135. * before gsapi_delete_instance.
  136. */
  137. GSDLLEXPORT void GSDLLAPI
  138. gsapi_delete_instance(void *instance);
  139. /* Set the callback functions for stdio
  140. * The stdin callback function should return the number of
  141. * characters read, 0 for EOF, or -1 for error.
  142. * The stdout and stderr callback functions should return
  143. * the number of characters written.
  144. * If a callback address is NULL, the real stdio will be used.
  145. */
  146. GSDLLEXPORT int GSDLLAPI
  147. gsapi_set_stdio(void *instance,
  148. int (GSDLLCALLPTR stdin_fn)(void *caller_handle, char *buf, int len),
  149. int (GSDLLCALLPTR stdout_fn)(void *caller_handle, const char *str, int len),
  150. int (GSDLLCALLPTR stderr_fn)(void *caller_handle, const char *str, int len));
  151. /* Set the callback function for polling.
  152. * This is used for handling window events or cooperative
  153. * multitasking. This function will only be called if
  154. * Ghostscript was compiled with CHECK_INTERRUPTS
  155. * as described in gpcheck.h.
  156. * The polling function should return 0 if all is well,
  157. * and negative if it wants ghostscript to abort.
  158. * The polling function must be fast.
  159. */
  160. GSDLLEXPORT int GSDLLAPI gsapi_set_poll(void *instance,
  161. int (GSDLLCALLPTR poll_fn)(void *caller_handle));
  162. /* Set the display device callback structure.
  163. * If the display device is used, this must be called
  164. * after gsapi_new_instance() and before gsapi_init_with_args().
  165. * See gdevdisp.h for more details.
  166. */
  167. GSDLLEXPORT int GSDLLAPI gsapi_set_display_callback(
  168. void *instance, display_callback *callback);
  169. /* Initialise the interpreter.
  170. * This calls gs_main_init_with_args() in imainarg.c
  171. * 1. If quit or EOF occur during gsapi_init_with_args(),
  172. * the return value will be e_Quit. This is not an error.
  173. * You must call gsapi_exit() and must not call any other
  174. * gsapi_XXX functions.
  175. * 2. If usage info should be displayed, the return value will be e_Info
  176. * which is not an error. Do not call gsapi_exit().
  177. * 3. Under normal conditions this returns 0. You would then
  178. * call one or more gsapi_run_*() functions and then finish
  179. * with gsapi_exit().
  180. */
  181. GSDLLEXPORT int GSDLLAPI gsapi_init_with_args(void *instance,
  182. int argc, char **argv);
  183. /*
  184. * The gsapi_run_* functions are like gs_main_run_* except
  185. * that the error_object is omitted.
  186. * If these functions return <= -100, either quit or a fatal
  187. * error has occured. You then call gsapi_exit() next.
  188. * The only exception is gsapi_run_string_continue()
  189. * which will return e_NeedInput if all is well.
  190. */
  191. GSDLLEXPORT int GSDLLAPI
  192. gsapi_run_string_begin(void *instance,
  193. int user_errors, int *pexit_code);
  194. GSDLLEXPORT int GSDLLAPI
  195. gsapi_run_string_continue(void *instance,
  196. const char *str, unsigned int length, int user_errors, int *pexit_code);
  197. GSDLLEXPORT int GSDLLAPI
  198. gsapi_run_string_end(void *instance,
  199. int user_errors, int *pexit_code);
  200. GSDLLEXPORT int GSDLLAPI
  201. gsapi_run_string_with_length(void *instance,
  202. const char *str, unsigned int length, int user_errors, int *pexit_code);
  203. GSDLLEXPORT int GSDLLAPI
  204. gsapi_run_string(void *instance,
  205. const char *str, int user_errors, int *pexit_code);
  206. GSDLLEXPORT int GSDLLAPI
  207. gsapi_run_file(void *instance,
  208. const char *file_name, int user_errors, int *pexit_code);
  209. /* Exit the interpreter.
  210. * This must be called on shutdown if gsapi_init_with_args()
  211. * has been called, and just before gsapi_delete_instance().
  212. */
  213. GSDLLEXPORT int GSDLLAPI
  214. gsapi_exit(void *instance);
  215. /* Visual Tracer */
  216. /* This function is only for debug purpose clients */
  217. struct vd_trace_interface_s;
  218. GSDLLEXPORT void GSDLLAPI
  219. gsapi_set_visual_tracer(struct vd_trace_interface_s *I);
  220. /* function prototypes */
  221. typedef int (GSDLLAPIPTR PFN_gsapi_revision)(
  222. gsapi_revision_t *pr, int len);
  223. typedef int (GSDLLAPIPTR PFN_gsapi_new_instance)(
  224. void **pinstance, void *caller_handle);
  225. typedef void (GSDLLAPIPTR PFN_gsapi_delete_instance)(
  226. void *instance);
  227. typedef int (GSDLLAPIPTR PFN_gsapi_set_stdio)(void *instance,
  228. int (GSDLLCALLPTR stdin_fn)(void *caller_handle, char *buf, int len),
  229. int (GSDLLCALLPTR stdout_fn)(void *caller_handle, const char *str, int len),
  230. int (GSDLLCALLPTR stderr_fn)(void *caller_handle, const char *str, int len));
  231. typedef int (GSDLLAPIPTR PFN_gsapi_set_poll)(void *instance,
  232. int(GSDLLCALLPTR poll_fn)(void *caller_handle));
  233. typedef int (GSDLLAPIPTR PFN_gsapi_set_display_callback)(
  234. void *instance, display_callback *callback);
  235. typedef int (GSDLLAPIPTR PFN_gsapi_init_with_args)(
  236. void *instance, int argc, char **argv);
  237. typedef int (GSDLLAPIPTR PFN_gsapi_run_string_begin)(
  238. void *instance, int user_errors, int *pexit_code);
  239. typedef int (GSDLLAPIPTR PFN_gsapi_run_string_continue)(
  240. void *instance, const char *str, unsigned int length,
  241. int user_errors, int *pexit_code);
  242. typedef int (GSDLLAPIPTR PFN_gsapi_run_string_end)(
  243. void *instance, int user_errors, int *pexit_code);
  244. typedef int (GSDLLAPIPTR PFN_gsapi_run_string_with_length)(
  245. void *instance, const char *str, unsigned int length,
  246. int user_errors, int *pexit_code);
  247. typedef int (GSDLLAPIPTR PFN_gsapi_run_string)(
  248. void *instance, const char *str,
  249. int user_errors, int *pexit_code);
  250. typedef int (GSDLLAPIPTR PFN_gsapi_run_file)(void *instance,
  251. const char *file_name, int user_errors, int *pexit_code);
  252. typedef int (GSDLLAPIPTR PFN_gsapi_exit)(void *instance);
  253. typedef void (GSDLLAPIPTR PFN_gsapi_set_visual_tracer)
  254. (struct vd_trace_interface_s *I);
  255. #ifdef __MACOS__
  256. #pragma export off
  257. #endif
  258. #ifdef __cplusplus
  259. } /* extern 'C' protection */
  260. #endif
  261. #endif /* iapi_INCLUDED */