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

« back to all changes in this revision

Viewing changes to src/gp.h

  • 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: gp.h 8022 2007-06-05 22:23:38Z giles $ */
15
 
/* Interface to platform-specific routines */
16
 
/* Requires gsmemory.h */
17
 
 
18
 
#ifndef gp_INCLUDED
19
 
#  define gp_INCLUDED
20
 
 
21
 
#include "gstypes.h"
22
 
/*
23
 
 * This file defines the interface to ***ALL*** platform-specific routines,
24
 
 * with the exception of the thread/synchronization interface (gpsync.h)
25
 
 * and getenv (gpgetenv.h).  The implementations are in gp_*.c files
26
 
 * specific to each platform.  We try very hard to keep this list short!
27
 
 */
28
 
/*
29
 
 * gp_getenv is declared in a separate file because a few places need it
30
 
 * and don't want to include any of the other gs definitions.
31
 
 */
32
 
#include "gpgetenv.h"
33
 
/*
34
 
 * The prototype for gp_readline is in srdline.h, since it is shared with
35
 
 * stream.h.
36
 
 */
37
 
#include "srdline.h"
38
 
 
39
 
/*
40
 
 * int64_t is used in the 64 bits file access.
41
 
 */
42
 
#include "stdint_.h"
43
 
 
44
 
/* ------ Initialization/termination ------ */
45
 
 
46
 
/*
47
 
 * This routine is called early in the initialization.
48
 
 * It should do as little as possible.  In particular, it should not
49
 
 * do things like open display connections: that is the responsibility
50
 
 * of the display device driver.
51
 
 */
52
 
void gp_init(void);
53
 
 
54
 
/*
55
 
 * This routine is called just before the program exits (normally or
56
 
 * abnormally).  It too should do as little as possible.
57
 
 */
58
 
void gp_exit(int exit_status, int code);
59
 
 
60
 
/*
61
 
 * Exit the program.  Normally this just calls the `exit' library procedure,
62
 
 * but it does something different on a few platforms.
63
 
 */
64
 
void gp_do_exit(int exit_status);
65
 
 
66
 
/* ------ Miscellaneous ------ */
67
 
 
68
 
/*
69
 
 * Get the string corresponding to an OS error number.
70
 
 * If no string is available, return NULL.  The caller may assume
71
 
 * the string is allocated statically and permanently.
72
 
 */
73
 
const char *gp_strerror(int);
74
 
 
75
 
/* ------ Date and time ------ */
76
 
 
77
 
/*
78
 
 * Read the current time (in seconds since an implementation-defined epoch)
79
 
 * into ptm[0], and fraction (in nanoseconds) into ptm[1].
80
 
 */
81
 
void gp_get_realtime(long ptm[2]);
82
 
 
83
 
/*
84
 
 * Read the current user CPU time (in seconds) into ptm[0],
85
 
 * and fraction (in nanoseconds) into ptm[1].
86
 
 */
87
 
void gp_get_usertime(long ptm[2]);
88
 
 
89
 
/* ------ Reading lines from stdin ------ */
90
 
 
91
 
/*
92
 
 * These routines are intended to provide an abstract interface to GNU
93
 
 * readline or to other packages that offer enhanced line-reading
94
 
 * capability.
95
 
 */
96
 
 
97
 
/*
98
 
 * Allocate a state structure for line reading.  This is called once at
99
 
 * initialization.  *preadline_data is an opaque pointer that is passed
100
 
 * back to gp_readline and gp_readline_finit.
101
 
 */
102
 
int gp_readline_init(void **preadline_data, gs_memory_t *mem);
103
 
 
104
 
/*
105
 
 * See srdline.h for the definition of sreadline_proc.
106
 
 */
107
 
int gp_readline(stream *s_in, stream *s_out, void *readline_data,
108
 
                gs_const_string *prompt, gs_string *buf,
109
 
                gs_memory_t *bufmem, uint *pcount, bool *pin_eol,
110
 
                bool (*is_stdin)(const stream *));
111
 
 
112
 
/*
113
 
 * Free a readline state.
114
 
 */
115
 
void gp_readline_finit(void *readline_data);
116
 
 
117
 
