version 1.3, 2017/02/06 19:02:37 |
version 1.13, 2022/04/14 16:43:44 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2017 Michael Stapelberg <stapelberg@debian.org> |
* Copyright (c) 2017 Michael Stapelberg <stapelberg@debian.org> |
* Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2017, 2019, 2021 Ingo Schwarze <schwarze@openbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
*/ |
*/ |
#include "config.h" |
#include "config.h" |
|
|
|
#if NEED_XPG4_2 |
|
#define _XPG4_2 |
|
#endif |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#include <sys/socket.h> |
#include <sys/socket.h> |
|
|
|
|
#include <unistd.h> |
#include <unistd.h> |
|
|
#include "mandoc.h" |
#include "mandoc.h" |
|
#if DEBUG_MEMORY |
|
#define DEBUG_NODEF 1 |
|
#include "mandoc_dbg.h" |
|
#endif |
#include "roff.h" |
#include "roff.h" |
#include "mdoc.h" |
#include "mdoc.h" |
#include "man.h" |
#include "man.h" |
|
#include "mandoc_parse.h" |
#include "main.h" |
#include "main.h" |
#include "manconf.h" |
#include "manconf.h" |
|
|
|
|
|
|
static void process(struct mparse *, enum outt, void *); |
static void process(struct mparse *, enum outt, void *); |
static int read_fds(int, int *); |
static int read_fds(int, int *); |
static void usage(void) __attribute__((noreturn)); |
static void usage(void) __attribute__((__noreturn__)); |
|
|
|
|
#define NUM_FDS 3 |
#define NUM_FDS 3 |
Line 124 main(int argc, char *argv[]) |
|
Line 133 main(int argc, char *argv[]) |
|
int state, opt; |
int state, opt; |
enum outt outtype; |
enum outt outtype; |
|
|
|
#if DEBUG_MEMORY |
|
mandoc_dbg_init(argc, argv); |
|
#endif |
|
|
defos = NULL; |
defos = NULL; |
outtype = OUTT_ASCII; |
outtype = OUTT_ASCII; |
while ((opt = getopt(argc, argv, "I:T:")) != -1) { |
while ((opt = getopt(argc, argv, "I:T:")) != -1) { |
Line 166 main(int argc, char *argv[]) |
|
Line 179 main(int argc, char *argv[]) |
|
errx(1, "file descriptor %s %s", argv[1], errstr); |
errx(1, "file descriptor %s %s", argv[1], errstr); |
|
|
mchars_alloc(); |
mchars_alloc(); |
parser = mparse_alloc(MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1, |
parser = mparse_alloc(MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1 | |
MANDOCLEVEL_BADARG, NULL, defos); |
MPARSE_VALIDATE, MANDOC_OS_OTHER, defos); |
|
|
memset(&options, 0, sizeof(options)); |
memset(&options, 0, sizeof(options)); |
switch (outtype) { |
switch (outtype) { |
Line 208 main(int argc, char *argv[]) |
|
Line 221 main(int argc, char *argv[]) |
|
|
|
process(parser, outtype, formatter); |
process(parser, outtype, formatter); |
mparse_reset(parser); |
mparse_reset(parser); |
|
if (outtype == OUTT_HTML) |
|
html_reset(formatter); |
|
|
fflush(stdout); |
fflush(stdout); |
fflush(stderr); |
fflush(stderr); |
Line 233 main(int argc, char *argv[]) |
|
Line 248 main(int argc, char *argv[]) |
|
} |
} |
mparse_free(parser); |
mparse_free(parser); |
mchars_free(); |
mchars_free(); |
|
#if DEBUG_MEMORY |
|
mandoc_dbg_finish(); |
|
#endif |
return state == -1 ? 1 : 0; |
return state == -1 ? 1 : 0; |
} |
} |
|
|
static void |
static void |
process(struct mparse *parser, enum outt outtype, void *formatter) |
process(struct mparse *parser, enum outt outtype, void *formatter) |
{ |
{ |
struct roff_man *man; |
struct roff_meta *meta; |
|
|
mparse_readfd(parser, STDIN_FILENO, "<unixfd>"); |
mparse_readfd(parser, STDIN_FILENO, "<unixfd>"); |
mparse_result(parser, &man, NULL); |
meta = mparse_result(parser); |
|
if (meta->macroset == MACROSET_MDOC) { |
if (man == NULL) |
|
return; |
|
|
|
if (man->macroset == MACROSET_MDOC) { |
|
mdoc_validate(man); |
|
switch (outtype) { |
switch (outtype) { |
case OUTT_ASCII: |
case OUTT_ASCII: |
case OUTT_UTF8: |
case OUTT_UTF8: |
terminal_mdoc(formatter, man); |
terminal_mdoc(formatter, meta); |
break; |
break; |
case OUTT_HTML: |
case OUTT_HTML: |
html_mdoc(formatter, man); |
html_mdoc(formatter, meta); |
break; |
break; |
} |
} |
} |
} |
if (man->macroset == MACROSET_MAN) { |
if (meta->macroset == MACROSET_MAN) { |
man_validate(man); |
|
switch (outtype) { |
switch (outtype) { |
case OUTT_ASCII: |
case OUTT_ASCII: |
case OUTT_UTF8: |
case OUTT_UTF8: |
terminal_man(formatter, man); |
terminal_man(formatter, meta); |
break; |
break; |
case OUTT_HTML: |
case OUTT_HTML: |
html_man(formatter, man); |
html_man(formatter, meta); |
break; |
break; |
} |
} |
} |
} |