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

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

version 1.225, 2015/03/10 13:50:03 version 1.227, 2015/03/17 13:35:52
Line 27 
Line 27 
 #include <errno.h>  #include <errno.h>
 #include <fcntl.h>  #include <fcntl.h>
 #include <glob.h>  #include <glob.h>
   #include <signal.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdint.h>  #include <stdint.h>
 #include <stdlib.h>  #include <stdlib.h>
Line 92  static int    fs_lookup(const struct manpaths *,
Line 93  static int    fs_lookup(const struct manpaths *,
 static  void              fs_search(const struct mansearch *,  static  void              fs_search(const struct mansearch *,
                                 const struct manpaths *, int, char**,                                  const struct manpaths *, int, char**,
                                 struct manpage **, size_t *);                                  struct manpage **, size_t *);
   static  void              handle_sigpipe(int);
 static  int               koptions(int *, char *);  static  int               koptions(int *, char *);
 #if HAVE_SQLITE3  #if HAVE_SQLITE3
 int                       mandocdb(int, char**);  int                       mandocdb(int, char**);
Line 99  int     mandocdb(int, char**);
Line 101  int     mandocdb(int, char**);
 static  int               moptions(int *, char *);  static  int               moptions(int *, char *);
 static  void              mmsg(enum mandocerr, enum mandoclevel,  static  void              mmsg(enum mandocerr, enum mandoclevel,
                                 const char *, int, int, const char *);                                  const char *, int, int, const char *);
 static  void              parse(struct curparse *, int,  static  void              parse(struct curparse *, int, const char *);
                                 const char *, enum mandoclevel *);  static  void              passthrough(const char *, int, int);
 static  enum mandoclevel  passthrough(const char *, int, int);  
 static  pid_t             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));
Line 111  static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2
Line 112  static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2
 static  char              help_arg[] = "help";  static  char              help_arg[] = "help";
 static  char             *help_argv[] = {help_arg, NULL};  static  char             *help_argv[] = {help_arg, NULL};
 static  const char       *progname;  static  const char       *progname;
   static  enum mandoclevel  rc;
   
   
 int  int
Line 127  main(int argc, char *argv[])
Line 129  main(int argc, char *argv[])
         size_t           isec, i, sz;          size_t           isec, i, sz;
         int              prio, best_prio, synopsis_only;          int              prio, best_prio, synopsis_only;
         char             sec;          char             sec;
         enum mandoclevel rc, rctmp;          enum mandoclevel rctmp;
         enum outmode     outmode;          enum outmode     outmode;
         int              fd;          int              fd;
         int              show_usage;          int              show_usage;
