[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.50 and 1.51

version 1.50, 2010/10/24 18:15:43 version 1.51, 2010/10/26 22:13:58
Line 178 
Line 178 
         "static buffer exhausted",          "static buffer exhausted",
 };  };
   
   static  void              pdesc(struct curparse *);
 static  void              fdesc(struct curparse *);  static  void              fdesc(struct curparse *);
 static  void              ffile(const char *, struct curparse *);  static  void              ffile(const char *, struct curparse *);
 static  int               moptions(enum intt *, char *);  static  int               moptions(enum intt *, char *);
Line 391 
Line 392 
 static void  static void
 fdesc(struct curparse *curp)  fdesc(struct curparse *curp)
 {  {
           struct man      *man;
           struct mdoc     *mdoc;
           struct roff     *roff;
   
           pdesc(curp);
   
           man  = curp->man;
           mdoc = curp->mdoc;
           roff = curp->roff;
   
           if (MANDOCLEVEL_FATAL <= exit_status)
                   goto cleanup;
   
           /* NOTE a parser may not have been assigned, yet. */
   
           if ( ! (man || mdoc)) {
                   fprintf(stderr, "%s: Not a manual\n", curp->file);
                   exit_status = MANDOCLEVEL_FATAL;
                   goto cleanup;
           }
   
           /* Clean up the parse routine ASTs. */
   
           if (mdoc && ! mdoc_endparse(mdoc)) {
                   assert(MANDOCLEVEL_FATAL <= exit_status);
                   goto cleanup;
           }
           if (man && ! man_endparse(man)) {
                   assert(MANDOCLEVEL_FATAL <= exit_status);
                   goto cleanup;
           }
           if (roff && ! roff_endparse(roff)) {
                   assert(MANDOCLEVEL_FATAL <= exit_status);
                   goto cleanup;
           }
   
           /*
            * With -Wstop and warnings or errors of at least
            * the requested level, do not produce output.
            */
   
           if (MANDOCLEVEL_OK != exit_status && curp->wstop)
                   goto cleanup;
   
           /* If unset, allocate output dev now (if applicable). */
   
           if ( ! (curp->outman && curp->outmdoc)) {
                   switch (curp->outtype) {
                   case (OUTT_XHTML):
                           curp->outdata = xhtml_alloc(curp->outopts);
                           break;
                   case (OUTT_HTML):
                           curp->outdata = html_alloc(curp->outopts);
                           break;
                   case (OUTT_ASCII):
                           curp->outdata = ascii_alloc(curp->outopts);
                           curp->outfree = ascii_free;
                           break;
                   case (OUTT_PDF):
                           curp->outdata = pdf_alloc(curp->outopts);
                           curp->outfree = pspdf_free;
                           break;
                   case (OUTT_PS):
                           curp->outdata = ps_alloc(curp->outopts);
                           curp->outfree = pspdf_free;
                           break;
                   default:
                           break;
                   }
   
                   switch (curp->outtype) {
                   case (OUTT_HTML):
                           /* FALLTHROUGH */
                   case (OUTT_XHTML):
                           curp->outman = html_man;
                           curp->outmdoc = html_mdoc;
                           curp->outfree = html_free;
                           break;
                   case (OUTT_TREE):
                           curp->outman = tree_man;
                           curp->outmdoc = tree_mdoc;
                           break;
                   case (OUTT_PDF):
                           /* FALLTHROUGH */
                   case (OUTT_ASCII):
                           /* FALLTHROUGH */
                   case (OUTT_PS):
                           curp->outman = terminal_man;
                           curp->outmdoc = terminal_mdoc;
                           break;
                   default:
                           break;
                   }
           }
   
           /* Execute the out device, if it exists. */
   
           if (man && curp->outman)
                   (*curp->outman)(curp->outdata, man);
           if (mdoc && curp->outmdoc)
                   (*curp->outmdoc)(curp->outdata, mdoc);
   
    cleanup:
           memset(&curp->regs, 0, sizeof(struct regset));
           if (mdoc)
                   mdoc_reset(mdoc);
           if (man)
                   man_reset(man);
           if (roff)
                   roff_reset(roff);
   
           return;
   }
   
   
   static void
   pdesc(struct curparse *curp)
   {
         struct buf       ln, blk;          struct buf       ln, blk;
         int              i, pos, lnn, lnn_start, with_mmap, of;          int              i, pos, lnn, lnn_start, with_mmap, of;
         enum rofferr     re;          enum rofferr     re;
Line 399 
Line 518 
         struct mdoc     *mdoc;          struct mdoc     *mdoc;
         struct roff     *roff;          struct roff     *roff;
   
         man = NULL;  
         mdoc = NULL;  
         roff = NULL;  
   
         memset(&ln, 0, sizeof(struct buf));          memset(&ln, 0, sizeof(struct buf));
   
         /*          /*
Line 419 
Line 534 
                 curp->roff = roff_alloc(&curp->regs, curp, mmsg);                  curp->roff = roff_alloc(&curp->regs, curp, mmsg);
         assert(curp->roff);          assert(curp->roff);
         roff = curp->roff;          roff = curp->roff;
           mdoc = curp->mdoc;
           man  = curp->man;
   
         for (i = 0, lnn = 1; i < (int)blk.sz;) {          for (i = 0, lnn = 1; i < (int)blk.sz;) {
                 pos = 0;                  pos = 0;
Line 511 
Line 628 
                         continue;                          continue;
                 } else if (ROFF_ERR == re) {                  } else if (ROFF_ERR == re) {
                         assert(MANDOCLEVEL_FATAL <= exit_status);                          assert(MANDOCLEVEL_FATAL <= exit_status);
                         goto cleanup;                          break;
                 }                  }
   
                 /*                  /*
Line 528 
Line 645 
   
                 if (man && ! man_parseln(man, lnn_start, ln.buf, of)) {                  if (man && ! man_parseln(man, lnn_start, ln.buf, of)) {
                         assert(MANDOCLEVEL_FATAL <= exit_status);                          assert(MANDOCLEVEL_FATAL <= exit_status);
                         goto cleanup;                          break;
                 }                  }
                 if (mdoc && ! mdoc_parseln(mdoc, lnn_start, ln.buf, of)) {                  if (mdoc && ! mdoc_parseln(mdoc, lnn_start, ln.buf, of)) {
                         assert(MANDOCLEVEL_FATAL <= exit_status);                          assert(MANDOCLEVEL_FATAL <= exit_status);
                         goto cleanup;  
                 }  
         }  
   
         /* NOTE a parser may not have been assigned, yet. */  
   
         if ( ! (man || mdoc)) {  
                 fprintf(stderr, "%s: Not a manual\n", curp->file);  
                 exit_status = MANDOCLEVEL_FATAL;  
                 goto cleanup;  
         }  
   
         /* Clean up the parse routine ASTs. */  
   
         if (mdoc && ! mdoc_endparse(mdoc)) {  
                 assert(MANDOCLEVEL_FATAL <= exit_status);  
                 goto cleanup;  
         }  
         if (man && ! man_endparse(man)) {  
                 assert(MANDOCLEVEL_FATAL <= exit_status);  
                 goto cleanup;  
         }  
         if (roff && ! roff_endparse(roff)) {  
                 assert(MANDOCLEVEL_FATAL <= exit_status);  
                 goto cleanup;  
         }  
   
         /*  
          * With -Wstop and warnings or errors of at least  
          * the requested level, do not produce output.  
          */  
   
         if (MANDOCLEVEL_OK != exit_status && curp->wstop)  
                 goto cleanup;  
   
         /* If unset, allocate output dev now (if applicable). */  
   
         if ( ! (curp->outman && curp->outmdoc)) {  
                 switch (curp->outtype) {  
                 case (OUTT_XHTML):  
                         curp->outdata = xhtml_alloc(curp->outopts);  
                         break;                          break;
                 case (OUTT_HTML):  
                         curp->outdata = html_alloc(curp->outopts);  
                         break;  
                 case (OUTT_ASCII):  
                         curp->outdata = ascii_alloc(curp->outopts);  
                         curp->outfree = ascii_free;  
                         break;  
                 case (OUTT_PDF):  
                         curp->outdata = pdf_alloc(curp->outopts);  
                         curp->outfree = pspdf_free;  
                         break;  
                 case (OUTT_PS):  
                         curp->outdata = ps_alloc(curp->outopts);  
                         curp->outfree = pspdf_free;  
                         break;  
                 default:  
                         break;  
                 }                  }
   
                 switch (curp->outtype) {  
                 case (OUTT_HTML):  
                         /* FALLTHROUGH */  
                 case (OUTT_XHTML):  
                         curp->outman = html_man;  
                         curp->outmdoc = html_mdoc;  
                         curp->outfree = html_free;  
                         break;  
                 case (OUTT_TREE):  
                         curp->outman = tree_man;  
                         curp->outmdoc = tree_mdoc;  
                         break;  
                 case (OUTT_PDF):  
                         /* FALLTHROUGH */  
                 case (OUTT_ASCII):  
                         /* FALLTHROUGH */  
                 case (OUTT_PS):  
                         curp->outman = terminal_man;  
                         curp->outmdoc = terminal_mdoc;  
                         break;  
                 default:  
                         break;  
                 }  
         }          }
   
         /* Execute the out device, if it exists. */          free(ln.buf);
   
         if (man && curp->outman)  
                 (*curp->outman)(curp->outdata, man);  
         if (mdoc && curp->outmdoc)  
                 (*curp->outmdoc)(curp->outdata, mdoc);  
   
  cleanup:  
         memset(&curp->regs, 0, sizeof(struct regset));  
         if (mdoc)  
                 mdoc_reset(mdoc);  
         if (man)  
                 man_reset(man);  
         if (roff)  
                 roff_reset(roff);  
         if (ln.buf)  
                 free(ln.buf);  
         if (with_mmap)          if (with_mmap)
                 munmap(blk.buf, blk.sz);                  munmap(blk.buf, blk.sz);
         else          else
                 free(blk.buf);                  free(blk.buf);
   
         return;  
 }  }
   
   

Legend:
Removed from v.1.50  
changed lines
  Added in v.1.51