summaryrefslogtreecommitdiff
path: root/doc/doc-scripts/f2txt
blob: 4f24f7b3f5cc3dd9328c1239cf0d93946ceb680f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/perl

# 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