diff options
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | man_term.c | 8 | ||||
-rw-r--r-- | mandoc_headers.3 | 10 | ||||
-rw-r--r-- | mdoc_term.c | 20 | ||||
-rw-r--r-- | tag.c | 25 | ||||
-rw-r--r-- | tag.h | 15 |
6 files changed, 49 insertions, 32 deletions
@@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.340 2019/07/28 19:41:21 schwarze Exp $ */ +/* $Id: main.c,v 1.341 2020/01/20 10:37:15 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2012, 2014-2019 Ingo Schwarze <schwarze@openbsd.org> @@ -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: man_term.c,v 1.232 2019/07/23 17:53:35 schwarze Exp $ */ +/* $Id: man_term.c,v 1.233 2020/01/20 10:37:15 schwarze Exp $ */ /* * 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 2cda75cb..1632b07c 100644 --- a/mandoc_headers.3 +++ b/mandoc_headers.3 @@ -1,4 +1,4 @@ -.\" $Id: mandoc_headers.3,v 1.31 2019/03/17 18:21:45 schwarze Exp $ +.\" $Id: mandoc_headers.3,v 1.32 2020/01/20 10:37:15 schwarze Exp $ .\" .\" Copyright (c) 2014-2019 Ingo Schwarze <schwarze@openbsd.org> .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: March 17 2019 $ +.Dd $Mdocdate: January 20 2020 $ .Dt MANDOC_HEADERS 3 .Os .Sh NAME @@ -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 134f82b8..e50f5423 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.375 2020/01/19 18:02:00 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.376 2020/01/20 10:37:15 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010, 2012-2020 Ingo Schwarze <schwarze@openbsd.org> @@ -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; } @@ -1,4 +1,4 @@ -/* $Id: tag.c,v 1.26 2020/01/19 18:02:00 schwarze Exp $ */ +/* $Id: tag.c,v 1.27 2020/01/20 10:37:15 schwarze Exp $ */ /* * Copyright (c) 2015,2016,2018,2019,2020 Ingo Schwarze <schwarze@openbsd.org> * @@ -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: tag.h,v 1.9 2019/07/27 13:40:57 schwarze Exp $ */ +/* $Id: tag.h,v 1.10 2020/01/20 10:37:15 schwarze Exp $ */ /* - * 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]; |