]> git.cameronkatri.com Git - mandoc.git/blobdiff - main.c
style message about missing .Fn markup; inspired by mdoclint
[mandoc.git] / main.c
diff --git a/main.c b/main.c
index 460fd05dc0b240b3e3901ba368e48ae44704596a..6a99ba2f5d1aa5965c7d80d1e9f5ca6a29d48f3c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
-/*     $Id: main.c,v 1.281 2017/02/10 15:45:28 schwarze Exp $ */
+/*     $Id: main.c,v 1.292 2017/06/03 12:17:25 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010-2012, 2014-2017 Ingo Schwarze <schwarze@openbsd.org>
 /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010-2012, 2014-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -56,7 +56,6 @@ enum  outmode {
        OUTMODE_FLN,
        OUTMODE_LST,
        OUTMODE_ALL,
        OUTMODE_FLN,
        OUTMODE_LST,
        OUTMODE_ALL,
-       OUTMODE_INT,
        OUTMODE_ONE
 };
 
        OUTMODE_ONE
 };
 
@@ -67,6 +66,7 @@ enum  outt {
        OUTT_TREE,      /* -Ttree */
        OUTT_MAN,       /* -Tman */
        OUTT_HTML,      /* -Thtml */
        OUTT_TREE,      /* -Ttree */
        OUTT_MAN,       /* -Tman */
        OUTT_HTML,      /* -Thtml */
+       OUTT_MARKDOWN,  /* -Tmarkdown */
        OUTT_LINT,      /* -Tlint */
        OUTT_PS,        /* -Tps */
        OUTT_PDF        /* -Tpdf */
        OUTT_LINT,      /* -Tlint */
        OUTT_PS,        /* -Tps */
        OUTT_PDF        /* -Tpdf */
@@ -92,7 +92,7 @@ static        void              fs_search(const struct mansearch *,
                                const struct manpaths *, int, char**,
                                struct manpage **, size_t *);
 static int               koptions(int *, char *);
                                const struct manpaths *, int, char**,
                                struct manpage **, size_t *);
 static int               koptions(int *, char *);
-static int               moptions(int *, char *);
+static void              moptions(int *, char *);
 static void              mmsg(enum mandocerr, enum mandoclevel,
                                const char *, int, int, const char *);
 static void              outdata_alloc(struct curparse *);
 static void              mmsg(enum mandocerr, enum mandoclevel,
                                const char *, int, int, const char *);
 static void              outdata_alloc(struct curparse *);
@@ -100,7 +100,7 @@ static      void              parse(struct curparse *, int, const char *);
 static void              passthrough(const char *, int, int);
 static pid_t             spawn_pager(struct tag_files *);
 static int               toptions(struct curparse *, char *);
 static void              passthrough(const char *, int, int);
 static pid_t             spawn_pager(struct tag_files *);
 static int               toptions(struct curparse *, char *);
-static void              usage(enum argmode) __attribute__((noreturn));
+static void              usage(enum argmode) __attribute__((__noreturn__));
 static int               woptions(struct curparse *, char *);
 
 static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
 static int               woptions(struct curparse *, char *);
 
 static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9};