/* ------ Reading from stdin, unbuffered if possible ------ */
118
 
 
119
 
/* Read bytes from stdin, using unbuffered if possible.
120
 
 * Store up to len bytes in buf.
121
 
 * Returns number of bytes read, or 0 if EOF, or -ve if error.
122
 
 * If unbuffered is NOT possible, fetch 1 byte if interactive
123
 
 * is non-zero, or up to len bytes otherwise.
124
 
 * If unbuffered is possible, fetch at least 1 byte (unless error or EOF) 
125
 
 * and any additional bytes that are available without blocking.
126
 
 */
127
 
int gp_stdin_read(char *buf, int len, int interactive, FILE *f);
128
 
 
129
 
/* ------ Screen management ------ */
130
 
 
131
 
/*
132
 
 * The following are only relevant for X Windows.
133
 
 */
134
 
 
135
 
/* Get the environment variable that specifies the display to use. */
136
 
const char *gp_getenv_display(void);
137
 
 
138
 
/* ------ File naming and accessing ------ */
139
 
 
140
 
/*
141
 
 * Define the maximum size of a file name returned by gp_open_scratch_file
142
 
 * or gp_open_printer.  (This should really be passed as an additional
143
 
 * parameter, but it would break too many clients to make this change now.)
144
 
 * Note that this is the size of the buffer, not the maximum number of
145
 
 * characters: the latter is one less, because of the terminating \0.
146
 
 */
147
 
#define gp_file_name_sizeof 260 /* == MAX_PATH on Windows */
148
 
 
149
 
/* Define the character used for separating file names in a list. */
150
 
extern const char gp_file_name_list_separator;
151
 
 
152
 
/* Define the default scratch file name prefix. */
153
 
extern const char gp_scratch_file_name_prefix[];
154
 
 
155
 
/* Define the name of the null output file. */
156
 
extern const char gp_null_file_name[];
157
 
 
158
 
/* Define the name that designates the current directory. */
159
 
extern const char gp_current_directory_name[];
160
 
 
161
 
/* Define the string to be concatenated with the file mode */
162
 
/* for opening files without end-of-line conversion. */
163
 
/* This is always either "" or "b". */
164
 
extern const char gp_fmode_binary_suffix[];
165
 
 
166
 
/* Define the file modes for binary reading or writing. */
167
 
/* (This is just a convenience: they are "r" or "w" + the suffix.) */
168
 
extern const char gp_fmode_rb[];
169
 
extern const char gp_fmode_wb[];
170
 
 
171
 
/**
172
 
 * gp_open_scratch_file: Create a scratch file.
173
 
 * @prefix: Name prefix.
174
 
 * @fname: Where to store filename of newly created file.
175
 
 * @mode: File access mode (in fopen syntax).
176
 
 *
177
 
 * Creates a scratch (temporary) file in the filesystem. The exact
178
 
 * location and name of the file is platform dependent, but in general
179
 
 * uses @prefix as a prefix. If @prefix is not absolute, then choose
180
 
 * an appropriate system directory, usually as determined from
181
 
 * gp_gettmpdir(), followed by a path as returned from a system call.
182
 
 *
183
 
 * Implementations should make sure that 
184
 
 *
185
 
 * Return value: Opened file object, or NULL on error.
186
 
 **/
187
 
FILE *gp_open_scratch_file(const char *prefix,
188
 
                           char fname[gp_file_name_sizeof],
189
 
                           const char *mode);
190
 
 
191
 
/* Open a file with the given name, as a stream of uninterpreted bytes. */
192
 
FILE *gp_fopen(const char *fname, const char *mode);
193
 
 
194
 
/* Force given file into binary mode (no eol translations, etc) */
195
 
/* if 2nd param true, text mode if 2nd param false */
196
 
int gp_setmode_binary(FILE * pfile, bool mode);
197
 
 
198
 
typedef enum {
199
 
    gp_combine_small_buffer = -1,
200
 
    gp_combine_cant_handle = 0,
201
 
    gp_combine_success = 1
202
 
} gp_file_name_combine_result;
203
 
 
204
 
