source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* pod2mdoc: handle function declarations spanning more than one line and
@ 2014-10-24  0:28 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-10-24  0:28 UTC (permalink / raw)
  To: source

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-10-24  0:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-24  0:28 pod2mdoc: handle function declarations spanning more than one line and schwarze

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).