From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (kristaps@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.5/8.14.5) with ESMTP id s32EoAS6008848 for ; Wed, 2 Apr 2014 10:50:10 -0400 (EDT) Received: (from kristaps@localhost) by krisdoz.my.domain (8.14.5/8.14.3/Submit) id s32Eo9VW009961; Wed, 2 Apr 2014 10:50:09 -0400 (EDT) Date: Wed, 2 Apr 2014 10:50:09 -0400 (EDT) Message-Id: <201404021450.s32Eo9VW009961@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: kristaps@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: pod2mdoc: Pick out the first B<> as an Nm when in SYNOPSIS. X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Pick out the first B<> as an Nm when in SYNOPSIS. Document all of these tricks in the manpage. Modified Files: -------------- pod2mdoc: pod2mdoc.1 pod2mdoc.c Revision Data ------------- Index: pod2mdoc.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/pod2mdoc/pod2mdoc.c,v retrieving revision 1.14 retrieving revision 1.15 diff -Lpod2mdoc.c -Lpod2mdoc.c -u -p -r1.14 -r1.15 --- pod2mdoc.c +++ pod2mdoc.c @@ -239,7 +239,6 @@ trylink(const char *buf, size_t *start, return(1); } - /* * Doclifting: if we're a bold "-xx" and we're in the SYNOPSIS section, * then it's likely that we're a flag. @@ -315,13 +314,16 @@ again: * been printed to the current line. * If "nomacro", then we don't print any macros, just contained data * (e.g., following "Sh" or "Nm"). + * "pos" is only significant in SYNOPSIS, and should be 0 when invoked + * as the first format code on a line (for decoration as an "Nm"), + * non-zero otherwise. * Return whether we've printed a macro or not--in other words, whether * this should trigger a subsequent newline (this should be ignored when * reentrant). */ static int -formatcode(struct state *st, const char *buf, - size_t *start, size_t end, int reentrant, int nomacro) +formatcode(struct state *st, const char *buf, size_t *start, + size_t end, int reentrant, int nomacro, int pos) { enum fmt fmt; size_t i, j, dsz; @@ -430,6 +432,8 @@ formatcode(struct state *st, const char if (SECT_SYNOPSIS == st->sect) { if (1 == dsz && '-' == buf[*start]) dosynopsisfl(buf, start, end); + else if (0 == pos) + printf("Nm "); else printf("Ar "); break; @@ -482,7 +486,7 @@ formatcode(struct state *st, const char } } if (*start + 1 < end && '<' == buf[*start + 1]) { - formatcode(st, buf, start, end, 1, nomacro); + formatcode(st, buf, start, end, 1, nomacro, 1); continue; } @@ -544,7 +548,7 @@ formatcodeln(struct state *st, const cha last = ' '; while (*start < end) { if (*start + 1 < end && '<' == buf[*start + 1]) { - formatcode(st, buf, start, end, 1, nomacro); + formatcode(st, buf, start, end, 1, nomacro, 1); continue; } /* @@ -873,6 +877,7 @@ static void ordinary(struct state *st, const char *buf, size_t start, size_t end) { size_t i, j, opstack; + int seq; if ( ! st->parsing || st->paused) return; @@ -884,8 +889,8 @@ ordinary(struct state *st, const char *b * To wit, print out a "Nm" and "Nd" in that format. */ if (SECT_NAME == st->sect) { - for (i = end - 1; i > start; i--) - if ('-' == buf[i]) + for (i = end - 2; i > start; i--) + if ('-' == buf[i] && ' ' == buf[i + 1]) break; if ('-' == buf[i]) { j = i; @@ -893,11 +898,11 @@ ordinary(struct state *st, const char *b for ( ; i > start; i--) if ('-' != buf[i]) break; - printf(".Nm "); + fputs(".Nm ", stdout); formatcodeln(st, buf, &start, i + 1, 1); putchar('\n'); start = j + 1; - printf(".Nd "); + fputs(".Nd ", stdout); formatcodeln(st, buf, &start, end, 1); putchar('\n'); return; @@ -911,7 +916,7 @@ ordinary(struct state *st, const char *b last = '\n'; opstack = 0; - while (start < end) { + for (seq = 0; start < end; seq++) { /* * Loop til we get either to a newline or escape. * Escape initial control characters. @@ -951,7 +956,7 @@ ordinary(struct state *st, const char *b * Consume all whitespace so we don't * accidentally start an implicit literal line. */ - if (formatcode(st, buf, &start, end, 0, 0)) { + if (formatcode(st, buf, &start, end, 0, 0, seq)) { putchar(last = '\n'); while (start < end && ' ' == buf[start]) start++; Index: pod2mdoc.1 =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/pod2mdoc/pod2mdoc.1,v retrieving revision 1.6 retrieving revision 1.7 diff -Lpod2mdoc.1 -Lpod2mdoc.1 -u -p -r1.6 -r1.7 --- pod2mdoc.1 +++ pod2mdoc.1 @@ -89,6 +89,73 @@ or, if the input file suffix is uses .Ar 3p . .El +.Ss Smarts +Since +.Xr mdoc 7 +is semantic and +.Xr perlpod 1 +is not, +.Nm +tries to figure out semantic context for some terms. +Specifically, within each paragraph of the SYNOPSIS section, the +following occur: +.Bl -bullet +.It +An initial +.Li B<> +format code is rendered as +.Sq \&Nm . +.It +Subsequent +.Li B<> +format codes are rendered as +.Sq \&Ar . +However, if the leading character of a +.Li B<> +format code is +.Sq - , +it is rendered as +.Sq \&Fl . +Subsequent space-separated terms without leading hyphens, e.g., +.Li B<-foo bar> , +are rendered as +.Sq \&Ar . +.It +Matching +.Li \&[ +and +.Li \&] +pairs are rendered as +.Sq \&Oo +and +.Sq \&Oc . +.El +.Pp +Thus, the input +.Li B [B<-bar baz>] +is rendered as follows: +.Bd -literal +\&.Nm foo +\&.Oo +\&.Fl bar Ar baz +\&.Oc +.Ed +.Pp +In the NAME section, an +.Sq \&Nm +and +.Sq \&Nd +macro are inferred from text leading and trailing the last hyphen +followed by a space (there may be any number of hyphens preceding the +space). +The space may occur on either side of the hyphen. +Thus, +.Li B - bar +will be rendered as follows: +.Bd -literal +\&.Nm foo +\&.Nd bar +.Ed .Sh EXIT STATUS .Ex -std .Sh EXAMPLES -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv