From 415c8ce0991f6e29bf229610fb5a7feeabe3598c Mon Sep 17 00:00:00 2001 From: Lauri Tirkkonen Date: Wed, 22 Feb 2017 11:02:58 +0200 Subject: [PATCH] mandoc: update to 1.14.1 --- bin/mandoc/LICENSE | 2 +- bin/mandoc/chars.c | 6 ++-- bin/mandoc/dba.c | 14 ++++----- bin/mandoc/dbm_map.c | 4 +-- bin/mandoc/eqn_term.c | 13 ++++---- bin/mandoc/libmandoc.h | 6 ++-- bin/mandoc/libmdoc.h | 4 +-- bin/mandoc/main.c | 49 +++++++++++++++++------------- bin/mandoc/man_term.c | 5 ++-- bin/mandoc/manconf.h | 1 + bin/mandoc/mandoc.1 | 17 +++++++++-- bin/mandoc/mandoc_aux.h | 4 +-- bin/mandoc/mandocdb.c | 6 ++-- bin/mandoc/manpath.c | 7 +++-- bin/mandoc/mdoc.7 | 10 +++---- bin/mandoc/mdoc.c | 6 ++-- bin/mandoc/mdoc_html.c | 4 +-- bin/mandoc/mdoc_macro.c | 80 ++++++++++++++++++++++++++++++++----------------- bin/mandoc/mdoc_man.c | 11 ++----- bin/mandoc/mdoc_term.c | 30 +++++++++---------- bin/mandoc/preconv.c | 14 ++++----- bin/mandoc/read.c | 6 ++-- bin/mandoc/roff.c | 16 +++++++--- bin/mandoc/roff.h | 5 ++-- bin/mandoc/tag.c | 4 +-- bin/mandoc/term_ps.c | 4 +-- bin/mandoc/tree.c | 4 ++- 27 files changed, 192 insertions(+), 140 deletions(-) diff --git a/bin/mandoc/LICENSE b/bin/mandoc/LICENSE index b9efcbba8d..c5ad12ed9f 100644 --- a/bin/mandoc/LICENSE +++ b/bin/mandoc/LICENSE @@ -5,7 +5,7 @@ contained in the mdocml toolkit is protected by the Copyright of the following developers: Copyright (c) 2008-2012, 2014 Kristaps Dzonsons -Copyright (c) 2010-2016 Ingo Schwarze +Copyright (c) 2010-2017 Ingo Schwarze Copyright (c) 2009, 2010, 2011, 2012 Joerg Sonnenberger Copyright (c) 2013 Franco Fichtner Copyright (c) 2014 Baptiste Daroussin diff --git a/bin/mandoc/chars.c b/bin/mandoc/chars.c index c2cfaf8184..f1f5d5d78c 100644 --- a/bin/mandoc/chars.c +++ b/bin/mandoc/chars.c @@ -1,4 +1,4 @@ -/* $Id: chars.c,v 1.68 2015/10/13 22:59:54 schwarze Exp $ */ +/* $Id: chars.c,v 1.69 2017/02/17 18:28:06 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2011, 2014, 2015 Ingo Schwarze @@ -101,8 +101,8 @@ static struct ln lines[] = { { "bq", ",", 0x201a }, { "lq", "\"", 0x201c }, { "rq", "\"", 0x201d }, - { "Lq", "``", 0x201c }, - { "Rq", "''", 0x201d }, + { "Lq", "\"", 0x201c }, + { "Rq", "\"", 0x201d }, { "oq", "`", 0x2018 }, { "cq", "\'", 0x2019 }, { "aq", "\'", 0x0027 }, diff --git a/bin/mandoc/dba.c b/bin/mandoc/dba.c index bb1539b741..ee43933de3 100644 --- a/bin/mandoc/dba.c +++ b/bin/mandoc/dba.c @@ -1,4 +1,4 @@ -/* $Id: dba.c,v 1.9 2017/01/15 15:28:55 schwarze Exp $ */ +/* $Id: dba.c,v 1.10 2017/02/17 14:43:54 schwarze Exp $ */ /* * Copyright (c) 2016, 2017 Ingo Schwarze * @@ -315,8 +315,8 @@ compare_names(const void *vp1, const void *vp2) const char *cp1, *cp2; int diff; - cp1 = *(char **)vp1; - cp2 = *(char **)vp2; + cp1 = *(const char * const *)vp1; + cp2 = *(const char * const *)vp2; return (diff = *cp2 - *cp1) ? diff : strcasecmp(cp1 + 1, cp2 + 1); } @@ -326,8 +326,8 @@ compare_strings(const void *vp1, const void *vp2) { const char *cp1, *cp2; - cp1 = *(char **)vp1; - cp2 = *(char **)vp2; + cp1 = *(const char * const *)vp1; + cp2 = *(const char * const *)vp2; return strcmp(cp1, cp2); } @@ -502,7 +502,7 @@ compare_entries(const void *vp1, const void *vp2) { const struct macro_entry *ep1, *ep2; - ep1 = *(struct macro_entry **)vp1; - ep2 = *(struct macro_entry **)vp2; + ep1 = *(const struct macro_entry * const *)vp1; + ep2 = *(const struct macro_entry * const *)vp2; return strcmp(ep1->value, ep2->value); } diff --git a/bin/mandoc/dbm_map.c b/bin/mandoc/dbm_map.c index d158302bad..87c085d22e 100644 --- a/bin/mandoc/dbm_map.c +++ b/bin/mandoc/dbm_map.c @@ -1,4 +1,4 @@ -/* $Id: dbm_map.c,v 1.7 2016/10/22 10:09:27 schwarze Exp $ */ +/* $Id: dbm_map.c,v 1.8 2017/02/17 14:43:54 schwarze Exp $ */ /* * Copyright (c) 2016 Ingo Schwarze * @@ -175,7 +175,7 @@ dbm_getint(int32_t offset) int32_t dbm_addr(const void *p) { - return htobe32((char *)p - dbm_base); + return htobe32((const char *)p - dbm_base); } int diff --git a/bin/mandoc/eqn_term.c b/bin/mandoc/eqn_term.c index 5f2818b405..4358015274 100644 --- a/bin/mandoc/eqn_term.c +++ b/bin/mandoc/eqn_term.c @@ -1,7 +1,7 @@ -/* $Id: eqn_term.c,v 1.8 2015/01/01 15:36:08 schwarze Exp $ */ +/* $Id: eqn_term.c,v 1.9 2017/02/12 14:19:01 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons - * Copyright (c) 2014, 2015 Ingo Schwarze + * Copyright (c) 2014, 2015, 2017 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -68,8 +68,10 @@ eqn_box(struct termp *p, const struct eqn_box *bp) if (bp->pos == EQNPOS_SQRT) { term_word(p, "sqrt"); - p->flags |= TERMP_NOSPACE; - eqn_box(p, bp->first); + if (bp->first != NULL) { + p->flags |= TERMP_NOSPACE; + eqn_box(p, bp->first); + } } else if (bp->type == EQN_SUBEXPR) { child = bp->first; eqn_box(p, child); @@ -93,7 +95,8 @@ eqn_box(struct termp *p, const struct eqn_box *bp) } } else { child = bp->first; - if (bp->type == EQN_MATRIX && child->type == EQN_LIST) + if (bp->type == EQN_MATRIX && + child != NULL && child->type == EQN_LIST) child = child->first; while (child != NULL) { eqn_box(p, diff --git a/bin/mandoc/libmandoc.h b/bin/mandoc/libmandoc.h index 96e726cbce..04b3a44565 100644 --- a/bin/mandoc/libmandoc.h +++ b/bin/mandoc/libmandoc.h @@ -1,4 +1,4 @@ -/* $Id: libmandoc.h,v 1.64 2016/07/19 13:36:13 schwarze Exp $ */ +/* $Id: libmandoc.h,v 1.66 2017/02/18 13:43:52 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015 Ingo Schwarze @@ -43,7 +43,7 @@ void mandoc_msg(enum mandocerr, struct mparse *, int, int, const char *); void mandoc_vmsg(enum mandocerr, struct mparse *, int, int, const char *, ...) - __attribute__((__format__ (printf, 5, 6))); + __attribute__((__format__ (__printf__, 5, 6))); char *mandoc_getarg(struct mparse *, char **, int, int *); char *mandoc_normdate(struct mparse *, char *, int, int); int mandoc_eos(const char *, size_t); @@ -59,7 +59,7 @@ int man_parseln(struct roff_man *, int, char *, int); void man_endparse(struct roff_man *); int preconv_cue(const struct buf *, size_t); -int preconv_encode(struct buf *, size_t *, +int preconv_encode(const struct buf *, size_t *, struct buf *, size_t *, int *); void roff_free(struct roff *); diff --git a/bin/mandoc/libmdoc.h b/bin/mandoc/libmdoc.h index 5a6cc3ed9b..ac1521410b 100644 --- a/bin/mandoc/libmdoc.h +++ b/bin/mandoc/libmdoc.h @@ -1,4 +1,4 @@ -/* $Id: libmdoc.h,v 1.108 2015/11/07 14:01:16 schwarze Exp $ */ +/* $Id: libmdoc.h,v 1.109 2017/02/16 03:00:23 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015 Ingo Schwarze @@ -70,7 +70,7 @@ struct roff_node *mdoc_block_alloc(struct roff_man *, int, int, int, struct mdoc_arg *); void mdoc_tail_alloc(struct roff_man *, int, int, int); struct roff_node *mdoc_endbody_alloc(struct roff_man *, int, int, int, - struct roff_node *, enum mdoc_endbody); + struct roff_node *); void mdoc_node_relink(struct roff_man *, struct roff_node *); void mdoc_node_validate(struct roff_man *); void mdoc_state(struct roff_man *, struct roff_node *); diff --git a/bin/mandoc/main.c b/bin/mandoc/main.c index 1b1b5b73a1..02abaaf791 100644 --- a/bin/mandoc/main.c +++ b/bin/mandoc/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.280 2017/01/27 13:47:10 schwarze Exp $ */ +/* $Id: main.c,v 1.283 2017/02/17 14:31:52 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014-2017 Ingo Schwarze @@ -100,7 +100,7 @@ static void parse(struct curparse *, int, const char *); static void passthrough(const char *, int, int); static pid_t spawn_pager(struct tag_files *); static int toptions(struct curparse *, char *); -static void usage(enum argmode) __attribute__((noreturn)); +static void usage(enum argmode) __attribute__((__noreturn__)); static int woptions(struct curparse *, char *); static const int sec_prios[] = {1, 4, 5, 8, 6, 3, 7, 2, 9}; @@ -113,17 +113,14 @@ int main(int argc, char *argv[]) { struct manconf conf; - struct curparse curp; struct mansearch search; + struct curparse curp; struct tag_files *tag_files; - const char *progname; - char *auxpaths; - char *defos; - unsigned char *uc; struct manpage *res, *resp; - char *conf_file, *defpaths; - const char *sec; - const char *thisarg; + const char *progname, *sec, *thisarg; + char *conf_file, *defpaths, *auxpaths; + char *defos, *oarg; + unsigned char *uc; size_t i, sz; int prio, best_prio; enum outmode outmode; @@ -169,6 +166,7 @@ main(int argc, char *argv[]) memset(&search, 0, sizeof(struct mansearch)); search.outkey = "Nd"; + oarg = NULL; if (strcmp(progname, BINM_MAN) == 0) search.argmode = ARG_NAME; @@ -247,15 +245,7 @@ main(int argc, char *argv[]) auxpaths = optarg; break; case 'O': - search.outkey = optarg; - while (optarg != NULL) { - thisarg = optarg; - if (manconf_output(&conf.output, - strsep(&optarg, ","), 0) == 0) - continue; - warnx("-O %s: Bad argument", thisarg); - return (int)MANDOCLEVEL_BADARG; - } + oarg = optarg; break; case 'S': search.arch = optarg; @@ -300,6 +290,21 @@ main(int argc, char *argv[]) } } + if (oarg != NULL) { + if (outmode == OUTMODE_LST) + search.outkey = oarg; + else { + while (oarg != NULL) { + thisarg = oarg; + if (manconf_output(&conf.output, + strsep(&oarg, ","), 0) == 0) + continue; + warnx("-O %s: Bad argument", thisarg); + return (int)MANDOCLEVEL_BADARG; + } + } + } + if (outmode == OUTMODE_FLN || outmode == OUTMODE_LST || !isatty(STDOUT_FILENO)) @@ -742,7 +747,8 @@ parse(struct curparse *curp, int fd, const char *file) if (man == NULL) return; if (man->macroset == MACROSET_MDOC) { - mdoc_validate(man); + if (curp->outtype != OUTT_TREE || !curp->outopts->noval) + mdoc_validate(man); switch (curp->outtype) { case OUTT_HTML: html_mdoc(curp->outdata, man); @@ -765,7 +771,8 @@ parse(struct curparse *curp, int fd, const char *file) } } if (man->macroset == MACROSET_MAN) { - man_validate(man); + if (curp->outtype != OUTT_TREE || !curp->outopts->noval) + man_validate(man); switch (curp->outtype) { case OUTT_HTML: html_man(curp->outdata, man); diff --git a/bin/mandoc/man_term.c b/bin/mandoc/man_term.c index fd2fc993b5..b2732d4558 100644 --- a/bin/mandoc/man_term.c +++ b/bin/mandoc/man_term.c @@ -1,4 +1,4 @@ -/* $Id: man_term.c,v 1.189 2017/02/04 11:58:09 schwarze Exp $ */ +/* $Id: man_term.c,v 1.191 2017/02/15 14:10:08 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2015, 2017 Ingo Schwarze @@ -822,7 +822,8 @@ pre_SH(DECL_ARGS) do { n = n->prev; - } while (n != NULL && termacts[n->tok].flags & MAN_NOTEXT); + } while (n != NULL && n->tok != TOKEN_NONE && + termacts[n->tok].flags & MAN_NOTEXT); if (n == NULL || (n->tok == MAN_SH && n->body->child == NULL)) break; diff --git a/bin/mandoc/manconf.h b/bin/mandoc/manconf.h index 80578f6a5f..f5c678e890 100644 --- a/bin/mandoc/manconf.h +++ b/bin/mandoc/manconf.h @@ -35,6 +35,7 @@ struct manoutput { int fragment; int mdoc; int synopsisonly; + int noval; }; struct manconf { diff --git a/bin/mandoc/mandoc.1 b/bin/mandoc/mandoc.1 index 91f5287bc5..45615d5d02 100644 --- a/bin/mandoc/mandoc.1 +++ b/bin/mandoc/mandoc.1 @@ -1,4 +1,4 @@ -.\" $Id: mandoc.1,v 1.173 2017/01/31 19:44:04 schwarze Exp $ +.\" $Id: mandoc.1,v 1.174 2017/02/10 15:45:28 schwarze Exp $ .\" .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons .\" Copyright (c) 2012, 2014-2017 Ingo Schwarze @@ -15,7 +15,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: January 31 2017 $ +.Dd $Mdocdate: February 10 2017 $ .Dt MANDOC 1 .Os .Sh NAME @@ -538,6 +538,8 @@ A closing parenthesis if the node is a closing delimiter. .It A full stop if the node ends a sentence. .It +BROKEN if the node is a block broken by another block. +.It NOSRC if the node is not in the input file, but automatically generated from macros. .It @@ -545,6 +547,17 @@ NOPRT if the node is not supposed to generate output for any output format. .El .El +.Pp +The following +.Fl O +argument is accepted: +.Bl -tag -width Ds +.It Cm noval +Skip validation and show the unvalidated syntax tree. +This can help to find out whether a given behaviour is caused by +the parser or by the validator. +Meta data is not available in this case. +.El .Sh ENVIRONMENT .Bl -tag -width MANPAGER .It Ev MANPAGER diff --git a/bin/mandoc/mandoc_aux.h b/bin/mandoc/mandoc_aux.h index 603cc5a725..a2425066c1 100644 --- a/bin/mandoc/mandoc_aux.h +++ b/bin/mandoc/mandoc_aux.h @@ -1,4 +1,4 @@ -/* $Id: mandoc_aux.h,v 1.5 2016/07/19 13:36:13 schwarze Exp $ */ +/* $Id: mandoc_aux.h,v 1.6 2017/02/17 14:31:52 schwarze Exp $ */ /* * Copyright (c) 2009, 2011 Kristaps Dzonsons * Copyright (c) 2014 Ingo Schwarze @@ -17,7 +17,7 @@ */ int mandoc_asprintf(char **, const char *, ...) - __attribute__((__format__ (printf, 2, 3))); + __attribute__((__format__ (__printf__, 2, 3))); void *mandoc_calloc(size_t, size_t); void *mandoc_malloc(size_t); void *mandoc_realloc(void *, size_t); diff --git a/bin/mandoc/mandocdb.c b/bin/mandoc/mandocdb.c index dcfa43bd33..3b26ca9649 100644 --- a/bin/mandoc/mandocdb.c +++ b/bin/mandoc/mandocdb.c @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.242 2017/01/27 11:33:26 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.244 2017/02/17 14:45:55 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011-2017 Ingo Schwarze @@ -162,7 +162,7 @@ static void putmdockey(const struct mpage *, const struct roff_node *, uint64_t, int); static int render_string(char **, size_t *); static void say(const char *, const char *, ...) - __attribute__((__format__ (printf, 2, 3))); + __attribute__((__format__ (__printf__, 2, 3))); static int set_basedir(const char *, int); static int treescan(void); static size_t utf8(unsigned int, char [7]); @@ -589,7 +589,7 @@ treescan(void) const char *argv[2]; argv[0] = "."; - argv[1] = (char *)NULL; + argv[1] = NULL; f = fts_open((char * const *)argv, FTS_PHYSICAL | FTS_NOCHDIR, fts_compare); diff --git a/bin/mandoc/manpath.c b/bin/mandoc/manpath.c index 6da3620e38..f43ace6069 100644 --- a/bin/mandoc/manpath.c +++ b/bin/mandoc/manpath.c @@ -1,4 +1,4 @@ -/* $Id: manpath.c,v 1.32 2017/01/27 13:47:10 schwarze Exp $ */ +/* $Id: manpath.c,v 1.33 2017/02/10 15:45:28 schwarze Exp $ */ /* * Copyright (c) 2011, 2014, 2015, 2017 Ingo Schwarze * Copyright (c) 2011 Kristaps Dzonsons @@ -226,7 +226,7 @@ manconf_output(struct manoutput *conf, const char *cp, int fromfile) { const char *const toks[] = { "includes", "man", "paper", "style", - "indent", "width", "fragment", "mdoc" + "indent", "width", "fragment", "mdoc", "noval" }; const char *errstr; @@ -310,6 +310,9 @@ manconf_output(struct manoutput *conf, const char *cp, int fromfile) case 7: conf->mdoc = 1; return 0; + case 8: + conf->noval = 1; + return 0; default: if (fromfile) warnx("-O %s: Bad argument", cp); diff --git a/bin/mandoc/mdoc.7 b/bin/mandoc/mdoc.7 index ce4bd92f0e..6d95887736 100644 --- a/bin/mandoc/mdoc.7 +++ b/bin/mandoc/mdoc.7 @@ -1,4 +1,4 @@ -.\" $Id: mdoc.7,v 1.261 2017/02/05 22:30:29 schwarze Exp $ +.\" $Id: mdoc.7,v 1.262 2017/02/16 14:38:12 schwarze Exp $ .\" .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons .\" Copyright (c) 2010, 2011, 2013-2017 Ingo Schwarze @@ -15,7 +15,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: February 5 2017 $ +.Dd $Mdocdate: February 16 2017 $ .Dt MDOC 7 .Os .Sh NAME @@ -974,10 +974,8 @@ argument. A columnated list. The .Fl width -argument has no effect; instead, each argument specifies the width -of one column, using either the scaling width syntax described in -.Xr roff 7 -or the string length of the argument. +argument has no effect; instead, the string length of each argument +specifies the width of one column. If the first line of the body of a .Fl column list is not an diff --git a/bin/mandoc/mdoc.c b/bin/mandoc/mdoc.c index 7c3613f4ce..5be1e7810d 100644 --- a/bin/mandoc/mdoc.c +++ b/bin/mandoc/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.259 2017/01/28 23:30:08 schwarze Exp $ */ +/* $Id: mdoc.c,v 1.260 2017/02/16 03:00:23 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012-2017 Ingo Schwarze @@ -136,7 +136,7 @@ mdoc_tail_alloc(struct roff_man *mdoc, int line, int pos, int tok) struct roff_node * mdoc_endbody_alloc(struct roff_man *mdoc, int line, int pos, int tok, - struct roff_node *body, enum mdoc_endbody end) + struct roff_node *body) { struct roff_node *p; @@ -145,7 +145,7 @@ mdoc_endbody_alloc(struct roff_man *mdoc, int line, int pos, int tok, p = roff_node_alloc(mdoc, line, pos, ROFFT_BODY, tok); p->body = body; p->norm = body->norm; - p->end = end; + p->end = ENDBODY_SPACE; roff_node_append(mdoc, p); mdoc->next = ROFF_NEXT_SIBLING; return p; diff --git a/bin/mandoc/mdoc_html.c b/bin/mandoc/mdoc_html.c index 88bab3332e..e824514166 100644 --- a/bin/mandoc/mdoc_html.c +++ b/bin/mandoc/mdoc_html.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.270 2017/02/06 03:44:58 schwarze Exp $ */ +/* $Id: mdoc_html.c,v 1.271 2017/02/16 03:00:23 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze @@ -417,8 +417,6 @@ print_mdoc_node(MDOC_ARGS) (*mdocs[n->tok].post)(meta, n, h); if (n->end != ENDBODY_NOT) n->body->flags |= NODE_ENDED; - if (n->end == ENDBODY_NOSPACE) - h->flags |= HTML_NOSPACE; break; } } diff --git a/bin/mandoc/mdoc_macro.c b/bin/mandoc/mdoc_macro.c index d4edcea141..5ab9c41258 100644 --- a/bin/mandoc/mdoc_macro.c +++ b/bin/mandoc/mdoc_macro.c @@ -1,7 +1,7 @@ -/* $Id: mdoc_macro.c,v 1.210 2017/01/10 13:47:00 schwarze Exp $ */ +/* $Id: mdoc_macro.c,v 1.217 2017/02/16 09:47:31 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons - * Copyright (c) 2010, 2012-2016 Ingo Schwarze + * Copyright (c) 2010, 2012-2017 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -50,6 +50,8 @@ static int find_pending(struct roff_man *, int, int, int, struct roff_node *); static int lookup(struct roff_man *, int, int, int, const char *); static int macro_or_word(MACRO_PROT_ARGS, int); +static void break_intermediate(struct roff_node *, + struct roff_node *); static int parse_rest(struct roff_man *, int, int, int *, char *); static int rew_alt(int); static void rew_elem(struct roff_man *, int); @@ -376,6 +378,20 @@ rew_elem(struct roff_man *mdoc, int tok) rew_last(mdoc, n); } +static void +break_intermediate(struct roff_node *n, struct roff_node *breaker) +{ + if (n != breaker && + n->type != ROFFT_BLOCK && n->type != ROFFT_HEAD && + (n->type != ROFFT_BODY || n->end != ENDBODY_NOT)) + n = n->parent; + while (n != breaker) { + if ( ! (n->flags & NODE_VALID)) + n->flags |= NODE_BROKEN; + n = n->parent; + } +} + /* * If there is an open sub-block of the target requiring * explicit close-out, postpone closing out the target until @@ -388,26 +404,26 @@ find_pending(struct roff_man *mdoc, int tok, int line, int ppos, struct roff_node *n; int irc; + if (target->flags & NODE_VALID) + return 0; + irc = 0; for (n = mdoc->last; n != NULL && n != target; n = n->parent) { - if (n->flags & NODE_ENDED) { - if ( ! (n->flags & NODE_VALID)) - n->flags |= NODE_BROKEN; + if (n->flags & NODE_ENDED) continue; - } if (n->type == ROFFT_BLOCK && mdoc_macros[n->tok].flags & MDOC_EXPLICIT) { irc = 1; - n->flags = NODE_BROKEN; + break_intermediate(mdoc->last, target); if (target->type == ROFFT_HEAD) - target->flags = NODE_ENDED; + target->flags |= NODE_ENDED; else if ( ! (target->flags & NODE_ENDED)) { mandoc_vmsg(MANDOCERR_BLK_NEST, mdoc->parse, line, ppos, "%s breaks %s", mdoc_macronames[tok], mdoc_macronames[n->tok]); mdoc_endbody_alloc(mdoc, line, ppos, - tok, target, ENDBODY_NOSPACE); + tok, target); } } } @@ -568,30 +584,34 @@ blk_exp_close(MACRO_PROT_ARGS) endbody = itblk = later = NULL; for (n = mdoc->last; n; n = n->parent) { - if (n->flags & NODE_ENDED) { - if ( ! (n->flags & NODE_VALID)) - n->flags |= NODE_BROKEN; + if (n->flags & NODE_ENDED) continue; - } /* - * Mismatching end macros can never break anything, - * SYNOPSIS name blocks can never be broken, + * Mismatching end macros can never break anything * and we only care about the breaking of BLOCKs. */ - if (body == NULL || - n->tok == MDOC_Nm || - n->type != ROFFT_BLOCK) + if (body == NULL || n->type != ROFFT_BLOCK) continue; + /* + * SYNOPSIS name blocks can not be broken themselves, + * but they do get broken together with a broken child. + */ + + if (n->tok == MDOC_Nm) { + if (later != NULL) + n->flags |= NODE_BROKEN | NODE_ENDED; + continue; + } + if (n->tok == MDOC_It) { itblk = n; continue; } if (atok == n->tok) { - assert(body); /* * Found the start of our own block. @@ -617,7 +637,7 @@ blk_exp_close(MACRO_PROT_ARGS) mdoc_macronames[later->tok]); endbody = mdoc_endbody_alloc(mdoc, line, ppos, - atok, body, ENDBODY_SPACE); + atok, body); if (tok == MDOC_El) itblk->flags |= NODE_ENDED | NODE_BROKEN; @@ -633,15 +653,22 @@ blk_exp_close(MACRO_PROT_ARGS) break; } - /* Explicit blocks close out description lines. */ + /* + * Explicit blocks close out description lines, but + * even those can get broken together with a child. + */ if (n->tok == MDOC_Nd) { - rew_last(mdoc, n); + if (later != NULL) + n->flags |= NODE_BROKEN | NODE_ENDED; + else + rew_last(mdoc, n); continue; } /* Breaking an open sub block. */ + break_intermediate(mdoc->last, body); n->flags |= NODE_BROKEN; if (later == NULL) later = n; @@ -706,15 +733,14 @@ blk_exp_close(MACRO_PROT_ARGS) } if (n != NULL) { + pending = 0; if (ntok != TOKEN_NONE && n->flags & NODE_BROKEN) { target = n; do target = target->parent; while ( ! (target->flags & NODE_ENDED)); - pending = find_pending(mdoc, ntok, line, ppos, - target); - } else - pending = 0; + pending = find_pending(mdoc, ntok, line, ppos, target); + } if ( ! pending) rew_pending(mdoc, n); } @@ -987,7 +1013,7 @@ blk_full(MACRO_PROT_ARGS) /* Close out prior implicit scopes. */ - rew_last(mdoc, n); + rew_pending(mdoc, n); } /* Skip items outside lists. */ diff --git a/bin/mandoc/mdoc_man.c b/bin/mandoc/mdoc_man.c index 1785a034c9..88d39370e8 100644 --- a/bin/mandoc/mdoc_man.c +++ b/bin/mandoc/mdoc_man.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_man.c,v 1.102 2017/02/06 03:44:58 schwarze Exp $ */ +/* $Id: mdoc_man.c,v 1.104 2017/02/17 19:15:41 schwarze Exp $ */ /* * Copyright (c) 2011-2017 Ingo Schwarze * @@ -639,9 +639,6 @@ print_node(DECL_ARGS) if (ENDBODY_NOT != n->end) n->body->flags |= NODE_ENDED; - - if (ENDBODY_NOSPACE == n->end) - outflags &= ~(MMAN_spc | MMAN_nl); } static int @@ -720,8 +717,7 @@ pre__t(DECL_ARGS) if (n->parent && MDOC_Rs == n->parent->tok && n->parent->norm->Rs.quote_T) { - print_word(""); - putchar('\"'); + print_word("\\(lq"); outflags &= ~MMAN_spc; } else font_push('I'); @@ -735,8 +731,7 @@ post__t(DECL_ARGS) if (n->parent && MDOC_Rs == n->parent->tok && n->parent->norm->Rs.quote_T) { outflags &= ~MMAN_spc; - print_word(""); - putchar('\"'); + print_word("\\(rq"); } else font_pop(); post_percent(meta, n); diff --git a/bin/mandoc/mdoc_term.c b/bin/mandoc/mdoc_term.c index dc17de54ac..e9ea455a48 100644 --- a/bin/mandoc/mdoc_term.c +++ b/bin/mandoc/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.343 2017/02/06 03:44:58 schwarze Exp $ */ +/* $Id: mdoc_term.c,v 1.346 2017/02/17 19:15:41 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2012-2017 Ingo Schwarze @@ -395,14 +395,6 @@ print_mdoc_node(DECL_ARGS) */ if (ENDBODY_NOT != n->end) n->body->flags |= NODE_ENDED; - - /* - * End of line terminating an implicit block - * while an explicit block is still open. - * Continue the explicit block without spacing. - */ - if (ENDBODY_NOSPACE == n->end) - p->flags |= TERMP_NOSPACE; break; } @@ -614,6 +606,7 @@ termp_ll_pre(DECL_ARGS) static int termp_it_pre(DECL_ARGS) { + struct roffsu su; char buf[24]; const struct roff_node *bl, *nn; size_t ncols, dcol; @@ -691,9 +684,12 @@ termp_it_pre(DECL_ARGS) for (i = 0, nn = n->prev; nn->prev && i < (int)ncols; - nn = nn->prev, i++) - offset += dcol + a2width(p, - bl->norm->Bl.cols[i]); + nn = nn->prev, i++) { + SCALE_HS_INIT(&su, + term_strlen(p, bl->norm->Bl.cols[i])); + su.scale /= term_strlen(p, "0"); + offset += term_hspan(p, &su) / 24 + dcol; + } /* * When exceeding the declared number of columns, leave @@ -708,7 +704,9 @@ termp_it_pre(DECL_ARGS) * Use the declared column widths, extended as explained * in the preceding paragraph. */ - width = a2width(p, bl->norm->Bl.cols[i]) + dcol; + SCALE_HS_INIT(&su, term_strlen(p, bl->norm->Bl.cols[i])); + su.scale /= term_strlen(p, "0"); + width = term_hspan(p, &su) / 24 + dcol; break; default: if (NULL == bl->norm->Bl.width) @@ -1716,6 +1714,8 @@ termp_quote_pre(DECL_ARGS) case MDOC_Bq: term_word(p, "["); break; + case MDOC__T: + /* FALLTHROUGH */ case MDOC_Do: case MDOC_Dq: term_word(p, "\\(Lq"); @@ -1730,7 +1730,6 @@ termp_quote_pre(DECL_ARGS) case MDOC_Pq: term_word(p, "("); break; - case MDOC__T: case MDOC_Qo: case MDOC_Qq: term_word(p, "\""); @@ -1773,6 +1772,8 @@ termp_quote_post(DECL_ARGS) case MDOC_Bq: term_word(p, "]"); break; + case MDOC__T: + /* FALLTHROUGH */ case MDOC_Do: case MDOC_Dq: term_word(p, "\\(Rq"); @@ -1789,7 +1790,6 @@ termp_quote_post(DECL_ARGS) case MDOC_Pq: term_word(p, ")"); break; - case MDOC__T: case MDOC_Qo: case MDOC_Qq: term_word(p, "\""); diff --git a/bin/mandoc/preconv.c b/bin/mandoc/preconv.c index 1fc137a964..08f8df86a6 100644 --- a/bin/mandoc/preconv.c +++ b/bin/mandoc/preconv.c @@ -1,4 +1,4 @@ -/* $Id: preconv.c,v 1.15 2015/10/06 18:32:19 schwarze Exp $ */ +/* $Id: preconv.c,v 1.16 2017/02/18 13:43:52 schwarze Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * Copyright (c) 2014 Ingo Schwarze @@ -26,14 +26,14 @@ #include "libmandoc.h" int -preconv_encode(struct buf *ib, size_t *ii, struct buf *ob, size_t *oi, +preconv_encode(const struct buf *ib, size_t *ii, struct buf *ob, size_t *oi, int *filenc) { - unsigned char *cu; - int nby; - unsigned int accum; + const unsigned char *cu; + int nby; + unsigned int accum; - cu = (unsigned char *)ib->buf + *ii; + cu = (const unsigned char *)ib->buf + *ii; assert(*cu & 0x80); if ( ! (*filenc & MPARSE_UTF8)) @@ -90,7 +90,7 @@ preconv_encode(struct buf *ib, size_t *ii, struct buf *ob, size_t *oi, assert(accum < 0xd800 || accum > 0xdfff); *oi += snprintf(ob->buf + *oi, 11, "\\[u%.4X]", accum); - *ii = (char *)cu - ib->buf; + *ii = (const char *)cu - ib->buf; *filenc &= ~MPARSE_LATIN1; return 1; diff --git a/bin/mandoc/read.c b/bin/mandoc/read.c index 6d831c48b3..3e5d41161a 100644 --- a/bin/mandoc/read.c +++ b/bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $Id: read.c,v 1.160 2017/02/03 18:18:23 schwarze Exp $ */ +/* $Id: read.c,v 1.161 2017/02/18 17:29:28 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -603,12 +602,11 @@ static int read_whole_file(struct mparse *curp, const char *file, int fd, struct buf *fb, int *with_mmap) { + struct stat st; gzFile gz; size_t off; ssize_t ssz; - struct stat st; - if (fstat(fd, &st) == -1) err((int)MANDOCLEVEL_SYSERR, "%s", file); diff --git a/bin/mandoc/roff.c b/bin/mandoc/roff.c index 966ed9d53d..ad55d320e4 100644 --- a/bin/mandoc/roff.c +++ b/bin/mandoc/roff.c @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.288 2017/01/12 18:02:20 schwarze Exp $ */ +/* $Id: roff.c,v 1.289 2017/02/17 03:03:03 schwarze Exp $ */ /* * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons * Copyright (c) 2010-2015, 2017 Ingo Schwarze @@ -1226,15 +1226,22 @@ deroff(char **dest, const struct roff_node *n) /* Skip leading whitespace. */ for (cp = n->string; *cp != '\0'; cp++) { - if (cp[0] == '\\' && strchr(" %&0^|~", cp[1]) != NULL) + if (cp[0] == '\\' && cp[1] != '\0' && + strchr(" %&0^|~", cp[1]) != NULL) cp++; else if ( ! isspace((unsigned char)*cp)) break; } + /* Skip trailing backslash. */ + + sz = strlen(cp); + if (cp[sz - 1] == '\\') + sz--; + /* Skip trailing whitespace. */ - for (sz = strlen(cp); sz; sz--) + for (; sz; sz--) if ( ! isspace((unsigned char)cp[sz-1])) break; @@ -3358,7 +3365,8 @@ roff_strdup(const struct roff *r, const char *p) ssz = 0; while ('\0' != *p) { - if ('\\' != *p && r->xtab && r->xtab[(int)*p].p) { + assert((unsigned int)*p < 128); + if ('\\' != *p && r->xtab && r->xtab[(unsigned int)*p].p) { sz = r->xtab[(int)*p].sz; res = mandoc_realloc(res, ssz + sz + 1); memcpy(res + ssz, r->xtab[(int)*p].p, sz); diff --git a/bin/mandoc/roff.h b/bin/mandoc/roff.h index 3039d4e9f5..b87cf132b7 100644 --- a/bin/mandoc/roff.h +++ b/bin/mandoc/roff.h @@ -1,4 +1,4 @@ -/* $Id: roff.h,v 1.39 2017/01/10 13:47:00 schwarze Exp $ */ +/* $Id: roff.h,v 1.40 2017/02/16 03:00:23 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze @@ -75,8 +75,7 @@ enum roff_next { */ enum mdoc_endbody { ENDBODY_NOT = 0, - ENDBODY_SPACE, /* Is broken: append a space. */ - ENDBODY_NOSPACE /* Is broken: don't append a space. */ + ENDBODY_SPACE /* Is broken: append a space. */ }; struct roff_node { diff --git a/bin/mandoc/tag.c b/bin/mandoc/tag.c index 0fbd2e1059..21ac6b32e4 100644 --- a/bin/mandoc/tag.c +++ b/bin/mandoc/tag.c @@ -1,4 +1,4 @@ -/* $Id: tag.c,v 1.17 2017/01/09 17:49:58 schwarze Exp $ */ +/* $Id: tag.c,v 1.18 2017/02/17 14:31:52 schwarze Exp $ */ /* * Copyright (c) 2015, 2016 Ingo Schwarze * @@ -38,7 +38,7 @@ struct tag_entry { char s[]; }; -static void tag_signal(int) __attribute__((noreturn)); +static void tag_signal(int) __attribute__((__noreturn__)); static struct ohash tag_data; static struct tag_files tag_files; diff --git a/bin/mandoc/term_ps.c b/bin/mandoc/term_ps.c index 286a89f91a..696ff22435 100644 --- a/bin/mandoc/term_ps.c +++ b/bin/mandoc/term_ps.c @@ -1,4 +1,4 @@ -/* $Id: term_ps.c,v 1.82 2016/08/10 11:03:43 schwarze Exp $ */ +/* $Id: term_ps.c,v 1.83 2017/02/17 14:31:52 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons * Copyright (c) 2014, 2015, 2016 Ingo Schwarze @@ -104,7 +104,7 @@ static void ps_pclose(struct termp *); static void ps_plast(struct termp *); static void ps_pletter(struct termp *, int); static void ps_printf(struct termp *, const char *, ...) - __attribute__((__format__ (printf, 2, 3))); + __attribute__((__format__ (__printf__, 2, 3))); static void ps_putchar(struct termp *, char); static void ps_setfont(struct termp *, enum termfont); static void ps_setwidth(struct termp *, int, int); diff --git a/bin/mandoc/tree.c b/bin/mandoc/tree.c index 9e68b69e5f..dd36ff594e 100644 --- a/bin/mandoc/tree.c +++ b/bin/mandoc/tree.c @@ -1,4 +1,4 @@ -/* $Id: tree.c,v 1.72 2017/01/12 17:29:33 schwarze Exp $ */ +/* $Id: tree.c,v 1.73 2017/02/10 15:45:28 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2011, 2014 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze @@ -192,6 +192,8 @@ print_mdoc(const struct roff_node *n, int indent) putchar(')'); if (NODE_EOS & n->flags) putchar('.'); + if (NODE_BROKEN & n->flags) + printf(" BROKEN"); if (NODE_NOSRC & n->flags) printf(" NOSRC"); if (NODE_NOPRT & n->flags) -- 2.11.4.GIT