mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-15 04:43:53 +00:00
mandoc: workaround lack of macro parsing in list -width
GNU tools parse macros in the -width argument of lists. mandoc does not, so it calculates an excessive width. This often squeezes the text into a very narrow column, especially in nested lists. Implement the easy workaround suggested in the TODO list. When there is only one macro, at the beginning of the -width argument, this fixes the formatting as well as a complete solution. Reviewed by: bapt Relnotes: yes MFC after: 1 week Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D35245
This commit is contained in:
parent
89e58b955c
commit
9f6a619a7d
|
@ -563,9 +563,7 @@ are mere guesses, and some may be wrong.
|
||||||
reported again by Franco Fichtner Fri, 27 Sep 2013 21:02:28 +0200
|
reported again by Franco Fichtner Fri, 27 Sep 2013 21:02:28 +0200
|
||||||
reported again by Bruce Evans Fri, 17 Feb 2017 21:22:44 +0100 via bapt@
|
reported again by Bruce Evans Fri, 17 Feb 2017 21:22:44 +0100 via bapt@
|
||||||
loc *** exist *** algo *** size ** imp ***
|
loc *** exist *** algo *** size ** imp ***
|
||||||
An easy partial fix would be to just skip the first word if it starts
|
An easy partial fix has been implemented as skip_leading_dot_word().
|
||||||
with a dot, including any following white space, when measuring.
|
|
||||||
loc * exist * algo * size * imp ***
|
|
||||||
|
|
||||||
- The \& zero-width character counts as output.
|
- The \& zero-width character counts as output.
|
||||||
That is, when it is alone on a line between two .Pp,
|
That is, when it is alone on a line between two .Pp,
|
||||||
|
|
|
@ -1818,6 +1818,45 @@ post_bl_block(POST_ARGS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If "in" begins with a dot, a word, and whitespace, return a dynamically
|
||||||
|
* allocated copy of "in" that skips all of those. Otherwise, return NULL.
|
||||||
|
*
|
||||||
|
* This is a partial workaround for the TODO list item beginning with:
|
||||||
|
* - When the -width string contains macros, the macros must be rendered
|
||||||
|
*/
|
||||||
|
static char *
|
||||||
|
skip_leading_dot_word(const char *in)
|
||||||
|
{
|
||||||
|
const char *iter = in;
|
||||||
|
const char *space;
|
||||||
|
|
||||||
|
if (*iter != '.')
|
||||||
|
return NULL;
|
||||||
|
iter++;
|
||||||
|
|
||||||
|
while (*iter != '\0' && !isspace(*iter))
|
||||||
|
iter++;
|
||||||
|
/*
|
||||||
|
* If the dot was followed by space or NUL,
|
||||||
|
* do not skip anything.
|
||||||
|
*/
|
||||||
|
if (iter == in + 1)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
space = iter;
|
||||||
|
while (isspace(*iter))
|
||||||
|
iter++;
|
||||||
|
/*
|
||||||
|
* If the word was not followed by space,
|
||||||
|
* do not skip anything.
|
||||||
|
*/
|
||||||
|
if (iter == space)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
return strdup(iter);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the argument of -offset or -width is a macro,
|
* If the argument of -offset or -width is a macro,
|
||||||
* replace it with the associated default width.
|
* replace it with the associated default width.
|
||||||
|
@ -1827,17 +1866,22 @@ rewrite_macro2len(struct roff_man *mdoc, char **arg)
|
||||||
{
|
{
|
||||||
size_t width;
|
size_t width;
|
||||||
enum roff_tok tok;
|
enum roff_tok tok;
|
||||||
|
char *newarg;
|
||||||
|
|
||||||
|
newarg = NULL;
|
||||||
if (*arg == NULL)
|
if (*arg == NULL)
|
||||||
return;
|
return;
|
||||||
else if ( ! strcmp(*arg, "Ds"))
|
else if ( ! strcmp(*arg, "Ds"))
|
||||||
width = 6;
|
width = 6;
|
||||||
else if ((tok = roffhash_find(mdoc->mdocmac, *arg, 0)) == TOKEN_NONE)
|
else if ((tok = roffhash_find(mdoc->mdocmac, *arg, 0)) != TOKEN_NONE)
|
||||||
return;
|
|
||||||
else
|
|
||||||
width = macro2len(tok);
|
width = macro2len(tok);
|
||||||
|
else if ((newarg = skip_leading_dot_word(*arg)) == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
free(*arg);
|
free(*arg);
|
||||||
|
if (newarg != NULL)
|
||||||
|
*arg = newarg;
|
||||||
|
else
|
||||||
mandoc_asprintf(arg, "%zun", width);
|
mandoc_asprintf(arg, "%zun", width);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue