2 # $Cambridge: exim/doc/doc-scripts/f2txt,v 1.1 2004/10/07 15:04:35 ph10 Exp $
4 # Script to turn the Exim FAQ into plain ASCII.
9 # Function to do text conversions to display paragraphs
18 # Function to do text conversions to paragraphs not in displays.
20 sub process_non_display {
23 $s =~ s/@\\/@@backslash@@/g; # @\ temporarily hidden
25 $s =~ s/\\#/ /g; # \# is a hard space
27 $s =~ s/\\\*\*([^*]*)\*\*\\/$1/g; # \**...**\ => text
28 $s =~ s/\\\*([^*]*)\*\\/"$1"/g; # \*.....*\ => "text"
29 $s =~ s/\\"([^"]*)"\\/"$1"/g; # \"....."\ => "text"
30 $s =~ s/\\\$([^\$]*)\$\\/\$$1/g; # \$.....$\ => $text
31 $s =~ s/\\\\([^\\]*)\\\\/$1/g; # \\.....\\ => text
32 $s =~ s/\\\(([^)]*)\)\\/$1/g; # \(.....)\ => text
33 $s =~ s/\\-([^-]*)-\\/-$1/g; # \-.....-\ => -text
34 $s =~ s/\\\[([^]]*)\]\\/<$1>/gx; # \[.....]\ => <text>
35 $s =~ s/\\\?(.*?)\?\\/$1/g; # \?.....?\ => text
36 $s =~ s/\\\^\^([^^]*)\^\^\\/$1/g; # \^^...^^\ => text
37 $s =~ s/\\\^([^^]*)\^\\/$1/g; # \^.....^\ => text
38 $s =~ s/\\%([^%]*)%\\/"$1"/g; # \%.....%\ => "text"
39 $s =~ s/\\\/([^\/]*)\/\\/$1/g; # \/...../\ => text
40 $s =~ s/\\([^\\]+)\\/"$1"/g; # \.......\ => "text"
42 $s =~ s"//([^/\"]*)//"$1"g; # //.....// => text
43 $s =~ s/::([^:]*)::/$1:/g; # ::.....:: => text:
45 $s =~ s/``(.*?)''/"$1"/g; # ``.....'' => "text"
47 $s =~ s/\s*\[\[br\]\]\s*\n/\n/g; # Remove [[br]]
49 $s =~ s/@@backslash@@/\\/g; # Put back single backslash
57 # We want to read the file paragraph by paragraph; Perl only does this if the
58 # separating lines are truly blank. Having been caught by lines containing
59 # whitespace before, do a detrailing pass first.
61 open(IN, "$ARGV[0]") || die "can't open $ARGV[0] (preliminary)\n";
62 open(OUT, ">$ARGV[0]-$$") || die "can't open $ARGV[0]-$$\n";
70 rename("$ARGV[0]-$$", "$ARGV[0]") ||
71 die "can't rename $ARGV[0]-$$ as $ARGV[0]\n";
73 # The second argument is the name of the output file.
75 open(IN, "$ARGV[0]") || die "can't open $ARGV[0] (for real)\n";
76 open(OUT, ">$ARGV[1]") || die "can't open $ARGV[1]\n";
82 # Comment lines start with ##
86 # If a paragraph begins ==> it is a display which must remain verbatin
87 # and not be reformatted. The flag gets turned into spaces.
91 $_ = &process_display($_);
94 # Non-display paragraph
98 $_ = &process_non_display($_);