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

Diff for /docbook2mdoc/statistics.c between version 1.23 and 1.40

version 1.23, 2019/04/14 12:38:33 version 1.40, 2019/05/01 12:52:05
Line 14 
Line 14 
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */   */
   #include <sys/types.h>
   
 #include <assert.h>  #include <assert.h>
 #include <ctype.h>  #include <ctype.h>
 #include <err.h>  #include <err.h>
Line 24 
Line 26 
 #include <string.h>  #include <string.h>
 #include <unistd.h>  #include <unistd.h>
   
   #include "xmalloc.h"
   
 /*  /*
  * Count parent-child element relations in a corpus of DocBook documents.   * Count parent-child element relations in a corpus of DocBook documents.
  *   *
Line 46 
Line 50 
  *   *
  * Example usage:   * Example usage:
  * statistics tgroup colspec < filenames.txt | grep colspec   * statistics tgroup colspec < filenames.txt | grep colspec
    *
    * Synchronized with parse.c up to rev. 1.42.
  */   */
   
 struct entry {  struct entry {
Line 123  table_add(const char *parent, const char *child)
Line 129  table_add(const char *parent, const char *child)
   
         if (tablei == tablesz) {          if (tablei == tablesz) {
                 tablesz += 64;                  tablesz += 64;
                 table = reallocarray(table, tablesz, sizeof(*table));                  table = xreallocarray(table, tablesz, sizeof(*table));
                 if (table == NULL)  
                         err(1, NULL);  
         }          }
   
         /* Add a new entry to the table. */          /* Add a new entry to the table. */
   
         if ((table[tablei].parent = strdup(parent)) == NULL)          table[tablei].parent = xstrdup(parent);
                 err(1, NULL);          table[tablei].child = child == NULL ? NULL : xstrdup(child);
         if (child == NULL)  
                 table[tablei].child = NULL;  
         else if ((table[tablei].child = strdup(child)) == NULL)  
                 err(1, NULL);  
         table[tablei++].count = init_done ? 1 : -1;          table[tablei++].count = init_done ? 1 : -1;
 }  }
   
Line 150  stack_push(const char *name)
Line 150  stack_push(const char *name)
   
         if (stacki == stacksz) {          if (stacki == stacksz) {
                 stacksz += 8;                  stacksz += 8;
                 stack = reallocarray(stack, stacksz, sizeof(*stack));                  stack = xreallocarray(stack, stacksz, sizeof(*stack));
                 if (stack == NULL)  
                         err(1, NULL);  
         }          }
         if ((stack[stacki++] = strdup(name)) == NULL)          stack[stacki++] = xstrdup(name);
                 err(1, NULL);  
 }  }
   
 /*  /*
Line 209  parse_file(int fd, char *fname)
Line 206  parse_file(int fd, char *fname)
         size_t           rlen;  /* Number of bytes in b[]. */          size_t           rlen;  /* Number of bytes in b[]. */
         size_t           poff;  /* Parse offset in b[]. */          size_t           poff;  /* Parse offset in b[]. */
         size_t           pend;  /* Offset of the end of the current word. */          size_t           pend;  /* Offset of the end of the current word. */
         int              in_tag, in_arg, in_quotes, elem_end;          int              in_tag, in_arg, in_quotes, in_doctype, elem_end;
   
         rlen = 0;          rlen = 0;
         in_tag = in_arg = in_quotes = 0;          in_tag = in_arg = in_quotes = in_doctype = 0;
         while ((rsz = read(fd, b + rlen, sizeof(b) - rlen - 1)) >= 0) {          while ((rsz = read(fd, b + rlen, sizeof(b) - rlen - 1)) >= 0) {
                 if ((rlen += rsz) == 0)                  if ((rlen += rsz) == 0)
                         break;                          break;
Line 249  parse_file(int fd, char *fname)
Line 246  parse_file(int fd, char *fname)
                                 if (elem_end)                                  if (elem_end)
                                         stack_pop(NULL);                                          stack_pop(NULL);
                         } else if (in_tag) {                          } else if (in_tag) {
                                   if (in_doctype && b[pend] == '[') {
                                           in_tag = in_doctype = 0;
                                           pend++;
                                           continue;
                                   }
                                 if (advance(b, rlen, &pend, " =>") && rsz > 0)                                  if (advance(b, rlen, &pend, " =>") && rsz > 0)
                                         break;                                          break;
                                 elem_end = 0;                                  elem_end = 0;
Line 299  parse_file(int fd, char *fname)
Line 301  parse_file(int fd, char *fname)
                                 if (b[++poff] == '/') {                                  if (b[++poff] == '/') {
                                         elem_end = 1;                                          elem_end = 1;
                                         poff++;                                          poff++;
                                   } else if (strcasecmp(b + poff,
                                       "!DOCTYPE") == 0) {
                                           in_doctype = 1;
                                 } else if (b[poff] != '!' && b[poff] != '?') {                                  } else if (b[poff] != '!' && b[poff] != '?') {
                                         table_add(stacki > 0 ?                                          table_add(stacki > 0 ?
                                             stack[stacki - 1] : "ROOT",                                              stack[stacki - 1] : "ROOT",
                                             b + poff);                                              b + poff);
                                         stack_push(b + poff);                                          stack_push(b + poff);
                                           if (strcmp(b + poff, "sbr") == 0)
                                                   elem_end = 1;
                                 }                                  }
                                 if (elem_end)                                  if (elem_end)
                                         stack_pop(b + poff);                                          stack_pop(b + poff);
Line 314  parse_file(int fd, char *fname)
Line 321  parse_file(int fd, char *fname)
                         }                          }
                 }                  }
                 assert(poff > 0);                  assert(poff > 0);
                 memmove(b, b + poff, rlen - poff);  
                 rlen -= poff;                  rlen -= poff;
                   memmove(b, b + poff, rlen);
         }          }
         if (rsz < 0)          if (rsz < 0)
                 perror(fname);                  perror(fname);
