source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: pod2mdoc: handle function declarations spanning more than one line and
Date: Thu, 23 Oct 2014 20:28:35 -0400 (EDT)	[thread overview]
Message-ID: <201410240028.s9O0SZ8e016538@krisdoz.my.domain> (raw)

Log Message:
-----------
handle function declarations spanning more than one line
and trim leading whitespace from function arguments;
kindly asked for by 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.35
retrieving revision 1.36
diff -Lpod2mdoc.c -Lpod2mdoc.c -u -p -r1.35 -r1.36
--- pod2mdoc.c
+++ pod2mdoc.c
@@ -1010,8 +1010,9 @@ command(struct state *st, const char *bu
 static void
 verbatim(struct state *st, char *buf, size_t start, size_t end)
 {
-	size_t		 i, ift, ifo, ifa, ifc;
+	size_t		 i, ift, ifo, ifa, ifc, inl;
 	char		*cp;
+	int		 nopen;
 
 	if ( ! st->parsing || st->paused || start == end)
 		return;
@@ -1052,18 +1053,51 @@ again:
 
 		/* Parse function declaration. */
 		ifo = ifa = ifc = 0;
-		for (ift = i; i < end && buf[i] != '\n'; i++) {
-			if (ifa) {
-				if (buf[i] == ')')
+		inl = end;
+		nopen = 0;
+		for (ift = i; i < end; i++) {
+			if (ifc) {
+				if (buf[i] != '\n')
+					continue;
+				inl = i;
+				break;
+			}
+			switch (buf[i]) {
+			case ' ':
+				if ( ! ifa)
+					ifo = i;
+				break;
+			case '(':
+				if (ifo) {
+					nopen++;
+					if ( ! ifa)
+						ifa = i;
+				} else
+					i = end;
+				break;
+			case ')':
+				switch (nopen) {
+				case 0:
+					i = end;
+					break;
+				case 1:
 					ifc = i;
-			} else if (ifo && buf[i] == '(')
-				ifa = i;
-			else if (buf[i] == ' ')
-				ifo = i;
+					break;
+				default:
+					nopen--;
+					break;
+				}
+				break;
+			default:
+				break;
+			}
 		}
 
 		/* Encode function declaration. */
 		if (ifc) {
+			for (i = ifa; i < ifc; i++)
+				if (buf[i] == '\n')
+					buf[i] = ' ';
 			buf[ifo++] = '\0';
 			printf(".Ft %s", buf + ift);
 			if (buf[ifo] == '*') {
@@ -1077,20 +1111,22 @@ again:
 			for (;;) {
 				cp = strchr(buf + ifa, ',');
 				if (cp != NULL)
-					*cp = '\0';
+					*cp++ = '\0';
 				printf(".Fa \"%s\"\n", buf + ifa);
 				if (cp == NULL)
 					break;
-				ifa = cp - buf + 1;
+				while (*cp == ' ')
+					cp++;
+				ifa = cp - buf;
 			}
 			puts(".Fc");
 			if (buf[ifc] == ';')
 				ifc++;
-			if (ifc < i) {
-				buf[i] = '\0';
+			if (ifc < inl) {
+				buf[inl] = '\0';
 				puts(buf + ifc);
 			}
-			start = i + 1;
+			start = inl + 1;
 			if (start < end) 
 				goto again;
 			return;
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2014-10-24  0:28 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=201410240028.s9O0SZ8e016538@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).