1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
4
This software is provided AS-IS with no warranty, either express or
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.
14
/* $Id: gxiodev.h 8022 2007-06-05 22:23:38Z giles $ */
15
/* Structure and default implementation of IODvices */
16
/* Requires gsmemory.h */
18
#ifndef gxiodev_INCLUDED
19
# define gxiodev_INCLUDED
24
* Note that IODevices are not the same as Ghostscript output devices.
25
* See section 3.8.2 of the PostScript Language Reference Manual,
26
* Second and Third Edition, for more information.
29
#ifndef gx_io_device_DEFINED
30
# define gx_io_device_DEFINED
31
typedef struct gx_io_device_s gx_io_device;
33
typedef struct gx_io_device_procs_s gx_io_device_procs; /* defined here */
35
/* The IODevice table is defined in gconf.c; its extern is in gscdefs.h. */
37
#ifndef file_enum_DEFINED /* also defined in gp.h */
38
# define file_enum_DEFINED
39
struct file_enum_s; /* opaque to client, defined by implementors */
40
typedef struct file_enum_s file_enum;
43
/* Define an opaque type for parameter lists. */
44
#ifndef gs_param_list_DEFINED
45
# define gs_param_list_DEFINED
46
typedef struct gs_param_list_s gs_param_list;
49
/* Define an opaque type for streams. */
50
#ifndef stream_DEFINED
51
# define stream_DEFINED
52
typedef struct stream_s stream;
56
* Define the IODevice procedures. Note that file names for fopen, delete,
57
* rename, and status are C strings, not pointer + length.
59
* open_device is called when opening a file whose name consists only of
60
* the IODevice name, e.g., '%lineedit'. open_file is called when opening
61
* a file whose name includes both an (optional) IODevice and a further
62
* name, e.g., '%os%xyz' or just 'xyz'.
64
* The open_device and open_file procedures return streams. The default
65
* implementation of open_device returns an error; the default
66
* implementation of open_file in the PostScript interpreter,
67
* iodev_os_open_file, uses the IODevice's fopen procedure to open a stream
68
* based on an OS FILE *. However, IODevices are free to implement
69
* open_file (and, if desired, open_device) in any way they want, returning
70
* a stream that need not have any relationship to the OS's file system.
71
* In this case there is no need to implement fopen or fclose.
73
/* Note also that "streams" are a higher-level concept; */
74
/* the open_device and open_file procedures are normally NULL. */
76
struct gx_io_device_procs_s {
78
#define iodev_proc_init(proc)\
79
int proc(gx_io_device *iodev, gs_memory_t *mem)
80
iodev_proc_init((*init)); /* one-time initialization */
82
#define iodev_proc_open_device(proc)\
83
int proc(gx_io_device *iodev, const char *access, stream **ps,\
85
iodev_proc_open_device((*open_device));
87
#define iodev_proc_open_file(proc)\
88
int proc(gx_io_device *iodev, const char *fname, uint namelen,\
89
const char *access, stream **ps, gs_memory_t *mem)
90
iodev_proc_open_file((*open_file));
92
/* fopen was changed in release 2.9.6, */
93
/* and again in 3.20 to return the real fname separately */
95
#define iodev_proc_fopen(proc)\
96
int proc(gx_io_device *iodev, const char *fname, const char *access,\
97
FILE **pfile, char *rfname, uint rnamelen)
98
iodev_proc_fopen((*fopen));
100
#define iodev_proc_fclose(proc)\
101
int proc(gx_io_device *iodev, FILE *file)
102
iodev_proc_fclose((*fclose));
104
#define iodev_proc_delete_file(proc)\
105
int proc(gx_io_device *iodev, const char *fname)
106
iodev_proc_delete_file((*delete_file));
108
#define iodev_proc_rename_file(proc)\
109
int proc(gx_io_device *iodev, const char *from, const char *to)
110
iodev_proc_rename_file((*rename_file));
112
#define iodev_proc_file_status(proc)\
113
int proc(gx_io_device *iodev, const char *fname, struct stat *pstat)
114
iodev_proc_file_status((*file_status));
116
#define iodev_proc_enumerate_files(proc)\
117
file_enum *proc(gx_io_device *iodev, const char *pat, uint patlen,\
119
iodev_proc_enumerate_files((*enumerate_files));
121
#define iodev_proc_enumerate_next(proc)\
122
uint proc(file_enum *pfen, char *ptr, uint maxlen)
123
iodev_proc_enumerate_next((*enumerate_next));
125
#define iodev_proc_enumerate_close(proc)\
126
void proc(file_enum *pfen)
127
iodev_proc_enumerate_close((*enumerate_close));
129
/* Added in release 2.9 */
131
#define iodev_proc_get_params(proc)\
132
int proc(gx_io_device *iodev, gs_param_list *plist)
133
iodev_proc_get_params((*get_params));
135
#define iodev_proc_put_params(proc)\
136
int proc(gx_io_device *iodev, gs_param_list *plist)
137
iodev_proc_put_params((*put_params));
141
/* The following typedef is needed because ansi2knr can't handle */
142
/* iodev_proc_fopen((*procname)) in a formal argument list. */
143
typedef iodev_proc_fopen((*iodev_proc_fopen_t));
145
/* Default implementations of procedures */
146
iodev_proc_init(iodev_no_init);
147
iodev_proc_open_device(iodev_no_open_device);
148
iodev_proc_open_file(iodev_no_open_file);
149
iodev_proc_fopen(iodev_no_fopen);
150
iodev_proc_fclose(iodev_no_fclose);
151
iodev_proc_delete_file(iodev_no_delete_file);
152
iodev_proc_rename_file(iodev_no_rename_file);
153
iodev_proc_file_status(iodev_no_file_status);
154
iodev_proc_enumerate_files(iodev_no_enumerate_files);
155
iodev_proc_get_params(iodev_no_get_params);
156
iodev_proc_put_params(iodev_no_put_params);
157
/* The %os% implemention of fopen and fclose. */
158
/* These are exported for pipes and for %null. */
159
iodev_proc_fopen(iodev_os_fopen);
160
iodev_proc_fclose(iodev_os_fclose);
162
/* Get the N'th IODevice. */
163
gx_io_device *gs_getiodevice(int);
165
#define iodev_default (gs_getiodevice(0))
167
/* Look up an IODevice name. */
168
gx_io_device *gs_findiodevice(const byte *, uint);
170
/* Get and put IODevice parameters. */
171
int gs_getdevparams(gx_io_device *, gs_param_list *);
172
int gs_putdevparams(gx_io_device *, gs_param_list *);
174
/* Convert an OS error number to a PostScript error */
175
/* if opening a file fails. */
176
int gs_fopen_errno_to_code(int);
178
/* Test whether a string is equal to a character. */
179
/* (This is used for access testing in file_open procedures.) */
180
#define streq1(str, chr)\
181
((str)[0] == (chr) && (str)[1] == 0)
183
/* Finally, the IODevice structure itself. */
184
struct gx_io_device_s {
185
const char *dname; /* the IODevice name */
186
const char *dtype; /* the type returned by currentdevparams */
187
gx_io_device_procs procs;
188
void *state; /* (if the IODevice has state) */
191
#define private_st_io_device() /* in gsiodev.c */\
192
gs_private_st_ptrs1(st_io_device, gx_io_device, "gx_io_device",\
193
io_device_enum_ptrs, io_device_reloc_ptrs, state)
195
#endif /* gxiodev_INCLUDED */