1#!/usr/bin/perl -w
2
3# This is a utility to aid prople who wish to edit the html
4# documentation for an application.  It is somewhat more friendly than
5# 'autodoc.pl' in that it only works with the specified application's
6# documentation and will confirm any action with the user.
7
8###################################################################
9#
10# Some useful definitions
11#
12###################################################################
13# where the URL for the html pages is
14$url = "http://www.uk.embnet.org/Software/EMBOSS/Apps/";
15
16# where the CVS tree program doc pages are
17$cvsdoc = "/packages/emboss_dev/$ENV{'USER'}/emboss/emboss/doc/programs/";
18
19# where the CVS tree scripts are
20$scripts = "/packages/emboss_dev/$ENV{'USER'}/emboss/emboss/scripts";
21
22# where the web pages live
23$docdir = "/data/www/Software/EMBOSS/Apps";
24
25
26###################################################################
27# check that we are on the CVS machine
28#require 'hostname.pl';
29#if (hostname() ne "tin") {
30#	die "This script should be executed on the CVS machine 'tin'\n";
31#}
32
33
34###################################################################
35# get an editor
36###################################################################
37$editor = $ENV{'EDITOR'};
38if (!defined $editor || $editor eq "") {
39    print "What is your favourite editor [emacs] >";
40    $editor = <STDIN>;
41    chomp $editor;
42    if ($editor eq "") {$editor = 'emacs';}
43}
44
45print "Utility to edit an application's html documentation\n\n";
46
47if ($#ARGV != 0) {
48	print "Name of the program >";
49	$application = <STDIN>;
50} else {
51	$application = $ARGV[0];
52}
53chomp $application;
54if (!defined $application || $application eq "") {die "No program specified\n";}
55
56###################################################################
57# get details of the program from wossname
58###################################################################
59
60# read in from the EMBOSS application 'wossname'
61# group names, application name and which application is in which groups
62
63open (PROGS, "wossname -auto -search $application |") || die "Cannot run wossname\n";
64$grp = "";
65while (<PROGS>) {
66  if (/^\s*$/) {next}
67  if (/^([A-Z ]+)$/) {
68    $capgrp = $1;
69    $grp = lc($capgrp);
70    $grp =~ s/ +/_/g;
71    next;
72  }
73  if (/^(\S+) +(.*)/) {
74    $progs{$1} = $2;
75  }
76}
77close PROGS;
78
79
80# look at all applications alphabetically
81foreach $x (sort (keys %progs)) {
82  if ($x eq $application) {
83	print "Description of this application according to wossname:\n$x '$progs{$x}'\n";
84	$desc = $progs{$x};
85  }
86}
87if (!defined $desc) {die "wossname can't find $application\nExiting.\n";}
88
89
90###################################################################
91# check to see if this application has been committed yet
92###################################################################
93
94# we need to cd to the directory where the application was committed
95chdir "/packages/emboss_dev/$ENV{'USER'}/emboss/emboss/emboss/";
96$result = system "cvs log $application.c  >/dev/null";
97$result /= 256;
98if ($result == 1) {
99	print "WARNING: This program has not yet been committed to CVS.\n";
100	print "This is not a problem because users won't see the web page\nuntil it is added to the index page.\n";
101	print "Continue (y/n) >";
102###	$ans = <STDIN>;
103	$ans = "skip";
104	$ans = lc($ans);
105	if ($ans !~ /^y/) {die "Exiting.\n";}
106}
107
108
109
110###################################################################
111# check to see if there is a web page already
112###################################################################
113if (!-e "$docdir/$application.html") {
114    print "Create a web page for this program? (y/n) ";
115###    $ans = <STDIN>;
116    $ans = "skip";
117    $ans=lc($ans);
118    if ($ans !~ /^y/) {
119	die "Exiting.\n";
120    } else {
121	system("cp $docdir/template.html.save $docdir/$application.html");
122        system "perl -p -i -e 's/ProgramNameToBeReplaced/$application/g;' $docdir/$application.html";
123	chmod 0664, "$docdir/$application.html";
124    }
125}
126system("$editor $docdir/$application.html");
127
128###################################################################
129# make the include files
130###################################################################
131
132# create the new one-line description output
133open(FH, ">$docdir/inc/$application.ione") || die "Can't open file $docdir/inc/$application.ione\n";
134print FH $desc;
135close(FH);
136chmod 0664, "$docdir/inc/$application.ione";
137print "$application.ione *created*\n";
138
139# create the new '-help' output
140system "acdc $application -help -verbose 2> $docdir/inc/$application.ihelp";
141chmod 0664, "$docdir/inc/$application.ihelp";
142print "$application.ihelp *created*\n";
143
144# create the new command table include file
145system "acdtable $application 2> $docdir/inc/$application.itable";
146chmod 0664, "$docdir/inc/$application.itable";
147print "$application.itable *created*\n";
148
149# create the new 'seealso' output
150system "seealso $application -auto -html -post '.html' -out $docdir/inc/$application.isee";
151system "perl -p -i -e 's/SEE ALSO/See also/g;' $docdir/inc/$application.isee";
152chmod 0664, "$docdir/inc/$application.isee";
153print "$application.isee *created*\n";
154
155# create the '.usage', '.input' and '.output' include files
156system "$scripts/makeexample.pl $application";
157
158###################################################################
159# edit the index.html file
160###################################################################
161print "\n\n
162To make the documentation available to the public you will have to
163manually edit the index.html file for the applications directory There
164will be an entry at the end of the index page for you to move into
165position.
166\n\n";
167print "Edit the index web page (y/n) >";
168###$ans = <STDIN>;
169$ans = "skip";
170$ans=lc($ans);
171if ($ans =~ /^y/) {
172
173    open (INDEX, ">> $docdir/index.html") || die "Can't open $docdir/index.html\n";
174    print INDEX "
175
176<tr><td><a href=\"$application.html\">$application</a></td><td>HGMP</td><td>
177$desc
178</td></tr>
179";
180    close (INDEX);
181    system("$editor $docdir/index.html");
182}
183
184###################################################################
185# CVS commit text and html copies in the EMBOSS package
186###################################################################
187
188print "CVS commit text and html copies in the EMBOSS package (y/n) >";
189###$ans = <STDIN>;
190$ans = "skip";
191$ans=lc($ans);
192if ($ans !~ /^y/) {
193    die "Exiting.\n";
194} else {
195
196    chdir $cvsdoc;
197
198# create the new text output
199    if (!-e "text/$application.txt") {
200      system "lynx -dump -nolist $url/$application.html > text/$application.txt";
201      chmod 0664, "text/$application.txt";
202      system "cvs add -m'documentation created' text/$application.txt";
203    } else {
204      system "lynx -dump -nolist $url/$application.html > text/$application.txt";
205      chmod 0664, "text/$application.txt";
206    }
207    system "cvs commit -m'documentation created' text/$application.txt";
208    print "$application.txt *created*\n";
209
210# create the new html output
211    if (!-e "html/$application.html") {
212      system "lynx -source $url/$application.html > html/$application.html";
213      chmod 0664, "html/$application.html";
214      system "cvs add -m'documentation created' html/$application.html";
215    } else {
216      system "lynx -source $url/$application.html > html/$application.html";
217      chmod 0664, "html/$application.html";
218    }
219# change ../emboss_icon.jpg and ../index.html to current directory
220    system "perl -p -i -e 's#\.\.\/index.html#index.html#g;' html/$application.html";
221    system "perl -p -i -e 's#\.\.\/emboss_icon.jpg#emboss_icon.jpg#g;' html/$application.html";
222    system "cvs commit -m'documentation created' html/$application.html";
223    print "$application.html *created*\n";
224}
225
226print "Create make files\n";
227#chdir "/packages/emboss_dev/$ENV{'USER'}/emboss/emboss/scripts";
228system("$scripts/makeMake.pl");        # no parameter == do text
229system("$scripts/makeMake.pl html");
230
231print "Done.\n";
232
233