From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (schwarze@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.5/8.14.5) with ESMTP id s6INv0KE030198 for ; Fri, 18 Jul 2014 19:57:00 -0400 (EDT) Received: (from schwarze@localhost) by krisdoz.my.domain (8.14.5/8.14.3/Submit) id s6INuxTo002104; Fri, 18 Jul 2014 19:56:59 -0400 (EDT) Date: Fri, 18 Jul 2014 19:56:59 -0400 (EDT) Message-Id: <201407182356.s6INuxTo002104@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: schwarze@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: pod2mdoc: Almost a rewrite of formatcodeln(). X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Almost a rewrite of formatcodeln(). It never handled spacing properly, and my recent overhaul of formatting code spacing introduced additional regressions. Besides, fix two more regressions, one regarding character escapes in outbuf_addstr(), and do not print Ns during invalid escapes in formatcode(). Finally, correct the name of the E character. Modified Files: -------------- pod2mdoc: pod2mdoc.c pod2mdoc/Regress/formatcode: Makefile Added Files: ----------- pod2mdoc/Regress: Makefile pod2mdoc/Regress/formatcode: escape.pod pod2mdoc/Regress/formatcodeln: Makefile item.pod Revision Data ------------- Index: pod2mdoc.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/pod2mdoc/pod2mdoc.c,v retrieving revision 1.32 retrieving revision 1.33 diff -Lpod2mdoc.c -Lpod2mdoc.c -u -p -r1.32 -r1.33 --- pod2mdoc.c +++ pod2mdoc.c @@ -169,6 +169,7 @@ outbuf_addstr(struct state *st, const ch if (st->outbuflen + slen >= st->outbufsz) outbuf_grow(st, slen); memcpy(st->outbuf + st->outbuflen, str, slen+1); + st->outbuflen += slen; last = str[slen - 1]; st->wantws = 0; } @@ -242,7 +243,7 @@ formatescape(struct state *st, const cha outbuf_addstr(st, "\\(la"); else if (0 == strcmp(esc, "gt")) outbuf_addstr(st, "\\(ra"); - else if (0 == strcmp(esc, "vb")) + else if (0 == strcmp(esc, "verbar")) outbuf_addstr(st, "\\(ba"); else if (0 == strcmp(esc, "sol")) outbuf_addstr(st, "\\(sl"); @@ -469,7 +470,7 @@ again: * We usually exit in OUST_MAC mode, except when * entering without OUST_MAC and the code is invalid. */ -static void +static int formatcode(struct state *st, const char *buf, size_t *start, size_t end, int nomacro, int pos) { @@ -512,7 +513,7 @@ formatcode(struct state *st, const char */ if (FMT_ESCAPE == fmt) { formatescape(st, buf, start, end); - return; + return(0); } else if (FMT_NULL == fmt || FMT_INDEX == fmt) { /* * Just consume til the end delimiter, accounting for @@ -542,7 +543,7 @@ formatcode(struct state *st, const char if (isspace(last)) while (*start < end && isspace((int)buf[*start])) (*start)++; - return; + return(0); } /* @@ -680,7 +681,7 @@ formatcode(struct state *st, const char continue; } - if (OUST_MAC == st->oust) { + if (OUST_MAC == st->oust && FMT__MAX != fmt) { if ( ! st->wantws) { printf(" Ns "); st->wantws = 1; @@ -708,11 +709,14 @@ formatcode(struct state *st, const char putchar('e'); } + if (FMT__MAX == fmt) + return(0); + if ( ! nomacro && FMT_CODE == fmt) printf(" Qc "); - if (FMT__MAX != fmt) - st->wantws = ' ' == last; + st->wantws = ' ' == last; + return(1); } /* @@ -725,25 +729,49 @@ static void formatcodeln(struct state *st, const char *linemac, const char *buf, size_t *start, size_t end, int nomacro) { + int gotmacro, wantws; assert(OUST_NL == st->oust); assert(st->wantws); printf(".%s ", linemac); st->oust = OUST_MAC; - last = ' '; + gotmacro = 0; while (*start < end) { + wantws = ' ' == buf[*start] || '\n' == buf[*start]; + if (wantws) { + last = ' '; + do { + (*start)++; + } while (*start < end && ' ' == buf[*start]); + } + if (*start + 1 < end && '<' == buf[*start + 1]) { - formatcode(st, buf, start, end, nomacro, 1); + st->wantws |= wantws; + gotmacro = formatcode(st, buf, + start, end, nomacro, 1); continue; } - if (OUST_MAC == st->oust) { - if ( ! st->wantws && - ' ' != buf[*start] && - '\n' != buf[*start]) - printf(" Ns "); - st->wantws = 1; + if (gotmacro) { + if (*start < end || st->outbuflen) { + if (st->wantws || + (wantws && !st->outbuflen)) + printf(" No "); + else + printf(" Ns "); + } + gotmacro = 0; + } + outbuf_flush(st); + st->wantws = wantws; + + if (*start >= end) + break; + + if (st->wantws) { + putchar(' '); + st->wantws = 0; } /* @@ -754,18 +782,15 @@ formatcodeln(struct state *st, const cha * something that needn't be escaped. */ if (' ' == last && end - *start > 1 && - isupper((int)buf[*start]) && - islower((int)buf[*start + 1]) && - (end - *start == 2 || - ' ' == buf[*start + 2])) + isupper((unsigned char)buf[*start]) && + islower((unsigned char)buf[*start + 1]) && + (end - *start == 2 || ' ' == buf[*start + 2])) printf("\\&"); - if ('\n' == buf[*start]) - putchar(last = ' '); - else - putchar(last = buf[*start]); + putchar(last = buf[*start]); /* Protect against character escapes. */ + if ('\\' == last) putchar('e'); --- /dev/null +++ Regress/Makefile @@ -0,0 +1,14 @@ +SUBDIR = formatcode formatcodeln +TARGETS = all clean mdoc mdoc-clean \ + groffmdoc groffmdoc-clean mandocmdoc mandocmdoc-clean \ + diffmdoc maindiff \ + manall allclean preman preman-clean man man-clean \ + groffman groffman-clean mandocman mandocman-clean \ + mandocmanm mandocmanm-clean diffman + +${TARGETS}: + @for subdir in ${SUBDIR}; do \ + (echo "===> $${subdir}"; \ + cd ${.CURDIR}/$${subdir}; \ + exec ${MAKE} ${MAKE_FLAGS} ${.TARGET}); \ + done --- /dev/null +++ Regress/formatcode/escape.pod @@ -0,0 +1,17 @@ +=head1 NAME + +escape - character entity escape sequences + +=head1 DESCRIPTION + +beforeEafter + +before E after + +first secondE + +BEnormal + +B E normal + +BE Index: Makefile =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/pod2mdoc/Regress/formatcode/Makefile,v retrieving revision 1.2 retrieving revision 1.3 diff -LRegress/formatcode/Makefile -LRegress/formatcode/Makefile -u -p -r1.2 -r1.3 --- Regress/formatcode/Makefile +++ Regress/formatcode/Makefile @@ -1,3 +1,3 @@ -TARGETS = code invalid macroline textline +TARGETS = code escape invalid macroline textline .include "../Makefile.inc" --- /dev/null +++ Regress/formatcodeln/item.pod @@ -0,0 +1,37 @@ +=head1 NAME + +item - formatting of item lists + +=head1 DESCRIPTION + +=over 8 + +=item tag + +text + +=item beforeBafter + +no space + +=item beforeBIafter + +no space + +=item before B I after + +space outside escapes + +=item beforeB< bold>I< italic>after + +space at the beginning of escapes + +=item beforeBIafter + +space at the end of escapes + +=item beforeEmiddleEafter + +text + +=back --- /dev/null +++ Regress/formatcodeln/Makefile @@ -0,0 +1,3 @@ +TARGETS = item + +.include "../Makefile.inc" -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv