diff options
author | Philip Hazel <ph10@hermes.cam.ac.uk> | 2004-10-07 15:04:35 +0000 |
---|---|---|
committer | Philip Hazel <ph10@hermes.cam.ac.uk> | 2004-10-07 15:04:35 +0000 |
commit | 495ae4b01f36d0d8bb0e34a1d7263c2b8224aa4a (patch) | |
tree | fcfaa2c623d4f155eef907b50b950b602829a30b /doc/doc-scripts/f2txt | |
parent | 0756eb3cb50d73a77b486e47528f7cb1bffdb299 (diff) |
Start
Diffstat (limited to 'doc/doc-scripts/f2txt')
-rwxr-xr-x | doc/doc-scripts/f2txt | 107 |
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 |