X-Git-Url: https://git.cameronkatri.com/mandoc.git/blobdiff_plain/7caa51ee5a0c6624eb97d1d6bf06b84bdbd7f034..9d70ad9e783183f60b7bf9ded3496003a1298237:/mmain.c diff --git a/mmain.c b/mmain.c index 370d23f8..5932d0ac 100644 --- a/mmain.c +++ b/mmain.c @@ -1,4 +1,4 @@ - /* $Id: mmain.c,v 1.2 2009/02/23 07:09:13 kristaps Exp $ */ + /* $Id: mmain.c,v 1.6 2009/03/08 11:41:22 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -44,11 +44,13 @@ struct mmain { u_long bufsz; /* Input buffer size. */ char *in; /* Input file name. */ int fdin; /* Input file desc. */ + int pflags; /* Parse flags. */ }; extern char *__progname; -static int getsopts(struct mmain *, char *); +static int optswarn(struct mmain *, char *); +static int optsopt(struct mmain *, char *); static int parse(struct mmain *); static void msg_msg(void *, int, int, const char *); static int msg_err(void *, int, int, const char *); @@ -57,6 +59,8 @@ static int msg_warn(void *, int, int, #ifdef __linux__ extern int getsubopt(char **, char *const *, char **); +extern size_t strlcpy(char *, const char *, size_t); +extern size_t strlcat(char *, const char *, size_t); #endif @@ -106,9 +110,8 @@ mmain_getopt(struct mmain *p, int argc, char *argv[], size_t sz; extern int optind; - extern int optreset; - sz = strlcpy(opts, "vW:", 32); + sz = strlcpy(opts, "VvW:f:", 32); assert(sz < 32); if (u) { @@ -116,24 +119,33 @@ mmain_getopt(struct mmain *p, int argc, char *argv[], assert(sz < 32); } + optind = 1; + /* LINTED */ while (-1 != (c = getopt(argc, argv, opts))) switch (c) { + case ('f'): + if ( ! optsopt(p, optarg)) + return(-1); + break; case ('v'): p->dbg++; break; + case ('V'): + (void)printf("%s %s\n", __progname, VERSION); + return(0); case ('W'): - if ( ! getsopts(p, optarg)) - return(0); + if ( ! optswarn(p, optarg)) + return(-1); break; case ('?'): mmain_usage(help); - return(0); + return(-1); default: assert(getopt_cb); if ((*getopt_cb)(arg, c, optarg)) break; - return(0); + return(-1); } argv += optind; @@ -144,8 +156,8 @@ mmain_getopt(struct mmain *p, int argc, char *argv[], } -__dead void -mmain_exit(struct mmain *p, int code) +dead_pre void +mmain_exit(struct mmain *p, int code) { if (p->mdoc) @@ -202,7 +214,26 @@ mmain_mdoc(struct mmain *p) static int -getsopts(struct mmain *p, char *arg) +optsopt(struct mmain *p, char *arg) +{ + char *v; + char *toks[] = { "ignore-scope", NULL }; + + while (*arg) + switch (getsubopt(&arg, toks, &v)) { + case (0): + p->pflags |= MDOC_IGN_SCOPE; + break; + default: + return(0); + } + + return(1); +} + + +static int +optswarn(struct mmain *p, char *arg) { char *v; char *toks[] = { "all", "compat",