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

Diff for /mandoc/main.c between version 1.52 and 1.56

version 1.52, 2009/10/30 05:58:37 version 1.56, 2009/11/02 08:13:48
Line 17 
Line 17 
 #include <sys/stat.h>  #include <sys/stat.h>
   
 #include <assert.h>  #include <assert.h>
 #include <err.h>  
 #include <fcntl.h>  #include <fcntl.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdint.h>  #include <stdint.h>
Line 31 
Line 30 
   
 #define UNCONST(a)      ((void *)(uintptr_t)(const void *)(a))  #define UNCONST(a)      ((void *)(uintptr_t)(const void *)(a))
   
 /* Account for FreeBSD and Linux in our declarations. */  /* FIXME: Intel's compiler?  LLVM?  pcc?  */
   
   #if !defined(__GNUC__) || (__GNUC__ < 2)
   # if !defined(lint)
   #  define __attribute__(x)
   # endif
   #endif /* !defined(__GNUC__) || (__GNUC__ < 2) */
   
 #ifdef __linux__  #ifdef __linux__
 extern  int               getsubopt(char **, char * const *, char **);  extern  int               getsubopt(char **, char * const *, char **);
 extern  size_t            strlcat(char *, const char *, size_t);  extern  size_t            strlcat(char *, const char *, size_t);
 # ifndef __dead  
 #  define __dead __attribute__((__noreturn__))  
 # endif  
 #elif defined(__dead2)  
 # ifndef __dead  
 #  define __dead __dead2  
 # endif  
 #endif  #endif
   
 typedef void            (*out_mdoc)(void *, const struct mdoc *);  typedef void            (*out_mdoc)(void *, const struct mdoc *);
Line 106  static int    pset(const char *, int, struct curparse 
Line 104  static int    pset(const char *, int, struct curparse 
                                 struct man **, struct mdoc **);                                  struct man **, struct mdoc **);
 static  struct man       *man_init(struct curparse *);  static  struct man       *man_init(struct curparse *);
 static  struct mdoc      *mdoc_init(struct curparse *);  static  struct mdoc      *mdoc_init(struct curparse *);
 __dead  static void       version(void);  static  void              version(void) __attribute__((noreturn));
 __dead  static void       usage(void);  static  void              usage(void) __attribute__((noreturn));
   
 extern  char             *__progname;  static  const char       *progname;
   
   
 int  int
Line 119  main(int argc, char *argv[])
Line 117  main(int argc, char *argv[])
         struct buf       ln, blk;          struct buf       ln, blk;
         struct curparse  curp;          struct curparse  curp;
   
           progname = strrchr(argv[0], '/');
           if (progname == NULL)
                   progname = argv[0];
           else
                   ++progname;
   
         memset(&curp, 0, sizeof(struct curparse));          memset(&curp, 0, sizeof(struct curparse));
   
         curp.inttype = INTT_AUTO;          curp.inttype = INTT_AUTO;
Line 207  main(int argc, char *argv[])
Line 211  main(int argc, char *argv[])
 }  }
   
   
 __dead static void  static void
 version(void)  version(void)
 {  {
   
         (void)printf("%s %s\n", __progname, VERSION);          (void)printf("%s %s\n", progname, VERSION);
         exit(EXIT_SUCCESS);          exit(EXIT_SUCCESS);
 }  }
   
   
 __dead static void  static void
 usage(void)  usage(void)
 {  {
   
         (void)fprintf(stderr, "usage: %s [-V] [-foption...] "          (void)fprintf(stderr, "usage: %s [-V] [-foption...] "
                         "[-mformat] [-Ooption] [-Toutput] "                          "[-mformat] [-Ooption] [-Toutput] "
                         "[-Werr...]\n", __progname);                          "[-Werr...]\n", progname);
         exit(EXIT_FAILURE);          exit(EXIT_FAILURE);
 }  }
   
Line 285  ffile(struct buf *blk, struct buf *ln, 
Line 289  ffile(struct buf *blk, struct buf *ln, 
   
         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))) {
                 warn("%s", curp->file);                  perror(curp->file);
                 return(-1);                  return(-1);
         }          }
   
         c = fdesc(blk, ln, curp);          c = fdesc(blk, ln, curp);
   
         if (-1 == close(curp->fd))          if (-1 == close(curp->fd))
                 warn("%s", curp->file);                  perror(curp->file);
   
         return(c);          return(c);
 }  }