@@ -113,17 +113,14 @@ int
 main(int argc, char *argv[])
 {
        struct manconf   conf;
 main(int argc, char *argv[])
 {
        struct manconf   conf;
-       struct curparse  curp;
        struct mansearch search;
        struct mansearch search;
+       struct curparse  curp;
        struct tag_files *tag_files;
        struct tag_files *tag_files;
-       const char      *progname;
-       char            *auxpaths;
-       char            *defos;
-       unsigned char   *uc;
        struct manpage  *res, *resp;
        struct manpage  *res, *resp;
-       char            *conf_file, *defpaths;
-       const char      *sec;
-       const char      *thisarg;
+       const char      *progname, *sec, *thisarg;
+       char            *conf_file, *defpaths, *auxpaths;
+       char            *defos, *oarg;
+       unsigned char   *uc;
        size_t           i, sz;
        int              prio, best_prio;
        enum outmode     outmode;
        size_t           i, sz;
        int              prio, best_prio;
        enum outmode     outmode;
@@ -152,7 +149,7 @@ main(int argc, char *argv[])
                return mandocdb(argc, argv);
 
 #if HAVE_PLEDGE
                return mandocdb(argc, argv);
 
 #if HAVE_PLEDGE
-       if (pledge("stdio rpath tmppath tty proc exec flock", NULL) == -1)
+       if (pledge("stdio rpath tmppath tty proc exec", NULL) == -1)
                err((int)MANDOCLEVEL_SYSERR, "pledge");
 #endif
 
                err((int)MANDOCLEVEL_SYSERR, "pledge");
 #endif
 
@@ -169,6 +166,7 @@ main(int argc, char *argv[])
 
        memset(&search, 0, sizeof(struct mansearch));
        search.outkey = "Nd";
 
        memset(&search, 0, sizeof(struct mansearch));
        search.outkey = "Nd";
+       oarg = NULL;
 
        if (strcmp(progname, BINM_MAN) == 0)
                search.argmode = ARG_NAME;
 
        if (strcmp(progname, BINM_MAN) == 0)
                search.argmode = ARG_NAME;
@@ -195,8 +193,12 @@ main(int argc, char *argv[])
        show_usage = 0;
        outmode = OUTMODE_DEF;
 
        show_usage = 0;
        outmode = OUTMODE_DEF;
 
-       while (-1 != (c = getopt(argc, argv,
-                       "aC:cfhI:iK:klM:m:O:S:s:T:VW:w"))) {
+       while ((c = getopt(argc, argv,
+           "aC:cfhI:iK:klM:m:O:S:s:T:VW:w")) != -1) {
+               if (c == 'i' && search.argmode == ARG_EXPR) {
+                       optind--;
+                       break;
+               }
                switch (c) {
                case 'a':
                        outmode = OUTMODE_ALL;
                switch (c) {
                case 'a':
                        outmode = OUTMODE_ALL;
@@ -226,9 +228,6 @@ main(int argc, char *argv[])
                        }
                        defos = mandoc_strdup(optarg + 3);
                        break;
                        }
                        defos = mandoc_strdup(optarg + 3);
                        break;
-               case 'i':
-                       outmode = OUTMODE_INT;
-                       break;
                case 'K':
                        if ( ! koptions(&options, optarg))
                                return (int)MANDOCLEVEL_BADARG;
                case 'K':
                        if ( ! koptions(&options, optarg))
                                return (int)MANDOCLEVEL_BADARG;
@@ -247,15 +246,7 @@ main(int argc, char *argv[])
                        auxpaths = optarg;
                        break;
                case 'O':
                        auxpaths = optarg;
                        break;
                case 'O':
-                       search.outkey = optarg;
-                       while (optarg != NULL) {
-                               thisarg = optarg;
-                               if (manconf_output(&conf.output,
-                                   strsep(&optarg, ","), 0) == 0)
-                                       continue;
-                               warnx("-O %s: Bad argument", thisarg);
-                               return (int)MANDOCLEVEL_BADARG;
-                       }
+                       oarg = optarg;
                        break;
                case 'S':
                        search.arch = optarg;
                        break;
                case 'S':
                        search.arch = optarg;
@@ -300,6 +291,21 @@ main(int argc, char *argv[])
                }
        }
 
                }
        }
 
+       if (oarg != NULL) {
+               if (outmode == OUTMODE_LST)
+                       search.outkey = oarg;
+               else {
+                       while (oarg != NULL) {
+                               thisarg = oarg;
+                               if (manconf_output(&conf.output,
+                                   strsep(&oarg, ","), 0) == 0)
+                                       continue;
+                               warnx("-O %s: Bad argument", thisarg);
+                               return (int)MANDOCLEVEL_BADARG;
+                       }
+               }
+       }
+
        if (outmode == OUTMODE_FLN ||
            outmode == OUTMODE_LST ||
            !isatty(STDOUT_FILENO))
        if (outmode == OUTMODE_FLN ||
            outmode == OUTMODE_LST ||
            !isatty(STDOUT_FILENO))
@@ -307,7 +313,7 @@ main(int argc, char *argv[])
 
 #if HAVE_PLEDGE
        if (!use_pager)
 
 #if HAVE_PLEDGE
        if (!use_pager)
