* pod2mdoc: Almost a rewrite of formatcodeln().
@ 2014-07-18 23:56 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2014-07-18 23:56 UTC (permalink / raw)
To: source
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<verbar> 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
+
+beforeE<verbar>after
+
+before E<verbar> after
+
+first secondE<verbar>
+
+B<bold>E<verbar>normal
+
+B<bold> E<verbar> normal
+
+B<bold >E<verbar>
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 beforeB<bold>after
+
+no space
+
+=item beforeB<bold>I<italic>after
+
+no space
+
+=item before B<bold> I<italic> after
+
+space outside escapes
+
+=item beforeB< bold>I< italic>after
+
+space at the beginning of escapes
+
+=item beforeB<bold >I<italic >after
+
+space at the end of escapes
+
+=item beforeE<lt>middleE<gt>after
+
+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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-07-18 23:57 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-18 23:56 pod2mdoc: Almost a rewrite of formatcodeln() 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).