[script] Report line number

Count the number of newlines processed in the trace and provide an API for
the user to query.
This commit is contained in:
Chris Wilson 2009-06-19 14:13:34 +01:00
parent 030ef4ca00
commit 55721d380d
4 changed files with 20 additions and 3 deletions

View file

@ -567,6 +567,12 @@ cairo_script_interpreter_feed_string (csi_t *ctx, const char *line, int len)
return ctx->status;
}
unsigned int
cairo_script_interpreter_get_line_number (csi_t *ctx)
{
return ctx->scanner.line_number + 1; /* 1 index based */
}
csi_t *
cairo_script_interpreter_reference (csi_t *ctx)
{

View file

@ -88,6 +88,9 @@ cairo_script_interpreter_feed_string (cairo_script_interpreter_t *ctx,
const char *line,
int len);
cairo_public unsigned int
cairo_script_interpreter_get_line_number (cairo_script_interpreter_t *ctx);
cairo_public cairo_script_interpreter_t *
cairo_script_interpreter_reference (cairo_script_interpreter_t *ctx);

View file

@ -441,6 +441,8 @@ struct _csi_scanner {
int string_p;
unsigned int accumulator;
unsigned int accumulator_count;
unsigned int line_number;
};
typedef cairo_script_interpreter_hooks_t csi_hooks_t;

View file

@ -678,9 +678,10 @@ scan_none (csi_t *ctx,
csi_object_t obj = { CSI_OBJECT_TYPE_NULL };
switch (c) {
case 0xa:
scan->line_number++;
case 0x0:
case 0x9:
case 0xa:
case 0xc:
case 0xd:
case 0x20: /* ignore whitespace */
@ -829,9 +830,10 @@ scan_token (csi_t *ctx, csi_scanner_t *scan, csi_file_t *src)
while ((c = scan_getc (scan, src)) != EOF) {
switch (c) {
case 0xa:
scan->line_number++;
case 0x0:
case 0x9:
case 0xa:
case 0xc:
case 0xd:
case 0x20:
@ -901,9 +903,10 @@ scan_hex (csi_t *ctx, csi_scanner_t *scan, csi_file_t *src)
while ((c = scan_getc (scan, src)) != EOF) {
switch (c) {
case 0xa:
scan->line_number++;
case 0x0:
case 0x9:
case 0xa:
case 0xc:
case 0xd:
case 0x20: /* ignore whitespace */
@ -1056,6 +1059,7 @@ scan_string (csi_t *ctx, csi_scanner_t *scan, csi_file_t *src)
scan_putc (scan, src, next);
break;
}
scan->line_number++;
break;
case 0xc:
break;
@ -1098,6 +1102,7 @@ scan_comment (csi_t *ctx, csi_scanner_t *scan, csi_file_t *src)
while ((c = scan_getc (scan, src)) != EOF) {
switch (c) {
case 0xa:
scan->line_number++;
case 0xc:
comment_end (scan);
return 1;
@ -1119,6 +1124,7 @@ _csi_scan_file (csi_t *ctx, csi_scanner_t *scan, csi_file_t *src)
scan_base85,
};
scan->line_number = 0;
while (func[scan->state] (ctx, scan, src))
;