aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2020-04-08 11:56:03 +0000
committerIngo Schwarze <schwarze@openbsd.org>2020-04-08 11:56:03 +0000
commit637b922ab2b2aa18419a0abed18ae9d2fed4e50a (patch)
tree43a6a061839c1d2a8278fd43533f585b09e81304
parentf4c07cc80595b2276a99fd6e5c95c734187feaab (diff)
downloadmandoc-637b922ab2b2aa18419a0abed18ae9d2fed4e50a.tar.gz
mandoc-637b922ab2b2aa18419a0abed18ae9d2fed4e50a.tar.zst
mandoc-637b922ab2b2aa18419a0abed18ae9d2fed4e50a.zip
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.
-rw-r--r--html.c6
-rw-r--r--mdoc_validate.c6
-rw-r--r--roff.c3
-rw-r--r--roff.h3
-rw-r--r--tag.c27
-rw-r--r--term_tag.c6
-rw-r--r--tree.c88
7 files changed, 68 insertions, 71 deletions
diff --git a/html.c b/html.c
index 15b87236..e7adea02 100644
--- a/html.c
+++ b/html.c
@@ -1,4 +1,4 @@
-/* $Id: html.c,v 1.266 2020/04/07 22:56:02 schwarze Exp $ */
+/* $Id: html.c,v 1.267 2020/04/08 11:56:03 schwarze Exp $ */
/*
* Copyright (c) 2011-2015, 2017-2020 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -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 8a8176b9..82c5e43c 100644
--- a/mdoc_validate.c
+++ b/mdoc_validate.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_validate.c,v 1.383 2020/04/06 10:16:17 schwarze Exp $ */
+/* $Id: mdoc_validate.c,v 1.384 2020/04/08 11:56:03 schwarze Exp $ */
/*
* Copyright (c) 2010-2020 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -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 2de0b7c3..435e9000 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.373 2020/04/06 10:16:17 schwarze Exp $ */
+/* $Id: roff.c,v 1.374 2020/04/08 11:56:03 schwarze Exp $ */
/*
* Copyright (c) 2010-2015, 2017-2020 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -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 e2ccc373..2933eb9c 100644
--- a/roff.h
+++ b/roff.h
@@ -1,4 +1,4 @@
-/* $Id: roff.h,v 1.73 2020/04/06 10:16:18 schwarze Exp $ */
+/* $Id: roff.h,v 1.74 2020/04/08 11:56:03 schwarze Exp $ */
/*
* Copyright (c) 2013-2015, 2017-2020 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -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 634b0f03..0c330f46 100644
--- a/tag.c
+++ b/tag.c
@@ -1,4 +1,4 @@
-/* $Id: tag.c,v 1.33 2020/04/07 22:56:02 schwarze Exp $ */
+/* $Id: tag.c,v 1.34 2020/04/08 11:56:04 schwarze Exp $ */
/*
* Copyright (c) 2015,2016,2018,2019,2020 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -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 f6203a6c..201471c5 100644
--- a/term_tag.c
+++ b/term_tag.c
@@ -1,4 +1,4 @@
-/* $Id: term_tag.c,v 1.2 2020/04/02 22:12:55 schwarze Exp $ */
+/* $Id: term_tag.c,v 1.3 2020/04/08 11:56:04 schwarze Exp $ */
/*
* Copyright (c) 2015,2016,2018,2019,2020 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -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 b901be1a..fb9df9d7 100644
--- a/tree.c
+++ b/tree.c
@@ -1,4 +1,4 @@
-/* $Id: tree.c,v 1.88 2020/04/07 22:56:02 schwarze Exp $ */
+/* $Id: tree.c,v 1.89 2020/04/08 11:56:04 schwarze Exp $ */
/*
* Copyright (c) 2013-2015, 2017-2020 Ingo Schwarze <schwarze@openbsd.org>
* Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -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;