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

Diff for /mandoc/main.c between version 1.185 and 1.188

version 1.185, 2014/08/22 18:07:15 version 1.188, 2014/08/30 18:08:10
Line 23 
Line 23 
 #include <assert.h>  #include <assert.h>
 #include <ctype.h>  #include <ctype.h>
 #include <errno.h>  #include <errno.h>
   #include <fcntl.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdint.h>  #include <stdint.h>
 #include <stdlib.h>  #include <stdlib.h>
Line 86  static void    mmsg(enum mandocerr, enum mandoclevel,
Line 87  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 *);
 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 105  main(int argc, char *argv[])
Line 107  main(int argc, char *argv[])
         char            *conf_file, *defpaths, *auxpaths;          char            *conf_file, *defpaths, *auxpaths;
         char            *defos;          char            *defos;
 #if HAVE_SQLITE3  #if HAVE_SQLITE3
         struct manpage  *res;          struct manpage  *res, *resp;
         char            **auxargv;  
         size_t           isec, i, sz;          size_t           isec, i, sz;
         int              prio, best_prio;          int              prio, best_prio;
         char             sec;          char             sec;
Line 153  main(int argc, char *argv[])
Line 154  main(int argc, char *argv[])
         show_usage = 0;          show_usage = 0;
         outmode = OUTMODE_DEF;          outmode = OUTMODE_DEF;
   
         while (-1 != (c = getopt(argc, argv, "aC:cfI:ikM:m:O:S:s:T:VW:w"))) {          while (-1 != (c = getopt(argc, argv, "aC:cfI:iklM:m:O:S:s:T:VW:w"))) {
                 switch (c) {                  switch (c) {
                 case 'a':                  case 'a':
                         outmode = OUTMODE_ALL;                          outmode = OUTMODE_ALL;
Line 188  main(int argc, char *argv[])
Line 189  main(int argc, char *argv[])
                 case 'k':                  case 'k':
                         search.argmode = ARG_EXPR;                          search.argmode = ARG_EXPR;
                         break;                          break;
                   case 'l':
                           search.argmode = ARG_FILE;
                           outmode = OUTMODE_ALL;
                           break;
                 case 'M':                  case 'M':
                         defpaths = optarg;                          defpaths = optarg;
                         break;                          break;
Line 250  main(int argc, char *argv[])
Line 255  main(int argc, char *argv[])
         argc -= optind;          argc -= optind;
         argv += optind;          argv += optind;
 #if HAVE_SQLITE3  #if HAVE_SQLITE3
         auxargv = NULL;          resp = NULL;
 #endif  #endif
   
         /* Quirk for a man(1) section argument without -s. */          /* Quirk for a man(1) section argument without -s. */
Line 280  main(int argc, char *argv[])
Line 285  main(int argc, char *argv[])
                 if( ! mansearch(&search, &paths, argc, argv, &res, &sz))                  if( ! mansearch(&search, &paths, argc, argv, &res, &sz))
                         usage(search.argmode);                          usage(search.argmode);
                 manpath_free(&paths);                  manpath_free(&paths);
                   resp = res;
   
                   if (sz == 0) {
                           if (search.argmode == ARG_NAME)
                                   fprintf(stderr, "%s: No entry for %s "
                                       "in the manual.\n", progname, argv[0]);
                           rc = MANDOCLEVEL_BADARG;
                           goto out;
                   }
   
                 /*                  /*
                  * For standard man(1) and -a output mode,                   * For standard man(1) and -a output mode,
                  * prepare for copying filename pointers                   * prepare for copying filename pointers
Line 289  main(int argc, char *argv[])
Line 303  main(int argc, char *argv[])
   
                 if (outmode == OUTMODE_ONE) {                  if (outmode == OUTMODE_ONE) {
                         argc = 1;                          argc = 1;
                         argv[0] = res[0].file;  
                         argv[1] = NULL;  
                         best_prio = 10;                          best_prio = 10;
                 } else if (outmode == OUTMODE_ALL) {                  } else if (outmode == OUTMODE_ALL)
                         argc = (int)sz;                          argc = (int)sz;
                         argv = auxargv = mandoc_reallocarray(  
                             NULL, sz + 1, sizeof(char *));  
                         argv[argc] = NULL;  
                 }  
   
                 /* Iterate all matching manuals. */                  /* Iterate all matching manuals. */
   
Line 308  main(int argc, char *argv[])
Line 316  main(int argc, char *argv[])
                                 printf("%s - %s\n", res[i].names,                                  printf("%s - %s\n", res[i].names,
                                     res[i].output == NULL ? "" :                                      res[i].output == NULL ? "" :
                                     res[i].output);                                      res[i].output);
                         else if (outmode == OUTMODE_ALL)                          else if (outmode == OUTMODE_ONE) {
                                 argv[i] = res[i].file;  
                         else {  
                                 /* Search for the best section. */                                  /* Search for the best section. */
                                 isec = strcspn(res[i].file, "123456789");                                  isec = strcspn(res[i].file, "123456789");
                                 sec = res[i].file[isec];                                  sec = res[i].file[isec];
Line 320  main(int argc, char *argv[])
Line 326  main(int argc, char *argv[])
                                 if (prio >= best_prio)                                  if (prio >= best_prio)
                                         continue;                                          continue;
                                 best_prio = prio;                                  best_prio = prio;
                                 argv[0] = res[i].file;                                  resp = res + i;
                         }                          }
                 }                  }
   
Line 355  main(int argc, char *argv[])
Line 361  main(int argc, char *argv[])
         if (OUTT_MAN == curp.outtype)          if (OUTT_MAN == curp.outtype)
                 mparse_keep(curp.mp);                  mparse_keep(curp.mp);
   
         if (NULL == *argv)          if (argc == 0)
                 parse(&curp, STDIN_FILENO, "<stdin>", &rc);                  parse(&curp, STDIN_FILENO, "<stdin>", &rc);
   
         while (*argv) {          while (argc) {
                 parse(&curp, -1, *argv, &rc);  #if HAVE_SQLITE3
                   if (resp != NULL) {
                           if (resp->form)
                                   parse(&curp, -1, resp->file, &rc);
                           else
                                   rc = passthrough(resp->file);
                           resp++;
                   } else
   #endif
                           parse(&curp, -1, *argv++, &rc);
                 if (MANDOCLEVEL_OK != rc && curp.wstop)                  if (MANDOCLEVEL_OK != rc && curp.wstop)
                         break;                          break;
                 ++argv;                  argc--;
         }          }
   
         if (curp.outfree)          if (curp.outfree)
Line 375  out:
Line 390  out:
         if (search.argmode != ARG_FILE) {          if (search.argmode != ARG_FILE) {
                 mansearch_free(res, sz);                  mansearch_free(res, sz);
                 mansearch_setup(0);                  mansearch_setup(0);
                 free(auxargv);  
         }          }
 #endif  #endif
   
Line 398  usage(enum argmode argmode)
Line 412  usage(enum argmode argmode)
   
         switch (argmode) {          switch (argmode) {
         case ARG_FILE:          case ARG_FILE:
                 fputs("usage: mandoc [-V] [-Ios=name] [-mformat]"                  fputs("usage: mandoc [-acfklV] [-Ios=name] "
                     " [-Ooption] [-Toutput] [-Wlevel]\n"                      "[-mformat] [-Ooption] [-Toutput] [-Wlevel]\n"
                     "\t      [file ...]\n", stderr);                      "\t      [file ...]\n", stderr);
                 break;                  break;
         case ARG_NAME:          case ARG_NAME:
                 fputs("usage: man [-acfhkVw] [-C file] "                  fputs("usage: man [-acfhklVw] [-C file] "
                     "[-M path] [-m path] [-S arch] [-s section]\n"                      "[-M path] [-m path] [-S arch] [-s section]\n"
                     "\t   [section] name ...\n", stderr);                      "\t   [section] name ...\n", stderr);
                 break;                  break;
         case ARG_WORD:          case ARG_WORD:
                 fputs("usage: whatis [-V] [-C file] [-M path] [-m path] "                  fputs("usage: whatis [-acfklVw] [-C file] "
                     "[-S arch] [-s section] name ...\n", stderr);                      "[-M path] [-m path] [-O outkey] [-S arch]\n"
                       "\t      [-s section] name ...\n", stderr);
                 break;                  break;
         case ARG_EXPR:          case ARG_EXPR:
                 fputs("usage: apropos [-V] [-C file] [-M path] [-m path] "                  fputs("usage: apropos [-acfklVw] [-C file] "
                     "[-O outkey] [-S arch]\n"                      "[-M path] [-m path] [-O outkey] [-S arch]\n"
                     "\t       [-s section] expression ...\n", stderr);                      "\t       [-s section] expression ...\n", stderr);
                 break;                  break;
         }          }
Line 531  parse(struct curparse *curp, int fd, const char *file,
Line 546  parse(struct curparse *curp, int fd, const char *file,
   
         if (*level < rc)          if (*level < rc)
                 *level = rc;                  *level = rc;
   }
   
   static enum mandoclevel
   passthrough(const char *file)
   {
           char             buf[BUFSIZ];
           const char      *syscall;
           ssize_t          nr, nw, off;
           int              fd;
   
           fd = open(file, O_RDONLY);
           if (fd == -1) {
                   syscall = "open";
                   goto fail;
           }
   
           while ((nr = read(fd, buf, BUFSIZ)) != -1 && nr != 0)
                   for (off = 0; off < nr; off += nw)
                           if ((nw = write(STDOUT_FILENO, buf + off,
                               (size_t)(nr - off))) == -1 || nw == 0) {
                                   syscall = "write";
                                   goto fail;
                           }
   
           if (nr == 0) {
                   close(fd);
                   return(MANDOCLEVEL_OK);
           }
   
           syscall = "read";
   fail:
           fprintf(stderr, "%s: %s: SYSERR: %s: %s",
               progname, file, syscall, strerror(errno));
           return(MANDOCLEVEL_SYSERR);
 }  }
   
 static int  static int

Legend:
Removed from v.1.185  
changed lines
  Added in v.1.188

CVSweb