Line 348  main(int argc, char *argv[])
Line 355  main(int argc, char *argv[])
   
         /* Exclude relations that are already fully implemented. */          /* Exclude relations that are already fully implemented. */
         if (show_all == 0) {          if (show_all == 0) {
                   table_add("ROOT", "appendix");
                   table_add("ROOT", "article");
                   table_add("ROOT", "book");
                   table_add("ROOT", "chapter");
                   table_add("ROOT", "glossary");
                   table_add("ROOT", "part");
                   table_add("ROOT", "preface");
                 table_add("ROOT", "refentry");                  table_add("ROOT", "refentry");
                   table_add("ROOT", "reference");
                   table_add("ROOT", "sect1");
                   table_add("ROOT", "sect2");
                   table_add("abstract", NULL);
                 table_add("acronym", "TEXT");                  table_add("acronym", "TEXT");
                   table_add("affiliation", "orgdiv");
                   table_add("affiliation", "orgname");
                 table_add("appendix", NULL);                  table_add("appendix", NULL);
                   table_add("application", "TEXT");
                   table_add("arg", "option");
                 table_add("article", NULL);                  table_add("article", NULL);
                   table_add("articleinfo", "abstract");
                   table_add("articleinfo", "author");
                   table_add("articleinfo", "authorgroup");
                   table_add("articleinfo", "copyright");
                   table_add("articleinfo", "date");
                   table_add("articleinfo", "legalnotice");
                 table_add("articleinfo", "pubdate");                  table_add("articleinfo", "pubdate");
                   table_add("articleinfo", "releaseinfo");
                   table_add("articleinfo", "subtitle");
                 table_add("articleinfo", "title");                  table_add("articleinfo", "title");
                   table_add("author", "affiliation");
                 table_add("author", "contrib");                  table_add("author", "contrib");
                 table_add("author", "email");                  table_add("author", "email");
                 table_add("author", "firstname");                  table_add("author", "firstname");
                 table_add("author", "othername");                  table_add("author", "othername");
                 table_add("author", "surname");                  table_add("author", "surname");
                   table_add("author", "TEXT");
                 table_add("authorgroup", "author");                  table_add("authorgroup", "author");
                   table_add("authorgroup", "editor");
                 table_add("authorgroup", "othercredit");                  table_add("authorgroup", "othercredit");
                 table_add("blockquote", NULL);                  table_add("blockquote", NULL);
                 table_add("book", NULL);                  table_add("book", NULL);
                   table_add("bookinfo", "abstract");
                 table_add("bookinfo", "authorgroup");                  table_add("bookinfo", "authorgroup");
                   table_add("bookinfo", "copyright");
                 table_add("bookinfo", "legalnotice");                  table_add("bookinfo", "legalnotice");
                 table_add("bookinfo", "pubdate");                  table_add("bookinfo", "pubdate");
                   table_add("bookinfo", "releaseinfo");
                   table_add("bookinfo", "subtitle");
                 table_add("bookinfo", "title");                  table_add("bookinfo", "title");
                   table_add("caption", "TEXT");
                 table_add("chapter", NULL);                  table_add("chapter", NULL);
                 table_add("citerefentry", "manvolnum");                  table_add("citerefentry", "manvolnum");
                 table_add("citerefentry", "refentrytitle");                  table_add("citerefentry", "refentrytitle");
                   table_add("citetitle", "TEXT");
                   table_add("cmdsynopsis", "arg");
                   table_add("cmdsynopsis", "command");
                   table_add("cmdsynopsis", "group");
                   table_add("cmdsynopsis", "sbr");
                 table_add("code", "TEXT");                  table_add("code", "TEXT");
                   table_add("command", "TEXT");
                 table_add("computeroutput", "TEXT");                  table_add("computeroutput", "TEXT");
                 table_add("constant", "TEXT");                  table_add("constant", "TEXT");
                   table_add("contrib", "TEXT");
                   table_add("copyright", "holder");
                   table_add("copyright", "year");
                 table_add("date", "TEXT");                  table_add("date", "TEXT");
                   table_add("editor", "affiliation");
                   table_add("editor", "firstname");
                   table_add("editor", "surname");
                   table_add("email", "TEXT");
                   table_add("emphasis", "errorname");
                   table_add("emphasis", "function");
                 table_add("emphasis", "TEXT");                  table_add("emphasis", "TEXT");
                 table_add("entry", NULL);                  table_add("entry", NULL);
                 table_add("errorname", "TEXT");                  table_add("errorname", "TEXT");
                   table_add("figure", "mediaobject");
                   table_add("figure", "title");
                 table_add("filename", "TEXT");                  table_add("filename", "TEXT");
                   table_add("firstname", "TEXT");
                   table_add("firstterm", "TEXT");
                   table_add("footnote", "para");
                 table_add("funcdef", "function");                  table_add("funcdef", "function");
                 table_add("funcdef", "TEXT");                  table_add("funcdef", "TEXT");
                   table_add("funcparams", "TEXT");
                 table_add("funcprototype", "funcdef");                  table_add("funcprototype", "funcdef");
                 table_add("funcprototype", "paramdef");                  table_add("funcprototype", "paramdef");
                   table_add("funcprototype", "void");
                 table_add("funcsynopsis", "funcprototype");                  table_add("funcsynopsis", "funcprototype");
                 table_add("funcsynopsis", "funcsynopsisinfo");                  table_add("funcsynopsis", "funcsynopsisinfo");
                 table_add("funcsynopsisinfo", "TEXT");                  table_add("funcsynopsisinfo", "TEXT");
                   table_add("function", "replaceable");
                 table_add("function", "TEXT");                  table_add("function", "TEXT");
                 table_add("glossary", "glossdiv");                  table_add("glossary", "glossdiv");
                 table_add("glossary", "glossentry");                  table_add("glossary", "glossentry");
Line 394  main(int argc, char *argv[])
Line 455  main(int argc, char *argv[])
                 table_add("glossentry", "glossterm");                  table_add("glossentry", "glossterm");
                 table_add("glossentry", "indexterm");                  table_add("glossentry", "indexterm");
                 table_add("glosslist", "glossentry");                  table_add("glosslist", "glossentry");
                   table_add("glossterm", "emphasis");
                 table_add("glossterm", "TEXT");                  table_add("glossterm", "TEXT");
                   table_add("group", "arg");
                   table_add("holder", "TEXT");
                   table_add("imageobject", "imagedata");
                 table_add("indexterm", "primary");                  table_add("indexterm", "primary");
                 table_add("indexterm", "secondary");                  table_add("indexterm", "secondary");
                 table_add("informaltable", "tgroup");                  table_add("informaltable", "tgroup");
                 table_add("itemizedlist", "listitem");                  table_add("itemizedlist", "listitem");
                   table_add("keycap", "TEXT");
                   table_add("keycode", "TEXT");
                   table_add("keycombo", "keycap");
                   table_add("keysym", "TEXT");
                 table_add("legalnotice", NULL);                  table_add("legalnotice", NULL);
                 table_add("link", NULL);                  table_add("link", NULL);
                 table_add("listitem", NULL);                  table_add("listitem", NULL);
Line 406  main(int argc, char *argv[])
Line 475  main(int argc, char *argv[])
                 table_add("literallayout", NULL);                  table_add("literallayout", NULL);
                 table_add("manvolnum", "TEXT");                  table_add("manvolnum", "TEXT");
                 table_add("markup", "TEXT");                  table_add("markup", "TEXT");
                   table_add("mediaobject", "caption");
                   table_add("mediaobject", "imageobject");
                   table_add("member", "constant");
                   table_add("member", "emphasis");
                   table_add("member", "function");
                   table_add("member", "property");
                   table_add("member", "symbol");
                 table_add("member", "TEXT");                  table_add("member", "TEXT");
                 table_add("note", NULL);                  table_add("note", NULL);
                   table_add("olink", "citetitle");
                   table_add("olink", "function");
                   table_add("olink", "TEXT");
                   table_add("option", "parameter");
                   table_add("option", "replaceable");
                   table_add("option", "TEXT");
                 table_add("orderedlist", "listitem");                  table_add("orderedlist", "listitem");
                   table_add("orgdiv", "TEXT");
                   table_add("orgname", "TEXT");
                   table_add("othercredit", "affiliation");
                 table_add("othercredit", "contrib");                  table_add("othercredit", "contrib");
                 table_add("othercredit", "email");                  table_add("othercredit", "email");
                 table_add("othercredit", "firstname");                  table_add("othercredit", "firstname");
                 table_add("othercredit", "othername");                  table_add("othercredit", "othername");
                 table_add("othercredit", "surname");                  table_add("othercredit", "surname");
                   table_add("othername", "TEXT");
                 table_add("para", NULL);                  table_add("para", NULL);
                   table_add("paramdef", "funcparams");
                 table_add("paramdef", "parameter");                  table_add("paramdef", "parameter");
                 table_add("paramdef", "TEXT");                  table_add("paramdef", "TEXT");
                 table_add("parameter", "TEXT");                  table_add("parameter", "TEXT");
                   table_add("part", NULL);
                   table_add("personname", "firstname");
                   table_add("personname", "surname");
                   table_add("phrase", "TEXT");
                   table_add("preface", NULL);
                 table_add("primary", NULL);                  table_add("primary", NULL);
                   table_add("productname", "TEXT");
                 table_add("programlisting", NULL);                  table_add("programlisting", NULL);
                   table_add("property", "TEXT");
                 table_add("pubdate", "TEXT");                  table_add("pubdate", "TEXT");
                   table_add("quote", "command");
                   table_add("quote", "filename");
                   table_add("quote", "literal");
                   table_add("quote", "TEXT");
                 table_add("refentry", "refentryinfo");                  table_add("refentry", "refentryinfo");
                 table_add("refentry", "refmeta");                  table_add("refentry", "refmeta");
                 table_add("refentry", "refnamediv");                  table_add("refentry", "refnamediv");
                 table_add("refentry", "refsect1");                  table_add("refentry", "refsect1");
                 table_add("refentry", "refsynopsisdiv");                  table_add("refentry", "refsynopsisdiv");
                   table_add("refentryinfo", "author");
                   table_add("refentryinfo", "authorgroup");
                   table_add("refentryinfo", "copyright");
                   table_add("refentryinfo", "date");
                   table_add("refentryinfo", "productname");
                 table_add("refentrytitle", "TEXT");                  table_add("refentrytitle", "TEXT");
                   table_add("reference", "refentry");
                 table_add("refmeta", "manvolnum");                  table_add("refmeta", "manvolnum");
                 table_add("refmeta", "refentrytitle");                  table_add("refmeta", "refentrytitle");
                 table_add("refmeta", "refmiscinfo");                  table_add("refmeta", "refmiscinfo");
Line 437  main(int argc, char *argv[])
Line 541  main(int argc, char *argv[])
                 table_add("refpurpose", "TEXT");                  table_add("refpurpose", "TEXT");
                 table_add("refsect1", NULL);                  table_add("refsect1", NULL);
                 table_add("refsect2", NULL);                  table_add("refsect2", NULL);
                   table_add("refsynopsisdiv", "cmdsynopsis");
                 table_add("refsynopsisdiv", "funcsynopsis");                  table_add("refsynopsisdiv", "funcsynopsis");
                   table_add("releaseinfo", "TEXT");
                   table_add("replaceable", "TEXT");
                   table_add("returnvalue", "TEXT");
                 table_add("row", "entry");                  table_add("row", "entry");
                 table_add("screen", NULL);                  table_add("screen", NULL);
                 table_add("secondary", NULL);                  table_add("secondary", NULL);
Line 449  main(int argc, char *argv[])
Line 557  main(int argc, char *argv[])
                 table_add("sgmltag", "TEXT");                  table_add("sgmltag", "TEXT");
                 table_add("simpara", NULL);                  table_add("simpara", NULL);
                 table_add("simplelist", "member");                  table_add("simplelist", "member");
                   table_add("simplesect", NULL);
                 table_add("structfield", "TEXT");                  table_add("structfield", "TEXT");
                 table_add("structname", "TEXT");                  table_add("structname", "TEXT");
                   table_add("subscript", "TEXT");
                   table_add("subtitle", "TEXT");
                   table_add("superscript", "emphasis");
                   table_add("superscript", "TEXT");
                   table_add("surname", "TEXT");
                 table_add("symbol", "TEXT");                  table_add("symbol", "TEXT");
                   table_add("synopsis", "function");
                   table_add("synopsis", "parameter");
                   table_add("synopsis", "type");
                   table_add("synopsis", "TEXT");
                 table_add("systemitem", "TEXT");                  table_add("systemitem", "TEXT");
                 table_add("table", "tgroup");                  table_add("table", "tgroup");
                 table_add("table", "title");                  table_add("table", "title");
Line 461  main(int argc, char *argv[])
Line 579  main(int argc, char *argv[])
                 table_add("tgroup", "tbody");                  table_add("tgroup", "tbody");
                 table_add("tgroup", "thead");                  table_add("tgroup", "thead");
                 table_add("thead", "row");                  table_add("thead", "row");
                   table_add("title", "acronym");
                   table_add("title", "emphasis");
                   table_add("title", "errorname");
                   table_add("title", "function");
                   table_add("title", "literal");
                   table_add("title", "quote");
                   table_add("title", "trademark");
                   table_add("title", "type");
                 table_add("title", "TEXT");                  table_add("title", "TEXT");
                   table_add("trademark", "TEXT");
                 table_add("type", "TEXT");                  table_add("type", "TEXT");
                 table_add("ulink", NULL);                  table_add("ulink", NULL);
                 table_add("userinput", "TEXT");                  table_add("userinput", "TEXT");
                 table_add("variablelist", "varlistentry");                  table_add("variablelist", "varlistentry");
                 table_add("varlistentry", "listitem");                  table_add("varlistentry", "listitem");
                 table_add("varlistentry", "term");                  table_add("varlistentry", "term");
                   table_add("varname", "TEXT");
                   table_add("warning", NULL);
                   table_add("year", "TEXT");
         }          }
         table_add(NULL, NULL);          table_add(NULL, NULL);
   

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.40

CVSweb