~ubuntu-branches/ubuntu/oneiric/ghostscript/oneiric

« back to all changes in this revision

Viewing changes to psi/ziodevs.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2011-07-15 16:49:55 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20110715164955-uga6qibao6kez05c
Tags: 9.04~dfsg~20110715-0ubuntu1
* New upstream release
   - GIT snapshot from Jult, 12 2011.
* debian/patches/020110406~a54df2d.patch,
  debian/patches/020110408~0791cc8.patch,
  debian/patches/020110408~507cbee.patch,
  debian/patches/020110411~4509a49.patch,
  debian/patches/020110412~78bb9a6.patch,
  debian/patches/020110418~a05ab8a.patch,
  debian/patches/020110420~20b6c78.patch,
  debian/patches/020110420~4ddefa2.patch: Removed upstream patches.
* debian/rules: Generate ABI version number (variable "abi") correctly,
  cutting off repackaging and pre-release parts.
* debian/rules: Added ./lcms2/ directory to DEB_UPSTREAM_REPACKAGE_EXCLUDES.
* debian/copyright: Added lcms2/* to the list of excluded files.
* debian/symbols.common: Updated for new upstream source. Applied patch
  which dpkg-gensymbols generated for debian/libgs9.symbols to this file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
2
2
   All Rights Reserved.
3
 
  
 
3
 
4
4
   This software is provided AS-IS with no warranty, either express or
5
5
   implied.
6
6
 
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
13
 
14
 
/* $Id: ziodevs.c 9043 2008-08-28 22:48:19Z giles $ */
 
14
/* $Id$ */
15
15
/* %stdxxx IODevice implementation for PostScript interpreter */
16
16
#include "stdio_.h"
17
17
#include "ghost.h"
20
20
#include "oper.h"
21
21
#include "stream.h"
22
22
#include "gxiodev.h"            /* must come after stream.h */
23
 
                                /* and before files.h */
 
23
                                /* and before files.h */
24
24
#include "files.h"
25
25
#include "store.h"
26
26
 
28
28
const char iodev_dtype_stdio[] = "Special";
29
29
#define iodev_special(dname, init, open) {\
30
30
    dname, iodev_dtype_stdio,\
31
 
        { init, open, iodev_no_open_file, iodev_no_fopen, iodev_no_fclose,\
32
 
          iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status,\
33
 
          iodev_no_enumerate_files, NULL, NULL,\
34
 
          iodev_no_get_params, iodev_no_put_params\
35
 
        }\
 
31
        { init, open, iodev_no_open_file, iodev_no_fopen, iodev_no_fclose,\
 
32
          iodev_no_delete_file, iodev_no_rename_file, iodev_no_file_status,\
 
33
          iodev_no_enumerate_files, NULL, NULL,\
 
34
          iodev_no_get_params, iodev_no_put_params\
 
35
        }\
36
36
}
37
37
 
38
38
/*
71
71
 
72
72
static int
73
73
    s_stdin_read_process(stream_state *, stream_cursor_read *,
74
 
                         stream_cursor_write *, bool);
 
74
                         stream_cursor_write *, bool);
75
75
 
76
76
static int
77
77
stdin_init(gx_io_device * iodev, gs_memory_t * mem)
84
84
/* If interactive, only read one character. */
85
85
static int
86
86
s_stdin_read_process(stream_state * st, stream_cursor_read * ignore_pr,
87
 
                     stream_cursor_write * pw, bool last)
 
87
                     stream_cursor_write * pw, bool last)
88
88
{
89
89
    FILE *file = ((stream *) st)->file;         /* hack for file streams */
90
90
    int wcount = (int)(pw->limit - pw->ptr);
91
91
    int count;
92
92
 
93
93
    if (wcount <= 0)
94
 
        return 0;
 
94
        return 0;
95
95
    count = gp_stdin_read( (char*) pw->ptr + 1, wcount,
96
 
                           st->memory->gs_lib_ctx->stdin_is_interactive, file);
 
96
                           st->memory->gs_lib_ctx->stdin_is_interactive, file);
97
97
    pw->ptr += (count < 0) ? 0 : count;
98
98
    return ((count < 0) ? ERRC : (count == 0) ? EOFC : count);
99
99
}
100
100
 
101
101
static int
102
102
stdin_open(gx_io_device * iodev, const char *access, stream ** ps,
103
 
           gs_memory_t * mem)
 
103
           gs_memory_t * mem)
