diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2012-02-07 00:59:58 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2012-02-07 00:59:58 +0100 |
commit | f9f7221b937ac1f38d0a0a52f553001a2d9efc48 (patch) | |
tree | ebf4ffd0b39dc047a26970056323421564a6eae6 | |
parent | 409020b21a2d822b57f3494eda355f5aca62dc2e (diff) | |
download | mupdf-f9f7221b937ac1f38d0a0a52f553001a2d9efc48.tar.xz |
Implement fz_open_document by hard coding the list of file types.
-rw-r--r-- | fitz/doc_document.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/fitz/doc_document.c b/fitz/doc_document.c index 36f43ee2..ca13af72 100644 --- a/fitz/doc_document.c +++ b/fitz/doc_document.c @@ -1,5 +1,42 @@ #include "fitz.h" +/* Yuck! Promiscuous we are. */ +extern struct pdf_document *pdf_open_document(fz_context *ctx, char *filename); +extern struct xps_document *xps_open_document(fz_context *ctx, char *filename); +extern struct cbz_document *cbz_open_document(fz_context *ctx, char *filename); + +static inline int fz_tolower(int c) +{ + if (c >= 'A' && c <= 'Z') + return c + 32; + return c; +} + +static inline int fz_strcasecmp(char *a, char *b) +{ + while (fz_tolower(*a) == fz_tolower(*b)) + { + if (*a++ == 0) + return 0; + b++; + } + return fz_tolower(*a) - fz_tolower(*b); +} + +fz_document * +fz_open_document(fz_context *ctx, char *filename) +{ + char *ext = strrchr(filename, '.'); + if (ext && !fz_strcasecmp(ext, ".pdf")) + return (fz_document*) pdf_open_document(ctx, filename); + if (ext && !fz_strcasecmp(ext, ".xps")) + return (fz_document*) xps_open_document(ctx, filename); + if (ext && !fz_strcasecmp(ext, ".cbz")) + return (fz_document*) cbz_open_document(ctx, filename); + fz_throw(ctx, "unknown document type: '%s'", filename); + return NULL; +} + void fz_close_document(fz_document *doc) { |