summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--base/gsioram.c10
-rw-r--r--base/gsiorom.c14
-rw-r--r--base/sfxfd.c6
-rw-r--r--base/sfxstdio.c6
-rw-r--r--base/stream.c60
-rw-r--r--base/stream.h41
-rw-r--r--psi/zfilter.c4
-rw-r--r--psi/zfrsd.c10
8 files changed, 73 insertions, 78 deletions
diff --git a/base/gsioram.c b/base/gsioram.c
index ece43a537..005abc9d0 100644
--- a/base/gsioram.c
+++ b/base/gsioram.c
@@ -241,18 +241,18 @@ s_ram_available(register stream * s, gs_offset_t *pl)
static int
s_ram_read_seek(register stream * s, gs_offset_t pos)
{
- uint end = s->srlimit - s->cbuf + 1;
+ uint end = s->cursor.r.limit - s->cbuf + 1;
long offset = pos - s->position;
if (offset >= 0 && offset <= end) { /* Staying within the same buffer */
- s->srptr = s->cbuf + offset - 1;
- return 0;
+ s->cursor.r.ptr = s->cbuf + offset - 1;
+ return 0;
}
if (pos < 0 || pos > s->file_limit ||
- ramfile_seek((ramhandle*)s->file, s->file_offset + pos, RAMFS_SEEK_SET) != 0
+ ramfile_seek((ramhandle*)s->file, s->file_offset + pos, RAMFS_SEEK_SET) != 0
)
return ERRC;
- s->srptr = s->srlimit = s->cbuf - 1;
+ s->cursor.r.ptr = s->cursor.r.limit = s->cbuf - 1;
s->end_status = 0;
s->position = pos;
return 0;
diff --git a/base/gsiorom.c b/base/gsiorom.c
index ab15c6ebe..416217a86 100644
--- a/base/gsiorom.c
+++ b/base/gsiorom.c
@@ -137,7 +137,7 @@ s_block_read_seek(register stream * s, gs_offset_t pos)
{
uint32_t *node = (uint32_t *)s->file;
uint32_t filelen = get_u32_big_endian(node) & 0x7fffffff; /* ignore compression bit */
- uint end = s->srlimit - s->cbuf + 1;
+ uint end = s->cursor.r.limit - s->cbuf + 1;
long offset = pos - s->position;
if (pos < 0 || pos > filelen)
@@ -151,16 +151,16 @@ s_block_read_seek(register stream * s, gs_offset_t pos)
s->position = pos - offset;
pw.ptr = s->cbuf - 1;
pw.limit = pw.ptr + s->cbsize;
- s->srptr = s->srlimit = s->cbuf - 1;
+ s->cursor.r.ptr = s->cursor.r.limit = s->cbuf - 1;
if ((s->end_status = s_block_read_process((stream_state *)s, NULL, &pw, 0)) == ERRC)
return ERRC;
if (s->end_status == 1)
s->end_status = 0;
- s->srptr = s->cbuf - 1;
- s->srlimit = pw.ptr; /* limit of the block just read */
+ s->cursor.r.ptr = s->cbuf - 1;
+ s->cursor.r.limit = pw.ptr; /* limit of the block just read */
}
/* Now set the read pointer to the correct place in the buffer */
- s->srptr = s->cbuf + offset - 1;
+ s->cursor.r.ptr = s->cbuf + offset - 1;
return 0;
}
@@ -186,7 +186,7 @@ s_block_read_process(stream_state * st, stream_cursor_read * ignore_pr,
int compression = ((get_u32_big_endian(node) & 0x80000000) != 0) ? 1 : 0;
uint32_t filelen = get_u32_big_endian(node) & 0x7fffffff; /* ignore compression bit */
uint32_t blocks = (filelen+ROMFS_BLOCKSIZE-1) / ROMFS_BLOCKSIZE;
- uint32_t iblock = (s->position + s->file_offset + (s->srlimit + 1 - s->cbuf)) / ROMFS_BLOCKSIZE;
+ uint32_t iblock = (s->position + s->file_offset + (s->cursor.r.limit + 1 - s->cbuf)) / ROMFS_BLOCKSIZE;
uint32_t block_length = get_u32_big_endian(node+1+(2*iblock));
uint32_t block_offset = get_u32_big_endian(node+2+(2*iblock));
unsigned const char *block_data = ((unsigned char *)node) + block_offset;
@@ -216,7 +216,7 @@ s_block_read_process(stream_state * st, stream_cursor_read * ignore_pr,
/* the cbuf, then the cbuf must be empty. */
if (max_count < count) {
#ifdef DEBUG
- if ((sbufptr(s)) != s->srlimit)
+ if ((sbufptr(s)) != s->cursor.r.limit)
emprintf(s->memory, "cbuf not empty as expected\n.");
#endif
dest = s->cbuf;
diff --git a/base/sfxfd.c b/base/sfxfd.c
index aa986d208..d2b85ea40 100644
--- a/base/sfxfd.c
+++ b/base/sfxfd.c
@@ -184,18 +184,18 @@ s_fileno_available(register stream * s, gs_offset_t *pl)
static int
s_fileno_read_seek(register stream * s, gs_offset_t pos)
{
- gs_offset_t end = s->srlimit - s->cbuf + 1;
+ gs_offset_t end = s->cursor.r.limit - s->cbuf + 1;
gs_offset_t offset = pos - s->position;
if (offset >= 0 && offset <= end) { /* Staying within the same buffer */
- s->srptr = s->cbuf + offset - 1;
+ s->cursor.r.ptr = s->cbuf + offset - 1;
return 0;
}
if (pos < 0 || pos > s->file_limit ||
lseek(sfileno(s), s->file_offset + pos, SEEK_SET) < 0
)
return ERRC;
- s->srptr = s->srlimit = s->cbuf - 1;
+ s->cursor.r.ptr = s->cursor.r.limit = s->cbuf - 1;
s->end_status = 0;
s->position = pos;
return 0;
diff --git a/base/sfxstdio.c b/base/sfxstdio.c
index 140796ef6..eb8b480d5 100644
--- a/base/sfxstdio.c
+++ b/base/sfxstdio.c
@@ -119,18 +119,18 @@ s_file_available(register stream * s, gs_offset_t *pl)
static int
s_file_read_seek(register stream * s, gs_offset_t pos)
{
- gs_offset_t end = s->srlimit - s->cbuf + 1;
+ gs_offset_t end = s->cursor.r.limit - s->cbuf + 1;
gs_offset_t offset = pos - s->position;
if (offset >= 0 && offset <= end) { /* Staying within the same buffer */
- s->srptr = s->cbuf + offset - 1;
+ s->cursor.r.ptr = s->cbuf + offset - 1;
return 0;
}
if (pos < 0 || pos > s->file_limit ||
gp_fseek_64(s->file, s->file_offset + pos, SEEK_SET) != 0
)
return ERRC;
- s->srptr = s->srlimit = s->cbuf - 1;
+ s->cursor.r.ptr = s->cursor.r.limit = s->cbuf - 1;
s->end_status = 0;
s->position = pos;
return 0;
diff --git a/base/stream.c b/base/stream.c
index 68e119fd7..60c369d5c 100644
--- a/base/stream.c
+++ b/base/stream.c
@@ -59,9 +59,9 @@ static RELOC_PTRS_WITH(stream_reloc_ptrs, stream *st)
RELOC_VAR(st->cbuf);
reloc = cbuf_old - st->cbuf;
/* Relocate the other buffer pointers. */
- st->srptr -= reloc;
- st->srlimit -= reloc; /* same as swptr */
- st->swlimit -= reloc;
+ st->cursor.r.ptr -= reloc;
+ st->cursor.r.limit -= reloc; /* same as swptr */
+ st->cursor.w.limit -= reloc;
}
RELOC_VAR(st->strm);
RELOC_VAR(st->prev);
@@ -159,8 +159,8 @@ s_std_init(register stream * s, byte * ptr, uint len, const stream_procs * pp,
{
s->templat = &s_no_template;
s->cbuf = ptr;
- s->srptr = s->srlimit = s->swptr = ptr - 1;
- s->swlimit = ptr - 1 + len;
+ s->cursor.r.ptr = s->cursor.r.limit = s->cursor.w.ptr = ptr - 1;
+ s->cursor.w.limit = ptr - 1 + len;
s->end_status = 0;
s->foreign = 0;
s->modes = modes;
@@ -227,14 +227,14 @@ s_std_null(stream * s)
void
s_std_read_reset(stream * s)
{
- s->srptr = s->srlimit = s->cbuf - 1;
+ s->cursor.r.ptr = s->cursor.r.limit = s->cbuf - 1;
}
/* Discard the contents of the buffer when writing. */
void
s_std_write_reset(stream * s)
{
- s->swptr = s->cbuf - 1;
+ s->cursor.w.ptr = s->cbuf - 1;
}
/* Flush data to end-of-file when reading. */
@@ -242,7 +242,7 @@ int
s_std_read_flush(stream * s)
{
while (1) {
- s->srptr = s->srlimit = s->cbuf - 1;
+ s->cursor.r.ptr = s->cursor.r.limit = s->cbuf - 1;
if (s->end_status)
break;
s_process_read_buf(s);
@@ -393,7 +393,7 @@ stell(stream * s)
* The stream might have been closed, but the position
* is still meaningful in this case.
*/
- const byte *ptr = (s_is_writing(s) ? s->swptr : s->srptr);
+ const byte *ptr = (s_is_writing(s) ? s->cursor.w.ptr : s->cursor.r.ptr);
return (ptr == 0 ? 0 : ptr + 1 - s->cbuf) + s->position;
}
@@ -456,7 +456,7 @@ spgetcc(register stream * s, bool close_at_eod)
int min_left = sbuf_min_left(s);
while (status = s->end_status,
- left = s->srlimit - s->srptr,
+ left = s->cursor.r.limit - s->cursor.r.ptr,
left <= min_left && status >= 0
)
s_process_read_buf(s);
@@ -474,7 +474,7 @@ spgetcc(register stream * s, bool close_at_eod)
}
return status;
}
- return *++(s->srptr);
+ return *++(s->cursor.r.ptr);
}
/* Implementing sputc when the buffer is full, */
@@ -486,7 +486,7 @@ spputc(register stream * s, byte b)
if (s->end_status)
return s->end_status;
if (!sendwp(s)) {
- *++(s->swptr) = b;
+ *++(s->cursor.w.ptr) = b;
return b;
}
s_process_write_buf(s, false);
@@ -503,9 +503,9 @@ sungetc(register stream * s, byte c)
unread from stdin, ever.
*/
if (s->cbuf == NULL || !s_is_reading(s) ||
- s->srptr < s->cbuf || *(s->srptr) != c)
+ s->cursor.r.ptr < s->cbuf || *(s->cursor.r.ptr) != c)
return ERRC;
- s->srptr--;
+ s->cursor.r.ptr--;
return 0;
}
@@ -523,10 +523,10 @@ sgets(stream * s, byte * buf, uint nmax, uint * pn)
while (cw.ptr < cw.limit) {
int left;
- if ((left = s->srlimit - s->srptr) > min_left) {
- s->srlimit -= min_left;
+ if ((left = s->cursor.r.limit - s->cursor.r.ptr) > min_left) {
+ s->cursor.r.limit -= min_left;
stream_move(&s->cursor.r, &cw);
- s->srlimit += min_left;
+ s->cursor.r.limit += min_left;
} else {
uint wanted = cw.limit - cw.ptr;
int c;
@@ -550,7 +550,7 @@ sgets(stream * s, byte * buf, uint nmax, uint * pn)
* update position. However, we need to reset the read
* cursor to indicate that there is no data in the buffer.
*/
- s->srptr = s->srlimit = s->cbuf - 1;
+ s->cursor.r.ptr = s->cursor.r.limit = s->cbuf - 1;
s->position += cw.ptr - wptr;
if (status <= 0 || cw.ptr == cw.limit)
break;
@@ -577,13 +577,13 @@ sputs(register stream * s, const byte * str, uint wlen, uint * pn)
if (status >= 0)
while (len > 0) {
- uint count = s->swlimit - s->swptr;
+ uint count = s->cursor.w.limit - s->cursor.w.ptr;
if (count > 0) {
if (count > len)
count = len;
- memcpy(s->swptr + 1, str, count);
- s->swptr += count;
+ memcpy(s->cursor.w.ptr + 1, str, count);
+ s->cursor.w.ptr += count;
str += count;
len -= count;
} else {
@@ -624,7 +624,7 @@ spskip(register stream * s, gs_offset_t nskip, gs_offset_t *pskipped)
int status;
n -= sbufavailable(s);
- s->srptr = s->srlimit;
+ s->cursor.r.ptr = s->cursor.r.limit;
if (s->end_status) {
*pskipped = nskip - n;
return s->end_status;
@@ -637,7 +637,7 @@ spskip(register stream * s, gs_offset_t nskip, gs_offset_t *pskipped)
--n;
}
/* Note that if min_left > 0, n < 0 is possible; this is harmless. */
- s->srptr += n;
+ s->cursor.r.ptr += n;
*pskipped = nskip;
return 0;
}
@@ -1023,19 +1023,19 @@ sread_string(register stream *s, const byte *ptr, uint len)
s->cbuf_string.data = (byte *)ptr;
s->cbuf_string.size = len;
s->end_status = EOFC;
- s->srlimit = s->swlimit;
+ s->cursor.r.limit = s->cursor.w.limit;
}
/* Initialize a reusable stream for reading a string. */
static void
s_string_reusable_reset(stream *s)
{
- s->srptr = s->cbuf - 1; /* just reset to the beginning */
- s->srlimit = s->srptr + s->bsize; /* might have gotten reset */
+ s->cursor.r.ptr = s->cbuf - 1; /* just reset to the beginning */
+ s->cursor.r.limit = s->cursor.r.ptr + s->bsize; /* might have gotten reset */
}
static int
s_string_reusable_flush(stream *s)
{
- s->srptr = s->srlimit = s->cbuf + s->bsize - 1; /* just set to the end */
+ s->cursor.r.ptr = s->cursor.r.limit = s->cbuf + s->bsize - 1; /* just set to the end */
return 0;
}
void
@@ -1071,9 +1071,9 @@ s_string_read_seek(register stream * s, gs_offset_t pos)
{
if (pos < 0 || pos > s->bsize)
return ERRC;
- s->srptr = s->cbuf + pos - 1;
+ s->cursor.r.ptr = s->cbuf + pos - 1;
/* We might be seeking after a reusable string reached EOF. */
- s->srlimit = s->cbuf + s->bsize - 1;
+ s->cursor.r.limit = s->cbuf + s->bsize - 1;
/*
* When the file reaches EOF,
* stream_compact sets s->position to its end.
@@ -1106,7 +1106,7 @@ s_string_write_seek(register stream * s, gs_offset_t pos)
{
if (pos < 0 || pos > s->bsize)
return ERRC;
- s->swptr = s->cbuf + pos - 1;
+ s->cursor.w.ptr = s->cbuf + pos - 1;
return 0;
}
diff --git a/base/stream.h b/base/stream.h
index 11e67372f..f5d094d8f 100644
--- a/base/stream.h
+++ b/base/stream.h
@@ -92,23 +92,23 @@ struct stream_s {
/*
* The following invariants apply at all times for read streams:
*
- * s->cbuf - 1 <= s->srptr <= s->srlimit.
+ * s->cbuf - 1 <= s->cursor.r.ptr <= s->cursor.r.limit.
*
- * The amount of data in the buffer is s->srlimit + 1 - s->cbuf.
+ * The amount of data in the buffer is s->cursor.r.limit + 1 - s->cbuf.
*
* s->position represents the stream position as of the beginning
* of the buffer, so the current position is s->position +
- * (s->srptr + 1 - s->cbuf).
+ * (s->cursor.r.ptr + 1 - s->cbuf).
*
* Analogous invariants apply for write streams:
*
- * s->cbuf - 1 <= s->swptr <= s->swlimit.
+ * s->cbuf - 1 <= s->cursor.w.ptr <= s->cursor.w.limit.
*
- * The amount of data in the buffer is s->swptr + 1 - s->cbuf.
+ * The amount of data in the buffer is s->cursor.w.ptr + 1 - s->cbuf.
*
* s->position represents the stream position as of the beginning
* of the buffer, so the current position is s->position +
- * (s->swptr + 1 - s->cbuf).
+ * (s->cursor.w.ptr + 1 - s->cbuf).
*/
stream_cursor cursor; /* cursor for reading/writing data */
byte *cbuf; /* base of buffer */
@@ -200,16 +200,11 @@ extern_st(st_stream);
/* ------ Stream functions ------ */
-#define srptr cursor.r.ptr
-#define srlimit cursor.r.limit
-#define swptr cursor.w.ptr
-#define swlimit cursor.w.limit
-
/* Some of these are macros -- beware. */
/* Note that unlike the C stream library, */
/* ALL stream procedures take the stream as the first argument. */
-#define sendrp(s) ((s)->srptr >= (s)->srlimit) /* NOT FOR CLIENTS */
-#define sendwp(s) ((s)->swptr >= (s)->swlimit) /* NOT FOR CLIENTS */
+#define sendrp(s) ((s)->cursor.r.ptr >= (s)->cursor.r.limit) /* NOT FOR CLIENTS */
+#define sendwp(s) ((s)->cursor.w.ptr >= (s)->cursor.w.limit) /* NOT FOR CLIENTS */
/*
* Following are valid for all streams.
@@ -236,16 +231,16 @@ int spgetcc(stream *, bool); /* bool indicates close at EOD */
* ahead to detect EOD.
*
* In the definition of sgetc, the first alternative should read
- * (int)(*++((s)->srptr))
+ * (int)(*++((s)->cursor.r.ptr))
* but the Borland compiler generates truly atrocious code for this.
* The SCO ODT compiler requires the first, pointless cast to int.
*/
#define sgetc(s)\
- ((int)((s)->srlimit - (s)->srptr > 1 ? (++((s)->srptr), (int)*(s)->srptr) : spgetc(s)))
+ ((int)((s)->cursor.r.limit - (s)->cursor.r.ptr > 1 ? (++((s)->cursor.r.ptr), (int)*(s)->cursor.r.ptr) : spgetc(s)))
int sgets(stream *, byte *, uint, uint *);
int sungetc(stream *, byte); /* ERRC on error, 0 if OK */
-#define sputback(s) ((s)->srptr--) /* can only do this once! */
+#define sputback(s) ((s)->cursor.r.ptr--) /* can only do this once! */
#define seofp(s) (sendrp(s) && (s)->end_status == EOFC)
#define serrorp(s) (sendrp(s) && (s)->end_status == ERRC)
int spskip(stream *, gs_offset_t, gs_offset_t *);
@@ -265,11 +260,11 @@ int spputc(stream *, byte); /* a procedure equivalent of sputc */
/*
* The first alternative should read
- * ((int)(*++((s)->swptr)=(c)))
+ * ((int)(*++((s)->cursor.w.ptr)=(c)))
* but the Borland compiler generates truly atrocious code for this.
*/
#define sputc(s,c)\
- (!sendwp(s) ? (++((s)->swptr), *(s)->swptr=(c), 0) : spputc((s),(c)))
+ (!sendwp(s) ? (++((s)->cursor.w.ptr), *(s)->cursor.w.ptr=(c), 0) : spputc((s),(c)))
int sputs(stream *, const byte *, uint, uint *);
/*
@@ -286,9 +281,9 @@ int spseek(stream *, gs_offset_t);
/* Following are for high-performance reading clients. */
/* bufptr points to the next item. */
-#define sbufptr(s) ((s)->srptr + 1)
-#define sbufavailable(s) ((s)->srlimit - (s)->srptr)
-#define sbufskip(s, n) ((s)->srptr += (n), 0)
+#define sbufptr(s) ((s)->cursor.r.ptr + 1)
+#define sbufavailable(s) ((s)->cursor.r.limit - (s)->cursor.r.ptr)
+#define sbufskip(s, n) ((s)->cursor.r.ptr += (n), 0)
/*
* Define the minimum amount of data that must be left in an input buffer
* after a read operation to handle filter read-ahead, either 0 or 1
@@ -312,9 +307,9 @@ int spseek(stream *, gs_offset_t);
register const byte *cp;\
const byte *ep
#define s_begin_inline(s, cp, ep)\
- cp = (s)->srptr, ep = (s)->srlimit
+ cp = (s)->cursor.r.ptr, ep = (s)->cursor.r.limit
#define s_end_inline(s, cp, ep)\
- (s)->srptr = cp
+ (s)->cursor.r.ptr = cp
#define sbufavailable_inline(s, cp, ep)\
(ep - cp)
#define sendbufp_inline(s, cp, ep)\
diff --git a/psi/zfilter.c b/psi/zfilter.c
index 0a03338f5..386a9e41d 100644
--- a/psi/zfilter.c
+++ b/psi/zfilter.c
@@ -438,8 +438,8 @@ filter_ensure_buf(stream ** ps, uint min_buf_size, gs_ref_memory_t *imem,
if (buf == 0)
return_error(gs_error_VMerror);
s->cbuf = buf;
- s->srptr = s->srlimit = s->swptr = buf - 1;
- s->swlimit = buf - 1 + len;
+ s->cursor.r.ptr = s->cursor.r.limit = s->cursor.w.ptr = buf - 1;
+ s->cursor.w.limit = buf - 1 + len;
s->bsize = s->cbsize = len;
return 0;
} else {
diff --git a/psi/zfrsd.c b/psi/zfrsd.c
index 1e47be0c4..2c4907c10 100644
--- a/psi/zfrsd.c
+++ b/psi/zfrsd.c
@@ -396,16 +396,16 @@ s_aos_available(stream *s, gs_offset_t *pl)
static int
s_aos_seek(register stream * s, gs_offset_t pos)
{
- uint end = s->srlimit - s->cbuf + 1;
+ uint end = s->cursor.r.limit - s->cbuf + 1;
long offset = pos - s->position;
if (offset >= 0 && offset <= end) { /* Staying within the same buffer */
- s->srptr = s->cbuf + offset - 1;
+ s->cursor.r.ptr = s->cbuf + offset - 1;
return 0;
}
if (pos < 0 || pos > s->file_limit)
return ERRC;
- s->srptr = s->srlimit = s->cbuf - 1;
+ s->cursor.r.ptr = s->cursor.r.limit = s->cbuf - 1;
s->end_status = 0;
s->position = pos;
return 0;
@@ -417,7 +417,7 @@ s_aos_reset(stream *s)
/* PLRM definition of reset operator is strange. */
/* Rewind the file and discard the buffer. */
s->position = 0;
- s->srptr = s->srlimit = s->cbuf - 1;
+ s->cursor.r.ptr = s->cursor.r.limit = s->cbuf - 1;
s->end_status = 0;
}
@@ -425,7 +425,7 @@ static int
s_aos_flush(stream *s)
{
s->position = ((aos_state_t *)s->state)->file_sz;
- s->srptr = s->srlimit = s->cbuf - 1;
+ s->cursor.r.ptr = s->cursor.r.limit = s->cbuf - 1;
return 0;
}