scdoc2mdoc

A fork of scdoc to output mdoc(7)
git clone git://git.sgregoratto.me/scdoc2mdoc
Log | Files | Refs | README | LICENSE

commit 01bbb8cb4538bb23aa152a59d77c8eb2129d41db
parent 8facd63447a77f450162a9cedfb4f1759bed7c72
Author: Stephen Gregoratto <dev@sgregoratto.me>
Date:   Sun, 16 Jun 2019 20:22:27 +1000

support reading files from arguments

Diffstat:
MMakefile | 6+++---
Mmain.c | 23++++++++++++++++-------
2 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/Makefile b/Makefile @@ -9,14 +9,14 @@ scdoc: $(OBJS) $(CC) -g -o $@ $(OBJS) scdoc.1: scdoc.1.scd scdoc - ./scdoc < scdoc.1.scd > $@ + ./scdoc scdoc.1.scd > $@ scdoc.5: scdoc.5.scd scdoc - ./scdoc < scdoc.5.scd > $@ + ./scdoc scdoc.5.scd > $@ scdoc.pc: scdoc.pc.in sed -e 's:@prefix@:$(PREFIX):g' \ - -e 's:@version@:$(VERSION):g' < scdoc.pc.in > $@ + -e 's:@version@:$(VERSION):g' scdoc.pc.in > $@ main.o: str.h utf8.h util.h string.o: str.h utf8.h diff --git a/main.c b/main.c @@ -719,15 +719,21 @@ output_scdoc_preamble(struct parser *p) int main(int argc, char **argv) { - if (argc == 2 && strcmp(argv[1], "-v") == 0) { - printf("scdoc " VERSION "\n"); - return 0; - } else if (argc > 1) { - fputs("Usage: scdoc < input.scd > output.roff", stderr); - return 1; + FILE *input; + if (argc > 2) { + fprintf(stderr, "%s: Too many arguments\n", argv[2]); + goto usage; + } else if (argc == 2) { + if ((input = fopen(argv[1], "r")) == NULL) { + fprintf(stderr, "cannot open file %s, exiting\n", argv[1]); + return 1; + } + } else { + input = stdin; } + struct parser p = { - .input = stdin, + .input = input, .output = stdout, .line = 1, .col = 1 @@ -736,4 +742,7 @@ main(int argc, char **argv) parse_preamble(&p); parse_document(&p); return 0; +usage: + fputs("usage: scdoc [file]\n", stderr); + return 1; }