Line 420  main(int argc, char *argv[])
Line 422  main(int argc, char *argv[])
         if (argc < 1) {          if (argc < 1) {
                 if (pager_pid == 1 && isatty(STDOUT_FILENO))                  if (pager_pid == 1 && isatty(STDOUT_FILENO))
                         pager_pid = spawn_pager();                          pager_pid = spawn_pager();
                 parse(&curp, STDIN_FILENO, "<stdin>", &rc);                  parse(&curp, STDIN_FILENO, "<stdin>");
         }          }
   
         while (argc > 0) {          while (argc > 0) {
Line 434  main(int argc, char *argv[])
Line 436  main(int argc, char *argv[])
                                 pager_pid = spawn_pager();                                  pager_pid = spawn_pager();
   
                         if (resp == NULL)                          if (resp == NULL)
                                 parse(&curp, fd, *argv, &rc);                                  parse(&curp, fd, *argv);
                         else if (resp->form & FORM_SRC) {                          else if (resp->form & FORM_SRC) {
                                 /* For .so only; ignore failure. */                                  /* For .so only; ignore failure. */
                                 chdir(paths.paths[resp->ipath]);                                  chdir(paths.paths[resp->ipath]);
                                 parse(&curp, fd, resp->file, &rc);                                  parse(&curp, fd, resp->file);
                         } else {                          } else
                                 rctmp = passthrough(resp->file, fd,                                  passthrough(resp->file, fd, synopsis_only);
                                     synopsis_only);  
                                 if (rc < rctmp)  
                                         rc = rctmp;  
                         }  
   
                         rctmp = mparse_wait(curp.mp);                          rctmp = mparse_wait(curp.mp);
                         if (rc < rctmp)                          if (rc < rctmp)
Line 629  fs_search(const struct mansearch *cfg, const struct ma
Line 627  fs_search(const struct mansearch *cfg, const struct ma
 }  }
   
 static void  static void
 parse(struct curparse *curp, int fd, const char *file,  parse(struct curparse *curp, int fd, const char *file)
         enum mandoclevel *level)  
 {  {
         enum mandoclevel  rc;          enum mandoclevel  rctmp;
         struct mdoc      *mdoc;          struct mdoc      *mdoc;
         struct man       *man;          struct man       *man;
   
Line 641  parse(struct curparse *curp, int fd, const char *file,
Line 638  parse(struct curparse *curp, int fd, const char *file,
         assert(file);          assert(file);
         assert(fd >= -1);          assert(fd >= -1);
   
         rc = mparse_readfd(curp->mp, fd, file);          rctmp = mparse_readfd(curp->mp, fd, file);
           if (rc < rctmp)
                   rc = rctmp;
   
         /*          /*
          * With -Wstop and warnings or errors of at least the requested           * With -Wstop and warnings or errors of at least the requested
          * level, do not produce output.           * level, do not produce output.
          */           */
   
         if (MANDOCLEVEL_OK != rc && curp->wstop)          if (rctmp != MANDOCLEVEL_OK && curp->wstop)
                 goto cleanup;                  return;
   
         /* If unset, allocate output dev now (if applicable). */          /* If unset, allocate output dev now (if applicable). */
   
Line 727  parse(struct curparse *curp, int fd, const char *file,
Line 726  parse(struct curparse *curp, int fd, const char *file,
                 (*curp->outman)(curp->outdata, man);                  (*curp->outman)(curp->outdata, man);
         if (mdoc && curp->outmdoc)          if (mdoc && curp->outmdoc)
                 (*curp->outmdoc)(curp->outdata, mdoc);                  (*curp->outmdoc)(curp->outdata, mdoc);
   
 cleanup:  
         if (*level < rc)  
                 *level = rc;  
 }  }
   
 static enum mandoclevel  static void
 passthrough(const char *file, int fd, int synopsis_only)  passthrough(const char *file, int fd, int synopsis_only)
 {  {
         const char       synb[] = "S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS";          const char       synb[] = "S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS";
Line 791  passthrough(const char *file, int fd, int synopsis_onl
Line 786  passthrough(const char *file, int fd, int synopsis_onl
   
 done:  done:
         fclose(stream);          fclose(stream);
         return(MANDOCLEVEL_OK);          return;
   
 fail:  fail:
         fprintf(stderr, "%s: %s: SYSERR: %s: %s",          fprintf(stderr, "%s: %s: SYSERR: %s: %s",
             progname, file, syscall, strerror(errno));              progname, file, syscall, strerror(errno));
         return(MANDOCLEVEL_SYSERR);          if (rc < MANDOCLEVEL_SYSERR)
                   rc = MANDOCLEVEL_SYSERR;
 }  }
   
 static int  static int
Line 940  mmsg(enum mandocerr t, enum mandoclevel lvl,
Line 936  mmsg(enum mandocerr t, enum mandoclevel lvl,
         fputc('\n', stderr);          fputc('\n', stderr);
 }  }
   
   static void
   handle_sigpipe(int signum)
   {
   
           exit((int)rc);
   }
   
 static pid_t  static pid_t
 spawn_pager(void)  spawn_pager(void)
 {  {
Line 972  spawn_pager(void)
Line 975  spawn_pager(void)
                         exit((int)MANDOCLEVEL_SYSERR);                          exit((int)MANDOCLEVEL_SYSERR);
                 }                  }
                 close(fildes[1]);                  close(fildes[1]);
                   signal(SIGPIPE, handle_sigpipe);
                 return(pager_pid);                  return(pager_pid);
         }          }
   

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

CVSweb