Allow user to select stylesheet from command line
This commit is contained in:
@@ -14,8 +14,9 @@ int main(int argc, char* argv[]) {
|
|||||||
Sermon sermon;
|
Sermon sermon;
|
||||||
xmlDocPtr document, transformed;
|
xmlDocPtr document, transformed;
|
||||||
int i = 0, block = 0, normal = 0;
|
int i = 0, block = 0, normal = 0;
|
||||||
InitOptions(argc, argv);
|
InitOptions(argc, (const char**)argv);
|
||||||
InitSermon(&sermon);
|
InitSermon(&sermon);
|
||||||
|
|
||||||
if (strcmp(options.inputFileName, "-") == 0) {
|
if (strcmp(options.inputFileName, "-") == 0) {
|
||||||
yyin = stdin;
|
yyin = stdin;
|
||||||
} else {
|
} else {
|
||||||
@@ -24,12 +25,12 @@ int main(int argc, char* argv[]) {
|
|||||||
yyparse(&sermon);
|
yyparse(&sermon);
|
||||||
|
|
||||||
document = sermonToXmlDoc(&sermon);
|
document = sermonToXmlDoc(&sermon);
|
||||||
transformed = applyStyleSheet(document, "html5");
|
transformed = applyStyleSheet(document, options.styleSheetName);
|
||||||
printXML(transformed);
|
printXML(transformed);
|
||||||
xmlFreeDoc(document);
|
|
||||||
xmlFreeDoc(transformed);
|
|
||||||
|
|
||||||
/* clean up, clean up, everybody, everywhere! */
|
/* clean up, clean up, everybody, everywhere! */
|
||||||
|
xmlFreeDoc(document);
|
||||||
|
xmlFreeDoc(transformed);
|
||||||
FreeSermon(&sermon);
|
FreeSermon(&sermon);
|
||||||
if (strcmp(options.inputFileName, "-") != 0) {
|
if (strcmp(options.inputFileName, "-") != 0) {
|
||||||
fclose(yyin);
|
fclose(yyin);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
Options options = { .progname = NULL, .datadir = DATADIR };
|
Options options = { .progname = NULL, .datadir = DATADIR, .styleSheetName = "html5" };
|
||||||
|
|
||||||
char*
|
char*
|
||||||
datadir(const char* progname) {
|
datadir(const char* progname) {
|
||||||
@@ -39,7 +39,8 @@ datadir(const char* progname) {
|
|||||||
static void usage(const char* progname) {
|
static void usage(const char* progname) {
|
||||||
fprintf(stderr, "Usage: %s [-h] FILE\n"
|
fprintf(stderr, "Usage: %s [-h] FILE\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -h Display help message\n"
|
" -h Display help message\n"
|
||||||
|
" -s STYLESHEET Apply stylesheet (default \"html5\")\n"
|
||||||
"\n"
|
"\n"
|
||||||
" FILE sermon file to scan (\"-\" for stdin)\n", progname);
|
" 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); }
|
if (strcmp(argv[i], "-h") == 0) { usage(options.progname); exit(0); }
|
||||||
else if (strcmp(argv[i], "-") == 0) {
|
else if (strcmp(argv[i], "-") == 0) {
|
||||||
options.inputFileName = argv[i];
|
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] == '-') {
|
} else if (argv[i][0] == '-') {
|
||||||
fprintf(stderr, "Unknown option: %s\n", argv[i]);
|
fprintf(stderr, "Unknown option: %s\n", argv[i]);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ typedef struct {
|
|||||||
const char* progname;
|
const char* progname;
|
||||||
char* datadir;
|
char* datadir;
|
||||||
const char* inputFileName;
|
const char* inputFileName;
|
||||||
|
const char* styleSheetName;
|
||||||
} Options;
|
} Options;
|
||||||
|
|
||||||
extern Options options;
|
extern Options options;
|
||||||
|
|||||||
Reference in New Issue
Block a user