source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* docbook2mdoc: allow excluding relations that are already fully
@ 2019-03-29 18:10 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2019-03-29 18:10 UTC (permalink / raw)
  To: source

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-03-29 18:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-29 18:10 docbook2mdoc: allow excluding relations that are already fully schwarze

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).