-               if (pledge("stdio rpath flock", NULL) == -1)
+               if (pledge("stdio rpath", NULL) == -1)
                        err((int)MANDOCLEVEL_SYSERR, "pledge");
 #endif
 
                        err((int)MANDOCLEVEL_SYSERR, "pledge");
 #endif
 
@@ -436,8 +442,8 @@ main(int argc, char *argv[])
        }
 #endif
 
        }
 #endif
 
-       if (search.argmode == ARG_FILE && ! moptions(&options, auxpaths))
-               return (int)MANDOCLEVEL_BADARG;
+       if (search.argmode == ARG_FILE)
+               moptions(&options, auxpaths);
 
        mchars_alloc();
        curp.mp = mparse_alloc(options, curp.wlevel, mmsg, defos);
 
        mchars_alloc();
        curp.mp = mparse_alloc(options, curp.wlevel, mmsg, defos);
@@ -586,24 +592,22 @@ usage(enum argmode argmode)
 
        switch (argmode) {
        case ARG_FILE:
 
        switch (argmode) {
        case ARG_FILE:
-               fputs("usage: mandoc [-acfhkl] [-I os=name] "
-                   "[-K encoding] [-mformat] [-O option]\n"
+               fputs("usage: mandoc [-ac] [-I os=name] "
+                   "[-K encoding] [-mdoc | -man] [-O options]\n"
                    "\t      [-T output] [-W level] [file ...]\n", stderr);
                break;
        case ARG_NAME:
                    "\t      [-T output] [-W level] [file ...]\n", stderr);
                break;
        case ARG_NAME:
-               fputs("usage: man [-acfhklw] [-C file] [-I os=name] "
-                   "[-K encoding] [-M path] [-m path]\n"
-                   "\t   [-O option=value] [-S subsection] [-s section] "
-                   "[-T output] [-W level]\n"
-                   "\t   [section] name ...\n", stderr);
+               fputs("usage: man [-acfhklw] [-C file] [-M path] "
+                   "[-m path] [-S subsection]\n"
+                   "\t   [[-s] section] name ...\n", stderr);
                break;
        case ARG_WORD:
                break;
        case ARG_WORD:
-               fputs("usage: whatis [-acfhklw] [-C file] "
+               fputs("usage: whatis [-afk] [-C file] "
                    "[-M path] [-m path] [-O outkey] [-S arch]\n"
                    "\t      [-s section] name ...\n", stderr);
                break;
        case ARG_EXPR:
                    "[-M path] [-m path] [-O outkey] [-S arch]\n"
                    "\t      [-s section] name ...\n", stderr);
                break;
        case ARG_EXPR:
-               fputs("usage: apropos [-acfhklw] [-C file] "
+               fputs("usage: apropos [-afk] [-C file] "
                    "[-M path] [-m path] [-O outkey] [-S arch]\n"
                    "\t       [-s section] expression ...\n", stderr);
                break;
                    "[-M path] [-m path] [-O outkey] [-S arch]\n"
                    "\t       [-s section] expression ...\n", stderr);
                break;
@@ -761,6 +765,9 @@ parse(struct curparse *curp, int fd, const char *file)
                case OUTT_PS:
                        terminal_mdoc(curp->outdata, man);
                        break;
                case OUTT_PS:
                        terminal_mdoc(curp->outdata, man);
                        break;
+               case OUTT_MARKDOWN:
+                       markdown_mdoc(curp->outdata, man);
+                       break;
                default:
                        break;
                }
                default:
                        break;
                }
@@ -910,24 +917,16 @@ koptions(int *options, char *arg)
        return 1;
 }
 
        return 1;
 }
 
-static int
+static void
 moptions(int *options, char *arg)
 {
 
        if (arg == NULL)
 moptions(int *options, char *arg)
 {
 
        if (arg == NULL)
-               /* nothing to do */;
-       else if (0 == strcmp(arg, "doc"))
+               return;
+       if (strcmp(arg, "doc") == 0)
                *options |= MPARSE_MDOC;
                *options |= MPARSE_MDOC;
-       else if (0 == strcmp(arg, "andoc"))
-               /* nothing to do */;
-       else if (0 == strcmp(arg, "an"))
+       else if (strcmp(arg, "an") == 0)
                *options |= MPARSE_MAN;
                *options |= MPARSE_MAN;
-       else {
-               warnx("-m %s: Bad argument", arg);
-               return 0;
-       }
-
-       return 1;
 }
 
 static int
 }
 
 static int
