source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: Use a separate node->tag attribute rather than abusing the
@ 2020-04-08 11:56 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2020-04-08 11:56 UTC (permalink / raw)
  To: source

Log Message:
-----------
Use a separate node->tag attribute rather than abusing the node->string
attribute for the purpose.  No functional change intended.
The purpose is to make it possible to later attach tags to text nodes.

Modified Files:
--------------
    mandoc:
        html.c
        mdoc_validate.c
        roff.c
        roff.h
        tag.c
        term_tag.c
        tree.c

Revision Data
-------------
Index: html.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/html.c,v
retrieving revision 1.266
retrieving revision 1.267
diff -Lhtml.c -Lhtml.c -u -p -r1.266 -r1.267
--- html.c
+++ html.c
@@ -344,8 +344,8 @@ html_make_id(const struct roff_node *n, 
 	unsigned int		 slot;
 	int			 suffix;
 
-	if (n->string != NULL)
-		buf = mandoc_strdup(n->string);
+	if (n->tag != NULL)
+		buf = mandoc_strdup(n->tag);
 	else {
 		switch (n->tok) {
 		case MDOC_Sh:
Index: tree.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/tree.c,v
retrieving revision 1.88
retrieving revision 1.89
diff -Ltree.c -Ltree.c -u -p -r1.88 -r1.89
--- tree.c
+++ tree.c
@@ -36,6 +36,7 @@
 #include "eqn.h"
 #include "main.h"
 
+static	void	print_attr(const struct roff_node *);
 static	void	print_box(const struct eqn_box *, int);
 static	void	print_cellt(enum tbl_cellt);
 static	void	print_man(const struct roff_node *, int);
@@ -191,38 +192,8 @@ print_mdoc(const struct roff_node *n, in
 			if (argv[i].sz > 0)
 				printf(" ]");
 		}
-
-		putchar(' ');
-		if (n->flags & NODE_DELIMO)
-			putchar('(');
-		if (n->flags & NODE_LINE)
-			putchar('*');
-		printf("%d:%d", n->line, n->pos + 1);
-		if (n->flags & NODE_DELIMC)
-			putchar(')');
-		if (n->flags & NODE_EOS)
-			putchar('.');
-		if (n->flags & NODE_ID) {
-			printf(" ID");
-			if (n->string != NULL)
-				printf("=%s", n->string);
-		}
-		if (n->flags & NODE_HREF) {
-			printf(" HREF");
-			if (n->string != NULL && (n->flags & NODE_ID) == 0)
-				printf("=%s", n->string);
-		}
-		if (n->flags & NODE_BROKEN)
-			printf(" BROKEN");
-		if (n->flags & NODE_NOFILL)
-			printf(" NOFILL");
-		if (n->flags & NODE_NOSRC)
-			printf(" NOSRC");
-		if (n->flags & NODE_NOPRT)
-			printf(" NOPRT");
-		putchar('\n');
+		print_attr(n);
 	}
-
 	if (n->eqn)
 		print_box(n->eqn->first, indent + 4);
 	if (n->child)
@@ -303,24 +274,9 @@ print_man(const struct roff_node *n, int
 	} else {
 		for (i = 0; i < indent; i++)
 			putchar(' ');
-		printf("%s (%s) ", p, t);
-		if (n->flags & NODE_LINE)
-			putchar('*');
-		printf("%d:%d", n->line, n->pos + 1);
-		if (n->flags & NODE_DELIMC)
-			putchar(')');
-		if (n->flags & NODE_EOS)
-			putchar('.');
-		if (n->flags & NODE_ID) {
-			printf(" ID");
-			if (n->string != NULL)
-				printf("=%s", n->string);
-		}
-		if (n->flags & NODE_NOFILL)
-			printf(" NOFILL");
-		putchar('\n');
+		printf("%s (%s)", p, t);
+		print_attr(n);
 	}
-
 	if (n->eqn)
 		print_box(n->eqn->first, indent + 4);
 	if (n->child)
@@ -328,6 +284,40 @@ print_man(const struct roff_node *n, int
 		    (n->type == ROFFT_BLOCK ? 2 : 4));
 	if (n->next)
 		print_man(n->next, indent);
+}
+
+static void
+print_attr(const struct roff_node *n)
+{
+	putchar(' ');
+	if (n->flags & NODE_DELIMO)
+		putchar('(');
+	if (n->flags & NODE_LINE)
+		putchar('*');
+	printf("%d:%d", n->line, n->pos + 1);
+	if (n->flags & NODE_DELIMC)
+		putchar(')');
+	if (n->flags & NODE_EOS)
+		putchar('.');
+	if (n->flags & NODE_ID) {
+		printf(" ID");
+		if (n->flags & NODE_HREF)
+			printf("=HREF");
+	} else if (n->flags & NODE_HREF)
+		printf(" HREF");
+	else if (n->tag != NULL)
+		printf(" STRAYTAG");
+	if (n->tag != NULL)
+		printf("=%s", n->tag);
+	if (n->flags & NODE_BROKEN)
+		printf(" BROKEN");
+	if (n->flags & NODE_NOFILL)
+		printf(" NOFILL");
+	if (n->flags & NODE_NOSRC)
+		printf(" NOSRC");
+	if (n->flags & NODE_NOPRT)
+		printf(" NOPRT");
+	putchar('\n');
 }
 
 static void
Index: roff.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff.c,v
retrieving revision 1.373
retrieving revision 1.374
diff -Lroff.c -Lroff.c -u -p -r1.373 -r1.374
--- roff.c
+++ roff.c
@@ -1103,6 +1103,7 @@ roff_node_free(struct roff_node *n)
 		free(n->norm);
 	eqn_box_free(n->eqn);
 	free(n->string);
+	free(n->tag);
 	free(n);
 }
 
