From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: docbook2mdoc: optional parent-child histogram for one relation
Date: Wed, 3 Apr 2019 04:50:19 -0500 (EST) [thread overview]
Message-ID: <e3fd2f96a9b7410e@fantadrom.bsd.lv> (raw)
Log Message:
-----------
optional parent-child histogram for one relation
Modified Files:
--------------
docbook2mdoc:
statistics.c
Revision Data
-------------
Index: statistics.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/statistics.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lstatistics.c -Lstatistics.c -u -p -r1.3 -r1.4
--- statistics.c
+++ statistics.c
@@ -36,6 +36,16 @@
* Typical usage:
* statistics < filenames.txt | sort -n
* statistics < filenames.txt | grep '\<listitem\>' | sort -n
+ *
+ * Relations already fully implemented are excluded by default.
+ * The option -a shows all relations.
+ *
+ * If two arguments (parent and child) are given, a histogram
+ * of the number of children of the kind in each parent is given
+ * in addition to the normal output.
+ *
+ * Example usage:
+ * statistics tgroup colspec < filenames.txt | grep colspec
*/
struct entry {
@@ -52,6 +62,17 @@ static char **stack;
static size_t stacksz;
static size_t stacki;
+static const int nchildsz = 8;
+struct nchild {
+ char *parent;
+ char *child;
+ int freq[nchildsz];
+ int count;
+};
+
+static struct nchild nchild;
+static char *fname;
+
/*
* Count one instance of a parent-child relation.
@@ -70,6 +91,21 @@ table_add(const char *parent, const char
return;
}
+ /* Optional parent-child histogram. */
+
+ if (init_done && parent != NULL && child != NULL &&
+ nchild.parent != NULL && nchild.child != NULL &&
+ strcmp(parent, nchild.parent) == 0 &&
+ strcmp(child, nchild.child) == 0) {
+ if (nchild.count < nchildsz) {
+ nchild.freq[nchild.count]++;
+ if (nchild.count > 0)
+ nchild.freq[nchild.count - 1]--;
+ } else if (nchild.count == nchildsz)
+ puts(fname);
+ nchild.count++;
+ }
+
/* If the table entry already exists, increment its count. */
for (i = 0; i < tablei; i++) {
@@ -109,6 +145,9 @@ table_add(const char *parent, const char
static void
stack_push(const char *name)
{
+ if (nchild.parent != NULL && strcmp(name, nchild.parent) == 0)
+ nchild.count = 0;
+
if (stacki == stacksz) {
stacksz += 8;
stack = reallocarray(stack, stacksz, sizeof(*stack));
@@ -283,7 +322,6 @@ parse_file(int fd, char *fname)
int
main(int argc, char *argv[])
{
- char *fname;
size_t fsz, i;
ssize_t rsz;
int ch, fd, show_all;
@@ -298,6 +336,13 @@ main(int argc, char *argv[])
return 1;
}
}
+ argc -= optind;
+ argv += optind;
+
+ if (argc > 1) {
+ nchild.parent = argv[0];
+ nchild.child = argv[1];
+ }
/* Exclude relations that are already fully implemented. */
if (show_all == 0) {
@@ -329,5 +374,13 @@ main(int argc, char *argv[])
if (table[i].count != -1)
printf("%d\t%s\t%s\n", table[i].count,
table[i].parent, table[i].child);
+
+ /* Optional parent-child histogram. */
+ if (nchild.parent != NULL) {
+ printf("%s %s", nchild.parent, nchild.child);
+ for (i = 0; i < nchildsz; i++)
+ printf(" %d", nchild.freq[i]);
+ putchar('\n');
+ }
return 0;
}
--
To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv
reply other threads:[~2019-04-03 9:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e3fd2f96a9b7410e@fantadrom.bsd.lv \
--to=schwarze@mandoc.bsd.lv \
--cc=source@mandoc.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).