source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* pod2mdoc: Re-wrap text lines.
@ 2015-02-23 14:30 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-02-23 14:30 UTC (permalink / raw)
  To: source

Log Message:
-----------
Re-wrap text lines.  Preserving the original man(7) input line
breaks has no syntactic or semantic relevance and merely results
in awkwardly wrapped mdoc(7) code.

Modified Files:
--------------
    pod2mdoc:
        pod2mdoc.c

Revision Data
-------------
Index: pod2mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/pod2mdoc/pod2mdoc.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -Lpod2mdoc.c -Lpod2mdoc.c -u -p -r1.57 -r1.58
--- pod2mdoc.c
+++ pod2mdoc.c
@@ -75,6 +75,7 @@ struct	state {
 	char		*outbuf; /* text buffered for output */
 	size_t		 outbufsz; /* allocated size of outbuf */
 	size_t		 outbuflen; /* current length of outbuf */
+	size_t		 outlnlen; /* chars so far on this output line */
 };
 
 enum	fmt {
@@ -208,6 +209,14 @@ outbuf_flush(struct state *st)
 	if (0 == st->outbuflen)
 		return;
 
+	st->outlnlen += st->outbuflen;
+	if (OUST_TXT == st->oust && st->wantws) {
+		if (++st->outlnlen > 72) {
+			putchar('\n');
+			st->oust = OUST_NL;
+			st->outlnlen = st->outbuflen;
+		}
+	}
 	if (OUST_NL != st->oust && st->wantws)
 		putchar(' ');
 
@@ -233,6 +242,7 @@ mdoc_newln(struct state *st)
 	putchar('\n');
 	last = '\n';
 	st->oust = OUST_NL;
+	st->outlnlen = 0;
 	st->wantws = 1;
 }
 
@@ -1632,7 +1642,7 @@ ordinary(struct state *st, const char *b
 			}
 		} else if (start < end && '\n' == buf[start]) {
 			outbuf_flush(st);
-			mdoc_newln(st);
+			st->wantws = 1;
 			if (++start >= end)
 				continue;
 			/*
@@ -1643,8 +1653,10 @@ ordinary(struct state *st, const char *b
 			 * have a macro subsequent it, which may be
 			 * possible if we have an escape next.
 			 */
-			if (' ' == buf[start] || '\t' == buf[start])
+			if (' ' == buf[start] || '\t' == buf[start]) {
+				mdoc_newln(st);
 				puts(".br");
+			}
 			for ( ; start < end; start++)
 				if (' ' != buf[start] && '\t' != buf[start])
 					break;
--
 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:[~2015-02-23 14:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-23 14:30 pod2mdoc: Re-wrap text lines 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).