summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Hazel <ph10@hermes.cam.ac.uk>2007-09-13 15:02:22 +0000
committerNigel Metheringham <nigel@exim.org>2010-06-09 12:42:07 +0000
commitabaf3d3690fae7bdc89335a5cf47d2e3a26c2da7 (patch)
tree59bb51207bccd3c902a3122345b8e0627aaecbb0
parent383466003e800a06ed6d3de9ede2185d03cca488 (diff)
downloadexim4-abaf3d3690fae7bdc89335a5cf47d2e3a26c2da7.tar.gz
Imported from /Users/nigel/Work/x/xfpt-0.04.tar.bz2.
-rw-r--r--src/globals.c2
-rw-r--r--src/para.c73
-rw-r--r--testing/infiles/0110
-rw-r--r--testing/outfiles/0110
4 files changed, 81 insertions, 14 deletions
diff --git a/src/globals.c b/src/globals.c
index 7140ea876..9aadfbf7a 100644
--- a/src/globals.c
+++ b/src/globals.c
@@ -11,7 +11,7 @@
uschar *xfpt_share = US DATADIR;
-uschar *xfpt_version = US "0.03 02-July-2007";
+uschar *xfpt_version = US "0.04 13-September-2007";
tree_node *entities = NULL;
diff --git a/src/para.c b/src/para.c
index 5b4ec4380..9de7f88bc 100644
--- a/src/para.c
+++ b/src/para.c
@@ -2,7 +2,7 @@
* xfpt - Simple ASCII->Docbook processor *
*************************************************/
-/* Copyright (c) University of Cambridge, 2006 */
+/* Copyright (c) University of Cambridge, 2007 */
/* Written by Philip Hazel. */
/* This module contains code for processing a paragraph by looking for flag
@@ -133,6 +133,51 @@ return q + 1;
/*************************************************
+* Check a flag string for literal *
+*************************************************/
+
+/* This function is called to scan flag replacement strings to check for
+<literal> and <literal/> so that we can avoid messing with single quotes in
+literal text.
+
+Arguments:
+ s the flag string
+ b a boolean that is set TRUE, FALSE, or left alone
+
+Returns: nothing
+*/
+
+static void
+check_literal(uschar *s, BOOL *b)
+{
+while (*s != 0)
+ {
+ s = Ustrchr(s, '<');
+ if (s == NULL) return;
+
+ if (Ustrncmp(s, "<literal", 8) == 0 && (s[8] == '>' || isspace(s[8])))
+ *b = TRUE;
+ else if (Ustrncmp(s, "</literal", 9) == 0 && (s[9] == '>' || isspace(s[9])))
+ *b = FALSE;
+
+ while (*s != 0 && *s != '>')
+ {
+ if (*s == '"' || *s == '\'')
+ {
+ int t = *s++;
+ while (*s != 0 && *s != t) s++;
+ if (*s == 0) return;
+ }
+ s++;
+ }
+
+ if (*s++ == 0) return;
+ }
+}
+
+
+
+/*************************************************
* Process a paragraph *
*************************************************/
@@ -150,6 +195,7 @@ para_process(uschar *p)
flagstr *f;
flagstr *fstack[FLAGSTACKSIZE];
int fstackcount = 0;
+BOOL inliteraltext = FALSE;
while (*p != 0)
{
@@ -168,6 +214,7 @@ while (*p != 0)
error(8, fstack[j]->flag2, f->flag2);
fstackcount = i;
(void)fprintf(outfile, "%s", CS f->rep2);
+ check_literal(f->rep2, &inliteraltext);
p += f->length2;
i = fstackcount; /* Reset in case another follows immediately */
continue;
@@ -180,23 +227,26 @@ while (*p != 0)
if (*p == 0) break;
/* Otherwise, scan character by character. Angle brackets are escaped,
- single quotes are mapped, and then everything other than ampersand is treated
- literally. */
+ single quotes are mapped except in literal text, and then everything other
+ than ampersand is treated literally. */
c = *p++;
if (c == '<') { (void)fprintf(outfile, "&lt;"); continue; }
if (c == '>') { (void)fprintf(outfile, "&gt;"); continue; }
- if (c == '`')
+ if (!inliteraltext)
{
- (void)fprintf(outfile, "&#x2018;");
- continue;
- }
+ if (c == '`')
+ {
+ (void)fprintf(outfile, "&#x2018;");
+ continue;
+ }
- if (c == '\'')
- {
- (void)fprintf(outfile, "&#x2019;");
- continue;
+ if (c == '\'')
+ {
+ (void)fprintf(outfile, "&#x2019;");
+ continue;
+ }
}
if (c != '&') { (void)fputc(c, outfile); continue; }
@@ -315,6 +365,7 @@ while (*p != 0)
if (f->length2 != 0) fstack[fstackcount++] = f;
(void)fprintf(outfile, "%s", CS f->rep1);
+ check_literal(f->rep1, &inliteraltext);
p += f->length1;
}
diff --git a/testing/infiles/01 b/testing/infiles/01
index e2e338484..9c1b059a5 100644
--- a/testing/infiles/01
+++ b/testing/infiles/01
@@ -403,6 +403,14 @@ figure &<<FIGsecond>>& below.
.row CCC DDD
.endtable
-A ref to table &<<TAB123>>&.
+A ref to table &<<TAB123>>&. Now check quotes: `normal' should be changed
+to typographic ones. In &`literal text, `they' shouldn't be`& changed.
+.code
+Check `quoted' in literal monospaced block.
+.endd
+.display
+But in a literal block that is `not monospaced' ...
+&`Check it's ok`& when `in the same line'.
+.endd
.makeindex
diff --git a/testing/outfiles/01 b/testing/outfiles/01
index 2bffb0a72..b30e1fcc7 100644
--- a/testing/outfiles/01
+++ b/testing/outfiles/01
@@ -446,8 +446,16 @@ figure <xref linkend="FIGsecond"/> below.
</tgroup>
</table>
<para>
-A ref to table <xref linkend="TAB123"/>.
+A ref to table <xref linkend="TAB123"/>. Now check quotes: &#x2018;normal&#x2019; should be changed
+to typographic ones. In <literal>literal text, `they' shouldn't be</literal> changed.
</para>
+<literallayout class="monospaced">
+Check `quoted' in literal monospaced block.
+</literallayout>
+<literallayout>
+But in a literal block that is &#x2018;not monospaced&#x2019; ...
+<literal>Check it's ok</literal> when &#x2018;in the same line&#x2019;.
+</literallayout>
</chapter>
<index>