[script] Enable error handling for recursive scanners

It's conceivable that a script could execute another file and so we should
only setjmp on the first invocation.
This commit is contained in:
Chris Wilson 2009-06-28 20:41:04 +01:00
parent 963664727b
commit f7021d8f3e
2 changed files with 13 additions and 3 deletions

View file

@ -424,6 +424,7 @@ union _csi_union_object {
struct _csi_scanner {
jmp_buf jmpbuf;
int depth;
enum {
NONE,

View file

@ -1101,13 +1101,22 @@ _csi_scan_file (csi_t *ctx, csi_scanner_t *scan, csi_file_t *src)
};
csi_status_t status;
if ((status = setjmp (scan->jmpbuf)))
return status;
/* This function needs to be reentrant to handle recursive scanners.
* i.e. one script executes a second.
*/
scan->line_number = 0;
if (scan->depth++ == 0) {
if ((status = setjmp (scan->jmpbuf))) {
scan->depth = 0;
return status;
}
}
scan->line_number = 0; /* XXX broken by recursive scanning */
while (func[scan->state] (ctx, scan, src))
;
--scan->depth;
return CSI_STATUS_SUCCESS;
}