1#!/usr/bin/perl -w
2
3# This is a utility to create the history
4# include files for the EMBOSS application documentation.
5
6# GWW 24 Jan 2003
7
8
9
10###################################################################
11#
12# Some useful definitions
13#
14###################################################################
15# where the web pages include files live
16$incdir = "/data/www/Software/EMBOSS/Apps/inc";
17
18# colours for backgrounds of usage examples, input and output files
19$outputcolour = "#FFFFCC"; # light yellow
20
21
22
23###################################################################
24# run cvs to create the logs for all applications
25    my $apps = "app.log";
26    my $acds = "acd.log";
27
28    my $app;
29    my $acd;
30    my @files;
31    my $line;
32    my ($date, $author, $desc);
33
34    chdir "/packages/emboss_dev/$ENV{'USER'}/emboss/emboss/emboss/";
35    system("cvs log *.c >$apps");
36
37    parse($apps);
38    unlink $apps;
39
40    chdir "/packages/emboss_dev/$ENV{'USER'}/emboss/emboss/emboss/acd/";
41    system("cvs log *.acd >$acds");
42
43    parse($acds);
44    unlink $acds;
45
46# merge the two sets of files together
47    chdir $incdir;
48    @files = glob("*.applog");
49    foreach $app (@files) {
50        ($file) = ($app =~ /(\S+)\.applog/);
51        $acd = $file . ".acdlog";
52        if (-f $acd) {
53            system("cat $acd >> $app");
54            system("sort $app > $app.sorted");
55            if (open(SORT, "< $app.sorted")) {
56                open (OUT, "> $file.history") || die "Can't open history file\n";
57                print OUT "<table border cellspacing=0 cellpadding=3 bgcolor=\"$outputcolour\">\n";
58                print OUT "<tr><th>Date</th><th>Editor</th><th>Comment</th></tr>\n";
59                while ($line = <SORT>) {
60                    ($date, $author, $desc) = ($line =~ /(\S+)\s+(\S+)\s+(.+)/);
61                    print OUT "<tr><td>$date</td><td>$author</td><td>$desc</td></tr>\n";
62                }
63                print OUT "</table>\n";
64                close(SORT);
65                close(OUT);
66                chmod 0664, "$file.history";    # rw-rw-r--
67            }
68            unlink "$app.sorted";
69            unlink $acd;
70        }
71        unlink $app;
72    }
73
74exit(0);
75
76###################################################################
77# Name:		parse
78# Function:	Gets history data from log files.
79#		Produces intermediate data file.
80# Args:
81#		file - file name to parse
82# Returns:	parsed data returned in 'data'
83###################################################################
84sub parse {
85    my ($file) = @_;
86    my $line;
87    my $desc;
88    my $outfile = "";	# initialise it to blank to indicate we have no open files
89
90    open (LOG, "< $file") || die "Couldn't open file $file";
91
92    while ($line = <LOG>) {
93# get the name of the next output file
94        if ($line =~ "RCS file:") {
95            ($outfile, $extension) = ($line =~ /RCS file: \/home\/repository\/emboss\/emboss\/emboss\/emboss\/(\S+)\.(\S)/);
96# close previous file
97            if ($outfile ne "") {
98                close (OUT);
99            }
100# open new file
101#print "ext=$extension\n";
102            if ($extension eq "c") {	# .c file
103#print "open $outfile.applog\n";
104                open (OUT, "> $incdir/$outfile.applog");
105		$extra = "Program:";
106            } else {			# .acd file
107                $outfile =~ s/acd\///;	# remove the 'acd/' from the file name
108#print "open $outfile.acdlog\n";
109                open (OUT, "> $incdir/$outfile.acdlog");
110		$extra = "ACD file:";
111            }
112        }
113        if ($line =~ "date") {
114            ($date, $author) = ($line =~ /\S+\s+(\S+)\s+\S+\s+\S+\s+(\S+);/);
115
116            $desc = <LOG>;
117            chomp $desc;
118# change any ampersands or angle brackets to HTML codes
119            $desc =~ s/&/&amp;/g;
120            $desc =~ s/</&lt;/g;
121            $desc =~ s/>/&gt;/g;
122
123# write data out
124	    print OUT "$date\t$author\t$extra $desc\n";
125        }
126
127    }
128
129    close (OUT);
130    close (LOG);
131
132}
133
134
135
136