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

Diff for /mandoc/mandocdb.c between version 1.45 and 1.49

version 1.45, 2012/03/23 05:45:45 version 1.49, 2012/05/27 17:48:57
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2011, 2012 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 137  static void    index_merge(const struct of *, struct m
Line 137  static void    index_merge(const struct of *, struct m
                                 const char *);                                  const char *);
 static  void              index_prune(const struct of *, struct mdb *,  static  void              index_prune(const struct of *, struct mdb *,
                                 struct recs *, const char *);                                  struct recs *, const char *);
 static  void              ofile_argbuild(int, char *[],  static  void              ofile_argbuild(int, char *[],
                                 struct of **, const char *);                                  struct of **, const char *);
 static  void              ofile_dirbuild(const char *, const char *,  static  void              ofile_dirbuild(const char *, const char *,
                                 const char *, int, struct of **, char *);                                  const char *, int, struct of **, char *);
 static  void              ofile_free(struct of *);  static  void              ofile_free(struct of *);
 static  void              pformatted(DB *, struct buf *, struct buf *,  static  void              pformatted(DB *, struct buf *, struct buf *,
                                 const struct of *, const char *);                                  const struct of *, const char *);
 static  int               pman_node(MAN_ARGS);  static  int               pman_node(MAN_ARGS);
 static  void              pmdoc_node(MDOC_ARGS);  static  void              pmdoc_node(MDOC_ARGS);
Line 396  main(int argc, char *argv[])
Line 396  main(int argc, char *argv[])
         info.lorder = 4321;          info.lorder = 4321;
         info.flags = R_DUP;          info.flags = R_DUP;
   
         mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL);          mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL, NULL);
   
         memset(&buf, 0, sizeof(struct buf));          memset(&buf, 0, sizeof(struct buf));
         memset(&dbuf, 0, sizeof(struct buf));          memset(&dbuf, 0, sizeof(struct buf));
Line 410  main(int argc, char *argv[])
Line 410  main(int argc, char *argv[])
                 ofile_argbuild(argc, argv, &of, ".");                  ofile_argbuild(argc, argv, &of, ".");
                 if (NULL == of)                  if (NULL == of)
                         goto out;                          goto out;
                 index_merge(of, mp, &dbuf, &buf,                  index_merge(of, mp, &dbuf, &buf,
                                 hash, &mdb, &recs, ".");                                  hash, &mdb, &recs, ".");
                 goto out;                  goto out;
         }          }
Line 547  out:
Line 547  out:
   
 usage:  usage:
         fprintf(stderr,          fprintf(stderr,
                 "usage: %s [-avvv] [-C file] | dir ... | -t file ...\n"                  "usage: %s [-av] [-C file] | dir ... | -t file ...\n"
                 "                        -d dir [file ...] | "                  "                        -d dir [file ...] | "
                 "-u dir [file ...]\n",                  "-u dir [file ...]\n",
                 progname);                  progname);
