From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp1.rz.uni-karlsruhe.de (Debian-exim@smtp1.rz.uni-karlsruhe.de [129.13.185.217]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id o5UNP1AI011023 for ; Wed, 30 Jun 2010 19:25:02 -0400 (EDT) Received: from hekate.usta.de (asta-nat.asta.uni-karlsruhe.de [172.22.63.82]) by smtp1.rz.uni-karlsruhe.de with esmtp (Exim 4.63 #1) id 1OU6eI-0005Jd-HE; Thu, 01 Jul 2010 01:25:00 +0200 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.71) (envelope-from ) id 1OU6eI-00005o-FZ for tech@mdocml.bsd.lv; Thu, 01 Jul 2010 01:24:58 +0200 Received: from iris.usta.de ([172.24.96.5] helo=usta.de) by donnerwolke.usta.de with esmtp (Exim 4.69) (envelope-from ) id 1OU6eI-0001u5-ES for tech@mdocml.bsd.lv; Thu, 01 Jul 2010 01:24:58 +0200 Received: from schwarze by usta.de with local (Exim 4.71) (envelope-from ) id 1OU6eI-000713-DZ for tech@mdocml.bsd.lv; Thu, 01 Jul 2010 01:24:58 +0200 Date: Thu, 1 Jul 2010 01:24:58 +0200 From: Ingo Schwarze To: tech@mdocml.bsd.lv Subject: [PATCH] .Nm indentation in the SYNOPSIS Message-ID: <20100630232458.GN24358@iris.usta.de> References: <20100626134712.GC22002@iris.usta.de> X-Mailinglist: mdocml-tech Reply-To: tech@mdocml.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100626134712.GC22002@iris.usta.de> User-Agent: Mutt/1.5.20 (2009-06-14) Hi, after much preliminary work and bug fixing, support for proper .Nm indentation in the SYNOPSIS is now finished. Here is the final diff: OK? The diff contains: * switching .Nm from in_line to ctx_synopsis * special .Nm handling in rewinding rules and blk_exp_close * a bit of related block scoping error message cleanup * termp_nm_pre and termp_nm_post output handlers Yours, Ingo Index: main.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/main.c,v retrieving revision 1.40 diff -u -p -r1.40 main.c --- main.c 30 Jun 2010 20:29:44 -0000 1.40 +++ main.c 30 Jun 2010 22:58:21 -0000 @@ -109,6 +109,7 @@ static const char * const mandocerrs[MAN "unknown manual section", "section not in conventional manual section", "end of line whitespace", + "blocks badly nested", "scope open on exit", "generic error", @@ -132,7 +133,6 @@ static const char * const mandocerrs[MAN "bad comment style", "unknown macro will be lost", "line scope broken", - "scope broken", "argument count wrong", "request scope close w/none open", "scope already open", @@ -151,7 +151,8 @@ static const char * const mandocerrs[MAN "missing font type", "displays may not be nested", "unsupported display type", - "no scope to rewind: syntax violated", + "blocks badly nested", + "no such block is open", "scope broken, syntax violated", "line scope broken, syntax violated", "argument count wrong, violates syntax", Index: mandoc.h =================================================================== RCS file: /cvs/src/usr.bin/mandoc/mandoc.h,v retrieving revision 1.8 diff -u -p -r1.8 mandoc.h --- mandoc.h 30 Jun 2010 20:29:44 -0000 1.8 +++ mandoc.h 30 Jun 2010 22:58:21 -0000 @@ -47,6 +47,7 @@ enum mandocerr { MANDOCERR_BADMSEC, /* unknown manual section */ MANDOCERR_SECMSEC, /* section not in conventional manual section */ MANDOCERR_EOLNSPACE, /* end of line whitespace */ + MANDOCERR_SCOPENEST, /* blocks badly nested */ MANDOCERR_SCOPEEXIT, /* scope open on exit */ MANDOCERR_ERROR, /* ===== end of errors ===== */ @@ -70,9 +71,8 @@ enum mandocerr { MANDOCERR_BADCOMMENT, /* bad comment style */ MANDOCERR_MACRO, /* unknown macro will be lost */ MANDOCERR_LINESCOPE, /* line scope broken */ - MANDOCERR_SCOPE, /* scope broken */ MANDOCERR_ARGCOUNT, /* argument count wrong */ - MANDOCERR_NOSCOPE, /* request scope close w/none open */ + MANDOCERR_NOSCOPE, /* no such block is open */ MANDOCERR_SCOPEREP, /* scope already open */ /* FIXME: merge following with MANDOCERR_ARGCOUNT */ MANDOCERR_NOARGS, /* macro requires line argument(s) */ @@ -92,6 +92,7 @@ enum mandocerr { /* FIXME: this should be a MANDOCERR_ERROR */ MANDOCERR_NESTEDDISP, /* displays may not be nested */ MANDOCERR_BADDISP, /* unsupported display type */ + MANDOCERR_SCOPEFATAL, /* blocks badly nested */ MANDOCERR_SYNTNOSCOPE, /* no scope to rewind: syntax violated */ MANDOCERR_SYNTSCOPE, /* scope broken, syntax violated */ MANDOCERR_SYNTLINESCOPE, /* line scope broken, syntax violated */ Index: mdoc_macro.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/mdoc_macro.c,v retrieving revision 1.50 diff -u -p -r1.50 mdoc_macro.c --- mdoc_macro.c 30 Jun 2010 03:57:49 -0000 1.50 +++ mdoc_macro.c 30 Jun 2010 22:58:22 -0000 @@ -93,7 +93,7 @@ const struct mdoc_macro __mdoc_macros[MD { in_line_argn, MDOC_CALLABLE | MDOC_PARSED }, /* In */ { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Li */ { blk_full, 0 }, /* Nd */ - { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Nm */ + { ctx_synopsis, MDOC_CALLABLE | MDOC_PARSED }, /* Nm */ { blk_part_imp, MDOC_CALLABLE | MDOC_PARSED }, /* Op */ { obsolete, 0 }, /* Ot */ { in_line, MDOC_CALLABLE | MDOC_PARSED }, /* Pa */ @@ -388,6 +388,8 @@ rew_dohalt(enum mdoct tok, enum mdoc_typ if (MDOC_Op == p->tok) return(REWIND_MORE); break; + case (MDOC_Nm): + return(REWIND_NONE); case (MDOC_Nd): /* FALLTHROUGH */ case (MDOC_Ss): @@ -405,9 +407,11 @@ rew_dohalt(enum mdoct tok, enum mdoc_typ /* * Default block rewinding rules. - * In particular, always skip block end markers. + * In particular, always skip block end markers, + * and let all blocks rewind Nm children. */ - if (p->end || (MDOC_BLOCK == p->type && + if (p->end || MDOC_Nm == p->tok || + (MDOC_BLOCK == p->type && ! (MDOC_EXPLICIT & mdoc_macros[tok].flags))) return(REWIND_MORE); @@ -503,8 +507,9 @@ make_pending(struct mdoc_node *broken, e taker->pending = broken->pending; } broken->pending = breaker; - mdoc_vmsg(m, MANDOCERR_SCOPE, line, ppos, "%s breaks %s", - mdoc_macronames[tok], mdoc_macronames[broken->tok]); + mdoc_vmsg(m, MANDOCERR_SCOPENEST, line, ppos, + "%s breaks %s", mdoc_macronames[tok], + mdoc_macronames[broken->tok]); return(1); } @@ -538,7 +543,9 @@ rew_sub(enum mdoc_type t, struct mdoc *m return(make_pending(n, tok, m, line, ppos)); case (REWIND_ERROR): /* XXX Make this non-fatal. */ - mdoc_pmsg(m, line, ppos, MANDOCERR_SYNTNOSCOPE); + mdoc_vmsg(m, MANDOCERR_SCOPEFATAL, line, ppos, + "%s cannot break %s", mdoc_macronames[tok], + mdoc_macronames[n->tok]); return 0; } break; @@ -648,7 +655,7 @@ blk_exp_close(MACRO_PROT_ARGS) continue; } - if (MDOC_BLOCK != n->type) + if (MDOC_BLOCK != n->type || MDOC_Nm == n->tok) continue; if (atok == n->tok) { assert(body); @@ -1284,8 +1291,8 @@ blk_part_imp(MACRO_PROT_ARGS) * is ugly behaviour nodding its head to OpenBSD's overwhelming * crufty use of `Op' breakage. */ - if (n != body && ! mdoc_vmsg(m, MANDOCERR_SCOPE, line, ppos, - "%s broken", mdoc_macronames[tok])) + if (n != body && ! mdoc_vmsg(m, MANDOCERR_SCOPENEST, + line, ppos, "%s broken", mdoc_macronames[tok])) return(0); if (n && ! rew_sub(MDOC_BODY, m, tok, line, ppos)) @@ -1638,7 +1645,9 @@ ctx_synopsis(MACRO_PROT_ARGS) * up formatting the block scope, then child nodes will inherit * the formatting. Be careful. */ - + if (MDOC_Nm == tok) + return(blk_full(m, tok, line, ppos, pos, buf)); + assert(MDOC_Vt == tok); return(blk_part_imp(m, tok, line, ppos, pos, buf)); } Index: mdoc_term.c =================================================================== RCS file: /cvs/src/usr.bin/mandoc/mdoc_term.c,v retrieving revision 1.93 diff -u -p -r1.93 mdoc_term.c --- mdoc_term.c 29 Jun 2010 17:10:30 -0000 1.93 +++ mdoc_term.c 30 Jun 2010 22:58:22 -0000 @@ -81,6 +81,7 @@ static void termp_fo_post(DECL_ARGS); static void termp_in_post(DECL_ARGS); static void termp_it_post(DECL_ARGS); static void termp_lb_post(DECL_ARGS); +static void termp_nm_post(DECL_ARGS); static void termp_op_post(DECL_ARGS); static void termp_pf_post(DECL_ARGS); static void termp_pq_post(DECL_ARGS); @@ -166,7 +167,7 @@ static const struct termact termacts[MDO { termp_in_pre, termp_in_post }, /* In */ { termp_li_pre, NULL }, /* Li */ { termp_nd_pre, NULL }, /* Nd */ - { termp_nm_pre, NULL }, /* Nm */ + { termp_nm_pre, termp_nm_post }, /* Nm */ { termp_op_pre, termp_op_post }, /* Op */ { NULL, NULL }, /* Ot */ { termp_under_pre, NULL }, /* Pa */ @@ -1021,11 +1022,35 @@ static int termp_nm_pre(DECL_ARGS) { - if (NULL == n->child && NULL == m->name) + if (MDOC_BLOCK == n->type) + return(1); + + if (MDOC_BODY == n->type) { + if (NULL == n->child) + return(0); + p->flags |= TERMP_NOLPAD | TERMP_NOSPACE; + p->offset += term_len(p, 1) + + (NULL == n->prev->child ? term_strlen(p, m->name) : + MDOC_TEXT == n->prev->child->type ? + term_strlen(p, n->prev->child->string) : + term_len(p, 5)); return(1); + } + + if (NULL == n->child && NULL == m->name) + return(0); synopsis_pre(p, n); + if (MDOC_HEAD == n->type && n->next->child) { + p->flags |= TERMP_NOSPACE | TERMP_NOBREAK | TERMP_HANG; + p->rmargin = p->offset + term_len(p, 1) + + (NULL == n->child ? term_strlen(p, m->name) : + MDOC_TEXT == n->child->type ? + term_strlen(p, n->child->string) : + term_len(p, 5)); + } + term_fontpush(p, TERMFONT_BOLD); if (NULL == n->child) term_word(p, m->name); @@ -1033,6 +1058,21 @@ termp_nm_pre(DECL_ARGS) } +/* ARGSUSED */ +static void +termp_nm_post(DECL_ARGS) +{ + + if (MDOC_HEAD == n->type && n->next->child) { + term_flushln(p); + p->flags &= ~(TERMP_NOBREAK | TERMP_HANG); + } else if (MDOC_BODY == n->type && n->child) { + term_flushln(p); + p->flags &= ~TERMP_NOLPAD; + } +} + + /* ARGSUSED */ static int termp_fl_pre(DECL_ARGS) -- To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv