* pod2mdoc: Escape literal double quotes when they start a macro argument.
@ 2015-02-19 15:27 schwarze
0 siblings, 0 replies; only message in thread
From: schwarze @ 2015-02-19 15:27 UTC (permalink / raw)
To: source
Log Message:
-----------
Escape literal double quotes when they start a macro argument.
Making this work requires properly keeping track of the output state
in the function formatcode() - which actually simplifies the code
in that function and removes one local variable.
Modified Files:
--------------
pod2mdoc:
pod2mdoc.c
Revision Data
-------------
Index: pod2mdoc.c
===================================================================
RCS file: /home/cvs/mdocml/pod2mdoc/pod2mdoc.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -Lpod2mdoc.c -Lpod2mdoc.c -u -p -r1.53 -r1.54
--- pod2mdoc.c
+++ pod2mdoc.c
@@ -185,7 +185,11 @@ outbuf_flush(struct state *st)
if (OUST_TXT == st->oust && st->wantws)
putchar(' ');
- fputs(st->outbuf, stdout);
+ if (OUST_MAC == st->oust && '"' == *st->outbuf)
+ printf("\\(dq%s", st->outbuf + 1);
+ else
+ fputs(st->outbuf, stdout);
+
*st->outbuf = '\0';
st->outbuflen = 0;
@@ -480,7 +484,6 @@ formatcode(struct state *st, const char
{
size_t i, j, dsz;
enum fmt fmt;
- int wantws;
unsigned char uc;
assert(*start + 1 < end);
@@ -559,45 +562,43 @@ formatcode(struct state *st, const char
if (FMT__MAX != fmt && !nomacro) {
/*
- * We may already have wantws if there was whitespace
- * before the code ("text B<text"), but initial
- * whitespace inside our scope ("textB< text")
- * allows to break at this point as well.
- */
-
- wantws = ' ' == buf[*start] ||
- (OUST_MAC == st->oust ? st->wantws : ! st->outbuflen);
-
- /*
* If we are on a text line and there is no
* whitespace before our content, we have to make
* the previous word a prefix to the macro line.
- * In the following, mdoc_newln() must not be used
- * lest we clobber out output state.
*/
- if (OUST_MAC != st->oust && ! wantws) {
+ if (OUST_MAC != st->oust && ' ' != buf[*start] &&
+ st->outbuflen) {
if (OUST_NL != st->oust)
- putchar('\n');
+ mdoc_newln(st);
printf(".Pf ");
- st->wantws = 0;
+ st->oust = OUST_MAC;
+ st->wantws = 1;
}
outbuf_flush(st);
- /* Whitespace is easier to suppress on macro lines. */
+ /*
+ * Whitespace is easier to suppress on macro lines.
+ * We may already have wantws if there was whitespace
+ * before the code ("text B<text"), or there may be
+ * whitespace inside our scope ("textB< text").
+ */
- if (OUST_MAC == st->oust && ! wantws)
- printf(" Ns ");
+ if (OUST_MAC == st->oust && ' ' != buf[*start] &&
+ ! st->wantws)
+ printf(" Ns");
/* Unless we are on a macro line, start one. */
- if (OUST_MAC != st->oust && wantws) {
+ if (OUST_MAC != st->oust) {
if (OUST_NL != st->oust)
- putchar('\n');
+ mdoc_newln(st);
putchar('.');
+ st->oust = OUST_MAC;
} else
putchar(' ');
+ st->wantws = 1;
/*
* Print the macro corresponding to this format code,
@@ -657,8 +658,6 @@ formatcode(struct state *st, const char
default:
abort();
}
- st->oust = OUST_MAC;
- st->wantws = 1;
} else
outbuf_flush(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:[~2015-02-19 15:27 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-19 15:27 pod2mdoc: Escape literal double quotes when they start a macro argument 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).