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

Diff for /mandoc/main.c between version 1.224 and 1.225

version 1.224, 2015/03/10 03:02:28 version 1.225, 2015/03/10 13:50:03
Line 102  static void    mmsg(enum mandocerr, enum mandoclevel,
Line 102  static void    mmsg(enum mandocerr, enum mandoclevel,
 static  void              parse(struct curparse *, int,  static  void              parse(struct curparse *, int,
                                 const char *, enum mandoclevel *);                                  const char *, enum mandoclevel *);
 static  enum mandoclevel  passthrough(const char *, int, int);  static  enum mandoclevel  passthrough(const char *, int, int);
 static  void              spawn_pager(void);  static  pid_t             spawn_pager(void);
 static  int               toptions(struct curparse *, char *);  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  int               woptions(struct curparse *, char *);
Line 131  main(int argc, char *argv[])
Line 131  main(int argc, char *argv[])
         enum outmode     outmode;          enum outmode     outmode;
         int              fd;          int              fd;
         int              show_usage;          int              show_usage;
         int              use_pager;  
         int              options;          int              options;
         int              c;          int              c;
           pid_t            pager_pid;  /* 0: don't use; 1: not yet spawned. */
   
         if (argc < 1)          if (argc < 1)
                 progname = "mandoc";                  progname = "mandoc";
Line 175  main(int argc, char *argv[])
Line 175  main(int argc, char *argv[])
         options = MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1;          options = MPARSE_SO | MPARSE_UTF8 | MPARSE_LATIN1;
         defos = NULL;          defos = NULL;
   
         use_pager = 1;          pager_pid = 1;
         show_usage = 0;          show_usage = 0;
         synopsis_only = 0;          synopsis_only = 0;
         outmode = OUTMODE_DEF;          outmode = OUTMODE_DEF;
Line 190  main(int argc, char *argv[])
Line 190  main(int argc, char *argv[])
                         conf_file = optarg;                          conf_file = optarg;
                         break;                          break;
                 case 'c':                  case 'c':
                         use_pager = 0;                          pager_pid = 0;
                         break;                          break;
                 case 'f':                  case 'f':
                         search.argmode = ARG_WORD;                          search.argmode = ARG_WORD;
Line 198  main(int argc, char *argv[])
Line 198  main(int argc, char *argv[])
                 case 'h':                  case 'h':
                         (void)strlcat(curp.outopts, "synopsis,", BUFSIZ);                          (void)strlcat(curp.outopts, "synopsis,", BUFSIZ);
                         synopsis_only = 1;                          synopsis_only = 1;
                         use_pager = 0;                          pager_pid = 0;
                         outmode = OUTMODE_ALL;                          outmode = OUTMODE_ALL;
                         break;                          break;
                 case 'I':                  case 'I':
Line 273  main(int argc, char *argv[])
Line 273  main(int argc, char *argv[])
                 switch (search.argmode) {                  switch (search.argmode) {
                 case ARG_FILE:                  case ARG_FILE:
                         outmode = OUTMODE_ALL;                          outmode = OUTMODE_ALL;
                         use_pager = 0;                          pager_pid = 0;
                         break;                          break;
                 case ARG_NAME:                  case ARG_NAME:
                         outmode = OUTMODE_ONE;                          outmode = OUTMODE_ONE;
Line 418  main(int argc, char *argv[])
Line 418  main(int argc, char *argv[])
                 mparse_keep(curp.mp);                  mparse_keep(curp.mp);
   
         if (argc < 1) {          if (argc < 1) {
                 if (use_pager && isatty(STDOUT_FILENO))                  if (pager_pid == 1 && isatty(STDOUT_FILENO))
                         spawn_pager();                          pager_pid = spawn_pager();
                 parse(&curp, STDIN_FILENO, "<stdin>", &rc);                  parse(&curp, STDIN_FILENO, "<stdin>", &rc);
         }          }
   
Line 430  main(int argc, char *argv[])
Line 430  main(int argc, char *argv[])
                         rc = rctmp;                          rc = rctmp;
   
                 if (fd != -1) {                  if (fd != -1) {
                         if (use_pager && isatty(STDOUT_FILENO))                          if (pager_pid == 1 && isatty(STDOUT_FILENO))
                                 spawn_pager();                                  pager_pid = spawn_pager();
                         use_pager = 0;  
   
                         if (resp == NULL)                          if (resp == NULL)
                                 parse(&curp, fd, *argv, &rc);                                  parse(&curp, fd, *argv, &rc);
Line 483  out:
Line 482  out:
         free(defos);          free(defos);
   
         /*          /*
          * Flush the output and signal end of file.           * If a pager is attached, flush the pipe leading to it
          * If a pager is attached, it allows browsing to the end.           * and signal end of file such that the user can browse
          * Otherwise, it does no harm, we are about to exit anyway.           * to the end.  Then wait for the user to close the pager.
          */           */
   
         fclose(stdout);          if (pager_pid != 0 && pager_pid != 1) {
                   fclose(stdout);
                   waitpid(pager_pid, NULL, 0);
           }
   
         /*  
          * If we spawned a pager, wait for the user to close it.  
          * Otherwise, this call fails with no adverse effect.  
          */  
   
         wait(NULL);  
   
         return((int)rc);          return((int)rc);
 }  }
   
Line 945  mmsg(enum mandocerr t, enum mandoclevel lvl,
Line 940  mmsg(enum mandocerr t, enum mandoclevel lvl,
         fputc('\n', stderr);          fputc('\n', stderr);
 }  }
   
 static void  static pid_t
 spawn_pager(void)  spawn_pager(void)
 {  {
 #define MAX_PAGER_ARGS 16  #define MAX_PAGER_ARGS 16
Line 954  spawn_pager(void)
Line 949  spawn_pager(void)
         char            *cp;          char            *cp;
         int              fildes[2];          int              fildes[2];
         int              argc;          int              argc;
           pid_t            pager_pid;
   
         if (pipe(fildes) == -1) {          if (pipe(fildes) == -1) {
                 fprintf(stderr, "%s: pipe: %s\n",                  fprintf(stderr, "%s: pipe: %s\n",
                     progname, strerror(errno));                      progname, strerror(errno));
                 return;                  return(0);
         }          }
   
         switch (fork()) {          switch (pager_pid = fork()) {
         case -1:          case -1:
                 fprintf(stderr, "%s: fork: %s\n",                  fprintf(stderr, "%s: fork: %s\n",
                     progname, strerror(errno));                      progname, strerror(errno));
Line 976  spawn_pager(void)
Line 972  spawn_pager(void)
                         exit((int)MANDOCLEVEL_SYSERR);                          exit((int)MANDOCLEVEL_SYSERR);
                 }                  }
                 close(fildes[1]);                  close(fildes[1]);
                 return;                  return(pager_pid);
         }          }
   
         /* The child process becomes the pager. */          /* The child process becomes the pager. */

Legend:
Removed from v.1.224  
changed lines
  Added in v.1.225

CVSweb