tidying
[exim.git] / doc / doc-scripts / f2txt
CommitLineData
495ae4b0 1#!/usr/bin/perl
495ae4b0
PH
2
3# Script to turn the Exim FAQ into plain ASCII.
4
5use integer;
6
7
8# Function to do text conversions to display paragraphs
9
10sub process_display {
11my($s) = $_[0];
12$s =~ s/^==>/ /;
13return $s;
14}
15
16
17# Function to do text conversions to paragraphs not in displays.
18
19sub process_non_display {
20my($s) = $_[0];
21
22$s =~ s/@\\/@@backslash@@/g; # @\ temporarily hidden
23
24$s =~ s/\\#/ /g; # \# is a hard space
25
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"
40
41$s =~ s"//([^/\"]*)//"$1"g; # //.....// => text
42$s =~ s/::([^:]*)::/$1:/g; # ::.....:: => text:
43
44$s =~ s/``(.*?)''/"$1"/g; # ``.....'' => "text"
45
46$s =~ s/\s*\[\[br\]\]\s*\n/\n/g; # Remove [[br]]
47
48$s =~ s/@@backslash@@/\\/g; # Put back single backslash
49
50return $s;
51}
52
53
54# Main program
55
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
4c04137d 58# whitespace before, do a de-trailing pass first.
495ae4b0
PH
59
60open(IN, "$ARGV[0]") || die "can't open $ARGV[0] (preliminary)\n";
61open(OUT, ">$ARGV[0]-$$") || die "can't open $ARGV[0]-$$\n";
62while (<IN>)
63 {
64 s/[ \t]+$//;
65 print OUT;
66 }
67close(IN);
68close(OUT);
69rename("$ARGV[0]-$$", "$ARGV[0]") ||
70 die "can't rename $ARGV[0]-$$ as $ARGV[0]\n";
71
72# The second argument is the name of the output file.
73
74open(IN, "$ARGV[0]") || die "can't open $ARGV[0] (for real)\n";
75open(OUT, ">$ARGV[1]") || die "can't open $ARGV[1]\n";
76
77$/ = "";
78
79while ($_ = <IN>)
80 {
81 # Comment lines start with ##
82
83 next if /^\#\#/;
84
4c04137d 85 # If a paragraph begins ==> it is a display which must remain verbatim
495ae4b0
PH
86 # and not be reformatted. The flag gets turned into spaces.
87
88 if ($_ =~ /^==>/)
89 {
90 $_ = &process_display($_);
91 }
92
93 # Non-display paragraph
94
95 else
96 {
97 $_ = &process_non_display($_);
98 }
99
100 print OUT;
101 }
102
103close(IN);
104close(OUT);
105
106End