[BACK]Return to main.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/main.c between version 1.347 and 1.348

version 1.347, 2020/03/28 16:18:43 version 1.348, 2020/04/02 22:12:55
Line 54 
Line 54 
 #include "mdoc.h"  #include "mdoc.h"
 #include "man.h"  #include "man.h"
 #include "mandoc_parse.h"  #include "mandoc_parse.h"
   #include "tag.h"
 #include "term_tag.h"  #include "term_tag.h"
 #include "main.h"  #include "main.h"
 #include "manconf.h"  #include "manconf.h"
Line 107  static void    parse(struct mparse *, int, const char 
Line 108  static void    parse(struct mparse *, int, const char 
 static  void              passthrough(int, int);  static  void              passthrough(int, int);
 static  void              process_onefile(struct mparse *, struct manpage *,  static  void              process_onefile(struct mparse *, struct manpage *,
                                 int, struct outstate *, struct manconf *);                                  int, struct outstate *, struct manconf *);
 static  void              run_pager(struct tag_files *);  static  void              run_pager(struct tag_files *, char *);
 static  pid_t             spawn_pager(struct tag_files *);  static  pid_t             spawn_pager(struct tag_files *, char *);
 static  void              usage(enum argmode) __attribute__((__noreturn__));  static  void              usage(enum argmode) __attribute__((__noreturn__));
 static  int               woptions(char *, enum mandoc_os *, int *);  static  int               woptions(char *, enum mandoc_os *, int *);
   
Line 609  main(int argc, char *argv[])
Line 610  main(int argc, char *argv[])
                 (void)fchdir(startdir);                  (void)fchdir(startdir);
                 close(startdir);                  close(startdir);
         }          }
         term_tag_finish();          if (conf.output.tag != NULL && conf.output.tag_found == 0) {
                   mandoc_msg(MANDOCERR_TAG, 0, 0, "%s", conf.output.tag);
                   conf.output.tag = NULL;
           }
         if (outst.outdata != NULL) {          if (outst.outdata != NULL) {
                 switch (outst.outtype) {                  switch (outst.outtype) {
                 case OUTT_HTML:                  case OUTT_HTML:
Line 638  out:
Line 642  out:
                 manconf_free(&conf);                  manconf_free(&conf);
   
         if (outst.tag_files != NULL) {          if (outst.tag_files != NULL) {
                 fclose(stdout);                  if (term_tag_close() != -1)
                 run_pager(outst.tag_files);                          run_pager(outst.tag_files, conf.output.tag);
                 term_tag_unlink();                  term_tag_unlink();
         } else if (outst.had_output && outst.outtype != OUTT_LINT)          } else if (outst.had_output && outst.outtype != OUTT_LINT)
                 mandoc_msg_summary();                  mandoc_msg_summary();
Line 833  process_onefile(struct mparse *mp, struct manpage *res
Line 837  process_onefile(struct mparse *mp, struct manpage *res
   
         if (outst->use_pager) {          if (outst->use_pager) {
                 outst->use_pager = 0;                  outst->use_pager = 0;
                 outst->tag_files = term_tag_init(conf->output.tag);                  outst->tag_files = term_tag_init();
         }          }
         if (outst->had_output && outst->outtype <= OUTT_UTF8) {          if (outst->had_output && outst->outtype <= OUTT_UTF8) {
                 if (outst->outdata == NULL)                  if (outst->outdata == NULL)
Line 947  parse(struct mparse *mp, int fd, const char *file,
Line 951  parse(struct mparse *mp, int fd, const char *file,
                         break;                          break;
                 }                  }
         }          }
           if (outconf->tag != NULL && outconf->tag_found == 0 &&
               tag_exists(outconf->tag))
                   outconf->tag_found = 1;
         if (mandoc_msg_getmin() < MANDOCERR_STYLE)          if (mandoc_msg_getmin() < MANDOCERR_STYLE)
                 check_xr();                  check_xr();
 }  }
Line 1137  woptions(char *arg, enum mandoc_os *os_e, int *wstop)
Line 1144  woptions(char *arg, enum mandoc_os *os_e, int *wstop)
  * then fork the pager and wait for the user to close it.   * then fork the pager and wait for the user to close it.
  */   */
 static void  static void
 run_pager(struct tag_files *tag_files)  run_pager(struct tag_files *tag_files, char *tag_target)
 {  {
         int      signum, status;          int      signum, status;
         pid_t    man_pgid, tc_pgid;          pid_t    man_pgid, tc_pgid;
Line 1152  run_pager(struct tag_files *tag_files)
Line 1159  run_pager(struct tag_files *tag_files)
         for (;;) {          for (;;) {
                 /* Stop here until moved to the foreground. */                  /* Stop here until moved to the foreground. */
   
                 tc_pgid = tcgetpgrp(tag_files->ofd);                  tc_pgid = tcgetpgrp(STDOUT_FILENO);
                 if (tc_pgid != man_pgid) {                  if (tc_pgid != man_pgid) {
                         if (tc_pgid == pager_pid) {                          if (tc_pgid == pager_pid) {
                                 (void)tcsetpgrp(tag_files->ofd, man_pgid);                                  (void)tcsetpgrp(STDOUT_FILENO, man_pgid);
                                 if (signum == SIGTTIN)                                  if (signum == SIGTTIN)
                                         continue;                                          continue;
                         } else                          } else
Line 1167  run_pager(struct tag_files *tag_files)
Line 1174  run_pager(struct tag_files *tag_files)
                 /* Once in the foreground, activate the pager. */                  /* Once in the foreground, activate the pager. */
   
                 if (pager_pid) {                  if (pager_pid) {
                         (void)tcsetpgrp(tag_files->ofd, pager_pid);                          (void)tcsetpgrp(STDOUT_FILENO, pager_pid);
                         kill(pager_pid, SIGCONT);                          kill(pager_pid, SIGCONT);
                 } else                  } else
                         pager_pid = spawn_pager(tag_files);                          pager_pid = spawn_pager(tag_files, tag_target);
   
                 /* Wait for the pager to stop or exit. */                  /* Wait for the pager to stop or exit. */
   
Line 1191  run_pager(struct tag_files *tag_files)
Line 1198  run_pager(struct tag_files *tag_files)
 }  }
   
 static pid_t  static pid_t
 spawn_pager(struct tag_files *tag_files)  spawn_pager(struct tag_files *tag_files, char *tag_target)
 {  {
         const struct timespec timeout = { 0, 100000000 };  /* 0.1s */          const struct timespec timeout = { 0, 100000000 };  /* 0.1s */
 #define MAX_PAGER_ARGS 16  #define MAX_PAGER_ARGS 16
Line 1204  spawn_pager(struct tag_files *tag_files)
Line 1211  spawn_pager(struct tag_files *tag_files)
         int              argc, use_ofn;          int              argc, use_ofn;
         pid_t            pager_pid;          pid_t            pager_pid;
   
           assert(tag_files->ofd == -1);
           assert(tag_files->tfs == NULL);
   
         pager = getenv("MANPAGER");          pager = getenv("MANPAGER");
         if (pager == NULL || *pager == '\0')          if (pager == NULL || *pager == '\0')
                 pager = getenv("PAGER");                  pager = getenv("PAGER");
Line 1238  spawn_pager(struct tag_files *tag_files)
Line 1248  spawn_pager(struct tag_files *tag_files)
                 if (strcmp(cp, "less") == 0) {                  if (strcmp(cp, "less") == 0) {
                         argv[argc++] = mandoc_strdup("-T");                          argv[argc++] = mandoc_strdup("-T");
                         argv[argc++] = tag_files->tfn;                          argv[argc++] = tag_files->tfn;
                         if (tag_files->tagname != NULL) {                          if (tag_target != NULL) {
                                 argv[argc++] = mandoc_strdup("-t");                                  argv[argc++] = mandoc_strdup("-t");
                                 argv[argc++] = tag_files->tagname;                                  argv[argc++] = tag_target;
                                 use_ofn = 0;                                  use_ofn = 0;
                         }                          }
                 }                  }
Line 1258  spawn_pager(struct tag_files *tag_files)
Line 1268  spawn_pager(struct tag_files *tag_files)
                 break;                  break;
         default:          default:
                 (void)setpgid(pager_pid, 0);                  (void)setpgid(pager_pid, 0);
                 (void)tcsetpgrp(tag_files->ofd, pager_pid);                  (void)tcsetpgrp(STDOUT_FILENO, pager_pid);
 #if HAVE_PLEDGE  #if HAVE_PLEDGE
                 if (pledge("stdio rpath tmppath tty proc", NULL) == -1) {                  if (pledge("stdio rpath tmppath tty proc", NULL) == -1) {
                         mandoc_msg(MANDOCERR_PLEDGE, 0, 0,                          mandoc_msg(MANDOCERR_PLEDGE, 0, 0,
Line 1270  spawn_pager(struct tag_files *tag_files)
Line 1280  spawn_pager(struct tag_files *tag_files)
                 return pager_pid;                  return pager_pid;
         }          }
   
         /* The child process becomes the pager. */          /*
            * The child process becomes the pager.
         if (dup2(tag_files->ofd, STDOUT_FILENO) == -1) {           * Do not start it before controlling the terminal.
                 mandoc_msg(MANDOCERR_DUP, 0, 0, "%s", strerror(errno));           */
                 _exit(mandoc_msg_getrc());  
         }  
         close(tag_files->ofd);  
         assert(tag_files->tfs == NULL);  
   
         /* Do not start the pager before controlling the terminal. */  
   
         while (tcgetpgrp(STDOUT_FILENO) != getpid())          while (tcgetpgrp(STDOUT_FILENO) != getpid())
                 nanosleep(&timeout, NULL);                  nanosleep(&timeout, NULL);

Legend:
Removed from v.1.347  
changed lines
  Added in v.1.348

CVSweb