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

Diff for /mandoc/mandocdb.c between version 1.55 and 1.56

version 1.55, 2012/06/09 14:11:16 version 1.56, 2013/06/03 19:01:31
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2011, 2012 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above   * purpose with or without fee is hereby granted, provided that the above
Line 47 
Line 47 
 #include "manpath.h"  #include "manpath.h"
 #include "mansearch.h"  #include "mansearch.h"
   
 /* Post a warning to stderr. */  
 #define WARNING(_f, _b, _fmt, _args...) \  
         do if (warnings) { \  
                 fprintf(stderr, "%s: ", (_b)); \  
                 fprintf(stderr, (_fmt), ##_args); \  
                 if ('\0' != *(_f)) \  
                         fprintf(stderr, ": %s", (_f)); \  
                 fprintf(stderr, "\n"); \  
         } while (/* CONSTCOND */ 0)  
 /* Post a "verbose" message to stderr. */  
 #define DEBUG(_f, _b, _fmt, _args...) \  
         do if (verb) { \  
                 fprintf(stderr, "%s: ", (_b)); \  
                 fprintf(stderr, (_fmt), ##_args); \  
                 fprintf(stderr, ": %s\n", (_f)); \  
         } while (/* CONSTCOND */ 0)  
   
 #define SQL_EXEC(_v) \  #define SQL_EXEC(_v) \
         if (SQLITE_OK != sqlite3_exec(db, (_v), NULL, NULL, NULL)) \          if (SQLITE_OK != sqlite3_exec(db, (_v), NULL, NULL, NULL)) \
                 fprintf(stderr, "%s\n", sqlite3_errmsg(db))                  fprintf(stderr, "%s\n", sqlite3_errmsg(db))
Line 179  static void  putkeys(const struct of *, 
Line 162  static void  putkeys(const struct of *, 
                         const char *, int, uint64_t);                          const char *, int, uint64_t);
 static  void     putmdockey(const struct of *,  static  void     putmdockey(const struct of *,
                         const struct mdoc_node *, uint64_t);                          const struct mdoc_node *, uint64_t);
   static  void     say(const char *, const char *, const char *, ...);
 static  char    *stradd(const char *);  static  char    *stradd(const char *);
 static  char    *straddbuf(const char *, size_t);  static  char    *straddbuf(const char *, size_t);
 static  int      treescan(const char *);  static  int      treescan(const char *);
Line 600  treescan(const char *base)
Line 584  treescan(const char *base)
                  */                   */
                 if (FTS_F == ff->fts_info) {                  if (FTS_F == ff->fts_info) {
                         if ( ! use_all && ff->fts_level < 2) {                          if ( ! use_all && ff->fts_level < 2) {
                                 WARNING(path, base, "Extraneous file");                                  if (warnings)
                                           say(base, path, "Extraneous file");
                                 continue;                                  continue;
                         } else if (inocheck(ff->fts_statp)) {                          } else if (inocheck(ff->fts_statp)) {
                                 WARNING(path, base, "Duplicate file");                                  if (warnings)
                                           say(base, path, "Duplicate file");
                                 continue;                                  continue;
                         }                          }
   
                         cp = ff->fts_name;                          cp = ff->fts_name;
   
                         if (0 == strcmp(cp, "mandocdb.db")) {                          if (0 == strcmp(cp, "mandocdb.db")) {
                                 WARNING(path, base, "Skip database");                                  if (warnings)
                                           say(base, path, "Skip database");
                                 continue;                                  continue;
                         } else if (NULL != (cp = strrchr(cp, '.'))) {                          } else if (NULL != (cp = strrchr(cp, '.'))) {
                                 if (0 == strcmp(cp + 1, "html")) {                                  if (0 == strcmp(cp + 1, "html")) {
                                         WARNING(path, base, "Skip html");                                          if (warnings)
                                                   say(base, path, "Skip html");
                                         continue;                                          continue;
                                 } else if (0 == strcmp(cp + 1, "gz")) {                                  } else if (0 == strcmp(cp + 1, "gz")) {
                                         WARNING(path, base, "Skip gz");                                          if (warnings)
                                                   say(base, path, "Skip gz");
                                         continue;                                          continue;
                                 } else if (0 == strcmp(cp + 1, "ps")) {                                  } else if (0 == strcmp(cp + 1, "ps")) {
                                         WARNING(path, base, "Skip ps");                                          if (warnings)
                                                   say(base, path, "Skip ps");
                                         continue;                                          continue;
                                 } else if (0 == strcmp(cp + 1, "pdf")) {                                  } else if (0 == strcmp(cp + 1, "pdf")) {
                                         WARNING(path, base, "Skip pdf");                                          if (warnings)
                                                   say(base, path, "Skip pdf");
                                         continue;                                          continue;
                                 }                                  }
                         }                          }
Line 667  treescan(const char *base)
Line 658  treescan(const char *base)
                         if (NULL != dsec || use_all)                          if (NULL != dsec || use_all)
                                 break;                                  break;
   
                         WARNING(path, base, "Unknown directory part");                          if (warnings)
                                   say(base, path, "Unknown directory part");
                         fts_set(f, ff, FTS_SKIP);                          fts_set(f, ff, FTS_SKIP);
                         break;                          break;
                 case (2):                  case (2):
Line 682  treescan(const char *base)
Line 674  treescan(const char *base)
                 default:                  default:
                         if (FTS_DP == ff->fts_info || use_all)                          if (FTS_DP == ff->fts_info || use_all)
                                 break;                                  break;
                         WARNING(path, base, "Extraneous directory part");                          if (warnings)
                                   say(base, path, "Extraneous directory part");
                         fts_set(f, ff, FTS_SKIP);                          fts_set(f, ff, FTS_SKIP);
                         break;                          break;
                 }                  }
Line 721  filescan(const char *file, const char *base)
Line 714  filescan(const char *file, const char *base)
                 file += 2;                  file += 2;
   
         if (-1 == stat(file, &st)) {          if (-1 == stat(file, &st)) {
                 WARNING(file, base, "%s", strerror(errno));                  if (warnings)
                           say(base, file, "%s", strerror(errno));
                 return;                  return;
         } else if ( ! (S_IFREG & st.st_mode)) {          } else if ( ! (S_IFREG & st.st_mode)) {
                 WARNING(file, base, "Not a regular file");                  if (warnings)
                           say(base, file, "Not a regular file");
                 return;                  return;
         } else if (inocheck(&st)) {          } else if (inocheck(&st)) {
                 WARNING(file, base, "Duplicate file");                  if (warnings)
                           say(base, file, "Duplicate file");
                 return;                  return;
         }          }
   
Line 941  ofmerge(struct mchars *mc, struct mparse *mp, const ch
Line 937  ofmerge(struct mchars *mc, struct mparse *mp, const ch
                 if ( ! use_all && FORM_CAT == of->dform) {                  if ( ! use_all && FORM_CAT == of->dform) {
                         sz = strlcpy(buf, of->file, MAXPATHLEN);                          sz = strlcpy(buf, of->file, MAXPATHLEN);
                         if (sz >= MAXPATHLEN) {                          if (sz >= MAXPATHLEN) {
                                 WARNING(of->file, base,                                  if (warnings)
                                         "Filename too long");                                          say(base, of->file,
                                               "Filename too long");
                                 continue;                                  continue;
                         }                          }
                         bufp = strstr(buf, "cat");                          bufp = strstr(buf, "cat");
Line 952  ofmerge(struct mchars *mc, struct mparse *mp, const ch
Line 949  ofmerge(struct mchars *mc, struct mparse *mp, const ch
                                 *++bufp = '\0';                                  *++bufp = '\0';
                         strlcat(buf, of->dsec, MAXPATHLEN);                          strlcat(buf, of->dsec, MAXPATHLEN);
                         if (filecheck(buf)) {                          if (filecheck(buf)) {
                                 WARNING(of->file, base, "Man "                                  if (warnings)
                                         "source exists: %s", buf);                                          say(base, of->file, "Man "
                                               "source exists: %s", buf);
                                 continue;                                  continue;
                         }                          }
                 }                  }
Line 1006  ofmerge(struct mchars *mc, struct mparse *mp, const ch
Line 1004  ofmerge(struct mchars *mc, struct mparse *mp, const ch
                  * section, like encrypt(1) = makekey(8).  Do not skip                   * section, like encrypt(1) = makekey(8).  Do not skip
                  * manuals for such reasons.                   * manuals for such reasons.
                  */                   */
                 if ( ! use_all && form && strcasecmp(msec, of->dsec))                  if (warnings && !use_all && form &&
                         WARNING(of->file, base, "Section \"%s\" "                                  strcasecmp(msec, of->dsec))
                           say(base, of->file, "Section \"%s\" "
                                 "manual in %s directory",                                  "manual in %s directory",
                                 msec, of->dsec);                                  msec, of->dsec);
   
Line 1025  ofmerge(struct mchars *mc, struct mparse *mp, const ch
Line 1024  ofmerge(struct mchars *mc, struct mparse *mp, const ch
                  * Thus, warn about architecture mismatches,                   * Thus, warn about architecture mismatches,
                  * but don't skip manuals for this reason.                   * but don't skip manuals for this reason.
                  */                   */
                 if ( ! use_all && strcasecmp(march, of->arch))                  if (warnings && !use_all && strcasecmp(march, of->arch))
                         WARNING(of->file, base, "Architecture \"%s\" "                          say(base, of->file, "Architecture \"%s\" "
                                 "manual in \"%s\" directory",                                  "manual in \"%s\" directory",
                                 march, of->arch);                                  march, of->arch);
   
Line 1055  parse_catpage(struct of *of, const char *base)
Line 1054  parse_catpage(struct of *of, const char *base)
         size_t           len, plen, titlesz;          size_t           len, plen, titlesz;
   
         if (NULL == (stream = fopen(of->file, "r"))) {          if (NULL == (stream = fopen(of->file, "r"))) {
                 WARNING(of->file, base, "%s", strerror(errno));                  if (warnings)
                           say(base, of->file, "%s", strerror(errno));
                 return;                  return;
         }          }
   
Line 1107  parse_catpage(struct of *of, const char *base)
Line 1107  parse_catpage(struct of *of, const char *base)
          */           */
   
         if (NULL == title || '\0' == *title) {          if (NULL == title || '\0' == *title) {
                 WARNING(of->file, base, "Cannot find NAME section");                  if (warnings)
                           say(base, of->file, "Cannot find NAME section");
                 fclose(stream);                  fclose(stream);
                 free(title);                  free(title);
                 return;                  return;
Line 1126  parse_catpage(struct of *of, const char *base)
Line 1127  parse_catpage(struct of *of, const char *base)
                 for (p += 2; ' ' == *p || '\b' == *p; p++)                  for (p += 2; ' ' == *p || '\b' == *p; p++)
                         /* Skip to next word. */ ;                          /* Skip to next word. */ ;
         } else {          } else {
                 WARNING(of->file, base, "No dash in title line");                  if (warnings)
                           say(base, of->file, "No dash in title line");
                 p = title;                  p = title;
         }          }
   
Line 1804  dbindex(struct mchars *mc, int form, 
Line 1806  dbindex(struct mchars *mc, int form, 
         int64_t          recno;          int64_t          recno;
         size_t           i;          size_t           i;
   
         DEBUG(of->file, base, "Adding to index");          if (verb)
                   say(base, of->file, "Adding to index");
   
         if (nodb)          if (nodb)
                 return;                  return;
Line 1859  dbprune(const char *base)
Line 1862  dbprune(const char *base)
                 SQL_BIND_TEXT(stmts[STMT_DELETE], i, of->file);                  SQL_BIND_TEXT(stmts[STMT_DELETE], i, of->file);
                 SQL_STEP(stmts[STMT_DELETE]);                  SQL_STEP(stmts[STMT_DELETE]);
                 sqlite3_reset(stmts[STMT_DELETE]);                  sqlite3_reset(stmts[STMT_DELETE]);
                 DEBUG(of->file, base, "Deleted from index");                  if (verb)
                           say(base, of->file, "Deleted from index");
         }          }
 }  }
   
Line 2011  path_reset(const char *cwd, int fd, const char *base)
Line 2015  path_reset(const char *cwd, int fd, const char *base)
                 return(0);                  return(0);
         }          }
         return(1);          return(1);
   }
   
   static void
   say(const char *dir, const char *file, const char *format, ...)
   {
           va_list          ap;
   
           fprintf(stderr, "%s", dir);
           if ('\0' != *file)
                   fprintf(stderr, "//%s", file);
           fputs(": ", stderr);
   
           va_start(ap, format);
           vfprintf(stderr, format, ap);
           va_end(ap);
   
           fputc('\n', stderr);
 }  }

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

CVSweb