From 495ae4b01f36d0d8bb0e34a1d7263c2b8224aa4a Mon Sep 17 00:00:00 2001 From: Philip Hazel Date: Thu, 7 Oct 2004 15:04:35 +0000 Subject: Start --- doc/doc-scripts/f2txt | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100755 doc/doc-scripts/f2txt (limited to 'doc/doc-scripts/f2txt') 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; # \[.....]\ => +$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 () + { + 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 ($_ = ) + { + # 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 -- cgit v1.2.3