summaryrefslogtreecommitdiff
path: root/doc/doc-scripts/f2txt
diff options
context:
space:
mode:
Diffstat (limited to 'doc/doc-scripts/f2txt')
-rwxr-xr-xdoc/doc-scripts/f2txt107
1 files changed, 107 insertions, 0 deletions
diff --git a/doc/doc-scripts/f2txt b/doc/doc-scripts/f2txt
new file mode 100755
index 000000000..ff5d70392
--- /dev/null
+++ b/doc/doc-scripts/f2txt
@@ -0,0 +1,107 @@
+#!/usr/bin/perl
+# $Cambridge: exim/doc/doc-scripts/f2txt,v 1.1 2004/10/07 15:04:35 ph10 Exp $
+
+# Script to turn the Exim FAQ into plain ASCII.
+
+use integer;
+
+
+# Function to do text conversions to display paragraphs
+
+sub process_display {
+my($s) = $_[0];
+$s =~ s/^==>/ /;
+return $s;
+}
+
+
+# Function to do text conversions to paragraphs not in displays.
+
+sub process_non_display {
+my($s) = $_[0];
+
+$s =~ s/@\\/@@backslash@@/g; # @\ temporarily hidden
+
+$s =~ s/\\#/ /g; # \# is a hard space
+
+$s =~ s/\\\*\*([^*]*)\*\*\\/$1/g; # \**...**\ => text
+$s =~ s/\\\*([^*]*)\*\\/"$1"/g; # \*.....*\ => "text"
+$s =~ s/\\"([^"]*)"\\/"$1"/g; # \"....."\ => "text"
+$s =~ s/\\\$([^\$]*)\$\\/\$$1/g; # \$.....$\ => $text
+$s =~ s/\\\\([^\\]*)\\\\/$1/g; # \\.....\\ => text
+$s =~ s/\\\(([^)]*)\)\\/$1/g; # \(.....)\ => text
+$s =~ s/\\-([^-]*)-\\/-$1/g; # \-.....-\ => -text
+$s =~ s/\\\[([^]]*)\]\\/<$1>/gx; # \[.....]\ => <text>
+$s =~ s/\\\?(.*?)\?\\/$1/g; # \?.....?\ => text
+$s =~ s/\\\^\^([^^]*)\^\^\\/$1/g; # \^^...^^\ => text
+$s =~ s/\\\^([^^]*)\^\\/$1/g; # \^.....^\ => text
+$s =~ s/\\%([^%]*)%\\/"$1"/g; # \%.....%\ => "text"
+$s =~ s/\\\/([^\/]*)\/\\/$1/g; # \/...../\ => text
+$s =~ s/\\([^\\]+)\\/"$1"/g; # \.......\ => "text"
+
+$s =~ s"//([^/\"]*)//"$1"g; # //.....// => text
+$s =~ s/::([^:]*)::/$1:/g; # ::.....:: => text:
+
+$s =~ s/``(.*?)''/"$1"/g; # ``.....'' => "text"
+
+$s =~ s/\s*\[\[br\]\]\s*\n/\n/g; # Remove [[br]]
+
+$s =~ s/@@backslash@@/\\/g; # Put back single backslash
+
+return $s;
+}
+
+
+# Main program
+
+# We want to read the file paragraph by paragraph; Perl only does this if the
+# separating lines are truly blank. Having been caught by lines containing
+# whitespace before, do a detrailing pass first.
+
+open(IN, "$ARGV[0]") || die "can't open $ARGV[0] (preliminary)\n";
+open(OUT, ">$ARGV[0]-$$") || die "can't open $ARGV[0]-$$\n";
+while (<IN>)
+ {
+ s/[ \t]+$//;
+ print OUT;
+ }
+close(IN);
+close(OUT);
+rename("$ARGV[0]-$$", "$ARGV[0]") ||
+ die "can't rename $ARGV[0]-$$ as $ARGV[0]\n";
+
+# The second argument is the name of the output file.
+
+open(IN, "$ARGV[0]") || die "can't open $ARGV[0] (for real)\n";
+open(OUT, ">$ARGV[1]") || die "can't open $ARGV[1]\n";
+
+$/ = "";
+
+while ($_ = <IN>)
+ {
+ # Comment lines start with ##
+
+ next if /^\#\#/;
+
+ # If a paragraph begins ==> it is a display which must remain verbatin
+ # and not be reformatted. The flag gets turned into spaces.
+
+ if ($_ =~ /^==>/)
+ {
+ $_ = &process_display($_);
+ }
+
+ # Non-display paragraph
+
+ else
+ {
+ $_ = &process_non_display($_);
+ }
+
+ print OUT;
+ }
+
+close(IN);
+close(OUT);
+
+End