[gs-cvs] rev 7616 - trunk/gs/src
lpd at ghostscript.com
lpd at ghostscript.com
Wed Jan 17 13:10:48 PST 2007
Author: lpd
Date: 2007-01-17 13:10:47 -0800 (Wed, 17 Jan 2007)
New Revision: 7616
Modified:
trunk/gs/src/iccfont.c
trunk/gs/src/imain.c
trunk/gs/src/imainarg.c
trunk/gs/src/inobtokn.c
trunk/gs/src/interp.c
trunk/gs/src/iscan.c
trunk/gs/src/iscan.h
trunk/gs/src/iscanbin.c
trunk/gs/src/iscanbin.h
trunk/gs/src/itoken.h
trunk/gs/src/ziodev.c
trunk/gs/src/ztoken.c
Log:
For Adobe compatibility (PS3 CET 23-32), changes the token scanner so that
it pops the source operand from the stack and retains a copy of it
internally. THIS IS A NON-BACKWARD-COMPATIBLE CHANGE: it affects all
callers of scan_token (see src/iscan.h and src/itoken.h), and it also
changes the error behavior of the 'token' operator (the operand is no longer
on the stack if the error is detected during scanning, e.g. syntaxerror).
Modified: trunk/gs/src/iccfont.c
===================================================================
--- trunk/gs/src/iccfont.c 2007-01-17 19:59:36 UTC (rev 7615)
+++ trunk/gs/src/iccfont.c 2007-01-17 21:10:47 UTC (rev 7616)
@@ -325,10 +325,10 @@
stream s;
int code;
- scanner_state_init(&sstate, false);
s_init(&s, imemory);
sread_string(&s, (const byte *)str, len);
- code = scan_token(i_ctx_p, &s, pref, &sstate);
+ scanner_init_stream(&sstate, &s);
+ code = scan_token(i_ctx_p, pref, &sstate);
return (code <= 0 ? code : gs_note_error(e_Fatal));
}
Modified: trunk/gs/src/imain.c
===================================================================
--- trunk/gs/src/imain.c 2007-01-17 19:59:36 UTC (rev 7615)
+++ trunk/gs/src/imain.c 2007-01-17 21:10:47 UTC (rev 7616)
@@ -448,9 +448,8 @@
}
/* Check to make sure the first token is an integer */
/* (for the version number check.) */
- scanner_state_init(&state, false);
- code = scan_token(i_ctx_p, ifile.value.pfile, &first_token,
- &state);
+ scanner_init(&state, &ifile);
+ code = scan_token(i_ctx_p, &first_token, &state);
if (code != 0 || !r_has_type(&first_token, t_integer)) {
eprintf1("Initialization file %s does not begin with an integer.\n", gs_init_file);
*pexit_code = 255;
Modified: trunk/gs/src/imainarg.c
===================================================================
--- trunk/gs/src/imainarg.c 2007-01-17 19:59:36 UTC (rev 7615)
+++ trunk/gs/src/imainarg.c 2007-01-17 21:10:47 UTC (rev 7616)
@@ -582,9 +582,8 @@
s_init(&astream, NULL);
sread_string(&astream,
(const byte *)eqp, strlen(eqp));
- scanner_state_init(&state, false);
- code = scan_token(minst->i_ctx_p, &astream, &value,
- &state);
+ scanner_init_stream(&state, &astream);
+ code = scan_token(minst->i_ctx_p, &value, &state);
if (code) {
puts(minst->heap, "-dname= must be followed by a valid token");
return e_Fatal;
Modified: trunk/gs/src/inobtokn.c
===================================================================
--- trunk/gs/src/inobtokn.c 2007-01-17 19:59:36 UTC (rev 7615)
+++ trunk/gs/src/inobtokn.c 2007-01-17 21:10:47 UTC (rev 7616)
@@ -20,8 +20,7 @@
#include "iscanbin.h"
int
-scan_binary_token(i_ctx_t *i_ctx_p, stream *s, ref *pref,
- scanner_state *pstate)
+scan_binary_token(i_ctx_t *i_ctx_p, ref *pref, scanner_state *pstate)
{
return_error(e_unregistered);
}
Modified: trunk/gs/src/interp.c
===================================================================
--- trunk/gs/src/interp.c 2007-01-17 19:59:36 UTC (rev 7615)
+++ trunk/gs/src/interp.c 2007-01-17 21:10:47 UTC (rev 7616)
@@ -1291,7 +1291,7 @@
goto top;
}
case exec(t_file):
- { /* Executable file. Read the next token and interpret it. */
+ { /* Executable file. Read the next token and interpret it. */
stream *s;
scanner_state sstate;
@@ -1300,9 +1300,9 @@
if (iosp >= ostop) /* check early */
return_with_stackoverflow_iref();
osp = iosp; /* scan_token uses ostack */
- scanner_state_init_options(&sstate, i_ctx_p->scanner_options);
+ scanner_init_options(&sstate, IREF, i_ctx_p->scanner_options);
again:
- code = scan_token(i_ctx_p, s, &token, &sstate);
+ code = scan_token(i_ctx_p, &token, &sstate);
iosp = osp; /* ditto */
switch (code) {
case 0: /* read a token */
@@ -1358,8 +1358,7 @@
ref_assign_inline(iesp, &token);
esp = iesp;
osp = iosp;
- code = scan_handle_refill(i_ctx_p, &token, &sstate,
- true, true,
+ code = scan_handle_refill(i_ctx_p, &sstate, true,
ztokenexec_continue);
scan_cont:
iosp = osp;
@@ -1390,7 +1389,7 @@
ref_assign_inline(iesp, &file_token);
esp = iesp;
osp = iosp;
- code = ztoken_handle_comment(i_ctx_p, &file_token,
+ code = ztoken_handle_comment(i_ctx_p,
&sstate, &token,
code, true, true,
ztokenexec_continue);
@@ -1405,11 +1404,11 @@
stream ss;
scanner_state sstate;
- scanner_state_init_options(&sstate, SCAN_FROM_STRING);
s_init(&ss, NULL);
sread_string(&ss, IREF->value.bytes, r_size(IREF));
+ scanner_init_stream_options(&sstate, &ss, SCAN_FROM_STRING);
osp = iosp; /* scan_token uses ostack */
- code = scan_token(i_ctx_p, &ss, &token, &sstate);
+ code = scan_token(i_ctx_p, &token, &sstate);
iosp = osp; /* ditto */
switch (code) {
case 0: /* read a token */
Modified: trunk/gs/src/iscan.c
===================================================================
--- trunk/gs/src/iscan.c 2007-01-17 19:59:36 UTC (rev 7615)
+++ trunk/gs/src/iscan.c 2007-01-17 21:10:47 UTC (rev 7616)
@@ -172,23 +172,28 @@
{
scanner_state *const ssptr = vptr;
+ r_clear_attrs(&ssptr->s_file, l_mark);
r_clear_attrs(&ssarray, l_mark);
}
private
ENUM_PTRS_WITH(scanner_enum_ptrs, scanner_state *ssptr) return 0;
case 0:
+ ENUM_RETURN_REF(&ssptr->s_file);
+case 1:
if (ssptr->s_scan_type == scanning_none ||
!ssptr->s_da.is_dynamic
)
ENUM_RETURN(0);
return ENUM_STRING2(ssptr->s_da.base, da_size(&ssptr->s_da));
-case 1:
+case 2:
if (ssptr->s_scan_type != scanning_binary)
return 0;
ENUM_RETURN_REF(&ssarray);
ENUM_PTRS_END
private RELOC_PTRS_WITH(scanner_reloc_ptrs, scanner_state *ssptr)
{
+ RELOC_REF_VAR(ssptr->s_file);
+ r_clear_attrs(&ssptr->s_file, l_mark);
if (ssptr->s_scan_type != scanning_none && ssptr->s_da.is_dynamic) {
gs_string sda;
@@ -210,20 +215,34 @@
/* Initialize a scanner. */
void
-scanner_state_init_options(scanner_state *sstate, int options)
+scanner_init_options(scanner_state *sstate, const ref *fop, int options)
{
+ ref_assign(&sstate->s_file, fop);
sstate->s_scan_type = scanning_none;
sstate->s_pstack = 0;
sstate->s_options = options;
}
+void scanner_init_stream_options(scanner_state *sstate, stream *s,
+ int options)
+{
+ /*
+ * The file 'object' will never be accessed, but it must be in correct
+ * form for the GC.
+ */
+ ref fobj;
+ make_file(&fobj, a_read, 0, s);
+ scanner_init_options(sstate, &fobj, options);
+}
+
/* Handle a scan_Refill return from scan_token. */
/* This may return o_push_estack, 0 (meaning just call scan_token again), */
/* or an error code. */
int
-scan_handle_refill(i_ctx_t *i_ctx_p, const ref * fop, scanner_state * sstate,
- bool save, bool push_file, op_proc_t cont)
+scan_handle_refill(i_ctx_t *i_ctx_p, scanner_state * sstate,
+ bool save, op_proc_t cont)
{
+ const ref *const fop = &sstate->s_file;
stream *s = fptr(fop);
uint avail = sbufavailable(s);
int status;
@@ -247,9 +266,8 @@
case INTC:
case CALLC:
{
- ref rstate[2];
+ ref rstate[1];
scanner_state *pstate;
- int nstate = (push_file ? 2 : 1);
if (save) {
pstate =
@@ -260,16 +278,9 @@
*pstate = *sstate;
} else
pstate = sstate;
- /* If push_file is true, we want to push the file on the */
- /* o-stack before the state, for the continuation proc. */
- /* Since the refs passed to s_handle_read_exception */
- /* are pushed on the e-stack, we must ensure they are */
- /* literal, and also pass them in the opposite order! */
make_istruct(&rstate[0], 0, pstate);
- rstate[1] = *fop;
- r_clear_attrs(&rstate[1], a_executable);
return s_handle_read_exception(i_ctx_p, status, fop,
- rstate, nstate, cont);
+ rstate, 1, cont);
}
}
/* No more data available, but no exception. How can this be? */
@@ -355,8 +366,8 @@
return_error(e_invalidaccess);
s_init(s, NULL);
sread_string(s, pstr->value.bytes, r_size(pstr));
- scanner_state_init_options(&state, options | SCAN_FROM_STRING);
- switch (code = scan_token(i_ctx_p, s, pref, &state)) {
+ scanner_init_stream_options(&state, s, options | SCAN_FROM_STRING);
+ switch (code = scan_token(i_ctx_p, pref, &state)) {
default: /* error or comment */
if (code < 0)
break;
@@ -387,8 +398,9 @@
* as well as for scan_Refill.
*/
int
-scan_token(i_ctx_t *i_ctx_p, stream * s, ref * pref, scanner_state * pstate)
+scan_token(i_ctx_t *i_ctx_p, ref * pref, scanner_state * pstate)
{
+ stream *const s = pstate->s_file.value.pfile;
ref *myref = pref;
int retcode = 0;
int c;
@@ -473,7 +485,7 @@
switch (scan_type) {
case scanning_binary:
retcode = (*sstate.s_ss.binary.cont)
- (i_ctx_p, s, myref, &sstate);
+ (i_ctx_p, myref, &sstate);
scan_begin_inline();
if (retcode == scan_Refill)
goto pause;
@@ -493,6 +505,7 @@
/* scan_type == scanning_none. */
pstack = pstate->s_pstack;
pdepth = pstate->s_pdepth;
+ ref_assign(&sstate.s_file, &pstate->s_file);
sstate.s_options = pstate->s_options;
scan_begin_inline();
/*
@@ -878,7 +891,7 @@
#undef case4
if (recognize_btokens()) {
scan_end_inline();
- retcode = scan_binary_token(i_ctx_p, s, myref, &sstate);
+ retcode = scan_binary_token(i_ctx_p, myref, &sstate);
scan_begin_inline();
if (retcode == scan_Refill)
goto pause;
Modified: trunk/gs/src/iscan.h
===================================================================
--- trunk/gs/src/iscan.h 2007-01-17 19:59:36 UTC (rev 7615)
+++ trunk/gs/src/iscan.h 2007-01-17 21:10:47 UTC (rev 7616)
@@ -27,6 +27,10 @@
* Most of the state is only used if scanning is suspended because of
* an interrupt or a callout.
*
+ * Note that the scanner state includes a reference to the stream being
+ * scanned. We do this primarily for Adobe compatibility, so that we can
+ * remove the source object from the operand stack after the initial checks.
+ *
* We expose the entire state definition to the caller so that
* the state can normally be allocated on the stack.
*/
@@ -59,7 +63,7 @@
/* Define state specific to binary tokens and binary object sequences. */
typedef struct scan_binary_state_s {
int num_format;
- int (*cont)(i_ctx_t *, stream *, ref *, scanner_state *);
+ int (*cont)(i_ctx_t *, ref *, scanner_state *);
ref bin_array;
uint index;
uint max_array_index; /* largest legal index in objects */
@@ -70,6 +74,7 @@
/* Define the scanner state. */
struct scanner_state_s {
+ ref s_file; /* source file */
uint s_pstack; /* stack depth when starting current */
/* procedure, after pushing old pstack */
uint s_pdepth; /* pstack for very first { encountered, */
@@ -115,13 +120,14 @@
#define SCAN_PDF_INV_NUM 32 /* Adobe ignores invalid numbers */
/* This is for compatibility with Adobe */
/* Acrobat Reader */
-void scanner_state_init_options(scanner_state *sstate, int options);
-#define scanner_state_init_check(pstate, from_string, check_only)\
- scanner_state_init_options(pstate,\
- (from_string ? SCAN_FROM_STRING : 0) |\
- (check_only ? SCAN_CHECK_ONLY : 0))
-#define scanner_state_init(pstate, from_string)\
- scanner_state_init_check(pstate, from_string, false)
+void scanner_init_options(scanner_state *sstate, const ref *fop,
+ int options);
+#define scanner_init(sstate, fop)\
+ scanner_init_options(sstate, fop, 0)
+void scanner_init_stream_options(scanner_state *sstate, stream *s,
+ int options);
+#define scanner_init_stream(sstate, s)\
+ scanner_init_stream_options(sstate, s, 0)
/*
* Read a token from a stream. As usual, 0 is a normal return,
@@ -132,8 +138,7 @@
#define scan_Refill 3 /* get more input data, then call again */
#define scan_Comment 4 /* comment, non-DSC if processing DSC */
#define scan_DSC_Comment 5 /* DSC comment */
-int scan_token(i_ctx_t *i_ctx_p, stream * s, ref * pref,
- scanner_state * pstate);
+int scan_token(i_ctx_t *i_ctx_p, ref * pref, scanner_state * pstate);
/*
* Read a token from a string. Return like scan_token, but also
@@ -149,9 +154,8 @@
* This may return o_push_estack, 0 (meaning just call scan_token again),
* or an error code.
*/
-int scan_handle_refill(i_ctx_t *i_ctx_p, const ref * fop,
- scanner_state * pstate, bool save, bool push_file,
- op_proc_t cont);
+int scan_handle_refill(i_ctx_t *i_ctx_p, scanner_state * pstate,
+ bool save, op_proc_t cont);
/*
* Define the procedure "hook" for parsing DSC comments. If not NULL,
Modified: trunk/gs/src/iscanbin.c
===================================================================
--- trunk/gs/src/iscanbin.c 2007-01-17 19:59:36 UTC (rev 7615)
+++ trunk/gs/src/iscanbin.c 2007-01-17 21:10:47 UTC (rev 7616)
@@ -133,19 +133,19 @@
/* Forward references */
private int scan_bin_get_name(const gs_memory_t *mem, const ref *, int, ref *);
-private int scan_bin_num_array_continue(i_ctx_t *, stream *, ref *, scanner_state *);
-private int scan_bin_string_continue(i_ctx_t *, stream *, ref *, scanner_state *);
-private int scan_bos_continue(i_ctx_t *, stream *, ref *, scanner_state *);
+private int scan_bin_num_array_continue(i_ctx_t *, ref *, scanner_state *);
+private int scan_bin_string_continue(i_ctx_t *, ref *, scanner_state *);
+private int scan_bos_continue(i_ctx_t *, ref *, scanner_state *);
private byte *scan_bos_resize(i_ctx_t *, scanner_state *, uint, uint);
-private int scan_bos_string_continue(i_ctx_t *, stream *, ref *, scanner_state *);
+private int scan_bos_string_continue(i_ctx_t *, ref *, scanner_state *);
/* Scan a binary token. Called from the main scanner */
/* when it encounters an ASCII code 128-159, */
/* if binary tokens are being recognized (object format != 0). */
int
-scan_binary_token(i_ctx_t *i_ctx_p, stream *s, ref *pref,
- scanner_state *pstate)
+scan_binary_token(i_ctx_t *i_ctx_p, ref *pref, scanner_state *pstate)
{
+ stream *const s = pstate->s_file.value.pfile;
scan_binary_state *const pbs = &pstate->s_ss.binary;
s_declare_inline(s, p, rlimit);
@@ -217,7 +217,7 @@
pstate->s_da.is_dynamic = false;
pstate->s_da.base = pstate->s_da.next =
pstate->s_da.limit = pstate->s_da.buf;
- code = scan_bos_continue(i_ctx_p, s, pref, pstate);
+ code = scan_bos_continue(i_ctx_p, pref, pstate);
if (code == scan_Refill || code < 0) {
/* Clean up array for GC. */
uint index = pbs->index;
@@ -298,7 +298,7 @@
s_end_inline(s, p, rlimit);
pstate->s_da.base = pstate->s_da.next = str;
pstate->s_da.limit = str + arg;
- code = scan_bin_string_continue(i_ctx_p, s, pref, pstate);
+ code = scan_bin_string_continue(i_ctx_p, pref, pstate);
if (code == scan_Refill || code < 0) {
pstate->s_da.is_dynamic = true;
make_null(&pbs->bin_array); /* clean up for GC */
@@ -344,7 +344,7 @@
pbs->index = 0;
p += 3;
s_end_inline(s, p, rlimit);
- code = scan_bin_num_array_continue(i_ctx_p, s, pref, pstate);
+ code = scan_bin_num_array_continue(i_ctx_p, pref, pstate);
if (code == scan_Refill || code < 0) {
/* Make sure the array is clean for the GC. */
refset_null(pbs->bin_array.value.refs + pbs->index,
@@ -368,9 +368,9 @@
/* Continue collecting a binary string. */
private int
-scan_bin_string_continue(i_ctx_t *i_ctx_p, stream * s, ref * pref,
- scanner_state * pstate)
+scan_bin_string_continue(i_ctx_t *i_ctx_p, ref * pref, scanner_state * pstate)
{
+ stream *const s = pstate->s_file.value.pfile;
byte *q = pstate->s_da.next;
uint wanted = pstate->s_da.limit - q;
uint rcnt;
@@ -394,9 +394,10 @@
/* Continue scanning a binary number array. */
private int
-scan_bin_num_array_continue(i_ctx_t *i_ctx_p, stream * s, ref * pref,
+scan_bin_num_array_continue(i_ctx_t *i_ctx_p, ref * pref,
scanner_state * pstate)
{
+ stream *const s = pstate->s_file.value.pfile;
scan_binary_state *const pbs = &pstate->s_ss.binary;
uint index = pbs->index;
ref *np = pbs->bin_array.value.refs + index;
@@ -437,9 +438,9 @@
* all the pointers.
*/
private int
-scan_bos_continue(i_ctx_t *i_ctx_p, register stream * s, ref * pref,
- scanner_state * pstate)
+scan_bos_continue(i_ctx_t *i_ctx_p, ref * pref, scanner_state * pstate)
{
+ stream *const s = pstate->s_file.value.pfile;
scan_binary_state *const pbs = &pstate->s_ss.binary;
s_declare_inline(s, p, rlimit);
uint max_array_index = pbs->max_array_index;
@@ -602,7 +603,7 @@
pbs->index = max_array_index;
iresize_ref_array(&pbs->bin_array, max_array_index,
"binary object sequence(objects)");
- code = scan_bos_string_continue(i_ctx_p, s, pref, pstate);
+ code = scan_bos_string_continue(i_ctx_p, pref, pstate);
if (code == scan_Refill)
pbs->cont = scan_bos_string_continue;
return code;
@@ -637,13 +638,13 @@
/* Continue reading the strings for a binary object sequence. */
private int
-scan_bos_string_continue(i_ctx_t *i_ctx_p, register stream * s, ref * pref,
+scan_bos_string_continue(i_ctx_t *i_ctx_p, ref * pref,
scanner_state * pstate)
{
scan_binary_state *const pbs = &pstate->s_ss.binary;
ref rstr;
ref *op;
- int code = scan_bin_string_continue(i_ctx_p, s, &rstr, pstate);
+ int code = scan_bin_string_continue(i_ctx_p, &rstr, pstate);
uint space = ialloc_space(idmemory);
bool rescan = false;
uint i;
Modified: trunk/gs/src/iscanbin.h
===================================================================
--- trunk/gs/src/iscanbin.h 2007-01-17 19:59:36 UTC (rev 7615)
+++ trunk/gs/src/iscanbin.h 2007-01-17 21:10:47 UTC (rev 7616)
@@ -26,7 +26,6 @@
* this procedure: a dummy one for Level 1 systems, and the real one.
* The interface is entirely internal to the scanner.
*/
-int scan_binary_token(i_ctx_t *i_ctx_p, stream *s, ref *pref,
- scanner_state *pstate);
+int scan_binary_token(i_ctx_t *i_ctx_p, ref *pref, scanner_state *pstate);
#endif /* iscanbin_INCLUDED */
Modified: trunk/gs/src/itoken.h
===================================================================
--- trunk/gs/src/itoken.h 2007-01-17 19:59:36 UTC (rev 7615)
+++ trunk/gs/src/itoken.h 2007-01-17 21:10:47 UTC (rev 7616)
@@ -30,7 +30,7 @@
# define scanner_state_DEFINED
typedef struct scanner_state_s scanner_state;
#endif
-int ztoken_handle_comment(i_ctx_t *i_ctx_p, const ref *fop,
+int ztoken_handle_comment(i_ctx_t *i_ctx_p,
scanner_state *sstate, const ref *ptoken,
int scan_code, bool save, bool push_file,
op_proc_t cont);
Modified: trunk/gs/src/ziodev.c
===================================================================
--- trunk/gs/src/ziodev.c 2007-01-17 19:59:36 UTC (rev 7615)
+++ trunk/gs/src/ziodev.c 2007-01-17 21:10:47 UTC (rev 7616)
@@ -245,8 +245,8 @@
s_init(ts, NULL);
sread_string(ts, buf->data, count);
sc:
- scanner_state_init_check(&state, false, true);
- code = scan_token(i_ctx_p, ts, &ignore_value, &state);
+ scanner_init_stream_options(&state, ts, SCAN_CHECK_ONLY);
+ code = scan_token(i_ctx_p, &ignore_value, &state);
ref_stack_pop_to(&o_stack, depth);
if (code < 0)
code = scan_EOF; /* stop on scanner error */
Modified: trunk/gs/src/ztoken.c
===================================================================
--- trunk/gs/src/ztoken.c 2007-01-17 19:59:36 UTC (rev 7615)
+++ trunk/gs/src/ztoken.c 2007-01-17 21:10:47 UTC (rev 7616)
@@ -33,7 +33,7 @@
/* <string> token <post> <obj> -true- */
/* <string|file> token -false- */
private int ztoken_continue(i_ctx_t *);
-private int token_continue(i_ctx_t *, stream *, scanner_state *, bool);
+private int token_continue(i_ctx_t *, scanner_state *, bool);
int
ztoken(i_ctx_t *i_ctx_p)
{
@@ -48,12 +48,13 @@
check_read_file(s, op);
check_ostack(1);
- scanner_state_init(&state, false);
- return token_continue(i_ctx_p, s, &state, true);
+ scanner_init(&state, op);
+ return token_continue(i_ctx_p, &state, true);
}
case t_string: {
ref token;
- int orig_ostack_depth = ref_stack_count(&o_stack);
+ /* -1 is to remove the string operand in case of error. */
+ int orig_ostack_depth = ref_stack_count(&o_stack) - 1;
int code = scan_string_token(i_ctx_p, op, &token);
switch (code) {
@@ -62,7 +63,10 @@
return 0;
default:
if (code < 0) {
- /* Clear anything that may have been left on the ostack */
+ /*
+ * Clear anything that may have been left on the ostack,
+ * including the string operand.
+ */
if (orig_ostack_depth < ref_stack_count(&o_stack))
pop(ref_stack_count(&o_stack)- orig_ostack_depth);
return code;
@@ -76,45 +80,34 @@
}
}
/* Continue reading a token after an interrupt or callout. */
-/* *op is the scanner state; op[-1] is the file. */
+/* *op is the scanner state. */
private int
ztoken_continue(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
- stream *s;
scanner_state *pstate;
- check_read_file(s, op - 1);
check_stype(*op, st_scanner_state);
pstate = r_ptr(op, scanner_state);
- pop(1);
- return token_continue(i_ctx_p, s, pstate, false);
+ return token_continue(i_ctx_p, pstate, false);
}
/* Common code for token reading. */
private int
-token_continue(i_ctx_t *i_ctx_p, stream * s, scanner_state * pstate,
- bool save)
+token_continue(i_ctx_t *i_ctx_p, scanner_state * pstate, bool save)
{
os_ptr op = osp;
int code;
ref token;
/* Note that scan_token may change osp! */
- /* Also, we must temporarily remove the file from the o-stack */
- /* when calling scan_token, in case we are scanning a procedure. */
- ref fref;
-
- ref_assign(&fref, op);
+ pop(1); /* remove the file or scanner state */
again:
- pop(1);
- code = scan_token(i_ctx_p, s, &token, pstate);
+ code = scan_token(i_ctx_p, &token, pstate);
op = osp;
switch (code) {
default: /* error */
if (code > 0) /* comment, not possible */
code = gs_note_error(e_syntaxerror);
- push(1);
- ref_assign(op, &fref);
break;
case scan_BOS:
code = 0;
@@ -129,9 +122,7 @@
code = 0;
break;
case scan_Refill: /* need more data */
- push(1);
- ref_assign(op, &fref);
- code = scan_handle_refill(i_ctx_p, op, pstate, save, false,
+ code = scan_handle_refill(i_ctx_p, pstate, save,
ztoken_continue);
switch (code) {
case 0: /* state is not copied to the heap */
@@ -152,7 +143,7 @@
/* This is different from token + exec because literal procedures */
/* are not executed (although binary object sequences ARE executed). */
int ztokenexec_continue(i_ctx_t *); /* export for interpreter */
-private int tokenexec_continue(i_ctx_t *, stream *, scanner_state *, bool);
+private int tokenexec_continue(i_ctx_t *, scanner_state *, bool);
int
ztokenexec(i_ctx_t *i_ctx_p)
{
@@ -162,43 +153,34 @@
check_read_file(s, op);
check_estack(1);
- scanner_state_init(&state, false);
- return tokenexec_continue(i_ctx_p, s, &state, true);
+ scanner_init(&state, op);
+ return tokenexec_continue(i_ctx_p, &state, true);
}
/* Continue reading a token for execution after an interrupt or callout. */
-/* *op is the scanner state; op[-1] is the file. */
+/* *op is the scanner state. */
/* We export this because this is how the interpreter handles a */
/* scan_Refill for an executable file. */
int
ztokenexec_continue(i_ctx_t *i_ctx_p)
{
os_ptr op = osp;
- stream *s;
scanner_state *pstate;
- check_read_file(s, op - 1);
check_stype(*op, st_scanner_state);
pstate = r_ptr(op, scanner_state);
- pop(1);
- return tokenexec_continue(i_ctx_p, s, pstate, false);
+ return tokenexec_continue(i_ctx_p, pstate, false);
}
/* Common code for token reading + execution. */
private int
-tokenexec_continue(i_ctx_t *i_ctx_p, stream * s, scanner_state * pstate,
- bool save)
+tokenexec_continue(i_ctx_t *i_ctx_p, scanner_state * pstate, bool save)
{
- os_ptr op = osp;
+ os_ptr op;
int code;
/* Note that scan_token may change osp! */
- /* Also, we must temporarily remove the file from the o-stack */
- /* when calling scan_token, in case we are scanning a procedure. */
- ref fref;
-
- ref_assign(&fref, op);
pop(1);
again:
check_estack(1);
- code = scan_token(i_ctx_p, s, (ref *) (esp + 1), pstate);
+ code = scan_token(i_ctx_p, (ref *) (esp + 1), pstate);
op = osp;
switch (code) {
case 0:
@@ -217,7 +199,7 @@
code = 0;
break;
case scan_Refill: /* need more data */
- code = scan_handle_refill(i_ctx_p, &fref, pstate, save, true,
+ code = scan_handle_refill(i_ctx_p, pstate, save,
ztokenexec_continue);
switch (code) {
case 0: /* state is not copied to the heap */
@@ -228,15 +210,11 @@
break; /* error */
case scan_Comment:
case scan_DSC_Comment:
- return ztoken_handle_comment(i_ctx_p, &fref, pstate, esp + 1, code,
+ return ztoken_handle_comment(i_ctx_p, pstate, esp + 1, code,
save, true, ztokenexec_continue);
default: /* error */
break;
}
- if (code < 0) { /* Push the operand back on the stack. */
- push(1);
- ref_assign(op, &fref);
- }
if (!save) { /* Deallocate the scanner state record. */
ifree_object(pstate, "token_continue");
}
@@ -246,10 +224,10 @@
/*
* Handle a scan_Comment or scan_DSC_Comment return from scan_token
* (scan_code) by calling out to %Process[DSC]Comment. The continuation
- * procedure expects the file and scanner state on the o-stack.
+ * procedure expects the scanner state on the o-stack.
*/
int
-ztoken_handle_comment(i_ctx_t *i_ctx_p, const ref *fop, scanner_state *sstate,
+ztoken_handle_comment(i_ctx_t *i_ctx_p, scanner_state *sstate,
const ref *ptoken, int scan_code,
bool save, bool push_file, op_proc_t cont)
{
@@ -278,8 +256,8 @@
if (code < 0)
return code;
}
- check_estack(4);
- code = name_enter_string(imemory, proc_name, esp + 4);
+ check_estack(3);
+ code = name_enter_string(imemory, proc_name, esp + 3);
if (code < 0)
return code;
if (save) {
@@ -299,9 +277,7 @@
*/
make_op_estack(esp + 1, cont);
make_istruct(esp + 2, 0, pstate);
- esp[3] = *fop;
- r_clear_attrs(esp + 3, a_executable);
- ppcproc = dict_find_name(esp + 4);
+ ppcproc = dict_find_name(esp + 3);
if (ppcproc == 0) {
/*
* This can only happen during initialization.
@@ -309,7 +285,7 @@
*/
if (pstate->s_pstack)
--osp;
- esp += 3; /* do run the continuation */
+ esp += 2; /* do run the continuation */
} else {
/*
* Push the file and comment string on the o-stack.
@@ -322,9 +298,9 @@
op = osp += 2;
/* *op = *ptoken; */ /* saved above */
}
- op[-1] = *fop;
- esp[4] = *ppcproc;
- esp += 4;
+ op[-1] = pstate->s_file;
+ esp[3] = *ppcproc;
+ esp += 3;
}
return o_push_estack;
}
More information about the gs-cvs
mailing list