Line 651  index_merge(const struct of *of, struct mparse *mp,
Line 651  index_merge(const struct of *of, struct mparse *mp,
                 assert(march);                  assert(march);
                 if (strcasecmp(march, of->arch))                  if (strcasecmp(march, of->arch))
                         WARNING(fn, basedir, "Architecture \"%s\" "                          WARNING(fn, basedir, "Architecture \"%s\" "
                                 "manual in \"%s\" directory",                                  "manual in \"%s\" directory",
                                 march, of->arch);                                  march, of->arch);
   
                 /*                  /*
Line 822  index_merge(const struct of *of, struct mparse *mp,
Line 822  index_merge(const struct of *of, struct mparse *mp,
                 while (0 == (*files->seq)(files, &key, &val, seq)) {                  while (0 == (*files->seq)(files, &key, &val, seq)) {
                         seq = R_NEXT;                          seq = R_NEXT;
                         if (val.size)                          if (val.size)
                                 fprintf(stderr, "%s: probably "                                  WARNING((char *)val.data, basedir,
                                     "unreachable, title is %s\n",                                          "Probably unreachable, title "
                                     (char *)val.data, (char *)key.data);                                          "is %s", (char *)key.data);
                 }                  }
                 (*files->close)(files);                  (*files->close)(files);
         }          }
Line 837  index_merge(const struct of *of, struct mparse *mp,
Line 837  index_merge(const struct of *of, struct mparse *mp,
  * in `idx' (zeroing its value size).   * in `idx' (zeroing its value size).
  */   */
 static void  static void
 index_prune(const struct of *ofile, struct mdb *mdb,  index_prune(const struct of *ofile, struct mdb *mdb,
                 struct recs *recs, const char *basedir)                  struct recs *recs, const char *basedir)
 {  {
         const struct of *of;          const struct of *of;
Line 913  index_prune(const struct of *ofile, struct mdb *mdb, 
Line 913  index_prune(const struct of *ofile, struct mdb *mdb, 
                 }                  }
   
                 if (verb)                  if (verb)
                         printf("%s: Deleting from index: %s\n",                          printf("%s: Deleting from index: %s\n",
                                         basedir, fn);                                          basedir, fn);
   
                 val.size = 0;                  val.size = 0;
Line 1323  static int
Line 1323  static int
 pman_node(MAN_ARGS)  pman_node(MAN_ARGS)
 {  {
         const struct man_node *head, *body;          const struct man_node *head, *body;
         const char      *start, *sv;          char            *start, *sv, *title;
         size_t           sz;          size_t           sz, titlesz;
   
         if (NULL == n)          if (NULL == n)
                 return(0);                  return(0);
Line 1347  pman_node(MAN_ARGS)
Line 1347  pman_node(MAN_ARGS)
                                 NULL != (body = body->child) &&                                  NULL != (body = body->child) &&
                                 MAN_TEXT == body->type) {                                  MAN_TEXT == body->type) {
   
                         assert(body->string);                          title = NULL;
                         start = sv = body->string;                          titlesz = 0;
                           /*
                            * Suck the entire NAME section into memory.
                            * Yes, we might run away.
                            * But too many manuals have big, spread-out
                            * NAME sections over many lines.
                            */
                           for ( ; NULL != body; body = body->next) {
                                   if (MAN_TEXT != body->type)
                                           break;
                                   if (0 == (sz = strlen(body->string)))
                                           continue;
                                   title = mandoc_realloc
                                           (title, titlesz + sz + 1);
                                   memcpy(title + titlesz, body->string, sz);
                                   titlesz += sz + 1;
                                   title[(int)titlesz - 1] = ' ';
                           }
                           if (NULL == title)
                                   return(0);
   
                           title = mandoc_realloc(title, titlesz + 1);
                           title[(int)titlesz] = '\0';
   
                           /* Skip leading space.  */
   
                           sv = title;
                           while (isspace((unsigned char)*sv))
                                   sv++;
   
                           if (0 == (sz = strlen(sv))) {
                                   free(title);
                                   return(0);
                           }
   
                           /* Erase trailing space. */
   
                           start = &sv[sz - 1];
                           while (start > sv && isspace((unsigned char)*start))
                                   *start-- = '\0';
   
                           if (start == sv) {
                                   free(title);
                                   return(0);
                           }
   
                           start = sv;
   
                         /*                          /*
                          * Go through a special heuristic dance here.                           * Go through a special heuristic dance here.
                          * This is why -man manuals are great!                           * This is why -man manuals are great!
Line 1386  pman_node(MAN_ARGS)
Line 1432  pman_node(MAN_ARGS)
   
                         if (sv == start) {                          if (sv == start) {
                                 buf_append(buf, start);                                  buf_append(buf, start);
                                   free(title);
                                 return(1);                                  return(1);
                         }                          }
   
                         while (' ' == *start)                          while (isspace((unsigned char)*start))
                                 start++;                                  start++;
   
                         if (0 == strncmp(start, "-", 1))                          if (0 == strncmp(start, "-", 1))
Line 1411  pman_node(MAN_ARGS)
Line 1458  pman_node(MAN_ARGS)
                         buf_appendb(buf, start, sz);                          buf_appendb(buf, start, sz);
   
                         hash_put(hash, buf, TYPE_Nd);                          hash_put(hash, buf, TYPE_Nd);
                           free(title);
                 }                  }
         }          }
   
Line 1712  ofile_dirbuild(const char *dir, const char* psec, cons
Line 1760  ofile_dirbuild(const char *dir, const char* psec, cons
                                 continue;                                  continue;
                         }                          }
   
                         ofile_dirbuild(buf, sec, arch,                          ofile_dirbuild(buf, sec, arch,
                                         src_form, of, basedir);                                          src_form, of, basedir);
   
                         p = strrchr(basedir, '/');                          p = strrchr(basedir, '/');

Legend:
Removed from v.1.45  
changed lines
  Added in v.1.49

CVSweb