diff options
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | man_term.c | 6 | ||||
-rw-r--r-- | mandoc_headers.3 | 6 | ||||
-rw-r--r-- | mdoc_term.c | 18 | ||||
-rw-r--r-- | tag.c | 23 | ||||
-rw-r--r-- | tag.h | 13 |
6 files changed, 42 insertions, 25 deletions
@@ -32,6 +32,7 @@ #include <errno.h> #include <fcntl.h> #include <glob.h> +#include <limits.h> #if HAVE_SANDBOX_INIT #include <sandbox.h> #endif @@ -1,7 +1,7 @@ /* $Id$ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> - * Copyright (c) 2010-2015, 2017-2019 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2010-2015, 2017-2020 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -1180,12 +1180,12 @@ tag_man(struct termp *p, struct roff_node *n) assert(n->type == ROFFT_TEXT); cp = n->string; - prio = 1; + prio = TAG_STRONG; for (;;) { switch (*cp) { case ' ': case '\t': - prio = INT_MAX; + prio = TAG_WEAK; /* FALLTHROUGH */ case '-': cp++; diff --git a/mandoc_headers.3 b/mandoc_headers.3 index 2facbb69..9e2c1752 100644 --- a/mandoc_headers.3 +++ b/mandoc_headers.3 @@ -636,7 +636,11 @@ or Requires .In sys/types.h for -.Vt size_t . +.Vt size_t +and +.In limits.h +for +.Dv INT_MAX . .Pp Provides an interface to generate .Xr ctags 1 diff --git a/mdoc_term.c b/mdoc_term.c index a7e90bd2..c9f11926 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -249,7 +249,7 @@ static const struct mdoc_term_act mdoc_term_acts[MDOC_MAX - MDOC_Dd] = { { termp_tg_pre, NULL }, /* Tg */ }; -static int fn_prio; +static int fn_prio = TAG_STRONG; void @@ -1294,7 +1294,7 @@ termp_sh_pre(DECL_ARGS) term_tab_set(p, ".5i"); switch (n->sec) { case SEC_DESCRIPTION: - fn_prio = 0; + fn_prio = TAG_STRONG; break; case SEC_AUTHORS: p->flags &= ~(TERMP_SPLIT|TERMP_NOSPLIT); @@ -1383,7 +1383,7 @@ termp_fn_pre(DECL_ARGS) term_fontpop(p); if (n->sec == SEC_DESCRIPTION || n->sec == SEC_CUSTOM) - tag_put(n->string, ++fn_prio, p->line); + tag_put(n->string, fn_prio++, p->line); if (pretty) { term_flushln(p); @@ -1614,7 +1614,7 @@ termp_in_post(DECL_ARGS) static int termp_pp_pre(DECL_ARGS) { - fn_prio = 0; + fn_prio = TAG_STRONG; term_vspace(p); return 0; } @@ -2039,7 +2039,7 @@ termp_em_pre(DECL_ARGS) { if (n->child != NULL && n->child->type == ROFFT_TEXT) - tag_put(n->child->string, 0, p->line); + tag_put(n->child->string, TAG_FALLBACK, p->line); term_fontpush(p, TERMFONT_UNDER); return 1; } @@ -2049,7 +2049,7 @@ termp_sy_pre(DECL_ARGS) { if (n->child != NULL && n->child->type == ROFFT_TEXT) - tag_put(n->child->string, 0, p->line); + tag_put(n->child->string, TAG_FALLBACK, p->line); term_fontpush(p, TERMFONT_BOLD); return 1; } @@ -2062,7 +2062,7 @@ termp_er_pre(DECL_ARGS) (n->parent->tok == MDOC_It || (n->parent->tok == MDOC_Bq && n->parent->parent->parent->tok == MDOC_It))) - tag_put(n->child->string, 1, p->line); + tag_put(n->child->string, TAG_STRONG, p->line); return 1; } @@ -2079,14 +2079,14 @@ termp_tag_pre(DECL_ARGS) (n->parent->tok == MDOC_Xo && n->parent->parent->prev == NULL && n->parent->parent->parent->tok == MDOC_It))) - tag_put(n->child->string, 1, p->line); + tag_put(n->child->string, TAG_STRONG, p->line); return 1; } static int termp_tg_pre(DECL_ARGS) { - tag_put(n->child->string, -2, p->line); + tag_put(n->child->string, TAG_MANUAL, p->line); return 0; } @@ -18,6 +18,7 @@ #include <sys/types.h> +#include <assert.h> #include <errno.h> #include <limits.h> #include <signal.h> @@ -146,6 +147,7 @@ tag_put(const char *s, int prio, size_t line) size_t len; unsigned int slot; + assert(prio <= TAG_FALLBACK); if (tag_files.tfd <= 0) return; @@ -162,8 +164,8 @@ tag_put(const char *s, int prio, size_t line) return; se = s + len; - if (*se != '\0') - prio = INT_MAX; + if (*se != '\0' && prio < TAG_WEAK) + prio = TAG_WEAK; slot = ohash_qlookupi(&tag_data, s, &se); entry = ohash_find(&tag_data, slot); @@ -183,26 +185,25 @@ tag_put(const char *s, int prio, size_t line) /* * Lower priority numbers take precedence, - * but 0 is special. - * A tag with priority 0 is only used + * but TAG_FALLBACK is special. + * A tag with priority TAG_FALLBACK is only used * if the tag occurs exactly once. */ - if (prio == 0) { - if (entry->prio == 0) - entry->prio = -1; + if (prio == TAG_FALLBACK) { + if (entry->prio == TAG_FALLBACK) + entry->prio = TAG_DELETE; return; } /* A better entry is already present, ignore the new one. */ - if (entry->prio != -1 && entry->prio < prio) + if (entry->prio < prio) return; /* The existing entry is worse, clear it. */ - if (entry->prio == -1 || entry->prio == 0 || - entry->prio > prio) + if (entry->prio > prio) entry->nlines = 0; } @@ -242,7 +243,7 @@ tag_write(void) empty = 1; entry = ohash_first(&tag_data, &slot); while (entry != NULL) { - if (stream != NULL && entry->prio != -1) { + if (stream != NULL && entry->prio < TAG_DELETE) { for (i = 0; i < entry->nlines; i++) { fprintf(stream, "%s %s %zu\n", entry->s, tag_files.ofn, entry->lines[i]); @@ -1,6 +1,6 @@ /* $Id$ */ /* - * Copyright (c) 2015, 2018, 2019 Ingo Schwarze <schwarze@openbsd.org> + * Copyright (c) 2015, 2018, 2019, 2020 Ingo Schwarze <schwarze@openbsd.org> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -15,6 +15,17 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +/* + * Tagging priorities. + * Lower numbers indicate higher importance. + */ +#define TAG_MANUAL 1 /* Set with a .Tg macro. */ +#define TAG_STRONG 2 /* Good automatic tagging. */ +#define TAG_WEAK (INT_MAX - 2) /* Dubious automatic tagging. */ +#define TAG_FALLBACK (INT_MAX - 1) /* Tag only used if unique. */ +#define TAG_DELETE (INT_MAX) /* Tag not used at all. */ + + struct tag_files { char ofn[20]; char tfn[20]; |