Changed command line arguments
This commit is contained in:
@@ -15,11 +15,11 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifndef HAVE_TEMPLATE
|
#ifndef HAVE_MARKDOWN
|
||||||
#define HAVE_TEMPLATE
|
#define HAVE_MARKDOWN
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int parsetemplate(FILE *infile, FILE *outfile);
|
int parsemarkdown(FILE *infile, FILE *outfile);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
68
src/main.c
68
src/main.c
@@ -21,29 +21,20 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <html.h>
|
#include <html.h>
|
||||||
#include <template.h>
|
#include <markdown.h>
|
||||||
|
|
||||||
static void printhelp(FILE *file, char *name);
|
static void printhelp(FILE *file, char *name);
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
char *header, *template, *footer, *out;
|
int i;
|
||||||
|
char *out;
|
||||||
FILE *outfile;
|
FILE *outfile;
|
||||||
int c;
|
int c;
|
||||||
const char *filefailmsg = "Failed to open file %s\n";
|
|
||||||
|
|
||||||
header = template = footer = out = NULL;
|
out = NULL;
|
||||||
|
|
||||||
while ((c = getopt(argc, argv, "b:t:e:o:h")) >= 0) {
|
while ((c = getopt(argc, argv, "o:h")) >= 0) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'b':
|
|
||||||
header = optarg;
|
|
||||||
break;
|
|
||||||
case 't':
|
|
||||||
template = optarg;
|
|
||||||
break;
|
|
||||||
case 'e':
|
|
||||||
footer = optarg;
|
|
||||||
break;
|
|
||||||
case 'o':
|
case 'o':
|
||||||
out = optarg;
|
out = optarg;
|
||||||
break;
|
break;
|
||||||
@@ -61,54 +52,25 @@ int main(int argc, char **argv) {
|
|||||||
else
|
else
|
||||||
outfile = fopen(out, "w");
|
outfile = fopen(out, "w");
|
||||||
|
|
||||||
if (header != NULL) {
|
for (i = optind; i < argc; ++i) {
|
||||||
FILE *headerfile;
|
FILE *infile;
|
||||||
headerfile = fopen(header, "r");
|
infile = fopen(argv[i], "r");
|
||||||
if (headerfile != NULL) {
|
if (infile == NULL) {
|
||||||
if (copyhtml(headerfile, outfile)) {
|
fprintf(stderr, "Failed to open file %s\n", argv[i]);
|
||||||
fputs(filefailmsg, stderr);
|
return 1;
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
if (parsemarkdown(infile, outfile)) {
|
||||||
fprintf(stderr, filefailmsg, header);
|
fprintf(stderr, "Failed to parse file %s\n", argv[i]);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (template != NULL) {
|
|
||||||
FILE *templatefile;
|
|
||||||
templatefile = fopen(template, "r");
|
|
||||||
if (templatefile != NULL) {
|
|
||||||
if (parsetemplate(templatefile, outfile))
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fprintf(stderr, filefailmsg, template);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (footer != NULL) {
|
|
||||||
FILE *footerfile;
|
|
||||||
footerfile = fopen(footer, "r");
|
|
||||||
if (footerfile != NULL) {
|
|
||||||
if (copyhtml(footerfile, outfile)) {
|
|
||||||
fputs("Failed to copy footer\n", stderr);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fprintf(stderr, filefailmsg, footer);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (outfile != stdout)
|
|
||||||
fclose(outfile);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void printhelp(FILE *file, char *name) {
|
static void printhelp(FILE *file, char *name) {
|
||||||
fprintf(file,
|
fprintf(file,
|
||||||
"Usage: %s -b [header] -t [template] -e [footer] -o [output]\n", name);
|
"Usage: %s [file1.md] [file2.md] ... -o [output]\n", name);
|
||||||
fputs(
|
fputs(
|
||||||
"This program is free software. You can redistribute and/or modify it under\n"
|
"This program is free software. You can redistribute and/or modify it under\n"
|
||||||
"the terms of the GNU General Public License as published by the Free\n"
|
"the terms of the GNU General Public License as published by the Free\n"
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
#include <util.h>
|
#include <util.h>
|
||||||
#include <mdutil.h>
|
#include <mdutil.h>
|
||||||
#include <inlines.h>
|
#include <inlines.h>
|
||||||
#include <template.h>
|
#include <markdown.h>
|
||||||
|
|
||||||
struct parsestate {
|
struct parsestate {
|
||||||
struct linedata prev;
|
struct linedata prev;
|
||||||
@@ -43,7 +43,7 @@ static void handlehtmlcase(struct linedata *data, struct parsestate *state,
|
|||||||
static void handlehtmlmiddle(struct linedata *data, struct parsestate *state,
|
static void handlehtmlmiddle(struct linedata *data, struct parsestate *state,
|
||||||
char *line, FILE *out);
|
char *line, FILE *out);
|
||||||
|
|
||||||
int parsetemplate(FILE *infile, FILE *outfile) {
|
int parsemarkdown(FILE *infile, FILE *outfile) {
|
||||||
struct linefile *realin;
|
struct linefile *realin;
|
||||||
struct parsestate currstate;
|
struct parsestate currstate;
|
||||||
int code;
|
int code;
|
||||||
Reference in New Issue
Block a user