Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/makemandb Sync with API changes.



details:   https://anonhg.NetBSD.org/src/rev/6a15dc8a5512
branches:  trunk
changeset: 816644:6a15dc8a5512
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Jul 15 19:41:33 2016 +0000

description:
Sync with API changes.

diffstat:

 usr.sbin/makemandb/makemandb.c |  213 ++++++++++++++++------------------------
 1 files changed, 87 insertions(+), 126 deletions(-)

diffs (truncated from 518 to 300 lines):

diff -r e8763b42476f -r 6a15dc8a5512 usr.sbin/makemandb/makemandb.c
--- a/usr.sbin/makemandb/makemandb.c    Fri Jul 15 19:40:42 2016 +0000
+++ b/usr.sbin/makemandb/makemandb.c    Fri Jul 15 19:41:33 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: makemandb.c,v 1.39 2016/07/06 08:52:01 abhinav Exp $   */
+/*     $NetBSD: makemandb.c,v 1.40 2016/07/15 19:41:33 christos Exp $  */
 /*
  * Copyright (c) 2011 Abhinav Upadhyay <er.abhinav.upadhyay%gmail.com@localhost>
  * Copyright (c) 2011 Kristaps Dzonsons <kristaps%bsd.lv@localhost>
@@ -17,7 +17,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: makemandb.c,v 1.39 2016/07/06 08:52:01 abhinav Exp $");
+__RCSID("$NetBSD: makemandb.c,v 1.40 2016/07/15 19:41:33 christos Exp $");
 
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -38,6 +38,7 @@
 #include "dist/man.h"
 #include "dist/mandoc.h"
 #include "dist/mdoc.h"
+#include "dist/roff.h"
 
 #define BUFLEN 1024
 #define MDOC 0 //If the page is of mdoc(7) type
@@ -59,7 +60,7 @@
        int verbosity;  // 0: quiet, 1: default, 2: verbose
 } makemandb_flags;
 
-typedef struct mandb_rec {
+typedef struct roff_mandb_rec {
        /* Fields for mandb table */
        char *name;     // for storing the name of the man page
        char *name_desc; // for storing the one line description (.Nd)
@@ -90,32 +91,32 @@
        int page_type; //Indicates the type of page: mdoc or man
 } mandb_rec;
 
+typedef        void (*proff_nf)(const struct roff_node *n, mandb_rec *);
+
 static void append(secbuff *sbuff, const char *src);
 static void init_secbuffs(mandb_rec *);
 static void free_secbuffs(mandb_rec *);
 static int check_md5(const char *, sqlite3 *, const char *, char **, void *, size_t);
 static void cleanup(mandb_rec *);
-static void set_section(const struct mdoc *, const struct man *, mandb_rec *);
-static void set_machine(const struct mdoc *, mandb_rec *);
+static void set_section(const struct roff_man *, mandb_rec *);
+static void set_machine(const struct roff_man *, mandb_rec *);
 static int insert_into_db(sqlite3 *, mandb_rec *);
 static void begin_parse(const char *, struct mparse *, mandb_rec *,
                         const void *, size_t len);
-static void pmdoc_node(const struct mdoc_node *, mandb_rec *);
-static void pmdoc_Nm(const struct mdoc_node *, mandb_rec *);
-static void pmdoc_Nd(const struct mdoc_node *, mandb_rec *);
-static void pmdoc_Sh(const struct mdoc_node *, mandb_rec *);
-static void pmdoc_Xr(const struct mdoc_node *, mandb_rec *);
-static void pmdoc_Pp(const struct mdoc_node *, mandb_rec *);
-static void pmdoc_macro_handler(const struct mdoc_node *, mandb_rec *,
-                               enum mdoct);
-static void pman_node(const struct man_node *n, mandb_rec *);
-static void pman_parse_node(const struct man_node *, secbuff *);
-static void pman_parse_name(const struct man_node *, mandb_rec *);
-static void pman_sh(const struct man_node *, mandb_rec *);
-static void pman_block(const struct man_node *, mandb_rec *);
+static void proff_node(const struct roff_node *, mandb_rec *, const proff_nf *);
+static void pmdoc_Nm(const struct roff_node *, mandb_rec *);
+static void pmdoc_Nd(const struct roff_node *, mandb_rec *);
+static void pmdoc_Sh(const struct roff_node *, mandb_rec *);
+static void pmdoc_Xr(const struct roff_node *, mandb_rec *);
+static void pmdoc_Pp(const struct roff_node *, mandb_rec *);
+static void pmdoc_macro_handler(const struct roff_node *, mandb_rec *, int);
+static void pman_parse_node(const struct roff_node *, secbuff *);
+static void pman_parse_name(const struct roff_node *, mandb_rec *);
+static void pman_sh(const struct roff_node *, mandb_rec *);
+static void pman_block(const struct roff_node *, mandb_rec *);
 static void traversedir(const char *, const char *, sqlite3 *, struct mparse *);
