From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: pod2mdoc: Simple Ft/Fo/Fa/Fc parser and formatter for the SYNOPSIS.
Date: Wed, 22 Oct 2014 19:10:05 -0400 (EDT) [thread overview]
Message-ID: <201410222310.s9MNA5Of000365@krisdoz.my.domain> (raw)
Log Message:
-----------
Simple Ft/Fo/Fa/Fc parser and formatter for the SYNOPSIS.
Dedicated to bentley@.
Modified Files:
--------------
pod2mdoc:
pod2mdoc.c
Revision Data
-------------
Index: pod2mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/pod2mdoc/pod2mdoc.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -Lpod2mdoc.c -Lpod2mdoc.c -u -p -r1.34 -r1.35
--- pod2mdoc.c
+++ pod2mdoc.c
@@ -1008,11 +1008,12 @@ command(struct state *st, const char *bu
* always stays in OUST_NL/wantws mode.
*/
static void
-verbatim(struct state *st, const char *buf, size_t start, size_t end)
+verbatim(struct state *st, char *buf, size_t start, size_t end)
{
- size_t i;
+ size_t i, ift, ifo, ifa, ifc;
+ char *cp;
- if ( ! st->parsing || st->paused)
+ if ( ! st->parsing || st->paused || start == end)
return;
again:
/*
@@ -1023,10 +1024,11 @@ again:
*/
if (SECT_SYNOPSIS == st->sect) {
i = start;
- for (i = start; i < end && ' ' == buf[i]; i++)
- /* Spin. */ ;
+ while (i < end && buf[i] == ' ')
+ i++;
if (i == end)
return;
+
/* We're an include block! */
if (end - i > 10 &&
0 == memcmp(&buf[i], "#include <", 10)) {
@@ -1047,10 +1049,54 @@ again:
goto again;
return;
}
+
+ /* Parse function declaration. */
+ ifo = ifa = ifc = 0;
+ for (ift = i; i < end && buf[i] != '\n'; i++) {
+ if (ifa) {
+ if (buf[i] == ')')
+ ifc = i;
+ } else if (ifo && buf[i] == '(')
+ ifa = i;
+ else if (buf[i] == ' ')
+ ifo = i;
+ }
+
+ /* Encode function declaration. */
+ if (ifc) {
+ buf[ifo++] = '\0';
+ printf(".Ft %s", buf + ift);
+ if (buf[ifo] == '*') {
+ fputs(" *", stdout);
+ ifo++;
+ }
+ putchar('\n');
+ buf[ifa++] = '\0';
+ printf(".Fo %s\n", buf + ifo);
+ buf[ifc++] = '\0';
+ for (;;) {
+ cp = strchr(buf + ifa, ',');
+ if (cp != NULL)
+ *cp = '\0';
+ printf(".Fa \"%s\"\n", buf + ifa);
+ if (cp == NULL)
+ break;
+ ifa = cp - buf + 1;
+ }
+ puts(".Fc");
+ if (buf[ifc] == ';')
+ ifc++;
+ if (ifc < i) {
+ buf[i] = '\0';
+ puts(buf + ifc);
+ }
+ start = i + 1;
+ if (start < end)
+ goto again;
+ return;
+ }
}
- if (start == end)
- return;
puts(".Bd -literal");
for (last = ' '; start < end; start++) {
/*
@@ -1335,7 +1381,7 @@ ordinary(struct state *st, const char *b
* (default: starts with "=").
*/
static void
-dopar(struct state *st, const char *buf, size_t start, size_t end)
+dopar(struct state *st, char *buf, size_t start, size_t end)
{
assert(OUST_NL == st->oust);
@@ -1357,7 +1403,7 @@ dopar(struct state *st, const char *buf,
*/
static void
dofile(const struct args *args, const char *fname,
- const struct tm *tm, const char *buf, size_t sz)
+ const struct tm *tm, char *buf, size_t sz)
{
char datebuf[64];
struct state st;
--
To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv
reply other threads:[~2014-10-22 23:10 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201410222310.s9MNA5Of000365@krisdoz.my.domain \
--to=schwarze@mdocml.bsd.lv \
--cc=source@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).