~ubuntu-branches/ubuntu/jaunty/ghostscript/jaunty-updates

« back to all changes in this revision

Viewing changes to psi/iapi.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2009-01-20 16:40:45 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090120164045-lnfhi0n30o5lwhwa
Tags: 8.64.dfsg.1~svn9377-0ubuntu1
* New upstream release (SVN rev 9377)
   o Fixes many bugs concerning PDF rendering, to make the PDF printing
     workflow correctly working.
   o Fixes long-standing bugs in many drivers, like input paper tray and
     duplex options not working for the built-in PCL 4, 5, 5c, 5e, and
     6/XL drivers, PDF input not working for bjc600, bjc800, and cups
     output devices, several options not working and uninitialized
     memory with cups output device.
   o Merged nearly all patches of the Ubuntu and Debian packages upstream.
   o Fixes LP: #317810, LP: #314439, LP: #314018.
* debian/patches/03_libpaper_support.dpatch,
  debian/patches/11_gs-cjk_font_glyph_handling_fix.dpatch,
  debian/patches/12_gs-cjk_vertical_writing_metrics_fix.dpatch,
  debian/patches/13_gs-cjk_cjkps_examples.dpatch,
  debian/patches/20_bbox_segv_fix.dpatch,
  debian/patches/21_brother_7x0_gdi_fix.dpatch,
  debian/patches/22_epsn_margin_workaround.dpatch,
  debian/patches/24_gs_man_fix.dpatch,
  debian/patches/25_toolbin_insecure_tmp_usage_fix.dpatch,
  debian/patches/26_assorted_script_fixes.dpatch,
  debian/patches/29_gs_css_fix.dpatch,
  debian/patches/30_ps2pdf_man_improvement.dpatch,
  debian/patches/31_fix-gc-sigbus.dpatch,
  debian/patches/34_ftbfs-on-hurd-fix.dpatch,
  debian/patches/35_disable_libcairo.dpatch,
  debian/patches/38_pxl-duplex.dpatch,
  debian/patches/39_pxl-resolution.dpatch,
  debian/patches/42_gs-init-ps-delaybind-fix.dpatch,
  debian/patches/45_bjc600-bjc800-pdf-input.dpatch,
  debian/patches/48_cups-output-device-pdf-duplex-uninitialized-memory-fix.dpatch,
  debian/patches/50_lips4-floating-point-exception.dpatch,
  debian/patches/52_cups-device-logging.dpatch,
  debian/patches/55_pcl-input-slot-fix.dpatch,
  debian/patches/57_pxl-input-slot-fix.dpatch,
  debian/patches/60_pxl-cups-driver-pdf.dpatch,
  debian/patches/62_onebitcmyk-pdf.dpatch,
  debian/patches/65_too-big-temp-files-1.dpatch,
  debian/patches/67_too-big-temp-files-2.dpatch,
  debian/patches/70_take-into-account-data-in-stream-buffer-before-refill.dpatch:
  Removed, applied upstream.
* debian/patches/01_docdir_fix_for_debian.dpatch,
  debian/patches/02_gs_man_fix_debian.dpatch,
  debian/patches/01_docdir-fix-for-debian.dpatch,
  debian/patches/02_docdir-fix-for-debian.dpatch: Renamed patches to
  make merging with Debian easier.
* debian/patches/32_improve-handling-of-media-size-changes-from-gv.dpatch, 
  debian/patches/33_bad-params-to-xinitimage-on-large-bitmaps.dpatch:
  regenerated for new source directory structure.
* debian/rules: Corrected paths to remove cidfmap (it is in Resource/Init/
  in GS 8.64) and to install headers (source paths are psi/ and base/ now).
* debian/rules: Remove all fontmaps, as DeFoMa replaces them.
* debian/local/pdftoraster/pdftoraster.c,
  debian/local/pdftoraster/pdftoraster.convs, debian/rules: Removed
  added pdftoraster filter and use the one which comes with Ghostscript.
* debian/ghostscript.links: s/8.63/8.64/

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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: iapi.c 9043 2008-08-28 22:48:19Z giles $ */
 
15
 
 
16
/* Public Application Programming Interface to Ghostscript interpreter */
 
17
 
 
18
#include "string_.h"
 
19
#include "ierrors.h"
 
20
#include "gscdefs.h"
 
21
#include "gstypes.h"
 
22
#include "iapi.h"       /* Public API */
 
23
#include "iref.h"
 
24
#include "iminst.h"
 
25
#include "imain.h"
 
26
#include "imainarg.h"
 
27
#include "gsmemory.h"
 
28
#include "gsmalloc.h"
 
29
#include "gslibctx.h"
 
30
 
 
31
/* number of threads to allow per process
 
32
 * currently more than 1 is guarenteed to fail 
 
33
 */
 
34
static int gsapi_instance_counter = 0;
 
35
static const int gsapi_instance_max = 1;
 
36
 
 
37
/* Return revision numbers and strings of Ghostscript. */
 
38
/* Used for determining if wrong GSDLL loaded. */
 
