summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2013-05-28 22:23:40 +0200
committerTor Andersson <tor.andersson@artifex.com>2013-05-29 09:58:46 +0200
commitcbd2c7bbcb856fd4e9cccb67f1d27dbc95e9caeb (patch)
tree83812972fcc8de6efba3a15c3240d382933a3a41
parentd956556d0e06aa5c8e39eed410b3eb098cc2e742 (diff)
downloadmupdf-cbd2c7bbcb856fd4e9cccb67f1d27dbc95e9caeb.tar.xz
Killed pdf_cmap_token enum.
-rw-r--r--pdf/mupdf-internal.h2
-rw-r--r--pdf/pdf_cmap_parse.c144
-rw-r--r--pdf/pdf_lex.c4
3 files changed, 42 insertions, 108 deletions
diff --git a/pdf/mupdf-internal.h b/pdf/mupdf-internal.h
index d064f71c..bea1c0d3 100644
--- a/pdf/mupdf-internal.h
+++ b/pdf/mupdf-internal.h
@@ -57,7 +57,7 @@ void pdf_lexbuf_init(fz_context *ctx, pdf_lexbuf *lexbuf, int size);
void pdf_lexbuf_fin(pdf_lexbuf *lexbuf);
ptrdiff_t pdf_lexbuf_grow(pdf_lexbuf *lexbuf);
-int pdf_lex(fz_stream *f, pdf_lexbuf *lexbuf);
+pdf_token pdf_lex(fz_stream *f, pdf_lexbuf *lexbuf);
pdf_obj *pdf_parse_array(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf);
pdf_obj *pdf_parse_dict(pdf_document *doc, fz_stream *f, pdf_lexbuf *buf);
diff --git a/pdf/pdf_cmap_parse.c b/pdf/pdf_cmap_parse.c
index db9f7f2f..e2335de4 100644
--- a/pdf/pdf_cmap_parse.c
+++ b/pdf/pdf_cmap_parse.c
@@ -5,40 +5,6 @@
* CMap parser
*/
-enum
-{
- TOK_USECMAP = PDF_NUM_TOKENS,
- TOK_BEGIN_CODESPACE_RANGE,
- TOK_END_CODESPACE_RANGE,
- TOK_BEGIN_BF_CHAR,
- TOK_END_BF_CHAR,
- TOK_BEGIN_BF_RANGE,
- TOK_END_BF_RANGE,
- TOK_BEGIN_CID_CHAR,
- TOK_END_CID_CHAR,
- TOK_BEGIN_CID_RANGE,
- TOK_END_CID_RANGE,
- TOK_END_CMAP
-};
-
-static int
-pdf_cmap_token_from_keyword(char *key)
-{
- if (!strcmp(key, "usecmap")) return TOK_USECMAP;
- if (!strcmp(key, "begincodespacerange")) return TOK_BEGIN_CODESPACE_RANGE;
- if (!strcmp(key, "endcodespacerange")) return TOK_END_CODESPACE_RANGE;
- if (!strcmp(key, "beginbfchar")) return TOK_BEGIN_BF_CHAR;
- if (!strcmp(key, "endbfchar")) return TOK_END_BF_CHAR;
- if (!strcmp(key, "beginbfrange")) return TOK_BEGIN_BF_RANGE;
- if (!strcmp(key, "endbfrange")) return TOK_END_BF_RANGE;
- if (!strcmp(key, "begincidchar")) return TOK_BEGIN_CID_CHAR;
- if (!strcmp(key, "endcidchar")) return TOK_END_CID_CHAR;
- if (!strcmp(key, "begincidrange")) return TOK_BEGIN_CID_RANGE;
- if (!strcmp(key, "endcidrange")) return TOK_END_CID_RANGE;
- if (!strcmp(key, "endcmap")) return TOK_END_CMAP;
- return PDF_TOK_KEYWORD;
-}
-
static int
pdf_code_from_string(char *buf, int len)
{
@@ -48,23 +14,12 @@ pdf_code_from_string(char *buf, int len)
return a;
}
-static int
-pdf_lex_cmap(fz_stream *file, pdf_lexbuf *buf)
-{
- pdf_token tok = pdf_lex(file, buf);
-
- if (tok == PDF_TOK_KEYWORD)
- tok = pdf_cmap_token_from_keyword(buf->scratch);
-
- return tok;
-}
-
static void
pdf_parse_cmap_name(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf *buf)
{
pdf_token tok;
- tok = pdf_lex_cmap(file, buf);
+ tok = pdf_lex(file, buf);
if (tok == PDF_TOK_NAME)
fz_strlcpy(cmap->cmap_name, buf->scratch, sizeof(cmap->cmap_name));
@@ -77,7 +32,7 @@ pdf_parse_wmode(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf *bu
{
pdf_token tok;
- tok = pdf_lex_cmap(file, buf);
+ tok = pdf_lex(file, buf);
if (tok == PDF_TOK_INT)
pdf_set_cmap_wmode(ctx, cmap, buf->i);
@@ -93,15 +48,15 @@ pdf_parse_codespace_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_
while (1)
{
- tok = pdf_lex_cmap(file, buf);
+ tok = pdf_lex(file, buf);
- if (tok == TOK_END_CODESPACE_RANGE)
+ if (tok == PDF_TOK_KEYWORD && !strcmp(buf->scratch, "endcodespacerange"))
return;
else if (tok == PDF_TOK_STRING)
{
lo = pdf_code_from_string(buf->scratch, buf->len);
- tok = pdf_lex_cmap(file, buf);
+ tok = pdf_lex(file, buf);
if (tok == PDF_TOK_STRING)
{
hi = pdf_code_from_string(buf->scratch, buf->len);
@@ -124,9 +79,9 @@ pdf_parse_cid_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf
while (1)
{
- tok = pdf_lex_cmap(file, buf);
+ tok = pdf_lex(file, buf);
- if (tok == TOK_END_CID_RANGE)
+ if (tok == PDF_TOK_KEYWORD && !strcmp(buf->scratch, "endcidrange"))
return;
else if (tok != PDF_TOK_STRING)
@@ -134,13 +89,13 @@ pdf_parse_cid_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf
lo = pdf_code_from_string(buf->scratch, buf->len);
- tok = pdf_lex_cmap(file, buf);
+ tok = pdf_lex(file, buf);
if (tok != PDF_TOK_STRING)
fz_throw(ctx, "expected string");
hi = pdf_code_from_string(buf->scratch, buf->len);
- tok = pdf_lex_cmap(file, buf);
+ tok = pdf_lex(file, buf);
if (tok != PDF_TOK_INT)
fz_throw(ctx, "expected integer");
@@ -158,9 +113,9 @@ pdf_parse_cid_char(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf
while (1)
{
- tok = pdf_lex_cmap(file, buf);
+ tok = pdf_lex(file, buf);
- if (tok == TOK_END_CID_CHAR)
+ if (tok == PDF_TOK_KEYWORD && !strcmp(buf->scratch, "endcidchar"))
return;
else if (tok != PDF_TOK_STRING)
@@ -168,7 +123,7 @@ pdf_parse_cid_char(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf
src = pdf_code_from_string(buf->scratch, buf->len);
- tok = pdf_lex_cmap(file, buf);
+ tok = pdf_lex(file, buf);
if (tok != PDF_TOK_INT)
fz_throw(ctx, "expected integer");
@@ -187,7 +142,7 @@ pdf_parse_bf_range_array(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_l
while (1)
{
- tok = pdf_lex_cmap(file, buf);
+ tok = pdf_lex(file, buf);
if (tok == PDF_TOK_CLOSE_ARRAY)
return;
@@ -217,9 +172,9 @@ pdf_parse_bf_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf
while (1)
{
- tok = pdf_lex_cmap(file, buf);
+ tok = pdf_lex(file, buf);
- if (tok == TOK_END_BF_RANGE)
+ if (tok == PDF_TOK_KEYWORD && !strcmp(buf->scratch, "endbfrange"))
return;
else if (tok != PDF_TOK_STRING)
@@ -227,7 +182,7 @@ pdf_parse_bf_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf
lo = pdf_code_from_string(buf->scratch, buf->len);
- tok = pdf_lex_cmap(file, buf);
+ tok = pdf_lex(file, buf);
if (tok != PDF_TOK_STRING)
fz_throw(ctx, "expected string");
@@ -238,7 +193,7 @@ pdf_parse_bf_range(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf
return;
}
- tok = pdf_lex_cmap(file, buf);
+ tok = pdf_lex(file, buf);
if (tok == PDF_TOK_STRING)
{
@@ -290,9 +245,9 @@ pdf_parse_bf_char(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf *
while (1)
{
- tok = pdf_lex_cmap(file, buf);
+ tok = pdf_lex(file, buf);
- if (tok == TOK_END_BF_CHAR)
+ if (tok == PDF_TOK_KEYWORD && !strcmp(buf->scratch, "endbfchar"))
return;
else if (tok != PDF_TOK_STRING)
@@ -300,7 +255,7 @@ pdf_parse_bf_char(fz_context *ctx, pdf_cmap *cmap, fz_stream *file, pdf_lexbuf *
src = pdf_code_from_string(buf->scratch, buf->len);
- tok = pdf_lex_cmap(file, buf);
+ tok = pdf_lex(file, buf);
/* Note: does not handle /dstName */
if (tok != PDF_TOK_STRING)
fz_throw(ctx, "expected string");
@@ -322,74 +277,53 @@ pdf_load_cmap(fz_context *ctx, fz_stream *file)
char key[64];
pdf_lexbuf buf;
pdf_token tok;
- const char *where;
pdf_lexbuf_init(ctx, &buf, PDF_LEXBUF_SMALL);
cmap = pdf_new_cmap(ctx);
strcpy(key, ".notdef");
- fz_var(where);
-
fz_try(ctx)
{
while (1)
{
- where = "";
- tok = pdf_lex_cmap(file, &buf);
+ tok = pdf_lex(file, &buf);
- if (tok == PDF_TOK_EOF || tok == TOK_END_CMAP)
+ if (tok == PDF_TOK_EOF)
break;
else if (tok == PDF_TOK_NAME)
{
if (!strcmp(buf.scratch, "CMapName"))
- {
- where = " after CMapName";
pdf_parse_cmap_name(ctx, cmap, file, &buf);
- }
else if (!strcmp(buf.scratch, "WMode"))
- {
- where = " after WMode";
pdf_parse_wmode(ctx, cmap, file, &buf);
- }
else
fz_strlcpy(key, buf.scratch, sizeof key);
}
- else if (tok == TOK_USECMAP)
+ else if (tok == PDF_TOK_KEYWORD)
{
- fz_strlcpy(cmap->usecmap_name, key, sizeof(cmap->usecmap_name));
- }
+ if (!strcmp(buf.scratch, "endcmap"))
+ break;
- else if (tok == TOK_BEGIN_CODESPACE_RANGE)
- {
- where = " codespacerange";
- pdf_parse_codespace_range(ctx, cmap, file, &buf);
- }
+ else if (!strcmp(buf.scratch, "usecmap"))
+ fz_strlcpy(cmap->usecmap_name, key, sizeof(cmap->usecmap_name));
- else if (tok == TOK_BEGIN_BF_CHAR)
- {
- where = " bfchar";
- pdf_parse_bf_char(ctx, cmap, file, &buf);
- }
+ else if (!strcmp(buf.scratch, "begincodespacerange"))
+ pdf_parse_codespace_range(ctx, cmap, file, &buf);
- else if (tok == TOK_BEGIN_CID_CHAR)
- {
- where = " cidchar";
- pdf_parse_cid_char(ctx, cmap, file, &buf);
- }
+ else if (!strcmp(buf.scratch, "beginbfchar"))
+ pdf_parse_bf_char(ctx, cmap, file, &buf);
- else if (tok == TOK_BEGIN_BF_RANGE)
- {
- where = " bfrange";
- pdf_parse_bf_range(ctx, cmap, file, &buf);
- }
+ else if (!strcmp(buf.scratch, "begincidchar"))
+ pdf_parse_cid_char(ctx, cmap, file, &buf);
- else if (tok == TOK_BEGIN_CID_RANGE)
- {
- where = "cidrange";
- pdf_parse_cid_range(ctx, cmap, file, &buf);
+ else if (!strcmp(buf.scratch, "beginbfrange"))
+ pdf_parse_bf_range(ctx, cmap, file, &buf);
+
+ else if (!strcmp(buf.scratch, "begincidrange"))
+ pdf_parse_cid_range(ctx, cmap, file, &buf);
}
/* ignore everything else */
@@ -404,7 +338,7 @@ pdf_load_cmap(fz_context *ctx, fz_stream *file)
fz_catch(ctx)
{
pdf_drop_cmap(ctx, cmap);
- fz_throw(ctx, "syntaxerror in cmap%s", where);
+ fz_throw(ctx, "syntaxerror in cmap");
}
return cmap;
diff --git a/pdf/pdf_lex.c b/pdf/pdf_lex.c
index 9b4ff280..adb3aea3 100644
--- a/pdf/pdf_lex.c
+++ b/pdf/pdf_lex.c
@@ -372,7 +372,7 @@ end:
return PDF_TOK_STRING;
}
-static int
+static pdf_token
pdf_token_from_keyword(char *key)
{
switch (*key)
@@ -442,7 +442,7 @@ ptrdiff_t pdf_lexbuf_grow(pdf_lexbuf *lb)
return lb->scratch - old;
}
-int
+pdf_token
pdf_lex(fz_stream *f, pdf_lexbuf *buf)
{
while (1)