@@ -938,19 +937,19 @@ toptions(struct curparse *curp, char *arg)
                curp->outtype = OUTT_ASCII;
        else if (0 == strcmp(arg, "lint")) {
                curp->outtype = OUTT_LINT;
                curp->outtype = OUTT_ASCII;
        else if (0 == strcmp(arg, "lint")) {
                curp->outtype = OUTT_LINT;
-               curp->wlevel  = MANDOCLEVEL_WARNING;
+               curp->wlevel  = MANDOCLEVEL_STYLE;
        } else if (0 == strcmp(arg, "tree"))
                curp->outtype = OUTT_TREE;
        else if (0 == strcmp(arg, "man"))
                curp->outtype = OUTT_MAN;
        else if (0 == strcmp(arg, "html"))
                curp->outtype = OUTT_HTML;
        } else if (0 == strcmp(arg, "tree"))
                curp->outtype = OUTT_TREE;
        else if (0 == strcmp(arg, "man"))
                curp->outtype = OUTT_MAN;
        else if (0 == strcmp(arg, "html"))
                curp->outtype = OUTT_HTML;
+       else if (0 == strcmp(arg, "markdown"))
+               curp->outtype = OUTT_MARKDOWN;
        else if (0 == strcmp(arg, "utf8"))
                curp->outtype = OUTT_UTF8;
        else if (0 == strcmp(arg, "locale"))
                curp->outtype = OUTT_LOCALE;
        else if (0 == strcmp(arg, "utf8"))
                curp->outtype = OUTT_UTF8;
        else if (0 == strcmp(arg, "locale"))
                curp->outtype = OUTT_LOCALE;
-       else if (0 == strcmp(arg, "xhtml"))
-               curp->outtype = OUTT_HTML;
        else if (0 == strcmp(arg, "ps"))
                curp->outtype = OUTT_PS;
        else if (0 == strcmp(arg, "pdf"))
        else if (0 == strcmp(arg, "ps"))
                curp->outtype = OUTT_PS;
        else if (0 == strcmp(arg, "pdf"))
@@ -967,15 +966,16 @@ static int
 woptions(struct curparse *curp, char *arg)
 {
        char            *v, *o;
 woptions(struct curparse *curp, char *arg)
 {
        char            *v, *o;
-       const char      *toks[7];
+       const char      *toks[8];
 
        toks[0] = "stop";
        toks[1] = "all";
 
        toks[0] = "stop";
        toks[1] = "all";
-       toks[2] = "warning";
-       toks[3] = "error";
-       toks[4] = "unsupp";
-       toks[5] = "fatal";
-       toks[6] = NULL;
+       toks[2] = "style";
+       toks[3] = "warning";
+       toks[4] = "error";
+       toks[5] = "unsupp";
+       toks[6] = "fatal";
+       toks[7] = NULL;
 
        while (*arg) {
                o = arg;
 
        while (*arg) {
                o = arg;
@@ -985,15 +985,18 @@ woptions(struct curparse *curp, char *arg)
                        break;
                case 1:
                case 2:
                        break;
                case 1:
                case 2:
-                       curp->wlevel = MANDOCLEVEL_WARNING;
+                       curp->wlevel = MANDOCLEVEL_STYLE;
                        break;
                case 3:
                        break;
                case 3:
-                       curp->wlevel = MANDOCLEVEL_ERROR;
+                       curp->wlevel = MANDOCLEVEL_WARNING;
                        break;
                case 4:
                        break;
                case 4:
-                       curp->wlevel = MANDOCLEVEL_UNSUPP;
+                       curp->wlevel = MANDOCLEVEL_ERROR;
                        break;
                case 5:
                        break;
                case 5:
+                       curp->wlevel = MANDOCLEVEL_UNSUPP;
+                       break;
+               case 6:
                        curp->wlevel = MANDOCLEVEL_BADARG;
                        break;
                default:
                        curp->wlevel = MANDOCLEVEL_BADARG;
                        break;
                default:
@@ -1001,7 +1004,6 @@ woptions(struct curparse *curp, char *arg)
                        return 0;
                }
        }
                        return 0;
                }
        }
-
        return 1;
 }
 
        return 1;
 }