/*
205
 
 * Combine a file name with a prefix.
206
 
 * Concatenates two paths and reduce parten references and current 
207
 
 * directory references from the concatenation when possible.
208
 
 * The trailing zero byte is being added.
209
 
 * Various platforms may share this code.
210
 
 */
211
 
gp_file_name_combine_result gp_file_name_combine(const char *prefix, uint plen, 
212
 
            const char *fname, uint flen, bool no_sibling, char *buffer, uint *blen);
213
 
 
214
 
/* -------------- Helpers for gp_file_name_combine_generic ------------- */
215
 
/* Platforms, which do not call gp_file_name_combine_generic, */
216
 
/* must stub the helpers against linkage problems. */
217
 
 
218
 
/* Return length of root prefix of the file name, or zero. */
219
 
/*      unix:   length("/")         */
220
 
/*      Win:    length("c:/") or length("//computername/cd:/")  */
221
 
/*      mac:    length("volume:")    */
222
 
/*      VMS:    length("device:[root.]["            */
223
 
uint gp_file_name_root(const char *fname, uint len);
224
 
 
225
 
/* Check whether a part of file name starts (ends) with a separator. */
226
 
/* Must return the length of the separator.*/
227
 
/* If the 'len' is negative, must search in backward direction. */
228
 
/*      unix:   '/'         */
229
 
/*      Win:    '/' or '\'  */
230
 
/*      mac:    ':' except "::"     */
231
 
/*      VMS:    smart - see the implementation   */
232
 
uint gs_file_name_check_separator(const char *fname, int len, const char *item);
233
 
 
234
 
/* Check whether a part of file name is a parent reference. */
235
 
/*      unix, Win:  equal to ".."       */
236
 
/*      mac:    equal to ":"            */
237
 
/*      VMS:    equal to "."            */
238
 
bool gp_file_name_is_parent(const char *fname, uint len);
239
 
 
240
 
/* Check if a part of file name is a current directory reference. */
241
 
/*      unix, Win:  equal to "."        */
242
 
/*      mac:    equal to ""             */
243
 
/*      VMS:    equal to ""             */
244
 
bool gp_file_name_is_current(const char *fname, uint len);
245
 
 
246
 
/* Returns a string for referencing the current directory. */
247
 
/*      unix, Win:  "."     */
248
 
/*      mac:    ":"         */
249
 
/*      VMS:    ""          */
250
 
const char *gp_file_name_current(void);
251
 
 
252
 
/* Returns a string for separating a file name item. */
253
 
/*      unix, Win:  "/"     */
254
 
/*      mac:    ":"         */
255
 
/*      VMS:    "]"         */
256
 
const char *gp_file_name_separator(void);
257
 
 
258
 
/* Returns a string for separating a directory item. */
259
 
/*      unix, Win:  "/"     */
260
 
/*      mac:    ":"         */
261
 
/*      VMS:    "."         */
262
 
const char *gp_file_name_directory_separator(void);
263
 
 
264
 
/* Returns a string for representing a parent directory reference. */
265
 
/*      unix, Win:  ".."    */
266
 
/*      mac:    ":"         */
267
 
/*      VMS:    "."         */
268
 
const char *gp_file_name_parent(void);
269
 
 
270
 
/* Answer whether the platform allows parent refenences. */
271
 
/*      unix, Win, Mac: yes */
272
 
/*      VMS:    no.         */
273
 
bool gp_file_name_is_partent_allowed(void);
274
 
 
275
 
/* Answer whether an empty item is meanful in file names on the platform. */
276
 
/*      unix, Win:  no      */
277
 
/*      mac:    yes         */
278
 
/*      VMS:    yes         */
279
 
bool gp_file_name_is_empty_item_meanful(void);
280
 
 
281
 
/* Read a 'resource' stored in a special database indexed by a 32 bit  */
282
 
/* 'type' and 16 bit 'id' in an extended attribute of a file. The is   */
283
 
/* primarily for accessing fonts on MacOS, which classically used this */
284
 
/* format. Presumedly a 'nop' on systems that don't support Apple HFS. */
285
 
int gp_read_macresource(byte *buf, const char *fname, 
286
 
                                     const uint type, const ushort id);
287
 
 
288
 
 
289
 
