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

Diff for /mandoc/mandocdb.c between version 1.220.2.2 and 1.220.2.3

version 1.220.2.2, 2016/10/20 17:40:12 version 1.220.2.3, 2016/10/20 18:52:27
Line 2 
Line 2 
 /*  /*
  * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2011-2016 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2011-2016 Ingo Schwarze <schwarze@openbsd.org>
    * Copyright (c) 2016 Ed Maste <emaste@freebsd.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 103  struct mpage {
Line 104  struct mpage {
         char            *arch;    /* architecture from file content */          char            *arch;    /* architecture from file content */
         char            *title;   /* title from file content */          char            *title;   /* title from file content */
         char            *desc;    /* description from file content */          char            *desc;    /* description from file content */
           struct mpage    *next;    /* singly linked list */
         struct mlink    *mlinks;  /* singly linked list */          struct mlink    *mlinks;  /* singly linked list */
         int              form;    /* format from file content */          int              form;    /* format from file content */
         int              name_head_done;          int              name_head_done;
Line 149  static void  dbadd_mlink_name(const struct mlink *mlin
Line 151  static void  dbadd_mlink_name(const struct mlink *mlin
 static  int      dbopen(int);  static  int      dbopen(int);
 static  void     dbprune(void);  static  void     dbprune(void);
 static  void     filescan(const char *);  static  void     filescan(const char *);
   #if HAVE_FTS_COMPARE_CONST
   static  int      fts_compare(const FTSENT *const *, const FTSENT *const *);
   #else
   static  int      fts_compare(const FTSENT **, const FTSENT **);
   #endif
 static  void     mlink_add(struct mlink *, const struct stat *);  static  void     mlink_add(struct mlink *, const struct stat *);
 static  void     mlink_check(struct mpage *, struct mlink *);  static  void     mlink_check(struct mpage *, struct mlink *);
 static  void     mlink_free(struct mlink *);  static  void     mlink_free(struct mlink *);
Line 201  static int   write_utf8; /* write UTF-8 output; else A
Line 208  static int   write_utf8; /* write UTF-8 output; else A
 static  int              exitcode; /* to be returned by main */  static  int              exitcode; /* to be returned by main */
 static  enum op          op; /* operational mode */  static  enum op          op; /* operational mode */
 static  char             basedir[PATH_MAX]; /* current base directory */  static  char             basedir[PATH_MAX]; /* current base directory */
   static  struct mpage    *mpage_head; /* list of distinct manual pages */
 static  struct ohash     mpages; /* table of distinct manual pages */  static  struct ohash     mpages; /* table of distinct manual pages */
 static  struct ohash     mlinks; /* table of directory entries */  static  struct ohash     mlinks; /* table of directory entries */
 static  struct ohash     names; /* table of all names */  static  struct ohash     names; /* table of all names */
Line 576  usage:
Line 584  usage:
 }  }
   
 /*  /*
    * To get a singly linked list in alpha order while inserting entries
    * at the beginning, process directory entries in reverse alpha order.
    */
   static int
   #if HAVE_FTS_COMPARE_CONST
   fts_compare(const FTSENT *const *a, const FTSENT *const *b)
   #else
   fts_compare(const FTSENT **a, const FTSENT **b)
   #endif
   {
           return -strcmp((*a)->fts_name, (*b)->fts_name);
   }
   
   /*
  * Scan a directory tree rooted at "basedir" for manpages.   * Scan a directory tree rooted at "basedir" for manpages.
  * We use fts(), scanning directory parts along the way for clues to our   * We use fts(), scanning directory parts along the way for clues to our
  * section and architecture.   * section and architecture.
Line 604  treescan(void)
Line 626  treescan(void)
         argv[0] = ".";          argv[0] = ".";
         argv[1] = (char *)NULL;          argv[1] = (char *)NULL;
   
         f = fts_open((char * const *)argv,          f = fts_open((char * const *)argv, FTS_PHYSICAL | FTS_NOCHDIR,
             FTS_PHYSICAL | FTS_NOCHDIR, NULL);              fts_compare);
         if (f == NULL) {          if (f == NULL) {
                 exitcode = (int)MANDOCLEVEL_SYSERR;                  exitcode = (int)MANDOCLEVEL_SYSERR;
                 say("", "&fts_open");                  say("", "&fts_open");
Line 970  mlink_add(struct mlink *mlink, const struct stat *st)
Line 992  mlink_add(struct mlink *mlink, const struct stat *st)
                 mpage = mandoc_calloc(1, sizeof(struct mpage));                  mpage = mandoc_calloc(1, sizeof(struct mpage));
                 mpage->inodev.st_ino = inodev.st_ino;                  mpage->inodev.st_ino = inodev.st_ino;
                 mpage->inodev.st_dev = inodev.st_dev;                  mpage->inodev.st_dev = inodev.st_dev;
                   mpage->next = mpage_head;
                   mpage_head = mpage;
                 ohash_insert(&mpages, slot, mpage);                  ohash_insert(&mpages, slot, mpage);
         } else          } else
                 mlink->next = mpage->mlinks;                  mlink->next = mpage->mlinks;
Line 993  mpages_free(void)
Line 1017  mpages_free(void)
 {  {
         struct mpage    *mpage;          struct mpage    *mpage;
         struct mlink    *mlink;          struct mlink    *mlink;
         unsigned int     slot;  
   
         mpage = ohash_first(&mpages, &slot);          while ((mpage = mpage_head) != NULL) {
         while (NULL != mpage) {                  while ((mlink = mpage->mlinks) != NULL) {
                 while (NULL != (mlink = mpage->mlinks)) {  
                         mpage->mlinks = mlink->next;                          mpage->mlinks = mlink->next;
                         mlink_free(mlink);                          mlink_free(mlink);
                 }                  }
                   mpage_head = mpage->next;
                 free(mpage->sec);                  free(mpage->sec);
                 free(mpage->arch);                  free(mpage->arch);
                 free(mpage->title);                  free(mpage->title);
                 free(mpage->desc);                  free(mpage->desc);
                 free(mpage);                  free(mpage);
                 mpage = ohash_next(&mpages, &slot);  
         }          }
 }  }
   
Line 1127  mpages_merge(struct mparse *mp)
Line 1149  mpages_merge(struct mparse *mp)
         char                    *sodest;          char                    *sodest;
         char                    *cp;          char                    *cp;
         int                      fd;          int                      fd;
         unsigned int             pslot;  
   
         if ( ! nodb)          if ( ! nodb)
                 SQL_EXEC("BEGIN TRANSACTION");                  SQL_EXEC("BEGIN TRANSACTION");
   
         mpage = ohash_first(&mpages, &pslot);          for (mpage = mpage_head; mpage != NULL; mpage = mpage->next) {
         while (mpage != NULL) {  
                 mlinks_undupe(mpage);                  mlinks_undupe(mpage);
                 if ((mlink = mpage->mlinks) == NULL) {                  if ((mlink = mpage->mlinks) == NULL)
                         mpage = ohash_next(&mpages, &pslot);  
                         continue;                          continue;
                 }  
   
                 name_mask = NAME_MASK;                  name_mask = NAME_MASK;
                 mandoc_ohash_init(&names, 4, offsetof(struct str, key));                  mandoc_ohash_init(&names, 4, offsetof(struct str, key));
Line 1260  mpages_merge(struct mparse *mp)
Line 1278  mpages_merge(struct mparse *mp)
 nextpage:  nextpage:
                 ohash_delete(&strings);                  ohash_delete(&strings);
                 ohash_delete(&names);                  ohash_delete(&names);
                 mpage = ohash_next(&mpages, &pslot);  
         }          }
   
         if (0 == nodb)          if (0 == nodb)

Legend:
Removed from v.1.220.2.2  
changed lines
  Added in v.1.220.2.3

CVSweb