Line 319  fdesc(struct buf *blk, struct buf *ln, struct curparse
Line 323  fdesc(struct buf *blk, struct buf *ln, struct curparse
          */           */
   
         if (-1 == fstat(curp->fd, &st))          if (-1 == fstat(curp->fd, &st))
                 warn("%s", curp->file);                  perror(curp->file);
         else if ((size_t)st.st_blksize > sz)          else 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);                  blk->buf = realloc(blk->buf, sz);
                 if (NULL == blk->buf) {                  if (NULL == blk->buf) {
                         warn("realloc");                          perror(NULL);
                         return(-1);                          exit(EXIT_FAILURE);
                 }                  }
                 blk->sz = sz;                  blk->sz = sz;
         }          }
Line 336  fdesc(struct buf *blk, struct buf *ln, struct curparse
Line 340  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))) {
                         warn("%s", curp->file);                          perror(curp->file);
                         return(-1);                          return(-1);
                 } else if (0 == ssz)                  } else if (0 == ssz)
                         break;                          break;
Line 348  fdesc(struct buf *blk, struct buf *ln, struct curparse
Line 352  fdesc(struct buf *blk, struct buf *ln, struct curparse
                                 ln->sz += 256; /* Step-size. */                                  ln->sz += 256; /* Step-size. */
                                 ln->buf = realloc(ln->buf, ln->sz);                                  ln->buf = realloc(ln->buf, ln->sz);
                                 if (NULL == ln->buf) {                                  if (NULL == ln->buf) {
                                         warn("realloc");                                          perror(NULL);
                                         return(-1);                                          return(EXIT_FAILURE);
                                 }                                  }
                         }                          }
   
Line 412  fdesc(struct buf *blk, struct buf *ln, struct curparse
Line 416  fdesc(struct buf *blk, struct buf *ln, struct curparse
         /* NOTE a parser may not have been assigned, yet. */          /* NOTE a parser may not have been assigned, yet. */
   
         if ( ! (man || mdoc)) {          if ( ! (man || mdoc)) {
                 (void)fprintf(stderr, "%s: not a manual\n",                  fprintf(stderr, "%s: Not a manual\n", curp->file);
                                 curp->file);  
                 return(0);                  return(0);
         }          }
   
Line 528  moptions(enum intt *tflags, char *arg)
Line 531  moptions(enum intt *tflags, char *arg)
         else if (0 == strcmp(arg, "an"))          else if (0 == strcmp(arg, "an"))
                 *tflags = INTT_MAN;                  *tflags = INTT_MAN;
         else {          else {
                 warnx("bad argument: -m%s", arg);                  fprintf(stderr, "%s: Bad argument", arg);
                 return(0);                  return(0);
         }          }
   
Line 549  toptions(enum outt *tflags, char *arg)
Line 552  toptions(enum outt *tflags, char *arg)
         else if (0 == strcmp(arg, "html"))          else if (0 == strcmp(arg, "html"))
                 *tflags = OUTT_HTML;                  *tflags = OUTT_HTML;
         else {          else {
                 warnx("bad argument: -T%s", arg);                  fprintf(stderr, "%s: Bad argument", arg);
                 return(0);                  return(0);
         }          }
   
Line 598  foptions(int *fflags, char *arg)
Line 601  foptions(int *fflags, char *arg)
                         *fflags &= ~NO_IGN_ESCAPE;                          *fflags &= ~NO_IGN_ESCAPE;
                         break;                          break;
                 default:                  default:
                         warnx("bad argument: -f%s", o);                          fprintf(stderr, "%s: Bad argument", o);
                         return(0);                          return(0);
                 }                  }
         }          }
Line 627  woptions(int *wflags, char *arg)
Line 630  woptions(int *wflags, char *arg)
                         *wflags |= WARN_WERR;                          *wflags |= WARN_WERR;
                         break;                          break;
                 default:                  default:
                         warnx("bad argument: -W%s", o);                          fprintf(stderr, "%s: Bad argument", o);
                         return(0);                          return(0);
                 }                  }
         }          }

Legend:
Removed from v.1.52  
changed lines
  Added in v.1.56

CVSweb