104
104
{
105
105
    i_ctx_t *i_ctx_p = (i_ctx_t *)iodev->state; /* see above */
106
106
    stream *s;
107
107
 
108
108
    if (!streq1(access, 'r'))
109
 
        return_error(e_invalidfileaccess);
 
109
        return_error(e_invalidfileaccess);
110
110
    if (file_is_invalid(s, &ref_stdin)) {
111
 
        /****** stdin SHOULD NOT LINE-BUFFER ******/
112
 
        gs_memory_t *mem = imemory_system;
113
 
        byte *buf;
 
111
        /****** stdin SHOULD NOT LINE-BUFFER ******/
 
112
        gs_memory_t *mem = imemory_system;
 
113
        byte *buf;
114
114
 
115
 
        s = file_alloc_stream(mem, "stdin_open(stream)");
116
 
        /* We want stdin to read only one character at a time, */
117
 
        /* but it must have a substantial buffer, in case it is used */
118
 
        /* by a stream that requires more than one input byte */
119
 
        /* to make progress. */
120
 
        buf = gs_alloc_bytes(mem, STDIN_BUF_SIZE, "stdin_open(buffer)");
121
 
        if (s == 0 || buf == 0)
122
 
            return_error(e_VMerror);
123
 
        sread_file(s, gs_stdin, buf, STDIN_BUF_SIZE);
124
 
        s->procs.process = s_stdin_read_process;
125
 
        s->save_close = s_std_null;
126
 
        s->procs.close = file_close_file;
127
 
        make_file(&ref_stdin, a_readonly | avm_system, s->read_id, s);
128
 
        *ps = s;
129
 
        return 1;
 
115
        s = file_alloc_stream(mem, "stdin_open(stream)");
 
116
        /* We want stdin to read only one character at a time, */
 
117
        /* but it must have a substantial buffer, in case it is used */
 
118
        /* by a stream that requires more than one input byte */
 
119
        /* to make progress. */
 
120
        buf = gs_alloc_bytes(mem, STDIN_BUF_SIZE, "stdin_open(buffer)");
 
121
        if (s == 0 || buf == 0)
 
122
            return_error(e_VMerror);
 
123
        sread_file(s, gs_stdin, buf, STDIN_BUF_SIZE);
 
124
        s->procs.process = s_stdin_read_process;
 
125
        s->save_close = s_std_null;
 
126
        s->procs.close = file_close_file;
 
127
        make_file(&ref_stdin, a_readonly | avm_system, s->read_id, s);
 
128
        *ps = s;
 
129
        return 1;
130
130
    }
131
131
    *ps = s;
132
132
    return 0;
140
140
    int code;
141
141
 
142
142
    if (file_is_valid(s, &ref_stdin)) {
143
 
        *ps = s;
144
 
        return 0;
 
143
        *ps = s;
 
144
        return 0;
145
145
    }
146
146
    iodev = gs_findiodevice((const byte *)"%stdin", 6);
147
147
    iodev->state = i_ctx_p;
158
158
 
159
159
static int
160
160
    s_stdout_swrite_process(stream_state *, stream_cursor_read *,
161
 
                         stream_cursor_write *, bool);
 
161
                         stream_cursor_write *, bool);
162
162
 
163
163
/* Write a buffer to stdout, potentially writing to callback */
164
164
static int
165
165
s_stdout_write_process(stream_state * st, stream_cursor_read * ignore_pr,
166
 
                     stream_cursor_write * pw, bool last)
 
166
                     stream_cursor_write * pw, bool last)
167
167
{
168
168
    uint count = pr->limit - pr->ptr;
169
169
    int written;
170
170
 
171
 
    if (count == 0) 
172
 
        return 0;
 
171
    if (count == 0)
 
172
        return 0;
173
173
    written = outwrite(st->memory, pr->ptr + 1, count);
174
174
    if (written < count) {
175
 
        return ERRC;
 
175
        return ERRC;
176
176
    pr->ptr += written;
177
177
    return 0;
178
178
}
179
179
 
180
180
static int
181
181
stdout_open(gx_io_device * iodev, const char *access, stream ** ps,
182
 
            gs_memory_t * mem)
 
182
            gs_memory_t * mem)
