mirror of
https://github.com/michaelrsweet/mxml.git
synced 2024-11-14 07:45:31 +00:00
Make EPUB generation conditional on the presence of ZLIB (again).
This commit is contained in:
parent
4d322880f4
commit
e6146472e6
12
Makefile.in
12
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
|
||||
|
11
configure
vendored
11
configure
vendored
@ -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,6 +4022,11 @@ $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"
|
||||
|
||||
$as_echo "#define HAVE_ZLIB_H 1" >>confdefs.h
|
||||
|
||||
ZIPC="zipc.o"
|
||||
MXML_EPUB="mxml.epub"
|
||||
LIBS="-lz $LIBS"
|
||||
fi
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
121
mxmldoc.c
121
mxmldoc.c
@ -20,7 +20,6 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "mxml.h"
|
||||
#include "zipc.h"
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#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");
|
||||
|
||||
// <item id="imgl" href="images/sample.png" media-type="image/png" />
|
||||
|
||||
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,16 +3890,28 @@ 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 ((epubf = zipcCreateFile(epub, "OEBPS/body.xhtml", 1)) != NULL)
|
||||
{
|
||||
if ((fp = fopen(xhtmlfile, "r")) != NULL)
|
||||
{
|
||||
char buffer[65536]; /* Copy buffer */
|
||||
@ -3968,16 +3923,18 @@ write_epub(const char *section, /* I - Section */
|
||||
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 ((epubf = zipcCreateFile(epub, "OEBPS/nav.xhtml", 1)) != NULL)
|
||||
{
|
||||
if ((fp = fopen(toc_xhtmlfile, "r")) != NULL)
|
||||
{
|
||||
char buffer[65536]; /* Copy buffer */
|
||||
@ -3989,10 +3946,18 @@ write_epub(const char *section, /* I - Section */
|
||||
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 */
|
||||
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user