diff --git a/Makefile.in b/Makefile.in index 2942328..38b4f60 100644 --- a/Makefile.in +++ b/Makefile.in @@ -83,7 +83,7 @@ PUBLIBOBJS = mxml-attr.o mxml-entity.o mxml-file.o mxml-get.o \ mxml-index.o mxml-node.o mxml-search.o mxml-set.o LIBOBJS = $(PUBLIBOBJS) mxml-private.o mxml-string.o OBJS = mxmldoc.o testmxml.o zipc.o $(LIBOBJS) -ALLTARGETS = $(LIBMXML) mxmldoc testmxml mxml.xml +ALLTARGETS = $(LIBMXML) mxmldoc testmxml mxml.xml @MXML_EPUB@ CROSSTARGETS = $(LIBMXML) mxmldoc TARGETS = $(@TARGETS@) @@ -101,7 +101,7 @@ all: $(TARGETS) clean: echo Cleaning build files... - $(RM) $(OBJS) $(TARGETS) + $(RM) $(OBJS) $(ALLTARGETS) $(RM) mxmldoc-static libmxml.a libmxml.so.1.5 libmxml.sl.1 libmxml.1.dylib @@ -293,13 +293,13 @@ libmxml.1.dylib: $(LIBOBJS) # mxmldoc # -mxmldoc: $(LIBMXML) mxmldoc.o zipc.o +mxmldoc: $(LIBMXML) mxmldoc.o @ZIPC@ echo Linking $@... - $(CC) -L. $(LDFLAGS) -o $@ mxmldoc.o zipc.o -lmxml $(LIBS) + $(CC) -L. $(LDFLAGS) -o $@ mxmldoc.o @ZIPC@ -lmxml $(LIBS) -mxmldoc-static: libmxml.a mxmldoc.o +mxmldoc-static: libmxml.a mxmldoc.o @ZIPC@ echo Linking $@... - $(CC) $(LDFLAGS) -o $@ mxmldoc.o zipc.o libmxml.a $(LIBS) + $(CC) $(LDFLAGS) -o $@ mxmldoc.o @ZIPC@ libmxml.a $(LIBS) mxmldoc.o: mxml.h zipc.h zipc.o: zipc.h diff --git a/configure b/configure index 26c942f..d9a4995 100755 --- a/configure +++ b/configure @@ -635,6 +635,8 @@ PTHREAD_FLAGS EGREP GREP CPP +ZIPC +MXML_EPUB ARFLAGS RM MKDIR @@ -3963,6 +3965,10 @@ if test $ac_cv_c_long_long = yes; then fi +MXML_EPUB="" + +ZIPC="" + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing gzgets" >&5 $as_echo_n "checking for library containing gzgets... " >&6; } if ${ac_cv_search_gzgets+:} false; then : @@ -4016,7 +4022,12 @@ $as_echo "$ac_cv_search_gzgets" >&6; } ac_res=$ac_cv_search_gzgets if test "$ac_res" != no; then : test "$ac_res" = "none required" || LIBS="$ac_res $LIBS" - LIBS="-lz $LIBS" + + $as_echo "#define HAVE_ZLIB_H 1" >>confdefs.h + + ZIPC="zipc.o" + MXML_EPUB="mxml.epub" + LIBS="-lz $LIBS" fi diff --git a/configure.ac b/configure.ac index 4ae516c..a795376 100644 --- a/configure.ac +++ b/configure.ac @@ -117,8 +117,14 @@ if test $ac_cv_c_long_long = yes; then fi dnl EPUB support (via libz and zipc) +MXML_EPUB="" +AC_SUBST(MXML_EPUB) +ZIPC="" +AC_SUBST(ZIPC) AC_SEARCH_LIBS(gzgets,z,[ AC_DEFINE(HAVE_ZLIB_H) + ZIPC="zipc.o" + MXML_EPUB="mxml.epub" LIBS="-lz $LIBS"]) dnl Threading support diff --git a/doc/mxml.man b/doc/mxml.man index c475f3f..84a3347 100644 --- a/doc/mxml.man +++ b/doc/mxml.man @@ -1,4 +1,4 @@ -.TH mxml 3 "Mini-XML API" "04/04/17" "Mini-XML API" +.TH mxml 3 "Mini-XML API" "04/05/17" "Mini-XML API" .SH NAME mxml \- Mini-XML API .SH INCLUDE FILE diff --git a/mxmldoc.c b/mxmldoc.c index 6916dbd..f136f52 100644 --- a/mxmldoc.c +++ b/mxmldoc.c @@ -20,7 +20,6 @@ #include "config.h" #include "mxml.h" -#include "zipc.h" #include #include #ifndef WIN32 @@ -33,6 +32,10 @@ extern char **environ; #endif /* __APPLE__ */ +#ifdef HAVE_ZLIB_H +# include "zipc.h" +#endif /* HAVE_ZLIB_H */ + /* * This program scans source and header files and produces public API @@ -601,7 +604,11 @@ main(int argc, /* I - Number of command-line args */ * Write EPUB (XHTML) documentation... */ +#ifdef HAVE_ZLIB_H write_epub(section, title ? title : "Documentation", author ? author : "Unknown", copyright ? copyright : "Unknown", docversion ? docversion : "0.0", footerfile, headerfile, introfile, cssfile, epubfile, mxmldoc); +#else + fputs("mxmldoc: Sorry, not compiled with EPUB support.\n", stderr); +#endif /* HAVE_ZLIB_H */ break; case OUTPUT_HTML : @@ -3390,6 +3397,7 @@ write_element(FILE *out, /* I - Output file */ } +#ifdef HAVE_ZLIB_H /* * 'write_epub()' - Write documentation as an EPUB file. */ @@ -3407,6 +3415,7 @@ write_epub(const char *section, /* I - Section */ const char *epubfile, /* I - EPUB file (output) */ mxml_node_t *doc) /* I - XML documentation */ { + int status = 0; /* Write status */ size_t i; /* Looping var */ FILE *fp; /* Output file */ mxml_node_t *function, /* Current function */ @@ -3432,16 +3441,6 @@ write_epub(const char *section, /* I - Section */ *package_opf_string; /* package_opf file as a string */ toc_t *toc; /* Table of contents */ toc_entry_t *tentry; /* Current table of contents */ - mxml_node_t *toc_ncx, /* toc.ncx file */ - *ncx, /* ncx node */ - *head, /* head node */ - *docTitle, /* docTitle node */ - *docAuthor, /* docAuthor node */ - *nav, /* Current parent for nav nodes */ - *navMap, /* navMap node */ - *navPoint, /* navPoint node */ - *navLabel; /* navLabel node */ - char *toc_ncx_string; /* toc.ncx file as a string */ char toc_xhtmlfile[1024]; /* XHTML file for table-of-contents */ int toc_level; /* Current table-of-contents level */ static const char *mimetype = /* mimetype file as a string */ @@ -3810,11 +3809,6 @@ write_epub(const char *section, /* I - Section */ manifest = mxmlNewElement(package, "manifest"); -// temp = mxmlNewElement(manifest, "item"); -// mxmlElementSetAttr(temp, "id", "ncx"); -// mxmlElementSetAttr(temp, "href", "toc.ncx"); -// mxmlElementSetAttr(temp, "media-type", "application/x-dtbncx+xml"); - temp = mxmlNewElement(manifest, "item"); mxmlElementSetAttr(temp, "id", "nav"); mxmlElementSetAttr(temp, "href", "nav.xhtml"); @@ -3826,10 +3820,7 @@ write_epub(const char *section, /* I - Section */ mxmlElementSetAttr(temp, "href", "body.xhtml"); mxmlElementSetAttr(temp, "media-type", "application/xhtml+xml"); -// - spine = mxmlNewElement(package, "spine"); -// mxmlElementSetAttr(spine, "toc", "ncx"); temp = mxmlNewElement(spine, "itemref"); mxmlElementSetAttr(temp, "idref", "body"); @@ -3837,59 +3828,11 @@ write_epub(const char *section, /* I - Section */ package_opf_string = mxmlSaveAllocString(package_opf, epub_ws_cb); /* - * Make the toc.ncx file... + * Make the nav.xhtml file... */ toc = build_toc(doc, introfile); - toc_ncx = mxmlNewXML("1.0"); - - ncx = mxmlNewElement(toc_ncx, "ncx"); - mxmlElementSetAttr(ncx, "xmlns", "http://www.daisy.org/z3986/2005/ncx/"); - mxmlElementSetAttr(ncx, "version", "2005-1"); - mxmlElementSetAttr(ncx, "xml:lang", "en-US"); /* TODO: Make this settable */ - - head = mxmlNewElement(ncx, "head"); - - temp = mxmlNewElement(head, "meta"); - mxmlElementSetAttr(temp, "content", identifier); - mxmlElementSetAttr(temp, "name", "dtb:uid"); - - docTitle = mxmlNewElement(ncx, "docTitle"); - - temp = mxmlNewElement(docTitle, "text"); - mxmlNewOpaque(temp, title); - - docAuthor = mxmlNewElement(ncx, "docAuthor"); - - temp = mxmlNewElement(docAuthor, "text"); - mxmlNewOpaque(temp, author); - - navMap = mxmlNewElement(ncx, "navMap"); - - for (i = 0, tentry = toc->entries, nav = navMap; i < toc->num_entries; i ++, tentry ++) - { - if (tentry->level == 1) - nav = navMap; - - navPoint = mxmlNewElement(nav, "navPoint"); - mxmlElementSetAttrf(navPoint, "class", "h%d", tentry->level); - mxmlElementSetAttr(navPoint, "id", tentry->anchor); - mxmlElementSetAttrf(navPoint, "playOrder", "%d", (int)i + 1); - - if (tentry->level == 1) - nav = navPoint; - - navLabel = mxmlNewElement(navPoint, "navLabel"); - temp = mxmlNewElement(navLabel, "text"); - mxmlNewOpaque(temp, tentry->title); - - temp = mxmlNewElement(navPoint, "content"); - mxmlElementSetAttrf(temp, "src", "body.xhtml#%s", tentry->anchor); - } - - toc_ncx_string = mxmlSaveAllocString(toc_ncx, epub_ws_cb); - strlcpy(toc_xhtmlfile, epubfile, sizeof(toc_xhtmlfile)); if ((xhtmlptr = strstr(toc_xhtmlfile, ".epub")) != NULL) strlcpy(xhtmlptr, "-toc.xhtml", sizeof(toc_xhtmlfile) - (size_t)(xhtmlptr - toc_xhtmlfile)); @@ -3947,52 +3890,74 @@ write_epub(const char *section, /* I - Section */ * Make the EPUB archive... */ - epub = zipcOpen(epubfile, "w"); + if ((epub = zipcOpen(epubfile, "w")) == NULL) + { + fprintf(stderr, "mxmldoc: Unable to create \"%s\": %s\n", epubfile, strerror(errno)); + unlink(xhtmlfile); + return; + } /* mimetype file */ - zipcCreateFileWithString(epub, "mimetype", mimetype); + status |= zipcCreateFileWithString(epub, "mimetype", mimetype); + + /* META-INF/ directory */ + status |= zipcCreateDirectory(epub, "META-INF/"); /* META-INF/container.xml file */ - zipcCreateFileWithString(epub, "META-INF/container.xml", container_xml); + status |= zipcCreateFileWithString(epub, "META-INF/container.xml", container_xml); + + /* OEBPS/ directory */ + status |= zipcCreateDirectory(epub, "OEBPS/"); /* OEBPS/body.xhtml file */ - epubf = zipcCreateFile(epub, "OEBPS/body.xhtml", 1); - if ((fp = fopen(xhtmlfile, "r")) != NULL) + if ((epubf = zipcCreateFile(epub, "OEBPS/body.xhtml", 1)) != NULL) { - char buffer[65536]; /* Copy buffer */ - int length; /* Number of bytes */ + if ((fp = fopen(xhtmlfile, "r")) != NULL) + { + char buffer[65536]; /* Copy buffer */ + int length; /* Number of bytes */ - while ((length = (int)fread(buffer, 1, sizeof(buffer), fp)) > 0) - zipcFileWrite(epubf, buffer, length); + while ((length = (int)fread(buffer, 1, sizeof(buffer), fp)) > 0) + zipcFileWrite(epubf, buffer, length); - fclose(fp); - zipcFileFinish(epubf); + fclose(fp); + zipcFileFinish(epubf); + } } + else + status = -1; + unlink(xhtmlfile); /* OEBPS/package.opf file */ - zipcCreateFileWithString(epub, "OEBPS/package.opf", package_opf_string); - - /* OEBPS/toc.ncx file */ -// zipcCreateFileWithString(epub, "OEBPS/toc.ncx", toc_ncx_string); + status |= zipcCreateFileWithString(epub, "OEBPS/package.opf", package_opf_string); /* OEBPS/nav.xhtml file */ - epubf = zipcCreateFile(epub, "OEBPS/nav.xhtml", 1); - if ((fp = fopen(toc_xhtmlfile, "r")) != NULL) + if ((epubf = zipcCreateFile(epub, "OEBPS/nav.xhtml", 1)) != NULL) { - char buffer[65536]; /* Copy buffer */ - int length; /* Number of bytes */ + if ((fp = fopen(toc_xhtmlfile, "r")) != NULL) + { + char buffer[65536]; /* Copy buffer */ + int length; /* Number of bytes */ - while ((length = (int)fread(buffer, 1, sizeof(buffer), fp)) > 0) - zipcFileWrite(epubf, buffer, length); + while ((length = (int)fread(buffer, 1, sizeof(buffer), fp)) > 0) + zipcFileWrite(epubf, buffer, length); - fclose(fp); - zipcFileFinish(epubf); + fclose(fp); + zipcFileFinish(epubf); + } } + else + status = -1; + unlink(toc_xhtmlfile); - zipcClose(epub); + if (status) + fprintf(stderr, "mxmldoc: Unable to write \"%s\": %s\n", epubfile, zipcError(epub)); + else if (zipcClose(epub)) + fprintf(stderr, "mxmldoc: Unable to write \"%s\": %s\n", epubfile, strerror(errno)); } +#endif /* HAVE_ZLIB_H */ /*