~ubuntu-branches/ubuntu/hardy/ghostscript/hardy

« back to all changes in this revision

Viewing changes to src/stream.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2007-11-22 12:17:43 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071122121743-cd70s3ypq0r243mp
Tags: 8.61.dfsg.1-0ubtuntu1
* New upstream release
  o Final 8.61 release
* debian/patches/09_ijs_krgb_support.dpatch: Adapted to upstream changes.
* debian/rules: Updated CUPS-related variables for "make install" calls.
* debian/rules: Remove /usr/include/ghostscript from the ghostscript
  package, they go into lings-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
13
 
14
 
/* $Id: stream.c 8022 2007-06-05 22:23:38Z giles $ */
 
14
/* $Id: stream.c 8250 2007-09-25 13:31:24Z giles $ */
15
15
/* Stream package for Ghostscript interpreter */
16
16
#include "stdio_.h"             /* includes std.h */
17
17
#include "memory_.h"
22
22
 
23
23
/* Forward declarations */
24
24
int s_close_disable(stream *);
25
 
private int sreadbuf(stream *, stream_cursor_write *);
26
 
private int swritebuf(stream *, stream_cursor_read *, bool);
27
 
private void stream_compact(stream *, bool);
 
25
static int sreadbuf(stream *, stream_cursor_write *);
 
26
static int swritebuf(stream *, stream_cursor_read *, bool);
 
27
static void stream_compact(stream *, bool);
28
28
 
29
29
/* Structure types for allocating streams. */
30
30
public_st_stream();
31
31
public_st_stream_state();       /* default */
32
32
/* GC procedures */
33
 
private 
 
33
static 
34
34
ENUM_PTRS_WITH(stream_enum_ptrs, stream *st) return 0;
35
35
case 0:
36
36
if (st->foreign)
43
43
ENUM_PTR(4, stream, state);
44
44
case 5: return ENUM_CONST_STRING(&st->file_name);
45
45
ENUM_PTRS_END
46
 
private RELOC_PTRS_WITH(stream_reloc_ptrs, stream *st)
 
46
static RELOC_PTRS_WITH(stream_reloc_ptrs, stream *st)
47
47
{
48
48
    byte *cbuf_old = st->cbuf;
49
49
 
71
71
/* Finalize a stream by closing it. */
72
72
/* We only do this for file streams, because other kinds of streams */
73
73
/* may attempt to free storage when closing. */
74
 
private void
 
74
static void
75
75
stream_finalize(void *vptr)
76
76
{
77
77
    stream *const st = vptr;
90
90
}
91
91
 
92
92
/* Dummy template for streams that don't have a separate state. */
93
 
private const stream_template s_no_template = {
 
93
static const stream_template s_no_template = {
94
94
    &st_stream_state, 0, 0, 1, 1, 0
95
95
};
96
96
 
767
767
 * normally the same as s->end_status, except that if s->procs.process
768
768
 * returned 1, sreadbuf sets s->end_status to 0, but returns 1.
769
769
 */
770
 
private int
 
770
static int
771
771
sreadbuf(stream * s, stream_cursor_write * pbuf)
772
772
{
773
773
    stream *prev = 0;
841
841
}
842
842
 
843
843
/* Write to a pipeline. */
844
 
private int
 
844
static int
845
845
swritebuf(stream * s, stream_cursor_read * pbuf, bool last)
846
846
{
847
847
    stream *prev = 0;
967
967
}
968
968
 
969
969
/* If possible, compact the information in a stream buffer to the bottom. */
970
 
private void
 
970
static void
971
971
stream_compact(stream * s, bool always)
972
972
{
973
973
    if (s->cursor.r.ptr >= s->cbuf && (always || s->end_status >= 0)) {
984
984
/* ------ String streams ------ */
985
985
 
986
986
/* String stream procedures */
987
 
private int
 
987
static int
988
988
    s_string_available(stream *, long *),
989
989
    s_string_read_seek(stream *, long),
990
990
    s_string_write_seek(stream *, long),
1009
1009
    s->srlimit = s->swlimit;
1010
1010
}
1011
1011
/* Initialize a reusable stream for reading a string. */
1012
 
private void
 
1012
static void
1013
1013
s_string_reusable_reset(stream *s)
1014
1014
{
1015
1015
    s->srptr = s->cbuf - 1;     /* just reset to the beginning */
1016
1016
    s->srlimit = s->srptr + s->bsize;  /* might have gotten reset */
1017
1017
}
1018
 
private int
 
1018
static int
1019
1019
s_string_reusable_flush(stream *s)
1020
1020
{
1021
1021
    s->srptr = s->srlimit = s->cbuf + s->bsize - 1;  /* just set to the end */
1039
1039
}
1040
1040
 
1041
1041
/* Return the number of available bytes when reading from a string. */
1042
 
private int
 
1042
static int
1043
1043
s_string_available(stream *s, long *pl)
1044
1044
{
1045
1045
    *pl = sbufavailable(s);
1049
1049
}
1050
1050
 
1051
1051
/* Seek in a string being read.  Return 0 if OK, ERRC if not. */
1052
 
private int
 
1052
static int
1053
1053
s_string_read_seek(register stream * s, long pos)
1054
1054
{
1055
1055
    if (pos < 0 || pos > s->bsize)
1084
1084
}
1085
1085
 
1086
1086
/* Seek in a string being written.  Return 0 if OK, ERRC if not. */
1087
 
private int
 
1087
static int
1088
1088
s_string_write_seek(register stream * s, long pos)
1089
1089
{
1090
1090
    if (pos < 0 || pos > s->bsize)
1096
1096
/* Since we initialize the input buffer of a string read stream */
1097
1097
/* to contain all of the data in the string, if we are ever asked */
1098
1098
/* to refill the buffer, we should signal EOF. */
1099
 
private int
 
1099
static int
1100
1100
s_string_read_process(stream_state * st, stream_cursor_read * ignore_pr,
1101
1101
                      stream_cursor_write * pw, bool last)
1102
1102
{
1104
1104
}
1105
1105
/* Similarly, if we are ever asked to empty the buffer, it means that */
1106
1106
/* there has been an overrun (unless we are closing the stream). */
1107
 
private int
 
1107
static int
1108
1108
s_string_write_process(stream_state * st, stream_cursor_read * pr,
1109
1109
                       stream_cursor_write * ignore_pw, bool last)
1110
1110
{
1113
1113
 
1114
1114
/* ------ Position-tracking stream ------ */
1115
1115
 
1116
 
private int
 
1116
static int
1117
1117
    s_write_position_process(stream_state *, stream_cursor_read *,
1118
1118
                             stream_cursor_write *, bool);
1119
1119
 
1127
1127
    s->procs.process = s_write_position_process;
1128
1128
}
1129
1129
 
1130
 
private int
 
1130
static int
1131
1131
s_write_position_process(stream_state * st, stream_cursor_read * pr,
1132
1132
                         stream_cursor_write * ignore_pw, bool last)
1133
1133
{
1270
1270
/* ------ NullEncode/Decode ------ */
1271
1271
 
1272
1272
/* Process a buffer */
1273
 
private int
 
1273
static int
1274
1274
s_Null_process(stream_state * st, stream_cursor_read * pr,
1275
1275
               stream_cursor_write * pw, bool last)
1276
1276
{