=================================================================== RCS file: /cvs/mandoc/mandocd.c,v retrieving revision 1.1 retrieving revision 1.12 diff -u -p -r1.1 -r1.12 --- mandoc/mandocd.c 2017/02/04 12:03:07 1.1 +++ mandoc/mandocd.c 2020/06/14 23:40:31 1.12 @@ -1,7 +1,7 @@ -/* $Id: mandocd.c,v 1.1 2017/02/04 12:03:07 schwarze Exp $ */ +/* $Id: mandocd.c,v 1.12 2020/06/14 23:40:31 schwarze Exp $ */ /* * Copyright (c) 2017 Michael Stapelberg - * Copyright (c) 2017 Ingo Schwarze + * Copyright (c) 2017, 2019 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -17,6 +17,10 @@ */ #include "config.h" +#if NEED_XPG4_2 +#define _XPG4_2 +#endif + #include #include @@ -24,6 +28,7 @@ #include #endif #include +#include #include #include #include @@ -33,6 +38,7 @@ #include "roff.h" #include "mdoc.h" #include "man.h" +#include "mandoc_parse.h" #include "main.h" #include "manconf.h" @@ -44,7 +50,7 @@ enum outt { static void process(struct mparse *, enum outt, void *); static int read_fds(int, int *); -static void usage(void) __attribute__((noreturn)); +static void usage(void) __attribute__((__noreturn__)); #define NUM_FDS 3 @@ -113,6 +119,7 @@ main(int argc, char *argv[]) struct manoutput options; struct mparse *parser; void *formatter; + const char *defos; const char *errstr; int clientfd; int old_stdin; @@ -122,9 +129,18 @@ main(int argc, char *argv[]) int state, opt; enum outt outtype; + defos = NULL; outtype = OUTT_ASCII; - while ((opt = getopt(argc, argv, "T:")) != -1) { + while ((opt = getopt(argc, argv, "I:T:")) != -1) { switch (opt) { + case 'I': + if (strncmp(optarg, "os=", 3) == 0) + defos = optarg + 3; + else { + warnx("-I %s: Bad argument", optarg); + usage(); + } + break; case 'T': if (strcmp(optarg, "ascii") == 0) outtype = OUTT_ASCII; @@ -155,8 +171,8 @@ main(int argc, char *argv[]) errx(1, "file descriptor %s %s", argv[1], errstr); mchars_alloc(); - parser = mparse_alloc(MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1, - MANDOCLEVEL_BADARG, NULL, NULL); + parser = mparse_alloc(MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1 | + MPARSE_VALIDATE, MANDOC_OS_OTHER, defos); memset(&options, 0, sizeof(options)); switch (outtype) { @@ -197,6 +213,8 @@ main(int argc, char *argv[]) process(parser, outtype, formatter); mparse_reset(parser); + if (outtype == OUTT_HTML) + html_reset(formatter); fflush(stdout); fflush(stderr); @@ -228,35 +246,29 @@ main(int argc, char *argv[]) static void process(struct mparse *parser, enum outt outtype, void *formatter) { - struct roff_man *man; + struct roff_meta *meta; mparse_readfd(parser, STDIN_FILENO, ""); - mparse_result(parser, &man, NULL); - - if (man == NULL) - return; - - if (man->macroset == MACROSET_MDOC) { - mdoc_validate(man); + meta = mparse_result(parser); + if (meta->macroset == MACROSET_MDOC) { switch (outtype) { case OUTT_ASCII: case OUTT_UTF8: - terminal_mdoc(formatter, man); + terminal_mdoc(formatter, meta); break; case OUTT_HTML: - html_mdoc(formatter, man); + html_mdoc(formatter, meta); break; } } - if (man->macroset == MACROSET_MAN) { - man_validate(man); + if (meta->macroset == MACROSET_MAN) { switch (outtype) { case OUTT_ASCII: case OUTT_UTF8: - terminal_man(formatter, man); + terminal_man(formatter, meta); break; case OUTT_HTML: - html_man(formatter, man); + html_man(formatter, meta); break; } } @@ -265,6 +277,6 @@ process(struct mparse *parser, enum outt outtype, void void usage(void) { - fprintf(stderr, "usage: mandocd [-T output] socket_fd\n"); + fprintf(stderr, "usage: mandocd [-I os=name] [-T output] socket_fd\n"); exit(1); }