summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--html.c4
-rw-r--r--mdoc_validate.c4
-rw-r--r--roff.c1
-rw-r--r--roff.h1
-rw-r--r--tag.c25
-rw-r--r--term_tag.c4
-rw-r--r--tree.c86
7 files changed, 61 insertions, 64 deletions
diff --git a/html.c b/html.c
index 79288939..9b80efcd 100644
--- a/html.c
+++ b/html.c
@@ -344,8 +344,8 @@ html_make_id(const struct roff_node *n, int unique)
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:
diff --git a/mdoc_validate.c b/mdoc_validate.c
index 7d31bc7b..06298747 100644
--- a/mdoc_validate.c
+++ b/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;
}
}
diff --git a/roff.c b/roff.c
index 829388b4..174429e3 100644
--- a/roff.c
+++ b/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);
}
diff --git a/roff.h b/roff.h
index 6710935c..6be54228 100644
--- a/roff.h
+++ b/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. */
diff --git a/tag.c b/tag.c
index 730346eb..37e656ab 100644
--- a/tag.c
+++ b/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 roff_node *n)
*/
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 roff_node *n)
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;
}
}
diff --git a/term_tag.c b/term_tag.c
index cb504274..6bd8a34d 100644
--- a/term_tag.c
+++ b/term_tag.c
@@ -129,9 +129,7 @@ term_tag_write(struct roff_node *n, size_t line)
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\\");
diff --git a/tree.c b/tree.c
index 2c670dd6..3c05617a 100644
--- a/tree.c
+++ b/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, int indent)
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 indent)
} 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)
@@ -331,6 +287,40 @@ print_man(const struct roff_node *n, int 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
print_box(const struct eqn_box *ep, int indent)
{
int i;