[BACK]Return to main.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / mandoc

Diff for /src/usr.bin/mandoc/main.c between version 1.238 and 1.239

version 1.238, 2019/07/26 23:12:02 version 1.239, 2019/07/27 13:40:42
Line 78 
Line 78 
 };  };
   
 struct  outstate {  struct  outstate {
           struct tag_files *tag_files;    /* Tagging state variables. */
         void             *outdata;      /* data for output */          void             *outdata;      /* data for output */
           int               use_pager;
         int               wstop;        /* stop after a file with a warning */          int               wstop;        /* stop after a file with a warning */
         enum outt         outtype;      /* which output to use */          enum outt         outtype;      /* which output to use */
 };  };
Line 117 
Line 119 
         struct mansearch search;        /* Search options. */          struct mansearch search;        /* Search options. */
         struct manpage  *res, *resp;    /* Search results. */          struct manpage  *res, *resp;    /* Search results. */
         struct mparse   *mp;            /* Opaque parser object. */          struct mparse   *mp;            /* Opaque parser object. */
         struct tag_files *tag_files;    /* Tagging state variables. */  
         const char      *conf_file;     /* -C: alternate config file. */          const char      *conf_file;     /* -C: alternate config file. */
         const char      *os_s;          /* -I: Operating system for display. */          const char      *os_s;          /* -I: Operating system for display. */
         const char      *progname, *sec, *thisarg;          const char      *progname, *sec, *thisarg;
Line 130 
Line 131 
         size_t           i, ssz;          size_t           i, ssz;
         int              options;       /* Parser options. */          int              options;       /* Parser options. */
         int              show_usage;    /* Invalid argument: give up. */          int              show_usage;    /* Invalid argument: give up. */
         int              use_pager;     /* According to command line. */  
         int              prio, best_prio;          int              prio, best_prio;
         int              fd, startdir;          int              fd, startdir;
         int              c;          int              c;
Line 178 
Line 178 
         /* Formatter options. */          /* Formatter options. */
   
         memset(&outst, 0, sizeof(outst));          memset(&outst, 0, sizeof(outst));
           outst.tag_files = NULL;
         outst.outtype = OUTT_LOCALE;          outst.outtype = OUTT_LOCALE;
           outst.use_pager = 1;
   
         use_pager = 1;  
         tag_files = NULL;  
         show_usage = 0;          show_usage = 0;
         outmode = OUTMODE_DEF;          outmode = OUTMODE_DEF;
   
Line 199 
Line 199 
                         conf_file = optarg;                          conf_file = optarg;
                         break;                          break;
                 case 'c':                  case 'c':
                         use_pager = 0;                          outst.use_pager = 0;
                         break;                          break;
                 case 'f':                  case 'f':
                         search.argmode = ARG_WORD;                          search.argmode = ARG_WORD;
                         break;                          break;
                 case 'h':                  case 'h':
                         conf.output.synopsisonly = 1;                          conf.output.synopsisonly = 1;
                         use_pager = 0;                          outst.use_pager = 0;
                         outmode = OUTMODE_ALL;                          outmode = OUTMODE_ALL;
                         break;                          break;
                 case 'I':                  case 'I':
