From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: docbook2mdoc: allow excluding relations that are already fully
Date: Fri, 29 Mar 2019 13:10:13 -0500 (EST) [thread overview]
Message-ID: <e3fced4827e9711c@fantadrom.bsd.lv> (raw)
Log Message:
-----------
allow excluding relations that are already fully implemented
Modified Files:
--------------
docbook2mdoc:
statistics.c
Revision Data
-------------
Index: statistics.c
===================================================================
RCS file: /home/cvs/mdocml/docbook2mdoc/statistics.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lstatistics.c -Lstatistics.c -u -p -r1.1 -r1.2
--- statistics.c
+++ statistics.c
@@ -18,6 +18,7 @@
#include <ctype.h>
#include <err.h>
#include <fcntl.h>
+#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -54,18 +55,30 @@ static size_t stacki;
/*
* Count one instance of a parent-child relation.
+ * Before the special call table_add(NULL, NULL),
+ * mark relations to not be counted;
+ * in that phase, child can be NULL as a wildcard.
*/
static void
table_add(const char *parent, const char *child)
{
- size_t i;
+ static int init_done;
+ size_t i;
+
+ if (parent == NULL && child == NULL) {
+ init_done = 1;
+ return;
+ }
/* If the table entry already exists, increment its count. */
for (i = 0; i < tablei; i++) {
if (strcmp(parent, table[i].parent) == 0 &&
- strcmp(child, table[i].child) == 0) {
- table[i].count++;
+ (child == NULL || table[i].child == NULL ||
+ strcmp(child, table[i].child) == 0)) {
+ assert(init_done);
+ if (table[i].count != -1)
+ table[i].count++;
return;
}
}
@@ -83,9 +96,11 @@ table_add(const char *parent, const char
if ((table[tablei].parent = strdup(parent)) == NULL)
err(1, NULL);
- if ((table[tablei].child = strdup(child)) == NULL)
+ if (child == NULL)
+ table[tablei].child = NULL;
+ else if ((table[tablei].child = strdup(child)) == NULL)
err(1, NULL);
- table[tablei++].count = 1;
+ table[tablei++].count = init_done ? 1 : -1;
}
/*
@@ -232,7 +247,7 @@ parse_file(int fd, char *fname)
poff++;
} else if (b[poff] != '!' && b[poff] != '?') {
table_add(stacki > 0 ?
- stack[stacki - 1] : "",
+ stack[stacki - 1] : "ROOT",
b + poff);
stack_push(b + poff);
}
@@ -258,12 +273,28 @@ main(int argc, char *argv[])
char *fname;
size_t fsz, i;
ssize_t rsz;
- int fd;
+ int ch, fd, show_all;
- fd = -1;
- fname = NULL;
+ show_all = 0;
+ while ((ch = getopt(argc, argv, "a")) != -1) {
+ switch (ch) {
+ case 'a':
+ show_all = 1;
+ break;
+ default:
+ return 1;
+ }
+ }
+
+ /* Exclude relations that are already fully implemented. */
+ if (show_all == 0) {
+ table_add("para", NULL);
+ }
+ table_add(NULL, NULL);
/* Loop over input files. */
+ fd = -1;
+ fname = NULL;
while ((rsz = getline(&fname, &fsz, stdin)) != -1) {
if (fname[rsz - 1] == '\n')
fname[--rsz] = '\0';
@@ -282,7 +313,8 @@ main(int argc, char *argv[])
/* Dump results. */
for (i = 0; i < tablei; i++)
- printf("%d\t%s\t%s\n", table[i].count,
- table[i].parent, table[i].child);
+ if (table[i].count != -1)
+ printf("%d\t%s\t%s\n", table[i].count,
+ table[i].parent, table[i].child);
return 0;
}
--
To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv
reply other threads:[~2019-03-29 18:10 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=e3fced4827e9711c@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).