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

Diff for /mandoc/main.c between version 1.195 and 1.200

version 1.195, 2014/10/28 17:36:19 version 1.200, 2014/11/26 21:40:17
Line 88  static void    mmsg(enum mandocerr, enum mandoclevel,
Line 88  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 *, enum mandoclevel *);                                  const char *, enum mandoclevel *);
 static  enum mandoclevel  passthrough(const char *, int);  static  enum mandoclevel  passthrough(const char *, int, int);
 static  void              spawn_pager(void);  static  void              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 115  main(int argc, char *argv[])
Line 115  main(int argc, char *argv[])
 #endif  #endif
         enum mandoclevel rc;          enum mandoclevel rc;
         enum outmode     outmode;          enum outmode     outmode;
         pid_t            child_pid;  
         int              fd;          int              fd;
         int              show_usage;          int              show_usage;
         int              use_pager;          int              use_pager;
           int              synopsis_only;
         int              options;          int              options;
         int              c;          int              c;
   
Line 155  main(int argc, char *argv[])
Line 155  main(int argc, char *argv[])
   
         use_pager = 1;          use_pager = 1;
         show_usage = 0;          show_usage = 0;
           synopsis_only = 0;
         outmode = OUTMODE_DEF;          outmode = OUTMODE_DEF;
   
         while (-1 != (c = getopt(argc, argv,          while (-1 != (c = getopt(argc, argv,
Line 174  main(int argc, char *argv[])
Line 175  main(int argc, char *argv[])
                         break;                          break;
                 case 'h':                  case 'h':
                         (void)strlcat(curp.outopts, "synopsis,", BUFSIZ);                          (void)strlcat(curp.outopts, "synopsis,", BUFSIZ);
                           synopsis_only = 1;
                           use_pager = 0;
                         outmode = OUTMODE_ALL;                          outmode = OUTMODE_ALL;
                         break;                          break;
                 case 'I':                  case 'I':
Line 290  main(int argc, char *argv[])
Line 293  main(int argc, char *argv[])
                 if (argc == 0)                  if (argc == 0)
                         usage(search.argmode);                          usage(search.argmode);
   
                   if (search.argmode == ARG_NAME &&
                       outmode == OUTMODE_ONE)
                           search.firstmatch = 1;
   
                 /* Access the mandoc database. */                  /* Access the mandoc database. */
   
                 manpath_parse(&paths, conf_file, defpaths, auxpaths);                  manpath_parse(&paths, conf_file, defpaths, auxpaths);
Line 380  main(int argc, char *argv[])
Line 387  main(int argc, char *argv[])
         while (argc) {          while (argc) {
 #if HAVE_SQLITE3  #if HAVE_SQLITE3
                 if (resp != NULL) {                  if (resp != NULL) {
                         rc = mparse_open(curp.mp, &fd, resp->file,                          rc = mparse_open(curp.mp, &fd, resp->file);
                             &child_pid);  
                         if (fd == -1)                          if (fd == -1)
                                 /* nothing */;                                  /* nothing */;
                         else if (resp->form & FORM_SRC) {                          else if (resp->form & FORM_SRC) {
Line 389  main(int argc, char *argv[])
Line 395  main(int argc, char *argv[])
                                 chdir(paths.paths[resp->ipath]);                                  chdir(paths.paths[resp->ipath]);
                                 parse(&curp, fd, resp->file, &rc);                                  parse(&curp, fd, resp->file, &rc);
                         } else                          } else
                                 rc = passthrough(resp->file, fd);                                  rc = passthrough(resp->file, fd,
                                       synopsis_only);
                         resp++;                          resp++;
                 } else                  } else
 #endif  #endif
                 {                  {
                         rc = mparse_open(curp.mp, &fd, *argv++,                          rc = mparse_open(curp.mp, &fd, *argv++);
                             &child_pid);  
                         if (fd != -1)                          if (fd != -1)
                                 parse(&curp, fd, argv[-1], &rc);                                  parse(&curp, fd, argv[-1], &rc);
                 }                  }
   
                 if (child_pid &&                  if (mparse_wait(curp.mp) != MANDOCLEVEL_OK)
                     mparse_wait(curp.mp, child_pid) != MANDOCLEVEL_OK)  
                         rc = MANDOCLEVEL_SYSERR;                          rc = MANDOCLEVEL_SYSERR;
   
                 if (MANDOCLEVEL_OK != rc && curp.wstop)                  if (MANDOCLEVEL_OK != rc && curp.wstop)
Line 443  usage(enum argmode argmode)
Line 448  usage(enum argmode argmode)
         switch (argmode) {          switch (argmode) {
         case ARG_FILE:          case ARG_FILE:
                 fputs("usage: mandoc [-acfhklV] [-Ios=name] "                  fputs("usage: mandoc [-acfhklV] [-Ios=name] "
                     "[-mformat] [-Ooption] [-Toutput] [-Wlevel]\n"                      "[-Kencoding] [-mformat] [-Ooption]\n"
                     "\t      [file ...]\n", stderr);                      "\t      [-Toutput] [-Wlevel] [file ...]\n", stderr);
                 break;                  break;
         case ARG_NAME:          case ARG_NAME:
                 fputs("usage: man [-acfhklVw] [-C file] "                  fputs("usage: man [-acfhklVw] [-C file] "
Line 579  parse(struct curparse *curp, int fd, const char *file,
Line 584  parse(struct curparse *curp, int fd, const char *file,
 }  }
   
 static enum mandoclevel  static enum mandoclevel
 passthrough(const char *file, int fd)  passthrough(const char *file, int fd, int synopsis_only)
 {  {
         char             buf[BUFSIZ];          const char       synb[] = "S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS";
           const char       synr[] = "SYNOPSIS";
   
           FILE            *stream;
         const char      *syscall;          const char      *syscall;
         ssize_t          nr, nw, off;          char            *line;
           size_t           len, off;
           ssize_t          nw;
           int              print;
   
         while ((nr = read(fd, buf, BUFSIZ)) != -1 && nr != 0)          if ((stream = fdopen(fd, "r")) == NULL) {
                 for (off = 0; off < nr; off += nw)                  close(fd);
                         if ((nw = write(STDOUT_FILENO, buf + off,                  syscall = "fdopen";
                             (size_t)(nr - off))) == -1 || nw == 0) {                  goto fail;
                                 close(fd);          }
   
           print = 0;
           while ((line = fgetln(stream, &len)) != NULL) {
                   if (synopsis_only) {
                           if (print) {
                                   if ( ! isspace((unsigned char)*line))
                                           goto done;
                                   while (len &&
                                       isspace((unsigned char)*line)) {
                                           line++;
                                           len--;
                                   }
                           } else {
                                   if ((len == sizeof(synb) &&
                                        ! strncmp(line, synb, len - 1)) ||
                                       (len == sizeof(synr) &&
                                        ! strncmp(line, synr, len - 1)))
                                           print = 1;
                                   continue;
                           }
                   }
                   for (off = 0; off < len; off += nw)
                           if ((nw = write(STDOUT_FILENO, line + off,
                               len - off)) == -1 || nw == 0) {
                                   fclose(stream);
                                 syscall = "write";                                  syscall = "write";
                                 goto fail;                                  goto fail;
                         }                          }
           }
   
         close(fd);          if (ferror(stream)) {
                   fclose(stream);
                   syscall = "fgetln";
                   goto fail;
           }
   
         if (nr == 0)  done:
                 return(MANDOCLEVEL_OK);          fclose(stream);
           return(MANDOCLEVEL_OK);
   
         syscall = "read";  
 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));

Legend:
Removed from v.1.195  
changed lines
  Added in v.1.200

CVSweb