Line 307 
Line 307 
                 switch (search.argmode) {                  switch (search.argmode) {
                 case ARG_FILE:                  case ARG_FILE:
                         outmode = OUTMODE_ALL;                          outmode = OUTMODE_ALL;
                         use_pager = 0;                          outst.use_pager = 0;
                         break;                          break;
                 case ARG_NAME:                  case ARG_NAME:
                         outmode = OUTMODE_ONE;                          outmode = OUTMODE_ONE;
Line 336 
Line 336 
         if (outmode == OUTMODE_FLN ||          if (outmode == OUTMODE_FLN ||
             outmode == OUTMODE_LST ||              outmode == OUTMODE_LST ||
             !isatty(STDOUT_FILENO))              !isatty(STDOUT_FILENO))
                 use_pager = 0;                  outst.use_pager = 0;
   
         if (use_pager &&          if (outst.use_pager &&
             (conf.output.width == 0 || conf.output.indent == 0) &&              (conf.output.width == 0 || conf.output.indent == 0) &&
             ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) != -1 &&              ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) != -1 &&
             ws.ws_col > 1) {              ws.ws_col > 1) {
Line 348 
Line 348 
                         conf.output.indent = 3;                          conf.output.indent = 3;
         }          }
   
         if (use_pager == 0) {          if (outst.use_pager == 0) {
                 if (pledge("stdio rpath", NULL) == -1) {                  if (pledge("stdio rpath", NULL) == -1) {
                         mandoc_msg(MANDOCERR_PLEDGE, 0, 0,                          mandoc_msg(MANDOCERR_PLEDGE, 0, 0,
                             "%s", strerror(errno));                              "%s", strerror(errno));
Line 511 
Line 511 
   
         /* mandoc(1) */          /* mandoc(1) */
   
         if (use_pager) {          if (outst.use_pager) {
                 if (pledge("stdio rpath tmppath tty proc exec", NULL) == -1) {                  if (pledge("stdio rpath tmppath tty proc exec", NULL) == -1) {
                         mandoc_msg(MANDOCERR_PLEDGE, 0, 0,                          mandoc_msg(MANDOCERR_PLEDGE, 0, 0,
                             "%s", strerror(errno));                              "%s", strerror(errno));
Line 536 
Line 536 
         mp = mparse_alloc(options, os_e, os_s);          mp = mparse_alloc(options, os_e, os_s);
   
         if (argc < 1) {          if (argc < 1) {
                 if (use_pager) {                  if (outst.use_pager)
                         tag_files = tag_init();                          outst.tag_files = tag_init(conf.output.tag);
                         if (tag_files != NULL)  
                                 tag_files->tagname = conf.output.tag;  
                 }  
                 thisarg = "<stdin>";                  thisarg = "<stdin>";
                 mandoc_msg_setinfilename(thisarg);                  mandoc_msg_setinfilename(thisarg);
                 parse(mp, STDIN_FILENO, thisarg, &outst, &conf.output);                  parse(mp, STDIN_FILENO, thisarg, &outst, &conf.output);
Line 575 
Line 572 
                 mandoc_msg_setinfilename(thisarg);                  mandoc_msg_setinfilename(thisarg);
                 fd = mparse_open(mp, thisarg);                  fd = mparse_open(mp, thisarg);
                 if (fd != -1) {                  if (fd != -1) {
                         if (use_pager) {                          if (outst.use_pager) {
                                 use_pager = 0;                                  outst.use_pager = 0;
                                 tag_files = tag_init();                                  outst.tag_files = tag_init(conf.output.tag);
                                 if (tag_files != NULL)  
                                         tag_files->tagname = conf.output.tag;  
                         }                          }
   
                         if (resp == NULL || resp->form == FORM_SRC)                          if (resp == NULL || resp->form == FORM_SRC)
Line 588 
Line 583 
                                 passthrough(fd, conf.output.synopsisonly);                                  passthrough(fd, conf.output.synopsisonly);
   
                         if (ferror(stdout)) {                          if (ferror(stdout)) {
                                 if (tag_files != NULL) {                                  if (outst.tag_files != NULL) {
                                         mandoc_msg(MANDOCERR_WRITE, 0, 0,                                          mandoc_msg(MANDOCERR_WRITE, 0, 0,
                                             "%s: %s", tag_files->ofn,                                              "%s: %s", outst.tag_files->ofn,
                                             strerror(errno));                                              strerror(errno));
                                         tag_unlink();                                          tag_unlink();
                                         tag_files = NULL;                                          outst.tag_files = NULL;
                                 } else                                  } else
                                         mandoc_msg(MANDOCERR_WRITE, 0, 0,                                          mandoc_msg(MANDOCERR_WRITE, 0, 0,
                                             "%s", strerror(errno));                                              "%s", strerror(errno));
Line 654 
Line 649 
                 mansearch_free(res, sz);                  mansearch_free(res, sz);
         }          }
   
         if (tag_files != NULL) {          if (outst.tag_files != NULL) {
                 fclose(stdout);                  fclose(stdout);
                 tag_write();                  tag_write();
                 run_pager(tag_files);                  run_pager(outst.tag_files);
                 tag_unlink();                  tag_unlink();
         } else if (outst.outtype != OUTT_LINT &&          } else if (outst.outtype != OUTT_LINT &&
             (search.argmode == ARG_FILE || sz > 0))              (search.argmode == ARG_FILE || sz > 0))

Legend:
Removed from v.1.238  
changed lines
  Added in v.1.239