/* ------ persistent cache interface ------ */
290
 
 
291
 
/*
292
 
 * This is used for access to data cached between invocations of 
293
 
 * Ghostscript. It is generally used for saving reusable data that
294
 
 * is expensive to compute. Concurrent access by multiple instances
295
 
 * is safe. Because of this care should be taken to use a new data
296
 
 * type when the format of the cached data changes.
297
 
 *
298
 
 * Generic data buffers are stored under a combination of type and
299
 
 * key. It is up the to client to interpret the data buffer appropriately.
300
 
 * An insert overwrites any previous entry under that type and key.
301
 
 * A query if successful uses the passed callback to allocate a buffer
302
 
 * and fills it with the retrieved data. The caller is thus responsible
303
 
 * for the buffer's memory management.
304
 
 * 
305
 
 * See zmisc.c for postscript test operators and an example implementation.
306
 
 */
307
 
 
308
 
/* return 0 on successful insert, non-zero otherwise */
309
 
int gp_cache_insert(int type, byte *key, int keylen, void *buffer, int buflen);
310
 
 
311
 
/* return the length of the buffer on success, a negative value otherwise */
312
 
typedef void *(*gp_cache_alloc)(void *userdata, int bytes);
313
 
int gp_cache_query(int type, byte* key, int keylen, void **buffer,
314
 
    gp_cache_alloc alloc, void *userdata);
315
 
 
316
 
/* cache data types */
317
 
#define GP_CACHE_TYPE_TEST 0
318
 
#define GP_CACHE_TYPE_FONTMAP 1
319
 
#define GP_CACHE_TYPE_WTS_SIZE 2
320
 
#define GP_CACHE_TYPE_WTS_CELL 3
321
 
 
322
 
 
323
 
/* ------ Printer accessing ------ */
324
 
 
325
 
/*
326
 
 * Open a connection to a printer.  A null file name means use the standard
327
 
 * printer connected to the machine, if any.  Note that this procedure is
328
 
 * called only if the original file name (normally the value of the
329
 
 * OutputFile device parameter) was an ordinary file (not stdout, a pipe, or
330
 
 * other %filedevice%file name): stdout is handled specially, and other
331
 
 * values of filedevice are handled by calling the fopen procedure
332
 
 * associated with that kind of "file".
333
 
 *
334
 
 * Note that if the file name is null (0-length) and a default printer is
335
 
 * available, the file name may be replaced with the name of a scratch file
336
 
 * for spooling.  If the file name is null and no default printer is
337
 
 * available, this procedure returns 0.
338
 
 */
339
 
FILE *gp_open_printer(char fname[gp_file_name_sizeof], int binary_mode);
340
 
 
341
 
/*
342
 
 * Close the connection to the printer.  Note that this is only called
343
 
 * if the original file name was an ordinary file (not stdout, a pipe,
344
 
 * or other %filedevice%file name): stdout is handled specially, and other
345
 
 * values of filedevice are handled by calling the fclose procedure
346
 
 * associated with that kind of "file".
347
 
 */
348
 
void gp_close_printer(FILE * pfile, const char *fname);
349
 
 
350
 
/* ------ File enumeration ------ */
351
 
 
352
 
#ifndef file_enum_DEFINED       /* also defined in iodev.h */
353
 
#  define file_enum_DEFINED
354
 
typedef struct file_enum_s file_enum;
355
 
#endif
356
 
 
357
 
/*
358
 
 * Begin an enumeration.  pat is a C string that may contain *s or ?s.
359
 
 * The implementor should copy the string to a safe place.
360
 
 * If the operating system doesn't support correct, arbitrarily placed
361
 
 * *s and ?s, the implementation should modify the string so that it
362
 
 * will return a conservative superset of the request, and then use
363
 
 * the string_match procedure to select the desired subset.  E.g., if the
364
 
 * OS doesn't implement ? (single-character wild card), any consecutive
365
 
 * string of ?s should be interpreted as *.  Note that \ can appear in
366
 
 * the pattern also, as a quoting character.
367
 
 */
368
 
file_enum *gp_enumerate_files_init(const char *pat, uint patlen,
369
 
                                   gs_memory_t * memory);
