| 1 | #!/usr/bin/perl |
|---|
| 2 | # |
|---|
| 3 | # The main intention of this script is to make unchangable help files |
|---|
| 4 | # delivered with some of the integrated software compatible with |
|---|
| 5 | # the arb_hlp2xml help converter. |
|---|
| 6 | |
|---|
| 7 | use strict; |
|---|
| 8 | use warnings; |
|---|
| 9 | |
|---|
| 10 | sub clustalTopic2Section($) { |
|---|
| 11 | my ($line) = @_; |
|---|
| 12 | if ($line =~ /^\s*\>\>\s*([^<>]+)\s*\<\<\s*(.*)$/o) { |
|---|
| 13 | # '>>topic<< moretext' -> 'SECTION topic moretext' |
|---|
| 14 | $line = "SECTION $1 $2\n"; |
|---|
| 15 | } |
|---|
| 16 | return $line; |
|---|
| 17 | } |
|---|
| 18 | sub fancyitemind2star($) { |
|---|
| 19 | my ($line) = @_; |
|---|
| 20 | $line =~ s/^(\s+)[\+\=]\s/$1\* /; |
|---|
| 21 | return $line; |
|---|
| 22 | } |
|---|
| 23 | sub formatFormatHeadlines($) { |
|---|
| 24 | my ($line) = @_; |
|---|
| 25 | if ($line =~ /File\sFormat/o) { |
|---|
| 26 | $line =~ s/^\s+/ /g; |
|---|
| 27 | } |
|---|
| 28 | elsif ($line =~ /Example\s.*\sfile/o) { |
|---|
| 29 | $line =~ s/^\s+/ /g; |
|---|
| 30 | } |
|---|
| 31 | return $line; |
|---|
| 32 | } |
|---|
| 33 | sub readseq_promote_sections($) { |
|---|
| 34 | my ($line) = @_; |
|---|
| 35 | if ($line =~ /^\s+\|[\|]+\s+/) { |
|---|
| 36 | $line = "SECTION $'"; |
|---|
| 37 | } |
|---|
| 38 | return $line; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | sub main() { |
|---|
| 42 | my $args = scalar(@ARGV); |
|---|
| 43 | if ($args!=1) { |
|---|
| 44 | die "Usage: postprocess_genhelp.pl filename\n". |
|---|
| 45 | "(filters stdin to stdout, filename is only passed to trigger specific behavior)\n "; |
|---|
| 46 | } |
|---|
| 47 | my $filename = $ARGV[0]; |
|---|
| 48 | |
|---|
| 49 | my @reg = (); |
|---|
| 50 | my @fun = (); |
|---|
| 51 | |
|---|
| 52 | if ($filename =~ /clustalw/) { |
|---|
| 53 | push @reg, qr/([^\s]\s)\s+([\(])/; |
|---|
| 54 | push @reg, qr/([\.:])(\s)\s+/; |
|---|
| 55 | push @fun, \&clustalTopic2Section; |
|---|
| 56 | } |
|---|
| 57 | elsif ($filename =~ /readseq/) { |
|---|
| 58 | push @reg, qr/([\.])(\s)\s+/; |
|---|
| 59 | push @reg, qr/(LINE\s)\s+([0-9]+)/; |
|---|
| 60 | push @fun, \&fancyitemind2star; |
|---|
| 61 | push @fun, \&readseq_promote_sections; |
|---|
| 62 | if ($filename =~ /Formats/) { |
|---|
| 63 | push @fun, \&formatFormatHeadlines; |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | my $titled = 0; |
|---|
| 68 | |
|---|
| 69 | foreach (<STDIN>) { |
|---|
| 70 | chomp; |
|---|
| 71 | # convert all lines starting at column zero into SECTIONs |
|---|
| 72 | if (s/^([^ \#\n])/SECTION $1/) { |
|---|
| 73 | # convert first SECTION into TITLE |
|---|
| 74 | if ($titled==0) { |
|---|
| 75 | s/^SECTION/TITLE/; |
|---|
| 76 | $titled=1; |
|---|
| 77 | } |
|---|
| 78 | } |
|---|
| 79 | |
|---|
| 80 | foreach my $re (@reg) { |
|---|
| 81 | while ($_ =~ $re) { |
|---|
| 82 | $_ = $`.$1.$2.$'; |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | foreach my $fn (@fun) { |
|---|
| 86 | $_ = &$fn($_); |
|---|
| 87 | } |
|---|
| 88 | print $_."\n"; |
|---|
| 89 | } |
|---|
| 90 | } |
|---|
| 91 | main(); |
|---|