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

Diff for /mandoc/main.c between version 1.63 and 1.64

version 1.63, 2010/05/14 13:54:15 version 1.64, 2010/05/14 17:59:07
Line 98  static int    moptions(enum intt *, char *);
Line 98  static int    moptions(enum intt *, char *);
 static  int               woptions(int *, char *);  static  int               woptions(int *, char *);
 static  int               merr(void *, int, int, const char *);  static  int               merr(void *, int, int, const char *);
 static  int               mwarn(void *, int, int, const char *);  static  int               mwarn(void *, int, int, const char *);
 static  int               ffile(struct buf *, struct buf *,  static  void              ffile(struct buf *, struct buf *,
                                 const char *, struct curparse *);                                  const char *, struct curparse *);
 static  int               fdesc(struct buf *, struct buf *,  static  void              fdesc(struct buf *, struct buf *,
                                 struct curparse *);                                  struct curparse *);
 static  int               pset(const char *, int, struct curparse *,  static  int               pset(const char *, int, struct curparse *,
                                 struct man **, struct mdoc **);                                  struct man **, struct mdoc **);
Line 110  static void    version(void) __attribute__((noreturn))
Line 110  static void    version(void) __attribute__((noreturn))
 static  void              usage(void) __attribute__((noreturn));  static  void              usage(void) __attribute__((noreturn));
   
 static  const char       *progname;  static  const char       *progname;
   static  int               with_error, with_warning;
   
   
 int  int
 main(int argc, char *argv[])  main(int argc, char *argv[])
 {  {
         int              c, rc;          int              c;
         struct buf       ln, blk;          struct buf       ln, blk;
         struct curparse  curp;          struct curparse  curp;
   
Line 167  main(int argc, char *argv[])
Line 167  main(int argc, char *argv[])
         memset(&ln, 0, sizeof(struct buf));          memset(&ln, 0, sizeof(struct buf));
         memset(&blk, 0, sizeof(struct buf));          memset(&blk, 0, sizeof(struct buf));
   
         rc = 1;  
   
         if (NULL == *argv) {          if (NULL == *argv) {
                 curp.file = "<stdin>";                  curp.file = "<stdin>";
                 curp.fd = STDIN_FILENO;                  curp.fd = STDIN_FILENO;
   
                 c = fdesc(&blk, &ln, &curp);                  fdesc(&blk, &ln, &curp);
                 if ( ! (FL_IGN_ERRORS & curp.fflags))  
                         rc = 1 == c ? 1 : 0;  
                 else  
                         rc = -1 == c ? 0 : 1;  
         }          }
   
         while (rc && *argv) {          while (*argv) {
                 c = ffile(&blk, &ln, *argv, &curp);                  ffile(&blk, &ln, *argv, &curp);
                 if ( ! (FL_IGN_ERRORS & curp.fflags))  
                         rc = 1 == c ? 1 : 0;  
                 else  
                         rc = -1 == c ? 0 : 1;  
   
                 argv++;                  if (with_error && !(curp.fflags & FL_IGN_ERRORS))
                 if (*argv && rc) {                          break;
                         if (curp.lastman)                  ++argv;
                                 man_reset(curp.lastman);  
                         if (curp.lastmdoc)  
                                 mdoc_reset(curp.lastmdoc);  
                         curp.lastman = NULL;  
                         curp.lastmdoc = NULL;  
                 }  
         }          }
   
         if (blk.buf)          if (blk.buf)
Line 204  main(int argc, char *argv[])
Line 188  main(int argc, char *argv[])
                 free(ln.buf);                  free(ln.buf);
         if (curp.outfree)          if (curp.outfree)
                 (*curp.outfree)(curp.outdata);                  (*curp.outfree)(curp.outdata);
         if (curp.mdoc)  
                 mdoc_free(curp.mdoc);  
         if (curp.man)  
                 man_free(curp.man);  
   
         return(rc ? EXIT_SUCCESS : EXIT_FAILURE);          return((with_warning || with_error) ? EXIT_FAILURE :  EXIT_SUCCESS );
 }  }
   
   