183
183
{
184
184
    i_ctx_t *i_ctx_p = (i_ctx_t *)iodev->state; /* see above */
185
185
    stream *s;
186
186
 
187
187
    if (!streq1(access, 'w'))
188
 
        return_error(e_invalidfileaccess);
 
188
        return_error(e_invalidfileaccess);
189
189
    if (file_is_invalid(s, &ref_stdout)) {
190
 
        gs_memory_t *mem = imemory_system;
191
 
        byte *buf;
 
190
        gs_memory_t *mem = imemory_system;
 
191
        byte *buf;
192
192
 
193
 
        s = file_alloc_stream(mem, "stdout_open(stream)");
194
 
        buf = gs_alloc_bytes(mem, STDOUT_BUF_SIZE, "stdout_open(buffer)");
195
 
        if (s == 0 || buf == 0)
196
 
            return_error(e_VMerror);
197
 
        swrite_file(s, gs_stdout, buf, STDOUT_BUF_SIZE);
198
 
        s->save_close = s->procs.flush;
199
 
        s->procs.close = file_close_file;
200
 
        s->procs.process = s_stdout_write_process;
201
 
        make_file(&ref_stdout, a_write | avm_system, s->write_id, s);
202
 
        *ps = s;
203
 
        return 1;
 
193
        s = file_alloc_stream(mem, "stdout_open(stream)");
 
194
        buf = gs_alloc_bytes(mem, STDOUT_BUF_SIZE, "stdout_open(buffer)");
 
195
        if (s == 0 || buf == 0)
 
196
            return_error(e_VMerror);
 
197
        swrite_file(s, gs_stdout, buf, STDOUT_BUF_SIZE);
 
198
        s->save_close = s->procs.flush;
 
199
        s->procs.close = file_close_file;
 
200
        s->procs.process = s_stdout_write_process;
 
201
        make_file(&ref_stdout, a_write | avm_system, s->write_id, s);
 
202
        *ps = s;
 
203
        return 1;
204
204
    }
205
205
    *ps = s;
206
206
    return 0;
214
214
    int code;
215
215
 
216
216
    if (file_is_valid(s, &ref_stdout)) {
217
 
        *ps = s;
218
 
        return 0;
 
217
        *ps = s;
 
218
        return 0;
219
219
    }
220
220
    iodev = gs_findiodevice((const byte *)"%stdout", 7);
221
221
    iodev->state = i_ctx_p;
226
226
 
227
227
static int
228
228
stderr_open(gx_io_device * iodev, const char *access, stream ** ps,
229
 
            gs_memory_t * mem)
 
229
            gs_memory_t * mem)
230
230
{
231
231
    i_ctx_t *i_ctx_p = (i_ctx_t *)iodev->state; /* see above */
232
232
    stream *s;
233
233
 
234
234
    if (!streq1(access, 'w'))
235
 
        return_error(e_invalidfileaccess);
 
235
        return_error(e_invalidfileaccess);
236
236
    if (file_is_invalid(s, &ref_stderr)) {
237
 
        gs_memory_t *mem = imemory_system;
238
 
        byte *buf;
 
237
        gs_memory_t *mem = imemory_system;
 
238
        byte *buf;
239
239
 
240
 
        s = file_alloc_stream(mem, "stderr_open(stream)");
241
 
        buf = gs_alloc_bytes(mem, STDERR_BUF_SIZE, "stderr_open(buffer)");
242
 
        if (s == 0 || buf == 0)
243
 
            return_error(e_VMerror);
244
 
        swrite_file(s, gs_stderr, buf, STDERR_BUF_SIZE);
245
 
        s->save_close = s->procs.flush;
246
 
        s->procs.close = file_close_file;
247
 
        make_file(&ref_stderr, a_write | avm_system, s->write_id, s);
248
 
        *ps = s;
249
 
        return 1;
 
240
        s = file_alloc_stream(mem, "stderr_open(stream)");
 
241
        buf = gs_alloc_bytes(mem, STDERR_BUF_SIZE, "stderr_open(buffer)");
 
242
        if (s == 0 || buf == 0)
 
243
            return_error(e_VMerror);
 
244
        swrite_file(s, gs_stderr, buf, STDERR_BUF_SIZE);
 
245
        s->save_close = s->procs.flush;
 
246
        s->procs.close = file_close_file;
 
247
        make_file(&ref_stderr, a_write | avm_system, s->write_id, s);
 
248
        *ps = s;
 
249
        return 1;
250
250
    }
251
251
    *ps = s;
252
252
    return 0;
260
260
    int code;
261
261
 
262
262
    if (file_is_valid(s, &ref_stderr)) {
263
 
        *ps = s;
264
 
        return 0;
 
263
        *ps = s;
 
264
        return 0;
265
265
    }
266
266
    iodev = gs_findiodevice((const byte *)"%stderr", 7);
267
267
    iodev->state = i_ctx_p;