source: branches/lib/HELP_SOURCE/genhelp/postprocess_genhelp.pl

Last change on this file was 19532, checked in by westram, 4 months ago
  • reintegrates 'help' into 'trunk'
    • tweak arb documentation:
      • automatically link
        • ticket references to arb bug tracker (only affects html version).
        • found URLs.
      • page titles
        • warn about long titles.
        • introduce SUBTITLEs (automatically triggered by multi-line titles in source files).
        • increase allowed length (limited by subwindow width).
      • cleanup header sections in all helpfiles.
      • fix and/or update several help files.
      • document syntax of help sources.
      • build issues:
        • when xml validation fails, next build no longer uses invalid xml ⇒ keeps failing.
        • remove output files on error (including files below ARBHOME/lib).
        • pipe output through logs to ensure proper wrapping in Entering/Leaving lines.
    • moves Tree admin + NDS menu entries to top of menu
  • adds: log:branches/help@18783:19531
  • Property svn:executable set to *
File size: 2.6 KB
Line 
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
7use strict;
8use warnings;
9
10my $inputFilename;
11my $outputFilename;
12
13use Carp;
14
15sub die_input($) {
16  my ($msg) = @_;
17  confess("$inputFilename:$.: $msg");
18}
19
20sub clustalTopic2Section($) {
21  my ($line) = @_;
22  if ($line =~ /^\s*\>\>\s*([^<>]+)\s*\<\<\s*(.*)$/o) {
23    # '>>topic<< moretext' -> 'SECTION topic moretext'
24    $line = "SECTION $1 $2\n";
25  }
26  return $line;
27}
28sub fancyitemind2star($) {
29  my ($line) = @_;
30  $line =~ s/^(\s+)[\+\=]\s/$1\* /;
31  return $line;
32}
33sub formatFormatHeadlines($) {
34  my ($line) = @_;
35  if ($line =~ /File\sFormat/o) {
36    $line =~ s/^\s+/  /og;
37  }
38  elsif ($line =~ /Example\s.*\sfile/o) {
39    $line =~ s/^\s+/   /og;
40  }
41  return $line;
42}
43sub readseq_promote_sections($) {
44  my ($line) = @_;
45  if ($line =~ /^\s+\|[\|]+\s+/o) {
46    $line = "SECTION $'";
47  }
48  return $line;
49}
50
51sub linkToWeb($) {
52  my ($line) = @_;
53  if ($line =~ /LINK\{(http|ftp)[^\}]*\}/o) {
54    die_input "illegal LINK{web}-element in generated help";
55  }
56  $line =~ s/((http|ftp):\/\/[^\s]*)(\s|$)/LINK{$1}/og;
57  return $line;
58}
59
60sub elimEOLwhitespace($) {
61  my ($line) = @_;
62  $line =~ s/\s+$//o;
63  return $line;
64}
65
66sub main() {
67  my $args = scalar(@ARGV);
68  if ($args!=2) {
69    die "Usage: postprocess_genhelp.pl input-filename output-filename\n".
70      "Filters stdin to stdout, filenames are only passed to trigger specific behavior\n".
71      "OR to print proper error messages.\n ";
72  }
73
74  $inputFilename = $ARGV[0];
75  $outputFilename = $ARGV[1];
76
77  my $filename = $outputFilename;
78
79  my @reg = ();
80  my @fun = ();
81
82  if ($filename =~ /clustalw/) {
83    push @reg, qr/([^\s]\s)\s+([\(])/;
84    push @reg, qr/([\.:])(\s)\s+/;
85    push @fun, \&clustalTopic2Section;
86  }
87  elsif ($filename =~ /readseq/) {
88    push @reg, qr/([\.])(\s)\s+/;
89    push @reg, qr/(LINE\s)\s+([0-9]+)/;
90    push @fun, \&fancyitemind2star;
91    push @fun, \&readseq_promote_sections;
92    if ($filename =~ /Formats/) {
93      push @fun, \&formatFormatHeadlines;
94    }
95  }
96
97  push @fun, \&linkToWeb;
98  push @fun, \&elimEOLwhitespace;
99
100  my $titled = 0;
101
102  while (defined($_=<STDIN>)) {
103    chomp;
104    # convert all lines starting at column zero into SECTIONs
105    if (s/^([^ \#\n])/SECTION $1/) {
106      # convert first SECTION into TITLE
107      if ($titled==0) {
108        s/^SECTION/TITLE/;
109        $titled=1;
110      }
111    }
112
113    foreach my $re (@reg) {
114      while ($_ =~ $re) {
115        $_ = $`.$1.$2.$';
116      }
117    }
118    foreach my $fn (@fun) {
119      $_ = &$fn($_);
120    }
121    print $_."\n";
122  }
123}
124main();
Note: See TracBrowser for help on using the repository browser.