Line 279  mdoc_init(struct curparse *curp)
Line 259  mdoc_init(struct curparse *curp)
 }  }
   
   
 static int  static void
 ffile(struct buf *blk, struct buf *ln,  ffile(struct buf *blk, struct buf *ln,
                 const char *file, struct curparse *curp)                  const char *file, struct curparse *curp)
 {  {
         int              c;  
   
         curp->file = file;          curp->file = file;
         if (-1 == (curp->fd = open(curp->file, O_RDONLY, 0))) {          if (-1 == (curp->fd = open(curp->file, O_RDONLY, 0))) {
                 perror(curp->file);                  perror(curp->file);
                 return(-1);                  with_error = 1;
                   return;
         }          }
   
         c = fdesc(blk, ln, curp);          fdesc(blk, ln, curp);
   
         if (-1 == close(curp->fd))          if (-1 == close(curp->fd))
                 perror(curp->file);                  perror(curp->file);
   
         return(c);  
 }  }
   
   
 static int  static void
 fdesc(struct buf *blk, struct buf *ln, struct curparse *curp)  fdesc(struct buf *blk, struct buf *ln, struct curparse *curp)
 {  {
         size_t           sz;          size_t           sz;
Line 320  fdesc(struct buf *blk, struct buf *ln, struct curparse
Line 298  fdesc(struct buf *blk, struct buf *ln, struct curparse
          * growable, hence passed in by ptr-ptr.           * growable, hence passed in by ptr-ptr.
          */           */
   
         if (-1 == fstat(curp->fd, &st))          if (-1 == fstat(curp->fd, &st)) {
                 perror(curp->file);                  perror(curp->file);
         else if ((size_t)st.st_blksize > sz)                  with_error = 1;
                   return;
           }
           if ((size_t)st.st_blksize > sz)
                 sz = st.st_blksize;                  sz = st.st_blksize;
   
         if (sz > blk->sz) {          if (sz > blk->sz) {
                 blk->buf = realloc(blk->buf, sz);                  void *buf = realloc(blk->buf, sz);
                 if (NULL == blk->buf) {  
                   if (NULL == buf) {
                         perror(NULL);                          perror(NULL);
                         exit(EXIT_FAILURE);                          with_error = 1;
                           return;
                 }                  }
                   blk->buf = buf;
                 blk->sz = sz;                  blk->sz = sz;
         }          }
   
Line 339  fdesc(struct buf *blk, struct buf *ln, struct curparse
Line 323  fdesc(struct buf *blk, struct buf *ln, struct curparse
         for (lnn = pos = comment = 0; ; ) {          for (lnn = pos = comment = 0; ; ) {
                 if (-1 == (ssz = read(curp->fd, blk->buf, sz))) {                  if (-1 == (ssz = read(curp->fd, blk->buf, sz))) {
                         perror(curp->file);                          perror(curp->file);
                         return(-1);                          goto bailout;
                 } else if (0 == ssz)                  } else if (0 == ssz)
                         break;                          break;
   
Line 351  fdesc(struct buf *blk, struct buf *ln, struct curparse
Line 335  fdesc(struct buf *blk, struct buf *ln, struct curparse
                                 ln->buf = realloc(ln->buf, ln->sz);                                  ln->buf = realloc(ln->buf, ln->sz);
                                 if (NULL == ln->buf) {                                  if (NULL == ln->buf) {
                                         perror(NULL);                                          perror(NULL);
                                         return(EXIT_FAILURE);                                          goto bailout;
                                 }                                  }
                         }                          }
   
Line 404  fdesc(struct buf *blk, struct buf *ln, struct curparse
Line 388  fdesc(struct buf *blk, struct buf *ln, struct curparse
   
                         if ( ! (man || mdoc) && ! pset(ln->buf,                          if ( ! (man || mdoc) && ! pset(ln->buf,
                                                 pos, curp, &man, &mdoc))                                                  pos, curp, &man, &mdoc))
                                 return(-1);                                  goto bailout;
   
                         pos = comment = 0;                          pos = comment = 0;
   
                         /* Pass down into parsers. */                          /* Pass down into parsers. */
   
                         if (man && ! man_parseln(man, lnn, ln->buf))                          if (man && ! man_parseln(man, lnn, ln->buf))
                                 return(0);                                  goto bailout;
                         if (mdoc && ! mdoc_parseln(mdoc, lnn, ln->buf))                          if (mdoc && ! mdoc_parseln(mdoc, lnn, ln->buf))
                                 return(0);                                  goto bailout;
                 }                  }
         }          }
   
Line 421  fdesc(struct buf *blk, struct buf *ln, struct curparse
Line 405  fdesc(struct buf *blk, struct buf *ln, struct curparse
   
         if ( ! (man || mdoc)) {          if ( ! (man || mdoc)) {
                 fprintf(stderr, "%s: Not a manual\n", curp->file);                  fprintf(stderr, "%s: Not a manual\n", curp->file);
                 return(0);                  goto bailout;
         }          }
   
         if (mdoc && ! mdoc_endparse(mdoc))          if (mdoc && ! mdoc_endparse(mdoc))
                 return(0);                  goto bailout;
         if (man && ! man_endparse(man))          if (man && ! man_endparse(man))
                 return(0);                  goto bailout;
   
         /* If unset, allocate output dev now (if applicable). */          /* If unset, allocate output dev now (if applicable). */
   
Line 467  fdesc(struct buf *blk, struct buf *ln, struct curparse
Line 451  fdesc(struct buf *blk, struct buf *ln, struct curparse
         if (mdoc && curp->outmdoc)          if (mdoc && curp->outmdoc)
                 (*curp->outmdoc)(curp->outdata, mdoc);                  (*curp->outmdoc)(curp->outdata, mdoc);
   
         return(1);   cleanup:
           if (curp->mdoc) {
                   mdoc_free(curp->mdoc);
                   curp->mdoc = NULL;
           }
           if (curp->man) {
                   man_free(curp->man);
                   curp->man = NULL;
           }
           return;
   
    bailout:
           with_error = 1;
           goto cleanup;
 }  }
   
   
Line 660  merr(void *arg, int line, int col, const char *msg)
Line 657  merr(void *arg, int line, int col, const char *msg)
         (void)fprintf(stderr, "%s:%d:%d: error: %s\n",          (void)fprintf(stderr, "%s:%d:%d: error: %s\n",
                         curp->file, line, col + 1, msg);                          curp->file, line, col + 1, msg);
   
           with_error = 1;
   
         return(0);          return(0);
 }  }
   
Line 677  mwarn(void *arg, int line, int col, const char *msg)
Line 676  mwarn(void *arg, int line, int col, const char *msg)
         (void)fprintf(stderr, "%s:%d:%d: warning: %s\n",          (void)fprintf(stderr, "%s:%d:%d: warning: %s\n",
                         curp->file, line, col + 1, msg);                          curp->file, line, col + 1, msg);
   
         if ( ! (curp->wflags & WARN_WERR))          with_warning = 1;
                 return(1);          if (curp->wflags & WARN_WERR) {
                   with_error = 1;
         return(0);                  return(0);
           }
   
           return(1);
 }  }
   

Legend:
Removed from v.1.63  
changed lines
  Added in v.1.64

CVSweb