370
 
 
371
 
/*
372
 
 * Return the next file name in the enumeration.  The client passes in
373
 
 * a scratch string and a max length.  If the name of the next file fits,
374
 
 * the procedure returns the length.  If it doesn't fit, the procedure
375
 
 * returns max length +1.  If there are no more files, the procedure
376
 
 * returns -1.
377
 
 */
378
 
uint gp_enumerate_files_next(file_enum * pfen, char *ptr, uint maxlen);
379
 
 
380
 
/*
381
 
 * Clean up a file enumeration.  This is only called to abandon
382
 
 * an enumeration partway through: ...next should do it if there are
383
 
 * no more files to enumerate.  This should deallocate the file_enum
384
 
 * structure and any subsidiary structures, strings, buffers, etc.
385
 
 */
386
 
void gp_enumerate_files_close(file_enum * pfen);
387
 
 
388
 
 
389
 
/* ------ Font enumeration ------ */
390
 
 
391
 
/* This is used to query the native os for a list of font names and 
392
 
 * corresponding paths. The general idea is to save the hassle of 
393
 
 * building a custom fontmap file
394
 
 */
395
 
 
396
 
/* allocate and initialize the iterator
397
 
   returns a pointer to its local state or NULL on failure */
398
 
void *gp_enumerate_fonts_init(gs_memory_t *mem);
399
 
 
400
 
/* get the next element in the font enumeration
401
 
   Takes a pointer to its local state and pointers in which to
402
 
   return C strings. The string 'name' is the font name, 'path'
403
 
   is the access path for the font resource. The returned strings
404
 
   are only safe to reference until until the next call.
405
 
   Returns 0 when no more fonts are available, a positive value 
406
 
   on success, or negative value on error. */
407
 
int gp_enumerate_fonts_next(void *enum_state, char **fontname, char **path);
408
 
 
409
 
/* clean up and deallocate the iterator */
410
 
void gp_enumerate_fonts_free(void *enum_state);
411
 
 
412
 
/* --------- 64 bit file access ----------- */
413
 
 
414
 
/* The following functions are analogues of ones with
415
 
   same name without the "_64" suffix. 
416
 
   They perform same function with allowing big files
417
 
   (over 4 gygabytes length).
418
 
 
419
 
   If the platform does not allow big files,
420
 
   these functions are mapped to regular file i/o functions.
421
 
   On 64 bits platforms they work same as
422
 
   regular file i/o functions.
423
 
 
424
 
   We continue using the old file i/o functions
425
 
   because most files do not need 64 bits access.
426
 
   The upgrading of old code to the new 64 bits access
427
 
   to be done step by step on real necessity,
428
 
   with replacing old function names with 
429
 
   new function names through code,
430
 
   together with providing the int64_t type for storing 
431
 
   file offsets in intermediate structures and variables.
432
 
 
433
 
   We assume that the result of 64 bits variant of 'ftell'
434
 
   can be represented in int64_t on all platforms,
435
 
   rather the result type of the native 64 bits function is
436
 
   compiler dependent (__off_t on Linux, _off_t on Cygwin, 
437
 
   __int64 on Windows).
438
 
 */
439
 
 
440
 
FILE *gp_fopen_64(const char *filename, const char *mode);
441
 
 
442
 
FILE *gp_open_scratch_file_64(const char *prefix,
443
 
                           char fname[gp_file_name_sizeof],
444
 
                           const char *mode);
445
 
FILE *gp_open_printer_64(char fname[gp_file_name_sizeof], int binary_mode);
446
 
 
447
 
int64_t gp_ftell_64(FILE *strm);
448
 
 
449
 
int gp_fseek_64(FILE *strm, int64_t offset, int origin);
450
 
 
451
 
/* We don't define gp_fread_64, gp_fwrite_64,
452
 
   because (1) known platforms allow regular fread, fwrite
453
 
   to be applied to a file opened with O_LARGEFILE, 
454
 
   fopen64, etc.; (2) Ghostscript code does not
455
 
   perform writing/reading a long (over 4gb) block
456
 
   in one operation.
457
 
 */
458
 
 
459
 
#endif /* gp_INCLUDED */