diff options
author | Robin Watts <Robin.Watts@artifex.com> | 2011-10-04 18:44:19 +0100 |
---|---|---|
committer | Robin Watts <Robin.Watts@artifex.com> | 2011-10-04 18:44:19 +0100 |
commit | d208be26537db558edb70236ae517cea31b7ebab (patch) | |
tree | 57da95b97e354a53bd4517a42010e90968f007d9 /pdf/pdf_lex.c | |
parent | ba46cad4b09bb957085900a203206c8fa5868cd4 (diff) | |
download | mupdf-d208be26537db558edb70236ae517cea31b7ebab.tar.xz |
Move to exception handling rather than error passing throughout.
This frees us from passing errors back everywhere, and hence enables us
to pass results back as return values.
Rather than having to explicitly check for errors everywhere and bubble
them, we now allow exception handling to do the work for us; the
downside to this is that we no longer emit as much debugging information
as we did before (though this could be put back in). For now, the
debugging information we have lost has been retained in comments
with 'RJW:' at the start.
This code needs fuller testing, but is being committed as a work in
progress.
Diffstat (limited to 'pdf/pdf_lex.c')
-rw-r--r-- | pdf/pdf_lex.c | 55 |
1 files changed, 21 insertions, 34 deletions
diff --git a/pdf/pdf_lex.c b/pdf/pdf_lex.c index d34b2b6f..edb27b7b 100644 --- a/pdf/pdf_lex.c +++ b/pdf/pdf_lex.c @@ -379,8 +379,8 @@ pdf_token_from_keyword(char *key) return PDF_TOK_KEYWORD; } -fz_error -pdf_lex(int *tok, fz_stream *f, char *buf, int n, int *sl) +int +pdf_lex(fz_stream *f, char *buf, int n, int *sl) { while (1) { @@ -388,8 +388,7 @@ pdf_lex(int *tok, fz_stream *f, char *buf, int n, int *sl) switch (c) { case EOF: - *tok = PDF_TOK_EOF; - return fz_okay; + return PDF_TOK_EOF; case IS_WHITE: lex_white(f); break; @@ -399,63 +398,51 @@ pdf_lex(int *tok, fz_stream *f, char *buf, int n, int *sl) case '/': lex_name(f, buf, n); *sl = strlen(buf); - *tok = PDF_TOK_NAME; - return fz_okay; + return PDF_TOK_NAME; case '(': *sl = lex_string(f, buf, n); - *tok = PDF_TOK_STRING; - return fz_okay; + return PDF_TOK_STRING; case ')': - *tok = PDF_TOK_ERROR; - goto cleanuperror; + fz_throw(f->ctx, "lexical error (unexpected ')')"); case '<': c = fz_read_byte(f); if (c == '<') { - *tok = PDF_TOK_OPEN_DICT; + return PDF_TOK_OPEN_DICT; } else { fz_unread_byte(f); *sl = lex_hex_string(f, buf, n); - *tok = PDF_TOK_STRING; + return PDF_TOK_STRING; } - return fz_okay; case '>': c = fz_read_byte(f); if (c == '>') { - *tok = PDF_TOK_CLOSE_DICT; - return fz_okay; + return PDF_TOK_CLOSE_DICT; } - *tok = PDF_TOK_ERROR; - goto cleanuperror; + fz_throw(f->ctx, "lexical error (unexpected '>')"); case '[': - *tok = PDF_TOK_OPEN_ARRAY; - return fz_okay; + return PDF_TOK_OPEN_ARRAY; case ']': - *tok = PDF_TOK_CLOSE_ARRAY; - return fz_okay; + return PDF_TOK_CLOSE_ARRAY; case '{': - *tok = PDF_TOK_OPEN_BRACE; - return fz_okay; + return PDF_TOK_OPEN_BRACE; case '}': - *tok = PDF_TOK_CLOSE_BRACE; - return fz_okay; + return PDF_TOK_CLOSE_BRACE; case IS_NUMBER: - fz_unread_byte(f); - *sl = lex_number(f, buf, n, tok); - return fz_okay; + { + int tok; + fz_unread_byte(f); + *sl = lex_number(f, buf, n, &tok); + return tok; + } default: /* isregular: !isdelim && !iswhite && c != EOF */ fz_unread_byte(f); lex_name(f, buf, n); *sl = strlen(buf); - *tok = pdf_token_from_keyword(buf); - return fz_okay; + return pdf_token_from_keyword(buf); } } - -cleanuperror: - *tok = PDF_TOK_ERROR; - return fz_error_make("lexical error"); } |