39
/* This may be called before any other function. */
 
40
GSDLLEXPORT int GSDLLAPI
 
41
gsapi_revision(gsapi_revision_t *pr, int rvsize)
 
42
{
 
43
    if (rvsize < sizeof(gsapi_revision_t))
 
44
        return sizeof(gsapi_revision_t);
 
45
    pr->product = gs_product;
 
46
    pr->copyright = gs_copyright;
 
47
    pr->revision = gs_revision;
 
48
    pr->revisiondate = gs_revisiondate;
 
49
    return 0;
 
50
}
 
51
 
 
52
/* Create a new instance of Ghostscript. 
 
53
 * First instance per process call with *pinstance == NULL
 
54
 * next instance in a proces call with *pinstance == copy of valid_instance pointer
 
55
 * *pinstance is set to a new instance pointer.
 
56
 */
 
57
GSDLLEXPORT int GSDLLAPI 
 
58
gsapi_new_instance(void **pinstance, void *caller_handle)
 
59
{
 
60
    gs_memory_t *mem = NULL;
 
61
    gs_main_instance *minst = NULL;
 
62
 
 
63
    if (pinstance == NULL)
 
64
        return e_Fatal;
 
65
 
 
66
    /* limited to 1 instance, till it works :) */
 
67
    if ( gsapi_instance_counter >= gsapi_instance_max ) 
 
68
        return e_Fatal;
 
69
    ++gsapi_instance_counter;
 
70
 
 
71
    if (*pinstance == NULL)
 
72
        /* first instance in this process */
 
73
        mem = gs_malloc_init(NULL);
 
74
    else {
 
75
        /* nothing different for second thread initialization 
 
76
         * seperate memory, ids, only stdio is process shared.
 
77
         */
 
78
        mem = gs_malloc_init(NULL);
 
79
        
 
80
    }
 
81
    minst = gs_main_alloc_instance(mem);
 
82
    mem->gs_lib_ctx->top_of_system = (void*) minst;
 
83
    mem->gs_lib_ctx->caller_handle = caller_handle;
 
84
    mem->gs_lib_ctx->custom_color_callback = NULL;
 
85
    mem->gs_lib_ctx->stdin_fn = NULL;
 
86
    mem->gs_lib_ctx->stdout_fn = NULL;
 
87
    mem->gs_lib_ctx->stderr_fn = NULL;
 
88
    mem->gs_lib_ctx->poll_fn = NULL;
 
89
 
 
90
    *pinstance = (void*)(mem->gs_lib_ctx);
 
91
    return 0;
 
92
}
 
93
 
 
94
/* Destroy an instance of Ghostscript */
 
95
/* We do not support multiple instances, so make sure
 
96
 * we use the default instance only once.
 
97
 */
 
98
GSDLLEXPORT void GSDLLAPI 
 
99
gsapi_delete_instance(void *lib)
 
100
{
 
101
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
 
102
    if ((ctx != NULL)) {
 
103
        gs_main_instance *minst = get_minst_from_memory(ctx->memory);
 
104
 
 
105
        ctx->caller_handle = NULL;
 
106
        ctx->stdin_fn = NULL;
 
107
        ctx->stdout_fn = NULL;
 
108
        ctx->stderr_fn = NULL;
 
109
        ctx->poll_fn = NULL;
 
110
        minst->display = NULL;
 
111
        
 
112
        /* Release the memory (frees up everything) */
 
113
        gs_malloc_release(minst->heap);
 
114
        
 
115
        --gsapi_instance_counter;
 
116
    }
 
117
}
 
118
 
 
119
/* Set the callback functions for stdio */
 
120
GSDLLEXPORT int GSDLLAPI 
 
121
gsapi_set_stdio(void *lib,
 
122
    int(GSDLLCALL *stdin_fn)(void *caller_handle, char *buf, int len),
 
123
    int(GSDLLCALL *stdout_fn)(void *caller_handle, const char *str, int len),
 
124
    int(GSDLLCALL *stderr_fn)(void *caller_handle, const char *str, int len))
 
125
{
 
126
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
 
127
    if (lib == NULL)
 
128
        return e_Fatal;
 
129
    ctx->stdin_fn = stdin_fn;
 
130
    ctx->stdout_fn = stdout_fn;
 
131
    ctx->stderr_fn = stderr_fn;
 
132
    return 0;
 
133
}
 
134
 
 
135
/* Set the callback function for polling */
 
136
GSDLLEXPORT int GSDLLAPI 
 
137
gsapi_set_poll(void *lib, 
 
138
    int(GSDLLCALL *poll_fn)(void *caller_handle))
 
139
{
 
140
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
 
141
    if (lib == NULL)
 
142
        return e_Fatal;
 
143
    ctx->poll_fn = poll_fn;
 
144
    return 0;
 
145
}
 
146
 
 
147
/* Set the display callback structure */
 
148
GSDLLEXPORT int GSDLLAPI 
 
149
gsapi_set_display_callback(void *lib, display_callback *callback)
 
