source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* pod2mdoc: Simple Ft/Fo/Fa/Fc parser and formatter for the SYNOPSIS.
@ 2014-10-22 23:10 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-10-22 23:10 UTC (permalink / raw)
  To: source

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

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

only message in thread, other threads:[~2014-10-22 23:10 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-22 23:10 pod2mdoc: Simple Ft/Fo/Fa/Fc parser and formatter for the SYNOPSIS 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).