summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util/cairo-script/cairo-script-private.h1
-rw-r--r--util/cairo-script/cairo-script-scanner.c67
2 files changed, 37 insertions, 31 deletions
diff --git a/util/cairo-script/cairo-script-private.h b/util/cairo-script/cairo-script-private.h
index 1fd8125d..d63b639e 100644
--- a/util/cairo-script/cairo-script-private.h
+++ b/util/cairo-script/cairo-script-private.h
@@ -428,6 +428,7 @@ struct _csi_scanner {
jmp_buf jmpbuf;
int depth;
+ int bind;
csi_status_t (*push) (csi_t *ctx, csi_object_t *obj);
csi_status_t (*execute) (csi_t *ctx, csi_object_t *obj);
void *closure;
diff --git a/util/cairo-script/cairo-script-scanner.c b/util/cairo-script/cairo-script-scanner.c
index 587e7655..a1a2df99 100644
--- a/util/cairo-script/cairo-script-scanner.c
+++ b/util/cairo-script/cairo-script-scanner.c
@@ -411,44 +411,46 @@ token_end (csi_t *ctx, csi_scanner_t *scan, csi_file_t *src)
s = scan->buffer.base;
len = scan->buffer.ptr - scan->buffer.base;
- if (s[0] == '{') { /* special case procedures */
- if (scan->build_procedure.type != CSI_OBJECT_TYPE_NULL) {
- status = _csi_stack_push (ctx,
- &scan->procedure_stack,
- &scan->build_procedure);
+ if (_csi_likely (! scan->bind)) {
+ if (s[0] == '{') { /* special case procedures */
+ if (scan->build_procedure.type != CSI_OBJECT_TYPE_NULL) {
+ status = _csi_stack_push (ctx,
+ &scan->procedure_stack,
+ &scan->build_procedure);
+ if (_csi_unlikely (status))
+ longjmp (scan->jmpbuf, status);
+ }
+
+ status = csi_array_new (ctx, 0, &scan->build_procedure);
if (_csi_unlikely (status))
longjmp (scan->jmpbuf, status);
- }
- status = csi_array_new (ctx, 0, &scan->build_procedure);
- if (_csi_unlikely (status))
- longjmp (scan->jmpbuf, status);
+ scan->build_procedure.type |= CSI_OBJECT_ATTR_EXECUTABLE;
+ return;
+ } else if (s[0] == '}') {
+ if (_csi_unlikely
+ (scan->build_procedure.type == CSI_OBJECT_TYPE_NULL))
+ {
+ longjmp (scan->jmpbuf, _csi_error (CSI_STATUS_INVALID_SCRIPT));
+ }
- scan->build_procedure.type |= CSI_OBJECT_ATTR_EXECUTABLE;
- return;
- } else if (s[0] == '}') {
- if (_csi_unlikely
- (scan->build_procedure.type == CSI_OBJECT_TYPE_NULL))
- {
- longjmp (scan->jmpbuf, _csi_error (CSI_STATUS_INVALID_SCRIPT));
- }
+ if (scan->procedure_stack.len) {
+ csi_object_t *next;
- if (scan->procedure_stack.len) {
- csi_object_t *next;
+ next = _csi_stack_peek (&scan->procedure_stack, 0);
+ status = csi_array_append (ctx, next->datum.array,
+ &scan->build_procedure);
+ scan->build_procedure = *next;
+ scan->procedure_stack.len--;
+ } else {
+ status = scan_push (ctx, &scan->build_procedure);
+ scan->build_procedure.type = CSI_OBJECT_TYPE_NULL;
+ }
+ if (_csi_unlikely (status))
+ longjmp (scan->jmpbuf, status);
- next = _csi_stack_peek (&scan->procedure_stack, 0);
- status = csi_array_append (ctx, next->datum.array,
- &scan->build_procedure);
- scan->build_procedure = *next;
- scan->procedure_stack.len--;
- } else {
- status = scan_push (ctx, &scan->build_procedure);
- scan->build_procedure.type = CSI_OBJECT_TYPE_NULL;
+ return;
}
- if (_csi_unlikely (status))
- longjmp (scan->jmpbuf, status);
-
- return;
}
if (s[0] == '/') {
@@ -1238,6 +1240,7 @@ _csi_scanner_init (csi_t *ctx, csi_scanner_t *scanner)
if (status)
return status;
+ scanner->bind = 0;
scanner->push = _scan_push;
scanner->execute = _scan_execute;
@@ -1663,11 +1666,13 @@ _csi_translate_file (csi_t *ctx,
translator.closure = closure;
ctx->scanner.closure = &translator;
+ ctx->scanner.bind = 1;
ctx->scanner.push = _translate_push;
ctx->scanner.execute = _translate_execute;
_scan_file (ctx, file);
+ ctx->scanner.bind = 0;
ctx->scanner.push = _scan_push;
ctx->scanner.execute = _scan_execute;