1*698f87a4SGarrett D'Amore /* $Id: main.c,v 1.167 2012/11/19 17:22:26 schwarze Exp $ */ 295c635efSGarrett D'Amore /* 395c635efSGarrett D'Amore * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> 4*698f87a4SGarrett D'Amore * Copyright (c) 2010, 2011, 2012 Ingo Schwarze <schwarze@openbsd.org> 595c635efSGarrett D'Amore * 695c635efSGarrett D'Amore * Permission to use, copy, modify, and distribute this software for any 795c635efSGarrett D'Amore * purpose with or without fee is hereby granted, provided that the above 895c635efSGarrett D'Amore * copyright notice and this permission notice appear in all copies. 995c635efSGarrett D'Amore * 1095c635efSGarrett D'Amore * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1195c635efSGarrett D'Amore * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1295c635efSGarrett D'Amore * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1395c635efSGarrett D'Amore * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1495c635efSGarrett D'Amore * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1595c635efSGarrett D'Amore * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1695c635efSGarrett D'Amore * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1795c635efSGarrett D'Amore */ 1895c635efSGarrett D'Amore #ifdef HAVE_CONFIG_H 1995c635efSGarrett D'Amore #include "config.h" 2095c635efSGarrett D'Amore #endif 2195c635efSGarrett D'Amore 2295c635efSGarrett D'Amore #include <assert.h> 2395c635efSGarrett D'Amore #include <stdio.h> 2495c635efSGarrett D'Amore #include <stdint.h> 2595c635efSGarrett D'Amore #include <stdlib.h> 2695c635efSGarrett D'Amore #include <string.h> 2795c635efSGarrett D'Amore #include <unistd.h> 2895c635efSGarrett D'Amore 2995c635efSGarrett D'Amore #include "mandoc.h" 3095c635efSGarrett D'Amore #include "main.h" 3195c635efSGarrett D'Amore #include "mdoc.h" 3295c635efSGarrett D'Amore #include "man.h" 3395c635efSGarrett D'Amore 3495c635efSGarrett D'Amore #if !defined(__GNUC__) || (__GNUC__ < 2) 3595c635efSGarrett D'Amore # if !defined(lint) 3695c635efSGarrett D'Amore # define __attribute__(x) 3795c635efSGarrett D'Amore # endif 3895c635efSGarrett D'Amore #endif /* !defined(__GNUC__) || (__GNUC__ < 2) */ 3995c635efSGarrett D'Amore 4095c635efSGarrett D'Amore typedef void (*out_mdoc)(void *, const struct mdoc *); 4195c635efSGarrett D'Amore typedef void (*out_man)(void *, const struct man *); 4295c635efSGarrett D'Amore typedef void (*out_free)(void *); 4395c635efSGarrett D'Amore 4495c635efSGarrett D'Amore enum outt { 4595c635efSGarrett D'Amore OUTT_ASCII = 0, /* -Tascii */ 4695c635efSGarrett D'Amore OUTT_LOCALE, /* -Tlocale */ 4795c635efSGarrett D'Amore OUTT_UTF8, /* -Tutf8 */ 4895c635efSGarrett D'Amore OUTT_TREE, /* -Ttree */ 4995c635efSGarrett D'Amore OUTT_MAN, /* -Tman */ 5095c635efSGarrett D'Amore OUTT_HTML, /* -Thtml */ 5195c635efSGarrett D'Amore OUTT_XHTML, /* -Txhtml */ 5295c635efSGarrett D'Amore OUTT_LINT, /* -Tlint */ 5395c635efSGarrett D'Amore OUTT_PS, /* -Tps */ 5495c635efSGarrett D'Amore OUTT_PDF /* -Tpdf */ 5595c635efSGarrett D'Amore }; 5695c635efSGarrett D'Amore 5795c635efSGarrett D'Amore struct curparse { 5895c635efSGarrett D'Amore struct mparse *mp; 5995c635efSGarrett D'Amore enum mandoclevel wlevel; /* ignore messages below this */ 6095c635efSGarrett D'Amore int wstop; /* stop after a file with a warning */ 6195c635efSGarrett D'Amore enum outt outtype; /* which output to use */ 6295c635efSGarrett D'Amore out_mdoc outmdoc; /* mdoc output ptr */ 6395c635efSGarrett D'Amore out_man outman; /* man output ptr */ 6495c635efSGarrett D'Amore out_free outfree; /* free output ptr */ 6595c635efSGarrett D'Amore void *outdata; /* data for output */ 6695c635efSGarrett D'Amore char outopts[BUFSIZ]; /* buf of output opts */ 6795c635efSGarrett D'Amore }; 6895c635efSGarrett D'Amore 6995c635efSGarrett D'Amore static int moptions(enum mparset *, char *); 7095c635efSGarrett D'Amore static void mmsg(enum mandocerr, enum mandoclevel, 7195c635efSGarrett D'Amore const char *, int, int, const char *); 7295c635efSGarrett D'Amore static void parse(struct curparse *, int, 7395c635efSGarrett D'Amore const char *, enum mandoclevel *); 7495c635efSGarrett D'Amore static int toptions(struct curparse *, char *); 7595c635efSGarrett D'Amore static void usage(void) __attribute__((noreturn)); 7695c635efSGarrett D'Amore static void version(void) __attribute__((noreturn)); 7795c635efSGarrett D'Amore static int woptions(struct curparse *, char *); 7895c635efSGarrett D'Amore 7995c635efSGarrett D'Amore static const char *progname; 8095c635efSGarrett D'Amore 8195c635efSGarrett D'Amore int 8295c635efSGarrett D'Amore main(int argc, char *argv[]) 8395c635efSGarrett D'Amore { 8495c635efSGarrett D'Amore int c; 8595c635efSGarrett D'Amore struct curparse curp; 8695c635efSGarrett D'Amore enum mparset type; 8795c635efSGarrett D'Amore enum mandoclevel rc; 88*698f87a4SGarrett D'Amore char *defos; 8995c635efSGarrett D'Amore 9095c635efSGarrett D'Amore progname = strrchr(argv[0], '/'); 9195c635efSGarrett D'Amore if (progname == NULL) 9295c635efSGarrett D'Amore progname = argv[0]; 9395c635efSGarrett D'Amore else 9495c635efSGarrett D'Amore ++progname; 9595c635efSGarrett D'Amore 9695c635efSGarrett D'Amore memset(&curp, 0, sizeof(struct curparse)); 9795c635efSGarrett D'Amore 9895c635efSGarrett D'Amore type = MPARSE_AUTO; 9995c635efSGarrett D'Amore curp.outtype = OUTT_ASCII; 10095c635efSGarrett D'Amore curp.wlevel = MANDOCLEVEL_FATAL; 101*698f87a4SGarrett D'Amore defos = NULL; 10295c635efSGarrett D'Amore 10395c635efSGarrett D'Amore /* LINTED */ 104*698f87a4SGarrett D'Amore while (-1 != (c = getopt(argc, argv, "I:m:O:T:VW:"))) 10595c635efSGarrett D'Amore switch (c) { 106*698f87a4SGarrett D'Amore case ('I'): 107*698f87a4SGarrett D'Amore if (strncmp(optarg, "os=", 3)) { 108*698f87a4SGarrett D'Amore fprintf(stderr, "-I%s: Bad argument\n", 109*698f87a4SGarrett D'Amore optarg); 110*698f87a4SGarrett D'Amore return((int)MANDOCLEVEL_BADARG); 111*698f87a4SGarrett D'Amore } 112*698f87a4SGarrett D'Amore if (defos) { 113*698f87a4SGarrett D'Amore fprintf(stderr, "-I%s: Duplicate argument\n", 114*698f87a4SGarrett D'Amore optarg); 115*698f87a4SGarrett D'Amore return((int)MANDOCLEVEL_BADARG); 116*698f87a4SGarrett D'Amore } 117*698f87a4SGarrett D'Amore defos = mandoc_strdup(optarg + 3); 118*698f87a4SGarrett D'Amore break; 11995c635efSGarrett D'Amore case ('m'): 12095c635efSGarrett D'Amore if ( ! moptions(&type, optarg)) 12195c635efSGarrett D'Amore return((int)MANDOCLEVEL_BADARG); 12295c635efSGarrett D'Amore break; 12395c635efSGarrett D'Amore case ('O'): 12495c635efSGarrett D'Amore (void)strlcat(curp.outopts, optarg, BUFSIZ); 12595c635efSGarrett D'Amore (void)strlcat(curp.outopts, ",", BUFSIZ); 12695c635efSGarrett D'Amore break; 12795c635efSGarrett D'Amore case ('T'): 12895c635efSGarrett D'Amore if ( ! toptions(&curp, optarg)) 12995c635efSGarrett D'Amore return((int)MANDOCLEVEL_BADARG); 13095c635efSGarrett D'Amore break; 13195c635efSGarrett D'Amore case ('W'): 13295c635efSGarrett D'Amore if ( ! woptions(&curp, optarg)) 13395c635efSGarrett D'Amore return((int)MANDOCLEVEL_BADARG); 13495c635efSGarrett D'Amore break; 13595c635efSGarrett D'Amore case ('V'): 13695c635efSGarrett D'Amore version(); 13795c635efSGarrett D'Amore /* NOTREACHED */ 13895c635efSGarrett D'Amore default: 13995c635efSGarrett D'Amore usage(); 14095c635efSGarrett D'Amore /* NOTREACHED */ 14195c635efSGarrett D'Amore } 14295c635efSGarrett D'Amore 143*698f87a4SGarrett D'Amore curp.mp = mparse_alloc(type, curp.wlevel, mmsg, &curp, defos); 14495c635efSGarrett D'Amore 14595c635efSGarrett D'Amore /* 14695c635efSGarrett D'Amore * Conditionally start up the lookaside buffer before parsing. 14795c635efSGarrett D'Amore */ 14895c635efSGarrett D'Amore if (OUTT_MAN == curp.outtype) 14995c635efSGarrett D'Amore mparse_keep(curp.mp); 15095c635efSGarrett D'Amore 15195c635efSGarrett D'Amore argc -= optind; 15295c635efSGarrett D'Amore argv += optind; 15395c635efSGarrett D'Amore 15495c635efSGarrett D'Amore rc = MANDOCLEVEL_OK; 15595c635efSGarrett D'Amore 15695c635efSGarrett D'Amore if (NULL == *argv) 15795c635efSGarrett D'Amore parse(&curp, STDIN_FILENO, "<stdin>", &rc); 15895c635efSGarrett D'Amore 15995c635efSGarrett D'Amore while (*argv) { 16095c635efSGarrett D'Amore parse(&curp, -1, *argv, &rc); 16195c635efSGarrett D'Amore if (MANDOCLEVEL_OK != rc && curp.wstop) 16295c635efSGarrett D'Amore break; 16395c635efSGarrett D'Amore ++argv; 16495c635efSGarrett D'Amore } 16595c635efSGarrett D'Amore 16695c635efSGarrett D'Amore if (curp.outfree) 16795c635efSGarrett D'Amore (*curp.outfree)(curp.outdata); 16895c635efSGarrett D'Amore if (curp.mp) 16995c635efSGarrett D'Amore mparse_free(curp.mp); 170*698f87a4SGarrett D'Amore free(defos); 17195c635efSGarrett D'Amore 17295c635efSGarrett D'Amore return((int)rc); 17395c635efSGarrett D'Amore } 17495c635efSGarrett D'Amore 17595c635efSGarrett D'Amore static void 17695c635efSGarrett D'Amore version(void) 17795c635efSGarrett D'Amore { 17895c635efSGarrett D'Amore 17995c635efSGarrett D'Amore printf("%s %s\n", progname, VERSION); 18095c635efSGarrett D'Amore exit((int)MANDOCLEVEL_OK); 18195c635efSGarrett D'Amore } 18295c635efSGarrett D'Amore 18395c635efSGarrett D'Amore static void 18495c635efSGarrett D'Amore usage(void) 18595c635efSGarrett D'Amore { 18695c635efSGarrett D'Amore 18795c635efSGarrett D'Amore fprintf(stderr, "usage: %s " 18895c635efSGarrett D'Amore "[-V] " 189*698f87a4SGarrett D'Amore "[-Ios=name] " 19095c635efSGarrett D'Amore "[-mformat] " 19195c635efSGarrett D'Amore "[-Ooption] " 19295c635efSGarrett D'Amore "[-Toutput] " 193*698f87a4SGarrett D'Amore "[-Wlevel]\n" 194*698f87a4SGarrett D'Amore "\t [file ...]\n", 19595c635efSGarrett D'Amore progname); 19695c635efSGarrett D'Amore 19795c635efSGarrett D'Amore exit((int)MANDOCLEVEL_BADARG); 19895c635efSGarrett D'Amore } 19995c635efSGarrett D'Amore 20095c635efSGarrett D'Amore static void 20195c635efSGarrett D'Amore parse(struct curparse *curp, int fd, 20295c635efSGarrett D'Amore const char *file, enum mandoclevel *level) 20395c635efSGarrett D'Amore { 20495c635efSGarrett D'Amore enum mandoclevel rc; 20595c635efSGarrett D'Amore struct mdoc *mdoc; 20695c635efSGarrett D'Amore struct man *man; 20795c635efSGarrett D'Amore 20895c635efSGarrett D'Amore /* Begin by parsing the file itself. */ 20995c635efSGarrett D'Amore 21095c635efSGarrett D'Amore assert(file); 21195c635efSGarrett D'Amore assert(fd >= -1); 21295c635efSGarrett D'Amore 21395c635efSGarrett D'Amore rc = mparse_readfd(curp->mp, fd, file); 21495c635efSGarrett D'Amore 21595c635efSGarrett D'Amore /* Stop immediately if the parse has failed. */ 21695c635efSGarrett D'Amore 21795c635efSGarrett D'Amore if (MANDOCLEVEL_FATAL <= rc) 21895c635efSGarrett D'Amore goto cleanup; 21995c635efSGarrett D'Amore 22095c635efSGarrett D'Amore /* 22195c635efSGarrett D'Amore * With -Wstop and warnings or errors of at least the requested 22295c635efSGarrett D'Amore * level, do not produce output. 22395c635efSGarrett D'Amore */ 22495c635efSGarrett D'Amore 22595c635efSGarrett D'Amore if (MANDOCLEVEL_OK != rc && curp->wstop) 22695c635efSGarrett D'Amore goto cleanup; 22795c635efSGarrett D'Amore 22895c635efSGarrett D'Amore /* If unset, allocate output dev now (if applicable). */ 22995c635efSGarrett D'Amore 23095c635efSGarrett D'Amore if ( ! (curp->outman && curp->outmdoc)) { 23195c635efSGarrett D'Amore switch (curp->outtype) { 23295c635efSGarrett D'Amore case (OUTT_XHTML): 23395c635efSGarrett D'Amore curp->outdata = xhtml_alloc(curp->outopts); 23495c635efSGarrett D'Amore curp->outfree = html_free; 23595c635efSGarrett D'Amore break; 23695c635efSGarrett D'Amore case (OUTT_HTML): 23795c635efSGarrett D'Amore curp->outdata = html_alloc(curp->outopts); 23895c635efSGarrett D'Amore curp->outfree = html_free; 23995c635efSGarrett D'Amore break; 24095c635efSGarrett D'Amore case (OUTT_UTF8): 24195c635efSGarrett D'Amore curp->outdata = utf8_alloc(curp->outopts); 24295c635efSGarrett D'Amore curp->outfree = ascii_free; 24395c635efSGarrett D'Amore break; 24495c635efSGarrett D'Amore case (OUTT_LOCALE): 24595c635efSGarrett D'Amore curp->outdata = locale_alloc(curp->outopts); 24695c635efSGarrett D'Amore curp->outfree = ascii_free; 24795c635efSGarrett D'Amore break; 24895c635efSGarrett D'Amore case (OUTT_ASCII): 24995c635efSGarrett D'Amore curp->outdata = ascii_alloc(curp->outopts); 25095c635efSGarrett D'Amore curp->outfree = ascii_free; 25195c635efSGarrett D'Amore break; 25295c635efSGarrett D'Amore case (OUTT_PDF): 25395c635efSGarrett D'Amore curp->outdata = pdf_alloc(curp->outopts); 25495c635efSGarrett D'Amore curp->outfree = pspdf_free; 25595c635efSGarrett D'Amore break; 25695c635efSGarrett D'Amore case (OUTT_PS): 25795c635efSGarrett D'Amore curp->outdata = ps_alloc(curp->outopts); 25895c635efSGarrett D'Amore curp->outfree = pspdf_free; 25995c635efSGarrett D'Amore break; 26095c635efSGarrett D'Amore default: 26195c635efSGarrett D'Amore break; 26295c635efSGarrett D'Amore } 26395c635efSGarrett D'Amore 26495c635efSGarrett D'Amore switch (curp->outtype) { 26595c635efSGarrett D'Amore case (OUTT_HTML): 26695c635efSGarrett D'Amore /* FALLTHROUGH */ 26795c635efSGarrett D'Amore case (OUTT_XHTML): 26895c635efSGarrett D'Amore curp->outman = html_man; 26995c635efSGarrett D'Amore curp->outmdoc = html_mdoc; 27095c635efSGarrett D'Amore break; 27195c635efSGarrett D'Amore case (OUTT_TREE): 27295c635efSGarrett D'Amore curp->outman = tree_man; 27395c635efSGarrett D'Amore curp->outmdoc = tree_mdoc; 27495c635efSGarrett D'Amore break; 27595c635efSGarrett D'Amore case (OUTT_MAN): 27695c635efSGarrett D'Amore curp->outmdoc = man_mdoc; 27795c635efSGarrett D'Amore curp->outman = man_man; 27895c635efSGarrett D'Amore break; 27995c635efSGarrett D'Amore case (OUTT_PDF): 28095c635efSGarrett D'Amore /* FALLTHROUGH */ 28195c635efSGarrett D'Amore case (OUTT_ASCII): 28295c635efSGarrett D'Amore /* FALLTHROUGH */ 28395c635efSGarrett D'Amore case (OUTT_UTF8): 28495c635efSGarrett D'Amore /* FALLTHROUGH */ 28595c635efSGarrett D'Amore case (OUTT_LOCALE): 28695c635efSGarrett D'Amore /* FALLTHROUGH */ 28795c635efSGarrett D'Amore case (OUTT_PS): 28895c635efSGarrett D'Amore curp->outman = terminal_man; 28995c635efSGarrett D'Amore curp->outmdoc = terminal_mdoc; 29095c635efSGarrett D'Amore break; 29195c635efSGarrett D'Amore default: 29295c635efSGarrett D'Amore break; 29395c635efSGarrett D'Amore } 29495c635efSGarrett D'Amore } 29595c635efSGarrett D'Amore 29695c635efSGarrett D'Amore mparse_result(curp->mp, &mdoc, &man); 29795c635efSGarrett D'Amore 29895c635efSGarrett D'Amore /* Execute the out device, if it exists. */ 29995c635efSGarrett D'Amore 30095c635efSGarrett D'Amore if (man && curp->outman) 30195c635efSGarrett D'Amore (*curp->outman)(curp->outdata, man); 30295c635efSGarrett D'Amore if (mdoc && curp->outmdoc) 30395c635efSGarrett D'Amore (*curp->outmdoc)(curp->outdata, mdoc); 30495c635efSGarrett D'Amore 30595c635efSGarrett D'Amore cleanup: 30695c635efSGarrett D'Amore 30795c635efSGarrett D'Amore mparse_reset(curp->mp); 30895c635efSGarrett D'Amore 30995c635efSGarrett D'Amore if (*level < rc) 31095c635efSGarrett D'Amore *level = rc; 31195c635efSGarrett D'Amore } 31295c635efSGarrett D'Amore 31395c635efSGarrett D'Amore static int 31495c635efSGarrett D'Amore moptions(enum mparset *tflags, char *arg) 31595c635efSGarrett D'Amore { 31695c635efSGarrett D'Amore 31795c635efSGarrett D'Amore if (0 == strcmp(arg, "doc")) 31895c635efSGarrett D'Amore *tflags = MPARSE_MDOC; 31995c635efSGarrett D'Amore else if (0 == strcmp(arg, "andoc")) 32095c635efSGarrett D'Amore *tflags = MPARSE_AUTO; 32195c635efSGarrett D'Amore else if (0 == strcmp(arg, "an")) 32295c635efSGarrett D'Amore *tflags = MPARSE_MAN; 32395c635efSGarrett D'Amore else { 32495c635efSGarrett D'Amore fprintf(stderr, "%s: Bad argument\n", arg); 32595c635efSGarrett D'Amore return(0); 32695c635efSGarrett D'Amore } 32795c635efSGarrett D'Amore 32895c635efSGarrett D'Amore return(1); 32995c635efSGarrett D'Amore } 33095c635efSGarrett D'Amore 33195c635efSGarrett D'Amore static int 33295c635efSGarrett D'Amore toptions(struct curparse *curp, char *arg) 33395c635efSGarrett D'Amore { 33495c635efSGarrett D'Amore 33595c635efSGarrett D'Amore if (0 == strcmp(arg, "ascii")) 33695c635efSGarrett D'Amore curp->outtype = OUTT_ASCII; 33795c635efSGarrett D'Amore else if (0 == strcmp(arg, "lint")) { 33895c635efSGarrett D'Amore curp->outtype = OUTT_LINT; 33995c635efSGarrett D'Amore curp->wlevel = MANDOCLEVEL_WARNING; 34095c635efSGarrett D'Amore } else if (0 == strcmp(arg, "tree")) 34195c635efSGarrett D'Amore curp->outtype = OUTT_TREE; 34295c635efSGarrett D'Amore else if (0 == strcmp(arg, "man")) 34395c635efSGarrett D'Amore curp->outtype = OUTT_MAN; 34495c635efSGarrett D'Amore else if (0 == strcmp(arg, "html")) 34595c635efSGarrett D'Amore curp->outtype = OUTT_HTML; 34695c635efSGarrett D'Amore else if (0 == strcmp(arg, "utf8")) 34795c635efSGarrett D'Amore curp->outtype = OUTT_UTF8; 34895c635efSGarrett D'Amore else if (0 == strcmp(arg, "locale")) 34995c635efSGarrett D'Amore curp->outtype = OUTT_LOCALE; 35095c635efSGarrett D'Amore else if (0 == strcmp(arg, "xhtml")) 35195c635efSGarrett D'Amore curp->outtype = OUTT_XHTML; 35295c635efSGarrett D'Amore else if (0 == strcmp(arg, "ps")) 35395c635efSGarrett D'Amore curp->outtype = OUTT_PS; 35495c635efSGarrett D'Amore else if (0 == strcmp(arg, "pdf")) 35595c635efSGarrett D'Amore curp->outtype = OUTT_PDF; 35695c635efSGarrett D'Amore else { 35795c635efSGarrett D'Amore fprintf(stderr, "%s: Bad argument\n", arg); 35895c635efSGarrett D'Amore return(0); 35995c635efSGarrett D'Amore } 36095c635efSGarrett D'Amore 36195c635efSGarrett D'Amore return(1); 36295c635efSGarrett D'Amore } 36395c635efSGarrett D'Amore 36495c635efSGarrett D'Amore static int 36595c635efSGarrett D'Amore woptions(struct curparse *curp, char *arg) 36695c635efSGarrett D'Amore { 36795c635efSGarrett D'Amore char *v, *o; 36895c635efSGarrett D'Amore const char *toks[6]; 36995c635efSGarrett D'Amore 37095c635efSGarrett D'Amore toks[0] = "stop"; 37195c635efSGarrett D'Amore toks[1] = "all"; 37295c635efSGarrett D'Amore toks[2] = "warning"; 37395c635efSGarrett D'Amore toks[3] = "error"; 37495c635efSGarrett D'Amore toks[4] = "fatal"; 37595c635efSGarrett D'Amore toks[5] = NULL; 37695c635efSGarrett D'Amore 37795c635efSGarrett D'Amore while (*arg) { 37895c635efSGarrett D'Amore o = arg; 37995c635efSGarrett D'Amore switch (getsubopt(&arg, UNCONST(toks), &v)) { 38095c635efSGarrett D'Amore case (0): 38195c635efSGarrett D'Amore curp->wstop = 1; 38295c635efSGarrett D'Amore break; 38395c635efSGarrett D'Amore case (1): 38495c635efSGarrett D'Amore /* FALLTHROUGH */ 38595c635efSGarrett D'Amore case (2): 38695c635efSGarrett D'Amore curp->wlevel = MANDOCLEVEL_WARNING; 38795c635efSGarrett D'Amore break; 38895c635efSGarrett D'Amore case (3): 38995c635efSGarrett D'Amore curp->wlevel = MANDOCLEVEL_ERROR; 39095c635efSGarrett D'Amore break; 39195c635efSGarrett D'Amore case (4): 39295c635efSGarrett D'Amore curp->wlevel = MANDOCLEVEL_FATAL; 39395c635efSGarrett D'Amore break; 39495c635efSGarrett D'Amore default: 39595c635efSGarrett D'Amore fprintf(stderr, "-W%s: Bad argument\n", o); 39695c635efSGarrett D'Amore return(0); 39795c635efSGarrett D'Amore } 39895c635efSGarrett D'Amore } 39995c635efSGarrett D'Amore 40095c635efSGarrett D'Amore return(1); 40195c635efSGarrett D'Amore } 40295c635efSGarrett D'Amore 40395c635efSGarrett D'Amore static void 40495c635efSGarrett D'Amore mmsg(enum mandocerr t, enum mandoclevel lvl, 40595c635efSGarrett D'Amore const char *file, int line, int col, const char *msg) 40695c635efSGarrett D'Amore { 40795c635efSGarrett D'Amore 40895c635efSGarrett D'Amore fprintf(stderr, "%s:%d:%d: %s: %s", 40995c635efSGarrett D'Amore file, line, col + 1, 41095c635efSGarrett D'Amore mparse_strlevel(lvl), 41195c635efSGarrett D'Amore mparse_strerror(t)); 41295c635efSGarrett D'Amore 41395c635efSGarrett D'Amore if (msg) 41495c635efSGarrett D'Amore fprintf(stderr, ": %s", msg); 41595c635efSGarrett D'Amore 41695c635efSGarrett D'Amore fputc('\n', stderr); 41795c635efSGarrett D'Amore } 418