]> git.cameronkatri.com Git - mandoc.git/blobdiff - dbm.c
link to http://mdocml.bsd.lv/mdoc/ below SEE ALSO;
[mandoc.git] / dbm.c
diff --git a/dbm.c b/dbm.c
index d4e69bc35337c19738428af2a9f8a61770bf35c6..0800f7658f06120429fca69ac41da040ed9bbb96 100644 (file)
--- a/dbm.c
+++ b/dbm.c
@@ -1,4 +1,4 @@
-/*     $Id: dbm.c,v 1.1 2016/07/19 21:31:55 schwarze Exp $ */
+/*     $Id: dbm.c,v 1.4 2016/08/30 22:01:07 schwarze Exp $ */
 /*
  * Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Map-based version of the mandoc database, for read-only access.
  * The interface is defined in "dbm.h".
  */
+#include "config.h"
+
 #include <assert.h>
+#if HAVE_ENDIAN
 #include <endian.h>
+#elif HAVE_SYS_ENDIAN
+#include <sys/endian.h>
+#elif HAVE_NTOHL
+#include <arpa/inet.h>
+#endif
+#if HAVE_ERR
 #include <err.h>
+#endif
 #include <errno.h>
 #include <regex.h>
 #include <stdint.h>
@@ -140,10 +150,18 @@ dbm_page_get(int32_t ip)
        assert(ip >= 0);
        assert(ip < npages);
        res.name = dbm_get(pages[ip].name);
+       if (res.name == NULL)
+               res.name = "(NULL)";
        res.sect = dbm_get(pages[ip].sect);
+       if (res.sect == NULL)
+               res.sect = "(NULL)";
        res.arch = pages[ip].arch ? dbm_get(pages[ip].arch) : NULL;
        res.desc = dbm_get(pages[ip].desc);
+       if (res.desc == NULL)
+               res.desc = "(NULL)";
        res.file = dbm_get(pages[ip].file);
+       if (res.file == NULL)
+               res.file = " (NULL)";
        res.addr = dbm_addr(pages + ip);
        return &res;
 }
@@ -240,7 +258,13 @@ page_bytitle(enum iter arg_iter, const struct dbm_match *arg_match)
                default:
                        abort();
                }
-               ip = 0;
+               if (cp == NULL) {
+                       iteration = ITER_NONE;
+                       match = NULL;
+                       cp = NULL;
+                       ip = npages;
+               } else
+                       ip = 0;
                return res;
        }