]> git.cameronkatri.com Git - mandoc.git/blobdiff - main.c
add missing HISTORY information
[mandoc.git] / main.c
diff --git a/main.c b/main.c
index 02aa1968126a7b144ec9813d1db6f7b8d4df8b54..1b1b5b73a11a8c1b16a85cf709affcd88c35927c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,7 +1,7 @@
-/*     $Id: main.c,v 1.276 2016/09/18 15:22:08 schwarze Exp $ */
+/*     $Id: main.c,v 1.280 2017/01/27 13:47:10 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010-2012, 2014-2016 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010-2012, 2014-2017 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
@@ -123,6 +123,7 @@ main(int argc, char *argv[])
        struct manpage  *res, *resp;
        char            *conf_file, *defpaths;
        const char      *sec;
+       const char      *thisarg;
        size_t           i, sz;
        int              prio, best_prio;
        enum outmode     outmode;
@@ -247,9 +248,14 @@ main(int argc, char *argv[])
                        break;
                case 'O':
                        search.outkey = optarg;
-                       while (optarg != NULL)
-                               manconf_output(&conf.output,
-                                   strsep(&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;
+                       }
                        break;
                case 'S':
                        search.arch = optarg;
@@ -531,10 +537,10 @@ out:
 
                        /* Stop here until moved to the foreground. */
 
-                       tc_pgid = tcgetpgrp(STDIN_FILENO);
+                       tc_pgid = tcgetpgrp(tag_files->ofd);
                        if (tc_pgid != man_pgid) {
                                if (tc_pgid == pager_pid) {
-                                       (void)tcsetpgrp(STDIN_FILENO,
+                                       (void)tcsetpgrp(tag_files->ofd,
                                            man_pgid);
                                        if (signum == SIGTTIN)
                                                continue;
@@ -547,7 +553,7 @@ out:
                        /* Once in the foreground, activate the pager. */
 
                        if (pager_pid) {
-                               (void)tcsetpgrp(STDIN_FILENO, pager_pid);
+                               (void)tcsetpgrp(tag_files->ofd, pager_pid);
                                kill(pager_pid, SIGCONT);
                        } else
                                pager_pid = spawn_pager(tag_files);
@@ -781,6 +787,7 @@ parse(struct curparse *curp, int fd, const char *file)
                        break;
                }
        }
+       mparse_updaterc(curp->mp, &rc);
 }
 
 static void
@@ -820,11 +827,17 @@ passthrough(const char *file, int fd, int synopsis_only)
        const char      *syscall;
        char            *line, *cp;
        size_t           linesz;
+       ssize_t          len, written;
        int              print;
 
        line = NULL;
        linesz = 0;
 
+       if (fflush(stdout) == EOF) {
+               syscall = "fflush";
+               goto fail;
+       }
+
        if ((stream = fdopen(fd, "r")) == NULL) {
                close(fd);
                syscall = "fdopen";
@@ -832,14 +845,16 @@ passthrough(const char *file, int fd, int synopsis_only)
        }
 
        print = 0;
-       while (getline(&line, &linesz, stream) != -1) {
+       while ((len = getline(&line, &linesz, stream)) != -1) {
                cp = line;
                if (synopsis_only) {
                        if (print) {
                                if ( ! isspace((unsigned char)*cp))
                                        goto done;
-                               while (isspace((unsigned char)*cp))
+                               while (isspace((unsigned char)*cp)) {
                                        cp++;
+                                       len--;
+                               }
                        } else {
                                if (strcmp(cp, synb) == 0 ||
                                    strcmp(cp, synr) == 0)
@@ -847,9 +862,11 @@ passthrough(const char *file, int fd, int synopsis_only)
                                continue;
                        }
                }
-               if (fputs(cp, stdout)) {
+               for (; len > 0; len -= written) {
+                       if ((written = write(STDOUT_FILENO, cp, len)) != -1)
+                               continue;
                        fclose(stream);
-                       syscall = "fputs";
+                       syscall = "write";
                        goto fail;
                }
        }
@@ -1065,7 +1082,7 @@ spawn_pager(struct tag_files *tag_files)
                break;
        default:
                (void)setpgid(pager_pid, 0);
-               (void)tcsetpgrp(STDIN_FILENO, pager_pid);
+               (void)tcsetpgrp(tag_files->ofd, pager_pid);
 #if HAVE_PLEDGE
                if (pledge("stdio rpath tmppath tty proc", NULL) == -1)
                        err((int)MANDOCLEVEL_SYSERR, "pledge");
@@ -1083,7 +1100,7 @@ spawn_pager(struct tag_files *tag_files)
 
        /* Do not start the pager before controlling the terminal. */
 
-       while (tcgetpgrp(STDIN_FILENO) != getpid())
+       while (tcgetpgrp(STDOUT_FILENO) != getpid())
                nanosleep(&timeout, NULL);
 
        execvp(argv[0], argv);