=================================================================== RCS file: /cvs/pod2mdoc/pod2mdoc.c,v retrieving revision 1.57 retrieving revision 1.58 diff -u -p -r1.57 -r1.58 --- pod2mdoc/pod2mdoc.c 2015/02/21 21:15:41 1.57 +++ pod2mdoc/pod2mdoc.c 2015/02/23 14:30:29 1.58 @@ -1,4 +1,4 @@ -/* $Id: pod2mdoc.c,v 1.57 2015/02/21 21:15:41 schwarze Exp $ */ +/* $Id: pod2mdoc.c,v 1.58 2015/02/23 14:30:29 schwarze Exp $ */ /* * Copyright (c) 2014 Kristaps Dzonsons * Copyright (c) 2014, 2015 Ingo Schwarze @@ -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 *buf, size_t sta } } 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 *buf, size_t sta * 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;