Index: term_tag.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/term_tag.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lterm_tag.c -Lterm_tag.c -u -p -r1.2 -r1.3
--- term_tag.c
+++ term_tag.c
@@ -129,9 +129,7 @@ term_tag_write(struct roff_node *n, size
 
 	if (tag_files.tfs == NULL)
 		return;
-	if (n->string == NULL)
-		n = n->child;
-	cp = n->string;
+	cp = n->tag == NULL ? n->child->string : n->tag;
 	if (cp[0] == '\\' && (cp[1] == '&' || cp[1] == 'e'))
 		cp += 2;
 	len = strcspn(cp, " \t\\");
Index: tag.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/tag.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -Ltag.c -Ltag.c -u -p -r1.33 -r1.34
--- tag.c
+++ tag.c
@@ -83,6 +83,7 @@ void
 tag_put(const char *s, int prio, struct roff_node *n)
 {
 	struct tag_entry	*entry;
+	struct roff_node	*nold;
 	const char		*se;
 	size_t			 len;
 	unsigned int		 slot;
@@ -155,9 +156,12 @@ tag_put(const char *s, int prio, struct 
 	 */
 
 	else if (entry->prio > prio || prio == TAG_FALLBACK) {
-		while (entry->nnodes > 0)
-			entry->nodes[--entry->nnodes]->flags &= ~NODE_ID;
-
+		while (entry->nnodes > 0) {
+			nold = entry->nodes[--entry->nnodes];
+			nold->flags &= ~NODE_ID;
+			free(nold->tag);
+			nold->tag = NULL;
+		}
 		if (prio == TAG_FALLBACK) {
 			entry->prio = TAG_DELETE;
 			return;
@@ -175,8 +179,8 @@ tag_put(const char *s, int prio, struct 
 	entry->prio = prio;
 	n->flags |= NODE_ID;
 	if (n->child == NULL || n->child->string != s || *se != '\0') {
-		assert(n->string == NULL);
-		n->string = mandoc_strndup(s, len);
+		assert(n->tag == NULL);
+		n->tag = mandoc_strndup(s, len);
 	}
 }
 
@@ -222,9 +226,9 @@ tag_move_id(struct roff_node *n)
 			}
 			/* FALLTHROUGH */
 		case MDOC_Pp:	/* Target the ROFFT_ELEM = <p>. */
-			if (np->string == NULL) {
-				np->string = mandoc_strdup(n->string == NULL ?
-				    n->child->string : n->string);
+			if (np->tag == NULL) {
+				np->tag = mandoc_strdup(n->tag == NULL ?
+				    n->child->string : n->tag);
 				np->flags |= NODE_ID;
 				n->flags &= ~NODE_ID;
 			}
@@ -268,8 +272,11 @@ tag_postprocess(struct roff_node *n)
 				tag_move_id(n);
 			if (n->tok != MDOC_Tg)
 				n->flags |= NODE_HREF;
-			else if ((n->flags & NODE_ID) == 0)
+			else if ((n->flags & NODE_ID) == 0) {
 				n->flags |= NODE_NOPRT;
+				free(n->tag);
+				n->tag = NULL;
+			}
 			break;
 		}
 	}
Index: roff.h
===================================================================
RCS file: /home/cvs/mandoc/mandoc/roff.h,v
retrieving revision 1.73
retrieving revision 1.74
diff -Lroff.h -Lroff.h -u -p -r1.73 -r1.74
--- roff.h
+++ roff.h
@@ -506,6 +506,7 @@ struct	roff_node {
 	struct mdoc_arg	 *args;    /* BLOCK/ELEM */
 	union mdoc_data	 *norm;    /* Normalized arguments. */
 	char		 *string;  /* TEXT */
+	char		 *tag;     /* For less(1) :t and HTML id=. */
 	struct tbl_span	 *span;    /* TBL */
 	struct eqn_box	 *eqn;     /* EQN */
 	int		  line;    /* Input file line number. */
Index: mdoc_validate.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/mdoc_validate.c,v
retrieving revision 1.383
retrieving revision 1.384
diff -Lmdoc_validate.c -Lmdoc_validate.c -u -p -r1.383 -r1.384
--- mdoc_validate.c
+++ mdoc_validate.c
@@ -2212,8 +2212,8 @@ post_hyph(POST_ARGS)
 			if (*cp == '-' &&
 			    isalpha((unsigned char)cp[-1]) &&
 			    isalpha((unsigned char)cp[1])) {
-				if (n->string == NULL && n->flags & NODE_ID)
-					n->string = mandoc_strdup(nch->string);
+				if (n->tag == NULL && n->flags & NODE_ID)
+					n->tag = mandoc_strdup(nch->string);
 				*cp = ASCII_HYPH;
 			}
 	}
--
 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:[~2020-04-08 11:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-08 11:56 mandoc: Use a separate node->tag attribute rather than abusing the 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).