From f9f7221b937ac1f38d0a0a52f553001a2d9efc48 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 7 Feb 2012 00:59:58 +0100 Subject: Implement fz_open_document by hard coding the list of file types. --- fitz/doc_document.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) 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) { -- cgit v1.2.3