Use stylesheet transformations to output HTML, for example

This commit is contained in:
David Baer
2015-08-11 15:33:08 -04:00
parent cfc0ba7e9a
commit 10927bee25
19 changed files with 725 additions and 92 deletions

View File

@@ -2,73 +2,38 @@
#include <stdlib.h>
#include <string.h>
#include <libxml/tree.h>
#include "options.h"
#include "sermon.h"
#include "xml.h"
#include "xslt.h"
extern int yyparse(Sermon *);
extern FILE* yyin;
void usage(const char* progname) {
fprintf(stderr, "Usage: %s [-h] FILE\n"
"\n"
" -h Display help message\n"
"\n"
" FILE sermon file to scan\n", progname);
}
int main(int argc, char* argv[]) {
Sermon sermon;
xmlDocPtr document;
xmlDocPtr document, transformed;
int i = 0, block = 0, normal = 0;
const char* progname = argv[0], *filename = NULL;
while (++i < argc) {
if (strcmp(argv[i], "-h") == 0) { usage(progname); exit(0); }
else if ((argv[i][0] == '-') && (argv[i][1] != '\0')) {
fprintf(stderr, "Unknown option: %s\n", argv[i]);
}
else {
filename = argv[i];
}
}
if (!filename) {
usage(progname);
exit(1);
}
InitOptions(argc, argv);
InitSermon(&sermon);
if (strcmp(filename, "-") == 0) {
if (strcmp(options.inputFileName, "-") == 0) {
yyin = stdin;
} else {
yyin = fopen(argv[1], "rt");
yyin = fopen(options.inputFileName, "rt");
}
yyparse(&sermon);
/*
printf("Parsed sermon.\n");
printf("TITLE=%s\n", sermon.sermonTitle ? sermon.sermonTitle : "none");
printf("AUTHOR=%s\n", sermon.sermonAuthor ? sermon.sermonAuthor : "none");
printf("DATE=%s\n", sermon.sermonDate ? sermon.sermonDate : "none");
printf("OCCASION=%s\n", sermon.sermonOccasion ? sermon.sermonOccasion : "none");
printf("TEXT=%s\n", sermon.sermonText ? sermon.sermonText : "none");
printf("\nThere are %d paragraphs", sermon.numParagraphs);
for (i = 0; i < sermon.numParagraphs; i++) {
if (sermon.sermonParagraphs[i].paraType == PARA_DEFAULT) normal++;
else if (sermon.sermonParagraphs[i].paraType == PARA_BLOCKQUOTE) block++;
}
printf(" (%d regular, %d blockquote)\n", normal, block);
printf("\nThere are %d references.\n", sermon.numReferences);
for (i = 0; i < sermon.numReferences; i++) {
printf(" - %s: %s\n", sermon.sermonReferences[i].refId, sermon.sermonReferences[i].refText);
}
printf("\n");
*/
document = sermonToXmlDoc(&sermon);
printXML(document);
transformed = applyStyleSheet(document, "html5");
printXML(transformed);
xmlFreeDoc(document);
xmlFreeDoc(transformed);
/* clean up, clean up, everybody, everywhere! */
FreeSermon(&sermon);
if (strcmp(filename, "-") != 0) {
if (strcmp(options.inputFileName, "-") != 0) {
fclose(yyin);
}
FreeOptions();
}