3 # Script to turn the Exim FAQ into plain ASCII.
8 # Function to do text conversions to display paragraphs
17 # Function to do text conversions to paragraphs not in displays.
19 sub process_non_display {
22 $s =~ s/@\\/@@backslash@@/g; # @\ temporarily hidden
24 $s =~ s/\\#/ /g; # \# is a hard space
26 $s =~ s/\\\*\*([^*]*)\*\*\\/$1/g; # \**...**\ => text
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>/gx; # \[.....]\ => <text>
34 $s =~ s/\\\?(.*?)\?\\/$1/g; # \?.....?\ => 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"
41 $s =~ s"//([^/\"]*)//"$1"g; # //.....// => text
42 $s =~ s/::([^:]*)::/$1:/g; # ::.....:: => text:
44 $s =~ s/``(.*?)''/"$1"/g; # ``.....'' => "text"
46 $s =~ s/\s*\[\[br\]\]\s*\n/\n/g; # Remove [[br]]
48 $s =~ s/@@backslash@@/\\/g; # Put back single backslash
56 # We want to read the file paragraph by paragraph; Perl only does this if the
57 # separating lines are truly blank. Having been caught by lines containing
58 # whitespace before, do a detrailing pass first.
60 open(IN, "$ARGV[0]") || die "can't open $ARGV[0] (preliminary)\n";
61 open(OUT, ">$ARGV[0]-$$") || die "can't open $ARGV[0]-$$\n";
69 rename("$ARGV[0]-$$", "$ARGV[0]") ||
70 die "can't rename $ARGV[0]-$$ as $ARGV[0]\n";
72 # The second argument is the name of the output file.
74 open(IN, "$ARGV[0]") || die "can't open $ARGV[0] (for real)\n";
75 open(OUT, ">$ARGV[1]") || die "can't open $ARGV[1]\n";
81 # Comment lines start with ##
85 # If a paragraph begins ==> it is a display which must remain verbatin
86 # and not be reformatted. The flag gets turned into spaces.
90 $_ = &process_display($_);
93 # Non-display paragraph
97 $_ = &process_non_display($_);