150
{
 
151
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
 
152
    if (lib == NULL)
 
153
        return e_Fatal;
 
154
    get_minst_from_memory(ctx->memory)->display = callback;
 
155
    /* not in a language switched build */
 
156
    return 0;
 
157
}
 
158
 
 
159
 
 
160
/* Initialise the interpreter */
 
161
GSDLLEXPORT int GSDLLAPI 
 
162
gsapi_init_with_args(void *lib, int argc, char **argv)
 
163
{
 
164
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
 
165
    if (lib == NULL)
 
166
        return e_Fatal;
 
167
    return gs_main_init_with_args(get_minst_from_memory(ctx->memory), argc, argv);
 
168
}
 
169
 
 
170
 
 
171
 
 
172
/* The gsapi_run_* functions are like gs_main_run_* except
 
173
 * that the error_object is omitted.
 
174
 * An error object in minst is used instead.
 
175
 */
 
176
 
 
177
/* Setup up a suspendable run_string */
 
178
GSDLLEXPORT int GSDLLAPI 
 
179
gsapi_run_string_begin(void *lib, int user_errors, 
 
180
        int *pexit_code)
 
181
{
 
182
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
 
183
    if (lib == NULL)
 
184
        return e_Fatal;
 
185
 
 
186
    return gs_main_run_string_begin(get_minst_from_memory(ctx->memory), 
 
187
                                    user_errors, pexit_code, 
 
188
                                    &(get_minst_from_memory(ctx->memory)->error_object));
 
189
}
 
190
 
 
191
 
 
192
GSDLLEXPORT int GSDLLAPI 
 
193
gsapi_run_string_continue(void *lib, 
 
194
        const char *str, uint length, int user_errors, int *pexit_code)
 
195
{
 
196
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
 
197
    if (lib == NULL)
 
198
        return e_Fatal;
 
199
 
 
200
    return gs_main_run_string_continue(get_minst_from_memory(ctx->memory),
 
201
                                       str, length, user_errors, pexit_code, 
 
202
                                       &(get_minst_from_memory(ctx->memory)->error_object));
 
203
}
 
204
 
 
205
GSDLLEXPORT int GSDLLAPI 
 
206
gsapi_run_string_end(void *lib, 
 
207
        int user_errors, int *pexit_code)
 
208
{
 
209
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
 
210
    if (lib == NULL)
 
211
        return e_Fatal;
 
212
 
 
213
    return gs_main_run_string_end(get_minst_from_memory(ctx->memory),
 
214
                                  user_errors, pexit_code, 
 
215
                                  &(get_minst_from_memory(ctx->memory)->error_object));
 
216
}
 
217
 
 
218
GSDLLEXPORT int GSDLLAPI 
 
219
gsapi_run_string_with_length(void *lib, 
 
220
        const char *str, uint length, int user_errors, int *pexit_code)
 
221
{
 
222
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
 
223
    if (lib == NULL)
 
224
        return e_Fatal;
 
225
 
 
226
    return gs_main_run_string_with_length(get_minst_from_memory(ctx->memory),
 
227
                                          str, length, user_errors, pexit_code, 
 
228
                                          &(get_minst_from_memory(ctx->memory)->error_object));
 
229
}
 
230
 
 
231
GSDLLEXPORT int GSDLLAPI 
 
232
gsapi_run_string(void *lib, 
 
233
        const char *str, int user_errors, int *pexit_code)
 
234
{
 
235
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
 
236
    return gsapi_run_string_with_length(get_minst_from_memory(ctx->memory),
 
237
        str, (uint)strlen(str), user_errors, pexit_code);
 
238
}
 
239
 
 
240
GSDLLEXPORT int GSDLLAPI 
 
241
gsapi_run_file(void *lib, const char *file_name, 
 
242
        int user_errors, int *pexit_code)
 
243
{
 
244
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
 
245
    if (lib == NULL)
 
246
        return e_Fatal;
 
247
 
 
248
    return gs_main_run_file(get_minst_from_memory(ctx->memory),
 
249
                            file_name, user_errors, pexit_code, 
 
250
                            &(get_minst_from_memory(ctx->memory)->error_object));
 
251
}
 
252
 
 
253
 
 
254
/* Exit the interpreter */
 
255
GSDLLEXPORT int GSDLLAPI 
 
256
gsapi_exit(void *lib)
 
257
{
 
258
    gs_lib_ctx_t *ctx = (gs_lib_ctx_t *)lib;
 
259
    if (lib == NULL)
 
260
        return e_Fatal;
 
261
 
 
262
    gs_to_exit(ctx->memory, 0);
 
263
    return 0;
 
264
}
 
265
 
 
266
/* Visual tracer : */
 
267
struct vd_trace_interface_s;
 
268
extern struct vd_trace_interface_s * vd_trace0;
 
269
GSDLLEXPORT void GSDLLAPI
 
270
gsapi_set_visual_tracer(struct vd_trace_interface_s *I)
 
271
{   vd_trace0 = I;
 
272
}
 
273
 
 
274
/* end of iapi.c */