Enable writing ODT files with correct metadata

This commit is contained in:
David Baer
2016-06-30 14:01:55 -04:00
parent e7216708b6
commit 3b185cb32e
17 changed files with 413 additions and 48 deletions

View File

@@ -36,7 +36,9 @@
#include "options.h"
Options options = {
.progname = NULL, .datadir = DATADIR, .styleSheetName = "html5"
.progname = NULL, .datadir = DATADIR, .styleSheetName = NULL,
.outputFileName = "-", .placeName = "Highlands Presbyterian Church",
.authorName = "David A. Baer", .verbose = 0
};
char*
@@ -70,10 +72,14 @@ datadir(const char* progname) {
}
static void usage(const char* progname) {
fprintf(stderr, "Usage: %s [-h] [-s STYLESHEET] FILE\n"
fprintf(stderr, "Usage: %s [options] FILE\n"
"\n"
" -h Display help message\n"
" -s STYLESHEET Apply stylesheet (default \"html5\")\n"
"Options:\n"
" -h|--help Display this help message\n"
" -a|--author AUTHOR Author name\n"
" -o|--output OUTPUT Output file name\n"
" -s|--stylesheet STYLESHEET Apply stylesheet (default \"html5\")\n"
" -v|--verbose Verbose output\n"
"\n"
" FILE sermon file to scan (\"-\" for stdin)\n", progname);
}
@@ -83,13 +89,35 @@ void InitOptions(int argc, const char* argv[]) {
options.progname = argv[0];
options.datadir = datadir(options.progname);
while (++i < argc) {
if (strcmp(argv[i], "-h") == 0) { usage(options.progname); exit(0); }
else if (strcmp(argv[i], "-") == 0) {
if ((strcmp(argv[i], "-h") == 0) ||
(strcmp(argv[i], "--help") == 0)) {
usage(options.progname);
exit(0);
} else if (strcmp(argv[i], "-") == 0) {
options.inputFileName = argv[i];
} else if (strcmp(argv[i], "-s") == 0) {
} else if ((strcmp(argv[i], "-s") == 0) ||
(strcmp(argv[i], "--stylesheet") == 0)) {
options.styleSheetName = argv[++i];
} else if (strncmp(argv[i], "-s", 2) == 0) {
options.styleSheetName = argv[i] + 2;
} else if ((strcmp(argv[i], "-o") == 0) ||
(strcmp(argv[i], "--output") == 0)) {
options.outputFileName = argv[++i];
} else if (strncmp(argv[i], "-o", 2) == 0) {
options.outputFileName = argv[i] + 2;
} else if ((strcmp(argv[i], "-a") == 0) ||
(strcmp(argv[i], "--author") == 0)) {
options.authorName = argv[++i];
} else if (strncmp(argv[i], "-a", 2) == 0) {
options.authorName = argv[i] + 2;
} else if ((strcmp(argv[i], "-p") == 0) ||
(strcmp(argv[i], "--place") == 0)) {
options.placeName = argv[++i];
} else if (strncmp(argv[i], "-p", 2) == 0) {
options.placeName = argv[i] + 2;
} else if ((strcmp(argv[i], "-v") == 0) ||
(strcmp(argv[i], "--verbose") == 0)) {
options.verbose = 1;
} else if (argv[i][0] == '-') {
fprintf(stderr, "Unknown option: %s\n", argv[i]);
} else {
@@ -102,6 +130,23 @@ void InitOptions(int argc, const char* argv[]) {
usage(options.progname);
exit(1);
}
/* set stylesheet based on output file name */
if (!options.styleSheetName && options.outputFileName) {
char* outputExten = strrchr(options.outputFileName, '.');
if (outputExten) {
if (strcasecmp(outputExten, ".odt") == 0) {
options.styleSheetName = "odt";
} else if (strcasecmp(outputExten, ".html") == 0) {
options.styleSheetName = "html5";
}
}
}
/* default stylesheet is html5 */
if (!options.styleSheetName) {
options.styleSheetName = "html5";
}
}
char*