main.c revision 698f87a48e2e945bfe5493ce168e0d0ae1cedd5c
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore/* $Id: main.c,v 1.167 2012/11/19 17:22:26 schwarze Exp $ */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore * Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org>
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Permission to use, copy, modify, and distribute this software for any
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * purpose with or without fee is hereby granted, provided that the above
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * copyright notice and this permission notice appear in all copies.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore# if !defined(lint)
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore#endif /* !defined(__GNUC__) || (__GNUC__ < 2) */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoretypedef void (*out_mdoc)(void *, const struct mdoc *);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoretypedef void (*out_man)(void *, const struct man *);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amoretypedef void (*out_free)(void *);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore enum mandoclevel wlevel; /* ignore messages below this */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore int wstop; /* stop after a file with a warning */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore enum outt outtype; /* which output to use */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore char outopts[BUFSIZ]; /* buf of output opts */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void mmsg(enum mandocerr, enum mandoclevel,
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore const char *, int, int, const char *);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore const char *, enum mandoclevel *);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic int toptions(struct curparse *, char *);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void usage(void) __attribute__((noreturn));
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic void version(void) __attribute__((noreturn));
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic int woptions(struct curparse *, char *);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amorestatic const char *progname;
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore while (-1 != (c = getopt(argc, argv, "I:m:O:T:VW:")))
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore fprintf(stderr, "-I%s: Duplicate argument\n",
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore (void)strlcat(curp.outopts, optarg, BUFSIZ);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* NOTREACHED */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* NOTREACHED */
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore curp.mp = mparse_alloc(type, curp.wlevel, mmsg, &curp, defos);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * Conditionally start up the lookaside buffer before parsing.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore return((int)rc);
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore "[-Ios=name] "
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore "[-mformat] "
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore "[-Ooption] "
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore "[-Toutput] "
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore "[-Wlevel]\n"
698f87a48e2e945bfe5493ce168e0d0ae1cedd5cGarrett D'Amore "\t [file ...]\n",
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* Begin by parsing the file itself. */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* Stop immediately if the parse has failed. */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * With -Wstop and warnings or errors of at least the requested
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore * level, do not produce output.
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* If unset, allocate output dev now (if applicable). */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore curp->outdata = locale_alloc(curp->outopts);
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* FALLTHROUGH */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* FALLTHROUGH */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* FALLTHROUGH */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* FALLTHROUGH */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* FALLTHROUGH */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* Execute the out device, if it exists. */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore switch (getsubopt(&arg, UNCONST(toks), &v)) {
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore /* FALLTHROUGH */
95c635efb7c3b86efc493e0447eaec7aecca3f0fGarrett D'Amore const char *file, int line, int col, const char *msg)