-static void mdoc_parse_section(enum mdoc_sec, const char *, mandb_rec *);
-static void man_parse_section(enum man_sec, const struct man_node *, mandb_rec *);
+static void mdoc_parse_section(enum roff_sec, const char *, mandb_rec *);
+static void man_parse_section(enum man_sec, const struct roff_node *, mandb_rec *);
 static void build_file_cache(sqlite3 *, const char *, const char *,
                             struct stat *);
 static void update_db(sqlite3 *, struct mparse *, mandb_rec *);
@@ -125,9 +126,7 @@
 static void replace_hyph(char *);
 static makemandb_flags mflags = { .verbosity = 1 };
 
-typedef        void (*pman_nf)(const struct man_node *n, mandb_rec *);
-typedef        void (*pmdoc_nf)(const struct mdoc_node *n, mandb_rec *);
-static const pmdoc_nf mdocs[MDOC_MAX + 1] = {
+static const proff_nf mdocs[MDOC_MAX + 1] = {
        NULL, /* Ap */
        NULL, /* Dd */
        NULL, /* Dt */
@@ -284,7 +283,7 @@
        NULL, /* text */
 };
 
-static const pman_nf mans[MAN_MAX] = {
+static const proff_nf mans[MAN_MAX] = {
        NULL,   //br
        NULL,   //TH
        pman_sh, //SH
@@ -330,7 +329,6 @@
 main(int argc, char *argv[])
 {
        FILE *file;
-       struct mchars *mchars;
        const char *sqlstr, *manconf = NULL;
        char *line, *command, *parent;
        char *errmsg;
@@ -339,7 +337,7 @@
        sqlite3 *db;
        ssize_t len;
        size_t linesize;
-       struct mandb_rec rec;
+       struct roff_mandb_rec rec;
 
        while ((ch = getopt(argc, argv, "C:floQqv")) != -1) {
                switch (ch) {
@@ -372,10 +370,8 @@
        memset(&rec, 0, sizeof(rec));
 
        init_secbuffs(&rec);
-       mchars = mchars_alloc();
-       if (mchars == NULL)
-               errx(EXIT_FAILURE, "Can't allocate mchars");
-       mp = mparse_alloc(0, MANDOCLEVEL_BADARG, NULL, mchars, NULL);
+       mchars_alloc();
+       mp = mparse_alloc(0, MANDOCLEVEL_BADARG, NULL, NULL);
 
        if (manconf) {
                char *arg;
@@ -473,7 +469,7 @@
                printf("Performing index update\n");
        update_db(db, mp, &rec);
        mparse_free(mp);
-       mchars_free(mchars);
+       mchars_free();
        free_secbuffs(&rec);
 
        /* Commit the transaction */
@@ -910,8 +906,7 @@
 begin_parse(const char *file, struct mparse *mp, mandb_rec *rec,
     const void *buf, size_t len)
 {
-       struct mdoc *mdoc;
-       struct man *man;
+       struct roff_man *roff;
        mparse_reset(mp);
 
        rec->xr_found = 0;
@@ -926,22 +921,23 @@
                return;
        }
 
-       mparse_result(mp, &mdoc, &man, NULL);
-       if (mdoc == NULL && man == NULL) {
+       mparse_result(mp, &roff, NULL);
+       if (roff == NULL) {
                if (mflags.verbosity == 2)
-                       warnx("Not a man(7) or mdoc(7) page");
+                       warnx("Not a roff(7) page");
                return;
        }
 
-       set_machine(mdoc, rec);
-       set_section(mdoc, man, rec);
-       if (mdoc) {
+       set_machine(roff, rec);
+       set_section(roff, rec);
+       if (roff->macroset == MACROSET_MDOC) {
                rec->page_type = MDOC;
-               pmdoc_node(mdoc_node(mdoc), rec);
-       } else {
+               proff_node(roff->first->child, rec, mdocs);
+       } else if (roff->macroset == MACROSET_MAN) {
                rec->page_type = MAN;
-               pman_node(man_node(man), rec);
-       }
+               proff_node(roff->first->child, rec, mans);
+       } else
+               warnx("Unknown macroset %d", roff->macroset);
 }
 
 /*
@@ -950,23 +946,13 @@
  *  (Which should be the first character of the string).
  */
 static void
-set_section(const struct mdoc *md, const struct man *m, mandb_rec *rec)
+set_section(const struct roff_man *rm, mandb_rec *rec)
 {
-       if (md) {
-               const struct mdoc_meta *md_meta = mdoc_meta(md);
-               if (md_meta->msec == NULL) {
-                       easprintf(&rec->section, "%s", "?");
-               } else
-                       rec->section = estrdup(md_meta->msec);
-       } else if (m) {
-               const struct man_meta *m_meta = man_meta(m);
-               if (m_meta->msec == NULL)
-                       easprintf(&rec->section, "%s", "?");
-               else
-                       rec->section = estrdup(m_meta->msec);
-       } else
+       if (!rm)
                return;
-
+       const struct roff_meta *rm_meta = &rm->meta;
+       const char *s = rm_meta->msec == NULL ? "?" : rm_meta->msec;
+       easprintf(&rec->section, "%s", s);
        if (rec->section[0] == '?' && mflags.verbosity == 2)
                warnx("%s: Missing section number", rec->file_path);
 }
@@ -976,38 +962,13 @@
  *  Extracts the machine architecture information if available.
  */
 static void
-set_machine(const struct mdoc *md, mandb_rec *rec)
+set_machine(const struct roff_man *rm, mandb_rec *rec)
 {
-       if (md == NULL)
-               return;
-       const struct mdoc_meta *md_meta = mdoc_meta(md);
-       if (md_meta->arch)
-               rec->machine = estrdup(md_meta->arch);
-}
-
-static void
-pmdoc_node(const struct mdoc_node *n, mandb_rec *rec)
-{
-
-       if (n == NULL)
+       if (rm == NULL)
                return;
-
-       switch (n->type) {
-       case (MDOC_BODY):
-               /* FALLTHROUGH */
-       case (MDOC_TAIL):
-               /* FALLTHROUGH */
-       case (MDOC_ELEM):
-               if (mdocs[n->tok] == NULL)
-                       break;
-               (*mdocs[n->tok])(n, rec);
-               break;
-       default:
-               break;
-       }
-
-       pmdoc_node(n->child, rec);
-       pmdoc_node(n->next, rec);
+       const struct roff_meta *rm_meta = &rm->meta;
+       const char *a = rm_meta->arch == NULL ? "?" : rm_meta->arch;
+       rec->machine = estrdup(a);
 }
 
 /*
@@ -1015,13 +976,13 @@
  *  Extracts the Name of the manual page from the .Nm macro
  */
 static void
-pmdoc_Nm(const struct mdoc_node *n, mandb_rec *rec)
+pmdoc_Nm(const struct roff_node *n, mandb_rec *rec)
 {
        if (n->sec != SEC_NAME)
                return;
 
        for (n = n->child; n; n = n->next) {
-               if (n->type == MDOC_TEXT) {
+               if (n->type == ROFFT_TEXT) {
                        char *escaped_name = parse_escape(n->string);
                        concat(&rec->name, escaped_name);
                        free(escaped_name);
@@ -1034,16 +995,16 @@
  *  Extracts the one line description of the man page from the .Nd macro
  */
 static void
-pmdoc_Nd(const struct mdoc_node *n, mandb_rec *rec)
+pmdoc_Nd(const struct roff_node *n, mandb_rec *rec)
 {
        char *buf = NULL;
        char *name;
        char *nd_text;
 
-       if (n == NULL || (n->type != MDOC_TEXT && n->tok == MDOC_MAX))
+       if (n == NULL || (n->type != ROFFT_TEXT && n->tok == MDOC_MAX))
                return;
 
-       if (n->type == MDOC_TEXT) {
+       if (n->type == ROFFT_TEXT) {
                if (rec->xr_found && n->next) {
                        /*
                         * An Xr macro was seen previously, so parse this
@@ -1051,7 +1012,7 @@
                         */
                        name = n->string;



Home | Main Index | Thread Index | Old Index