Allow user to select stylesheet from command line

This commit is contained in:
David Baer
2015-08-14 22:43:41 -04:00
parent 10927bee25
commit 83fad2f6c4
3 changed files with 13 additions and 6 deletions

View File

@@ -14,8 +14,9 @@ int main(int argc, char* argv[]) {
Sermon sermon;
xmlDocPtr document, transformed;
int i = 0, block = 0, normal = 0;
InitOptions(argc, argv);
InitOptions(argc, (const char**)argv);
InitSermon(&sermon);
if (strcmp(options.inputFileName, "-") == 0) {
yyin = stdin;
} else {
@@ -24,12 +25,12 @@ int main(int argc, char* argv[]) {
yyparse(&sermon);
document = sermonToXmlDoc(&sermon);
transformed = applyStyleSheet(document, "html5");
transformed = applyStyleSheet(document, options.styleSheetName);
printXML(transformed);
xmlFreeDoc(document);
xmlFreeDoc(transformed);
/* clean up, clean up, everybody, everywhere! */
xmlFreeDoc(document);
xmlFreeDoc(transformed);
FreeSermon(&sermon);
if (strcmp(options.inputFileName, "-") != 0) {
fclose(yyin);

View File

@@ -6,7 +6,7 @@
#include <libgen.h>
#include "options.h"
Options options = { .progname = NULL, .datadir = DATADIR };
Options options = { .progname = NULL, .datadir = DATADIR, .styleSheetName = "html5" };
char*
datadir(const char* progname) {
@@ -39,7 +39,8 @@ datadir(const char* progname) {
static void usage(const char* progname) {
fprintf(stderr, "Usage: %s [-h] FILE\n"
"\n"
" -h Display help message\n"
" -h Display help message\n"
" -s STYLESHEET Apply stylesheet (default \"html5\")\n"
"\n"
" FILE sermon file to scan (\"-\" for stdin)\n", progname);
}
@@ -52,6 +53,10 @@ void InitOptions(int argc, const char* argv[]) {
if (strcmp(argv[i], "-h") == 0) { usage(options.progname); exit(0); }
else if (strcmp(argv[i], "-") == 0) {
options.inputFileName = argv[i];
} else if (strcmp(argv[i], "-s") == 0) {
options.styleSheetName = argv[++i];
} else if (strncmp(argv[i], "-s", 2) == 0) {
options.styleSheetName = argv[i] + 2;
} else if (argv[i][0] == '-') {
fprintf(stderr, "Unknown option: %s\n", argv[i]);
} else {

View File

@@ -5,6 +5,7 @@ typedef struct {
const char* progname;
char* datadir;
const char* inputFileName;
const char* styleSheetName;
} Options;
extern Options options;