File: autodoc.pl

package info (click to toggle)
emboss 6.6.0%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 571,544 kB
  • sloc: ansic: 460,579; java: 29,439; perl: 13,573; sh: 12,754; makefile: 3,283; csh: 706; asm: 351; xml: 239; pascal: 237; modula3: 8
file content (1531 lines) | stat: -rwxr-xr-x 41,886 bytes parent folder | download | duplicates (7)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
#!/usr/bin/perl -w

# Makes the apps/index.html web page
# Creates the command lines include files: .ione, .ihelp, .itable
# Warns of missing documentation pages
# Updates the doc/programs/{text,html} files in the CVS tree

###############################################################################
#
# To be done
# ==========
#
# programs/html version to have separate embassy directories
# emboss_doc/master with inc subdirectory for templates (or programs/master)
# emboss_doc/html and emboss_doc/text for the outputs
# to be installed as /emboss/apps and /embassy/*/
# and on sourceforge as /apps/release/N.N/emboss/apps etc. or /apps/cvs/
#
# Use these as the master copy to create the ~/sfdoc versions
#
# need to update included html for emboss and for embassy packages
#
# check emboss.cvs for files that need to be added - do not assume
# the cvs add will be run
#
# Why did domainatrix files get updated as zero length when the tests failed?
#
# Skeleton version for sourceforge apps directory (for Jemboss)
#
# embassy docs - /apps/ redirect (checked)
#     and embassy/*/ main pages (not yet checked?)
#
# plotorf copies plotorf.gif 3 times in 2 tests
#
# need to check new docs are created when new applications appear with
# master docs
#
#
# Changes needed for SourceForge version
# ======================================
# need to be better at identifying and fixing embassy missing documentation
# Need to check for EFUNC and EDATA HTML file updates with main server
#     including the index.html pages
###############################################################################

##################################################################
# 
# Definitions and global variables
# 
##################################################################


my %progdone = ();  # key=program name,
                    # value = set to 1 if documentation exists
my %progdir = ();   # key=program name,
                    # value = EMBASSY name if EMBASSY program

my $embassy;	    # name of current EMBASSY directory being done,
                    # "" if not an EMBASSY program
my $docdir;	    # name of directory holding the set of EMBASSY programs
                    # being done for local distribution

# read in from the EMBOSS application 'wossname'
# group names, application name and which application is in which groups
my %grpnames;	    # hash of key=lowercase group name,
                    # value = uppercase group description
my %progs;	    # hash of key=program name, value = description
my %groups;	    # hash of key=lowercase group name, value = program names
my %embassyprogs;   # hash of embassy package names for each program
my %missingdoc;     # hash of missing program documentation.
                    # Value is the directory it should be in

# where the URL for the html pages is
my $url = "http://emboss.sourceforge.net/apps/cvs";
my $urlembassy = "http://emboss.sourceforge.net/embassy";

# where the original distribution lives
my $distribtop = "./";

# where the installed package lives
my $installtop = "./";

open (VERS, "embossversion -full -auto|") || die "Cannot run embossversion";
while (<VERS>) {
    if(/InstallDirectory: +(\S+)/) {
	$installtop = $1;
	$installtop =~ s/\/$//;
    }
    if(/BaseDirectory: +(\S+)/) {
	$distribtop = $1;
	$distribtop =~ s/\/$//;
    }
}
close VERS;

# where the CVS tree program doc pages are
my $cvsdoc = "$distribtop/doc/programs";
my $cvsedoc = "$distribtop/embassy";

# where the CVS tree scripts are
my $scripts = "$distribtop/scripts";
 
# where the web pages live
my $doctop = "$cvsdoc/master/emboss/apps";
my $sfdoctop = "$ENV{HOME}/sfdoc/apps/cvs";

my @embassylist = ("appendixd",
		   "cbstools",
		   "clustalomega",
		   "domainatrix",
		   "domalign",
		   "domsearch",
		   "emnu",
		   "esim4",
		   "hmmer",
		   "hmmernew",
		   "iprscan",
		   "meme",
		   "memenew",
		   "mira",
		   "mse",
		   "myemboss", # we avoid documenting these examples
		   "myembossdemo", # we avoid documenting these examples
		   "phylip",
		   "phylipnew",
		   "signature",
		   "structure",
		   "topo",
		   "vienna",	# old vienna
		   "vienna2",
		   );

# the directories containing web pages - EMBOSS and EMBASSY
my @doclist = (
	       "$doctop"
	       );

# Filenames for cvs add and commit commands.
# These hold a list of the names of files to be added/committed
# to the text or html documentation directories
# This is done at the end of the script
my $cvsdochtmladd = '';
my $cvsdochtmlcommit = '';
my $cvsdoctextadd = '';
my $cvsdoctextcommit = '';
my $badlynx = 0;
my $badsrc = 0;

######################################################################
######################################################################
# 
# SUBROUTINES
# 
######################################################################
######################################################################

######################################################################
# 
# Name: usage
# 
# Description:
#       Reports command line options
#
######################################################################

sub usage () {
  print STDERR "Usage:\n";
  print STDERR "  autodoc.pl -create -embassy=package [appname]\n";
  print STDERR "\n";
  print STDERR "Default is to produce docuemntation for all applications\n";
  exit();
}
######################################################################
# 
# Name: htmlsource
# 
# Description: 
#	resolves #include directives from template
#       to make a simple html file
# 
# Args: 
# 	$tfile - HTML template filename
# 	$edir  - EMBASSY or emboss application dir for includes
# 
# Warning: 
#	uses temporary filename 'x.x'
# 
######################################################################
sub htmlsource ( $$ ) {
    my($tfile, $edir) = @_;
    @giffiles = ();
    open (X, ">x.x") || die "Cannot open temporary file x.x";

    open (H, "$edir/$tfile") ||
	die "Cannot open HTML template file '$edir/$tfile'";

    while (<H>) {
	if(/^\s*Function\s*$/) {
	    print X "Wiki\n";
	    print X "</H2>\n";
	    print X "\n";
	    print X "The master copies of EMBOSS documentation are available\n";
	    print X "at <a href=\"http://emboss.open-bio.org/wiki/Appdocs\">\n";
	    print X "http://emboss.open-bio.org/wiki/Appdocs</a>\n";
	    print X "on the EMBOSS Wiki.\n";
	    print X "\n";
	    print X "<p>\n";
	    print X "Please help by correcting and extending the Wiki pages.\n";
	    print X "\n";
	    print X "<H2>\n";
	}
	if (/[<][\!][-][-][\#]include file=\"([^\"]+)\" +[-][-][>]/) {
	    $ifile = $1;
	    if(-e "$edir/$ifile") {
		open (I, "$edir/$ifile") ||
		    die "Cannot open include file '$edir/$ifile'";
		while (<I>) {
		    print X;
		    if(/<p><img src=\"([^\"]+)\" alt=\"\[\S+ results\]\">/){
			push @giffiles, $1;
		    }
		}
		close I;
	    }
	    else {
		print STDERR "Cannot open include file '$edir/$ifile'\n";
		print X "[an error has occurred processing this directive]\n";
	    }
	    next;
	}
	elsif (/[<][\!][-][-][\#]include virtual=\"\/apps\/([^\"]+)\" +[-][-][>]/) {
	    $ifile = $1;
	    if(-e "$cvsdoc/master/emboss/apps/$ifile") {
		open (I, "$cvsdoc/master/emboss/apps/$ifile") ||
		    die "Cannot open include file '$cvsdoc/master/emboss/apps/$ifile'";
		while (<I>) {print X}
		close I;
	    }
	    else {
		print STDERR "Cannot open virtual file '$cvsdoc/master/emboss/apps/$ifile'\n";
		print X "[an error has occurred processing this directive]\n";
	    }
	    next;
	}
	else {print X}
    }
    close X;
    close H;
    return 1;
}

######################################################################
# 
# Name: cleantext
# 
# Description: 
#	removes unwanted acdtable output from text documentation
#	makes sure seealso output is reasonably spaced
# 
# Args: 
# 	$afile - first filename
#
# Returns:
# Warning: 
#	uses temporary filename 'z.z'
# 
######################################################################
sub cleantext ( $ ) {
    my $seealso = 0;
    my ($afile) = @_;
    if(-e $afile) {
	open (X, $afile);
	open (Z, ">z.z");
	my $acdtable = 0;
	while (<X>) {
	    if(/^See also$/) {
		    $seealso = 1;
		}
	    if(/^Author[\(s\)]$/) {
		    $seealso = 0;
		}
	    if($acdtable) {
		if(/^Input file format$/) {
		    $acdtable = 0;
		}
		if(/^Output file format$/) {
		    $acdtable = 0;
		}

		if(/^Data files$/) {
		    $acdtable = 0;
		}

	    }
	    else {
		if(/^\s+Qualifier Type Description Allowed values Default/) {
		    $acdtable = 1;
		}
	    }
	    if($seealso) {
		if(/   Program name Description/) {
		    $seealso = 2;
		    s/Program name Description/Program name     Description/;
		}
		else {
		    if(/^(\s+)(\S+) ([A-Z])/) {
			$name = sprintf "%-16s", $2;
			s/^(\s+)(\S+) ([A-Z])/$1$name $3/;
		    }
		    else {
			s/^  /                   /;
		    }
		}
		if(/^$/ && $seealso == 2) {$seealso = 0}
	    }
	
	    if(!$acdtable) { print Z }
	}
    }
    close X;
    close Z;
    open (X, ">$afile");
    open (Z, "z.z");
    while (<Z>) {
	print X;
    }
    close X;
    close Z;

}

######################################################################
# 
# Name: filediff
# 
# Description: 
#	runs diff on two files and returns 1 if they differ
# 
# Args: 
# 	$afile - first filename
# 	$bfile - second filename
#
# Returns:
#       "replaced" file differed and was replaced
#       "created"  file did not exist and was created
#       "same"     files were identical in size and content
# Warning: 
#	uses temporary filename 'z.z'
# 
######################################################################
sub filediff ( $$ ) {
    my ($afile, $bfile) = @_;
 $s = 0;
    my $action = "";

    if(-e $afile) {
	if ((-s $afile) !=  (-s $bfile)) {
	    print LOG "$afile " . (-s $afile) . ", $bfile " . (-s $bfile) . "\n";
	}
	system ("diff -b $afile $bfile > z.z");
	$s = (-s "z.z");
	if ($s) {
	    print LOG "$afile ** differences ** size:$s\n";
	    open (DIF, "z.z") || die "cannot open diff output file";
	    while (<DIF>) { print LOG "> $_";}
	    close DIF;
	    $action = "replaced";
	}
	unlink "z.z";
    }
    else {
	$s = (-s $bfile);
	$action = "created";
	$cvsdochtmladd .= " $afile";
    }

    if($s) {
	system "cp $bfile $afile";
	chmod 0664, "$afile";
	unlink "$bfile";
	print "$afile *$action*\n";
	print LOG "$afile *$action*\n";
	$cvsdochtmlcommit .= " $afile";
    }
    return $s;
}


######################################################################
# 
# Name: header1
# 
# Description: 
#	prints out the first part of the HTML header text (before title)
# 
# Args: 
# 	*OUT - filehandle to print to
# 
# 
######################################################################
sub header1 (*) {
    local (*OUT) = @_;

    print OUT "
<HTML>

<HEAD>
  <TITLE>
  EMBOSS
  </TITLE>
</HEAD>
<BODY BGCOLOR=\"#FFFFFF\" text=\"#000000\">


<!--#include file=\"header1.inc\" -->
";

}


######################################################################
# 
# Name: header2
# 
# Description: 
#	prints out the second part of the HTML header text (after title)
# 
# Args: 
# 	*OUT - filehandle to print to
# 
# 
######################################################################
sub header2 (*) {
    local (*OUT) = @_;

    print OUT "
<!--#include file=\"header2.inc\" -->

<!--END OF HEADER-->




";
}



######################################################################
# 
# Name: footer
# 
# Description: 
#	ends an HTML page
# 
# Args: 
# 	*OUT - filehandle to print to
# 
# 
######################################################################
sub footer (*) {
    local (*OUT) = @_;
    print OUT "

</BODY>
</HTML>
";
}


######################################################################
# 
# Name: indexheader
# 
# Description: 
# 	prints out the header and text at the start of the file
#	containing the table of applications.
#
# Args: 
#	*OUT - filehandle to print to 
# 
# 
######################################################################
sub indexheader (*) {
    local (*OUT) = @_;

    print OUT "
<HTML>

<HEAD>
  <TITLE>
  EMBOSS: The Applications (programs)
  </TITLE>
</HEAD>
<BODY BGCOLOR=\"#FFFFFF\" text=\"#000000\">



<table align=center border=0 cellspacing=0 cellpadding=0>
<tr><td valign=top>
<A HREF=\"http://emboss.sourceforge.net/\" ONMOUSEOVER=\"self.status='Go to the EMBOSS home page';return true\">
<img border=0 src=\"/emboss_icon.jpg\" alt=\"\" width=150 height=48></a>
</td>
<td align=left valign=middle>
<b><font size=\"+6\"> 
The Applications (programs)
</font></b>
</td></tr>
</table>
<br>&nbsp;
<p>




The programs are listed in alphabetical order, Look at the individual
applications or go to the 
<a href=\"groups.html\">GROUPS</a>
page to search by category. 
<p>

<a href=\"../../embassy/index.html\">EMBASSY applications</a>
are described in separate documentation for each package.

<h3><A NAME=\"current\">Applications</A> in the <a
href=\"ftp://emboss.open-bio.org/pub/EMBOSS/\">current release</a></h3>

<table border cellpadding=4 bgcolor=\"#FFFFF0\">

<tr>
<th>Program name</th>
<th>Description</th>
</tr>

";

}

######################################################################
# 
# Name: indexfooter
# 
# Description: 
# 	print out the end of the table for the file
#       containing the table of applications. 
#
# Args: 
# 	*OUT - filehandle to print to
# 
# 
######################################################################
sub indexfooter (*) {
    local (*OUT) = @_;

    print OUT "

</table>




</BODY>
</HTML>
";
}

######################################################################
# 
# Name: getprogramnames
# 
# Description: 
# 	Runs wossname to get the EMBOSS programs on the path
#	together with their groups
#
# Args: 
#   *** These are all global variables ***
# 	%grpnames - hash of key=lowercase group name,
#                        value = uppercase group description
# 	%progs - hash of key=program name, value = program description
#	%groups - hash of key=lowercase group name, value = program names
# 
######################################################################

sub getprogramnames ( ) {

    my $prog;	# program name
    my $capgrp;	# uppcase group name
    my $grp;	# lowercase group name

    open (PROGS, "wossname -noembassy -auto |") ||
	die "Cannot run wossname";
    while ($prog = <PROGS>) {
	if ($prog =~ /^\s*$/) {	# ignore blank lines
	    next;
	} elsif ($prog =~ /^([A-Z0-9 ]+)$/) {	# uppcase means a group name
	    $capgrp = $1;			
	    $grp = lc($capgrp);
	    $grp =~ s/ +/_/g;		# lowercase one-word group_name
	    $grpnames{$grp} = $capgrp;
#      print "Group $grp = $capgrp\n";
	} elsif ($prog =~ /^(\S+) +(.*)/) {
	    $progs{$1} = $2;		
	    $groups{$grp} .= "$1 ";
#      print "Program in $grp = $1\n";
	}
    }
    close PROGS;

    foreach $e(@embassylist) {
	open (PROGS, "wossname -showembassy $e -auto |") ||
	    die "Cannot run wossname";
	while ($prog = <PROGS>) {
	    if ($prog =~ /^\s*$/) {	# ignore blank lines
		next;
	    } elsif ($prog =~ /^([A-Z0-9 ]+)$/) {  # uppcase means a group name
		$capgrp = $1;			
		$grp = lc($capgrp);
		$grp =~ s/ +/_/g;		# lowercase one-word group_name
		$grpnames{$grp} = $capgrp;
#      print "Group $grp = $capgrp\n";
	    } elsif ($prog =~ /^(\S+) +(.*)/) {
		$progs{$1} = $2;		
		$groups{$grp} .= "$1 ";
		$embassyprogs{$1} = $e;
#      print "Program in $grp = $1\n";
	    }
	}
	close PROGS;
    }

}


######################################################################
# 
# Name: createnewdocumentation
# 
# Description: 
# 	Asks if the user wishes to create and edit new documentation
#	for a program.
#	If so, the template file is copied and the user's favorite
#	editor is started.
#
# Args: 
# 	$thisprogram - the name of the program
#	$docdir - the location of the web pages
#	
#
# Returns:
#	1 if the document is created and edited
#	0 if no document is created
# 
######################################################################

sub createnewdocumentation ( $$$ ) {

    my ($thisprogram, $progdocdir, $sfprogdocdir) = @_;
    my $ans;
    my $indexfile = "$progdocdir/index.html";

# application's document is missing
    print LOG "createnewdocumentation missing $progdocdir/$thisprogram.html\n";
    print "\n$progdocdir/$thisprogram.html =missing=\n";
    print STDERR "\n$progdocdir/$thisprogram.html =missing=\n";
    if ($doccreate) {
	print STDERR "Create a web page for this program? (y/n) ";
	$ans = <STDIN>;
    }
    else {
	$ans = "skip";
	print STDERR "Create later - run with create on commandline\n";
    }
    if ($ans =~ /^y/) {
        system("cp $progdocdir/template.html.save $progdocdir/$thisprogram.html");
        system "perl -p -i -e 's/ProgramNameToBeReplaced/$thisprogram/g;' $progdocdir/$thisprogram.html";
	chmod 0664, "$progdocdir/$thisprogram.html";
	if (defined $ENV{'EDITOR'} && $ENV{'EDITOR'} ne "") {
	    print STDERR "Generated $thisprogram.html:
	    Fill in the description section
	    Describe the input and output
	    Add notes, references
";
	    system("$ENV{'EDITOR'} $progdocdir/$thisprogram.html");
	    open (INDEX2, ">> $indexfile") || die "Cannot open $indexfile\n";
	    print INDEX2 "

<tr><td><a href=\"$thisprogram.html\">$thisprogram</a></td><td>
$progs{$thisprogram}
</td></tr>

";
	    close (INDEX2);
	    print STDERR "Edit $progdocdir/index.html:
	    Look for $thisprogram line (at end)
	    Move $thisprogram line to be in alphabetic order
";
	    system("$ENV{'EDITOR'} $progdocdir/index.html");
	}
	else {
	    print "*********************************

YOU DO NOT HAVE AN EDITOR DEFINED
REMEMBER TO EDIT THESE FILES:
 $progdocdir/$thisprogram.html
 $indexfile\n\n\n";
	}
        return 1;
    }
    else {
	$missingdoc{$thisprogram} = $progdocdir;
	return 0;
    }
}

######################################################################
# 
# Name: createnewdocumentationembassy
# 
# Description: 
# 	Asks if the user wishes to create and edit new documentation
#	for an embassy program.
#	If so, the top level redirect is created, and then 
#       the embassy template file is copied and the user's favorite
#	editor is started.
#
# Args: 
# 	$thisprogram - the name of the program
#	$progdocdir - the location of the web pages
#	
#
# Returns:
#	1 if the document is created and edited
#	0 if no document is created
# 
######################################################################

sub createnewdocumentationembassy ( $$$ ) {

    my ($thisprogram, $progdocdir, $sfprogdocdir) = @_;
    my $ans;
    my $indexfile = "$progdocdir/index.html";

# application's document is missing
    print LOG "createnewdocumentationembassy missing $progdocdir/$thisprogram.html\n";
    print "\n$progdocdir/$thisprogram.html =missing=\n";
    print STDERR "\n$progdocdir/$thisprogram.html =missing=\n";
    print STDERR "Create a web page for this program? (y/n) ";
    if ($doccreate) {
	print STDERR "Create a web page for this program? (y/n) ";
	$ans = <STDIN>;
    }
    else {
	$ans = "skip";
	print STDERR "Create later - run with create on commandline\n";
    }
    if ($ans =~ /^y/) {
        system("cp $progdocdir/template.html.save $progdocdir/$thisprogram.html");
        system "perl -p -i -e 's/ProgramNameToBeReplaced/$thisprogram/g;' $progdocdir/$thisprogram.html";
	chmod 0664, "$progdocdir/$thisprogram.html";
	if (defined $ENV{'EDITOR'} && $ENV{'EDITOR'} ne "") {
	    print STDERR "Generated $thisprogram.html:
	    Fill in the description section
	    Describe the input and output
	    Add notes, references
";
	    system("$ENV{'EDITOR'} $progdocdir/$thisprogram.html");
	    open (INDEX2, ">> $indexfile") || die "Cannot open $indexfile\n";
	    print INDEX2 "

<tr>
<td><a href=\"$thisprogram.html\">$thisprogram</a></td>
<td>
$progs{$thisprogram}
</td>
</tr>
";
	    close (INDEX2);
	    print STDERR "Edit $progdocdir/index.html:
	    Look for $thisprogram line (at end)
";
	    system("$ENV{'EDITOR'} $progdocdir/index.html");
	}
	else {
	    print "*********************************

YOU DO NOT HAVE AN EDITOR DEFINED
REMEMBER TO EDIT THESE FILES:
 $progdocdir/$thisprogram.html
 $indexfile\n\n\n";
	}
        return 1;
    }
    else {
	$missingdoc{$thisprogram} = $progdocdir;
	return 0;
    }
}

######################################################################
# 
# Name: checkincludefile
# 
# Description: 
# 	This checks for the existence of one of several types of include file
#	If the file doesn't exist, it is created from the 'x.x' file.
#	If the file exists, a new one is created and checked to see if it
#	is different to the old one, if different, it is updated
#	This assumes that the file 'x.x' has just been set up with the
#	new include file contents.
#
# Args: 
# 	$thisprogram - the name of the program
#	$docdir - the location of the web pages
#	$ext - extension of the include file
# 
# 
######################################################################

sub checkincludefile ( $$$ ) {

    my ($thisprogram, $docdir, $ext) = @_;


# check to see if the include file has changed
    filediff ("$docdir/inc/$thisprogram.$ext", "x.x");
}



######################################################################
# 
# Name: checkhistoryfile
# 
# Description: 
# 	This checks for the existence of a history file.
#       If no file is found, creates a blank file..
#
# Args: 
# 	$thisprogram - the name of the program
#	$docdir - the location of the web pages
# 
# 
######################################################################

sub checkhistoryfile ( $$ ) {

    my ($thisprogram, $docdir) = @_;

    my $histfile = "$docdir/inc/$thisprogram.history";

# check to see if the include file has changed
    if (! -e "$histfile") {
	open (HIST, ">$histfile") || die "Cannot open distribution $histfile";
	print HIST "\n";
	close HIST;
    }
}



######################################################################
# 
# Name: checkcommentfile
# 
# Description: 
# 	This checks for the existence of a coment file.
#       If no file is found, creates a file with the test 'None'..
#
# Args: 
# 	$thisprogram - the name of the program
#	$docdir - the location of the web pages
# 
# 
######################################################################

sub checkcommentfile ( $$ ) {

    my ($thisprogram, $docdir) = @_;

    my $commentfile = "$docdir/inc/$thisprogram.comment";

# check to see if the include file has changed
    if (! -e "$commentfile") {
	open (HIST, ">$commentfile") || die "Cannot open distribution $commentfile";
	print HIST "None\n";
	close HIST;
    }
}



##################################################################
##################################################################
#
# Main routine
#
##################################################################
##################################################################

foreach $x (@embassylist) {
    push @doclist, "$distribtop/embassy/$x";
}

$doccreate = "";

foreach $test (@ARGV) {
    if ($test =~ /^-(.*)/) {
	$opt=$1;
	if ($opt eq "create") {$doccreate = "Y"}
	elsif ($opt =~ /embassy[=](.*)/) {
	    $singlepackage=$1;
	    ###print STDERR "Singlepackage '$singlepackage'\n";
	}
	else {print STDERR "+++ unknown option '$opt'\n";usage()}
    }
    elsif(!defined($singleapp)) {
	$singleapp = $test;
	###print STDERR "Singleapp '$singleapp'\n";
    }
    else {print STDERR "+++ only one application name allowed\n;usage()"}
}

$cvscommit = $doccreate;
@giffiles=();
open(LOGEX, ">makeexample.log") || die "Cannot open makeexample.log";
close (LOGEX);

open(LOG, ">autodoc.log") || die "Cannot open autodoc.log";

# get the program and group names
getprogramnames();

# open the file 'i.i'
# This will be copied to the file 'index.html' at the end of the script
# if all goes well.
# 'index.html' is the file we will be putting in the distribution.
if(!defined($singlepackage) && !defined($singleapp)) {
    open (INDEX, "> i.i") || die "Cannot open i.i\n";
    indexheader(INDEX);
}


# main loop
# look at all directories in our documentation list
foreach $docdir (@doclist) {
    if ($docdir =~ /embassy\/(.*)/) {
	$embassy = $1;
	$sfdocdir = "$sfdoctop/embassy/$embassy/";
	if(defined($singlepackage) && $embassy ne $singlepackage) {next}
	print LOG "embassy $embassy\n";
	$eindex =  "$cvsedoc/$embassy/emboss_doc/master/inc/apps.itable";
	if(!defined($singleapp)) {
	    open (EINDEX, ">e.e") || die "Cannot open 'e.e'";
#	embassyindexheader(EINDEX, $embassy);
	    print EINDEX "<h3><A NAME=\"$embassy\">Applications</A> in the <a
href=\"ftp://emboss.open-bio.org/pub/EMBOSS/\">current $embassy release</a></h3>

<table border cellpadding=4 bgcolor=\"#FFFFF0\">

<tr>
<th>Program name</th>
<th>Description</th>
</tr>

";
	}
    }
    else {			# main EMBOSS applications
	$sfdocdir = "$sfdoctop/emboss/apps/";
	if(defined($singlepackage)) {next}
	$embassy = "";
	$eindex = "";
    }

# look at all applications alphabetically
    foreach $thisprogram (sort (keys %progs)) {
	if(defined($singleapp) && $thisprogram ne $singleapp) {next}
	if ($embassy eq "") {
	    if (defined($embassyprogs{$thisprogram})) {next}
	}
	elsif (!defined($embassyprogs{$thisprogram})) {next}
	else {
	    if ($embassyprogs{$thisprogram} ne $embassy) {next}
	}
	print "\n$thisprogram '$progs{$thisprogram}'\n";
	print LOG "\n$thisprogram '$progs{$thisprogram}'\n";
	
# if this is a non-EMBASSY program then add it to the index.html file
	if (!defined($embassyprogs{$thisprogram})) {
	    $progdocdir = $docdir;
	    $sfprogdocdir = $sfdocdir;
	    if(!defined($singleapp)) {
		print INDEX
"<tr>
<td><a href=\"$thisprogram.html\">$thisprogram</a></td>
<td>
$progs{$thisprogram}
</td>
</tr>\n";
	    }
	}
	else {
# update the embassy index here -
# or just use the %embassyprogs array to make a list?
	    $progdocdir = "$cvsedoc/$embassyprogs{$thisprogram}/emboss_doc/master";
	    $sfprogdocdir = "$sfdoctop/embassy/$embassyprogs{$thisprogram}";
	    if(!defined($singleapp)) {
		print EINDEX
"<tr>
<td><a href=\"$thisprogram.html\">$thisprogram</a></td>
<td>
$progs{$thisprogram}
</td>
</tr>\n";
	    }
	}

# check the documentation for this file exists and is not a symbolic link 
# if this is an EMBASSY document, note which EMBASSY directory it is in
	if (!defined($embassyprogs{$thisprogram})) {
	    if (-e "$cvsdoc/master/emboss/apps/$thisprogram.html") {
###	  print "$progdocdir/$thisprogram.html found\n";
		if (-e "$sfprogdocdir/$thisprogram.html") {
		    system("diff -b $cvsdoc/html/$thisprogram.html $sfprogdocdir/$thisprogram.html > z.z");
		    $s = (-s "z.z");
		    if ($s) {
			print LOG "** $sfprogdocdir/$thisprogram.html differences ** size:$s ($cvsdoc/html/$thisprogram.html)\n";
			print "cp  $cvsdoc/html/$thisprogram.html $sfprogdocdir/$thisprogram.html (differences)\n";
			system "cp  $cvsdoc/html/$thisprogram.html $sfprogdocdir/$thisprogram.html";
			chmod 0664, "$sfprogdocdir/$thisprogram.html";
		    }
		}
		else {
			print LOG "** $sfprogdocdir/$thisprogram.html copied\n";
			system "cp  $cvsdoc/html/$thisprogram.html $sfprogdocdir/$thisprogram.html";
			chmod 0664, "$sfprogdocdir/$thisprogram.html";
		}
	    }
	    else {
# optionally create the documentation and edit it,
#	  or abort and do the next program
###	  print "$progdocdir/$thisprogram.html missing - EMBOSS\n";
		if (!createnewdocumentation($thisprogram, $progdocdir, $sfprogdocdir)) {next;}
	    }
	    $progdone{$thisprogram} = 1;
	}
	else {
	    $progdir{$thisprogram} = $embassyprogs{$thisprogram};
	    $edir = "$cvsedoc/$progdir{$thisprogram}/emboss_doc/html";
	    $sfedir = "$sfdoctop/embassy/$progdir{$thisprogram}";
	    if(-e "$edir/$thisprogram.html") {
###	  print "$edir/$thisprogram.html found\n";
		if (-e "$sfedir/$thisprogram.html") {
		    system("diff -b $edir/$thisprogram.html $sfedir/$thisprogram.html > z.z");
		    $s = (-s "z.z");
		    if ($s) {
			print LOG "** $sfedir/$thisprogram.html differences ** size:$s ($edir/$thisprogram.html)\n";
			print "cp  $edir/$thisprogram.html $sfedir/$thisprogram.html (differences)\n";
			system "cp  $edir/$thisprogram.html $sfedir/$thisprogram.html";
			chmod 0664, "$sfedir/$thisprogram.html";
		    }
		}
		else {
			print LOG "** $edir/$thisprogram.html copied\n";
			system "cp  $edir/$thisprogram.html $sfedir/$thisprogram.html";
			chmod 0664, "$sfedir/$thisprogram.html";
		}
	    }
	    else {
###	  print "$progdocdir/$thisprogram.html missing - EMBASSY $embassyprogs{$thisprogram}\n";
		print STDERR "Missing embassy documentation $edir/$thisprogram.html\n";
		print STDERR "docdir: $docdir\n";
		print STDERR "progdocdir: $progdocdir\n";
		print STDERR "embassyprogs: $embassyprogs{$thisprogram}\n";
		if (!createnewdocumentationembassy($thisprogram, $progdocdir, $sfedir)) {next;}
	    }
	    $progdone{$thisprogram} = 1;
	}

# note whether we now have a documentation file or not
	if (!$progdone{$thisprogram}) {
	    print "++ Missing main docs: $thisprogram ++ \n";
	}

# check on the existence of the one-line description include file
# for this application
	open(FH, ">x.x") || die "Can't open file x.x\n";
	print FH $progs{$thisprogram};
	close(FH);
	checkincludefile($thisprogram, $progdocdir, 'ione');

# check on the existence of the '-help' include file for this application
	system "acdc $thisprogram -help -verbose 2> x.x";
	checkincludefile($thisprogram, $progdocdir, 'ihelp');


# check to see if the command table include file exists
	system "acdtable $thisprogram -verbose 2> x.x";
	checkincludefile($thisprogram, $progdocdir, 'itable');


# check to see if the comment file exists
	checkcommentfile($thisprogram, $progdocdir);

# check to see if the comment file exists
	checkhistoryfile($thisprogram, $progdocdir);


# check on the existence of the 'seealso' include file for this application
# if this is not an EMBASSY program, then we don't want to include EMBASSY
# programs in the SEE ALSO file
	if (!defined($embassyprogs{$thisprogram})) {
	    system "seealso $thisprogram -auto -noembassy -html -out x.x";
	    open (X, "x.x") || die "Cannot open x.x";
	    $text = "";
	    while (<X>) {
		if (/\"([^\/.]+)\.html/) {
		    $app = $1;
		    if (defined($embassyprogs{$app})) {
			$apppack = $embassyprogs{$app};
			s/\"([^\/.]+)\.html/\"..\/..\/embassy\/$apppack\/$app.html/;
		    }
		}
		$text .= $_;
	    }
	    close (X);
	    open (X, ">x.x") || die "Cannot open x.x for output";
	    print X $text;
	    close X;
	}
	else {
	    system "seealso $thisprogram -auto -html -out x.x";
	    open (X, "x.x") || die "Cannot open x.x";
	    $text = "";
	    while (<X>) {
		if (/\"([^\/.]+)\.html/) {
		    $app = $1;
		    if (defined($embassyprogs{$app})) {
			$apppack = $embassyprogs{$app};
			if ($apppack ne $embassyprogs{$thisprogram}) {
			    s/\"([^\/.]+)\.html/\"..\/..\/$apppack\/$app.html/;
			}
		    }
		    else {
			s/\"([^\/.]+)\.html/\"..\/..\/apps\/$app.html/;
		    }
		}
		$text .= $_;
	    }
	    close (X);
	    open (X, ">x.x") || die "Cannot open x.x for output";
	    print X $text;
	    close X;
	}
	system "perl -p -i -e 's/SEE ALSO/See also/g;' x.x";
	checkincludefile($thisprogram, $progdocdir, 'isee');

# create the '.usage', '.input' and '.output' include files
	if ($embassy eq "") {
	    $docurl = $url;
	    $mkstatus = system "$scripts/makeexample.pl $thisprogram";
	    $docmaster = "$cvsdoc/master/emboss/apps";
	    $dochtml   = "$cvsdoc/html";
	    $doctext   = "$cvsdoc/text";
	}
	else {
	    $docurl = "$urlembassy/$embassy";
	    $mkstatus = system "$scripts/makeexample.pl $thisprogram $embassy";
	    $docmaster = "$cvsedoc/$embassy/emboss_doc/master";
	    $dochtml   = "$cvsedoc/$embassy/emboss_doc/html";
	    $doctext   = "$cvsedoc/$embassy/emboss_doc/text";
	}
	if ($mkstatus) {
	    print STDERR "$thisprogram: makeexample.pl status $mkstatus\n";
	}

# check to see if the CVS tree copy of the html documentation needs updating
# check to see if the html file has changed
	$status = htmlsource("$thisprogram.html","$docmaster");
#	    $status = system "lynx -source $docurl/$thisprogram.html > x.x";
	if (!$status) {
	    $badsrc++;
	    print "htmlsource error $status $docmaster/$thisprogram.html";
	}
	else {
	    if($#giffiles >= 0) {
		foreach $gf (@giffiles) {
		    system("cp $docmaster/$gf g.g");
		    filediff("$dochtml/$gf", "g.g");
		    system("cp $docmaster/$gf g.g");
		    filediff("$sfprogdocdir/$gf", "g.g");
		}
	    }
# edit the HTML file
# change ../emboss_icon.jpg and ../index.html to current directory
	    system "perl -p -i -e 's#\.\.\/index.html#index.html#g;' x.x";
	    if ($embassy ne "") {
		system "perl -p -i -e 's#/images/emboss_icon.jpg#emboss_icon.jpg#g;' x.x";
	    }
	    $diff = filediff ("$dochtml/$thisprogram.html", "x.x");
	    if($diff)
	    {
		if (!defined($embassyprogs{$thisprogram})) {
		    if (-e "$cvsdoc/master/emboss/apps/$thisprogram.html") {
###	  print "$progdocdir/$thisprogram.html found\n";
			if (-e "$sfprogdocdir/$thisprogram.html") {
			    system("diff -b $cvsdoc/html/$thisprogram.html $sfprogdocdir/$thisprogram.html > z.z");
			    $s = (-s "z.z");
			    if ($s) {
				print LOG "** $sfprogdocdir/$thisprogram.html differences ** size:$s ($cvsdoc/html/$thisprogram.html)\n";
				print "cp  $cvsdoc/html/$thisprogram.html $sfprogdocdir/$thisprogram.html (differences)\n";
				system "cp  $cvsdoc/html/$thisprogram.html $sfprogdocdir/$thisprogram.html";
				chmod 0664, "$sfprogdocdir/$thisprogram.html";
			    }
			}
			else {
			    print LOG "** $sfprogdocdir/$thisprogram.html copied\n";
			    system "cp  $cvsdoc/html/$thisprogram.html $sfprogdocdir/$thisprogram.html";
			    chmod 0664, "$sfprogdocdir/$thisprogram.html";
			}
		    }
		}
		else {
		    $progdir{$thisprogram} = $embassyprogs{$thisprogram};
		    $edir = "$cvsedoc/$progdir{$thisprogram}/emboss_doc/html";
		    $sfedir = "$sfdoctop/embassy/$progdir{$thisprogram}";
		    if(-e "$edir/$thisprogram.html") {
###	  print "$edir/$thisprogram.html found\n";
			if (-e "$sfedir/$thisprogram.html") {
			    system("diff -b $edir/$thisprogram.html $sfedir/$thisprogram.html > z.z");
			    $s = (-s "z.z");
			    if ($s) {
				print LOG "** $sfedir/$thisprogram.html differences ** size:$s ($edir/$thisprogram.html)\n";
				print "cp  $edir/$thisprogram.html $sfedir/$thisprogram.html (differences)\n";
				system "cp  $edir/$thisprogram.html $sfedir/$thisprogram.html";
				chmod 0664, "$sfedir/$thisprogram.html";
			    }
			}
			else {
			    print LOG "** $edir/$thisprogram.html copied\n";
			    system "cp  $edir/$thisprogram.html $sfedir/$thisprogram.html";
			    chmod 0664, "$sfedir/$thisprogram.html";
			}
		    }
		}
	    }
	}

# check to see if the CVS tree copy of the text documentation needs updating
# check to see if the text has changed
	$status = system "lynx -dump -nolist $dochtml/$thisprogram.html > x.x";
	if ($status) {
	    $badlynx++;
	    print "lynx error $status $dochtml/$thisprogram.html";
	}
	else {
	    cleantext("x.x");
	    filediff ("$doctext/$thisprogram.txt", "x.x");
	}
    }
    if($embassy ne "") {
	if(!defined($singleapp)) {
	    print EINDEX "</table>\n";
	    close EINDEX;
# check to see if the index.html file has changed
	    $diff = filediff ("$eindex", "e.e");

	    $status = htmlsource("index.html", "$docmaster");
	    if (!$status) {
		$badsrc++;
		print "htmlsource error $status $docmaster/index.html";
	    }
	    else {
# change ../emboss_icon.jpg and ../index.html to current directory
		system "perl -p -i -e 's#\.\.\/index.html#index.html#g;' x.x";
		if ($embassy ne "") {
		    system "perl -p -i -e 's#/images/emboss_icon.jpg#emboss_icon.jpg#g;' x.x";
		}
		filediff ("$dochtml/index.html", "x.x");
	    }
	}
    }
}
# main loop over all directories completed.

# end the index.html file
if(defined($singleapp)) {exit()}

if(defined($singlepackage)) {exit()}
indexfooter(INDEX);
close(INDEX);

# check to see if the index.html file has changed
filediff ("$cvsdoc/html/index.html", "i.i");   

# look at all applications and report the ones with missing documentation
foreach $thisprogram (sort (keys %progs)) {
    if ($progdone{$thisprogram}) {next}
    print "$thisprogram.html =missing=\n";
}


#############################
#
# NOW PROCESS THE GROUPS FILE
#
#############################

open (GRPSTD, "$installtop/share/EMBOSS/acd/groups.standard") ||
    die "Cannot open $installtop/share/EMBOSS/acd/groups.standard";
while (<GRPSTD>) {
    if (/^\#/) {next}
    if (/^([^ ]+) (\S+) (.*)/) {
#	$gterm = $1;
	$gname = $2;
	$gdesc = ucfirst(lc($3));
	$gname =~ s/:/ /g;
	$gname =~ s/_/ /g;
	$gname = ucfirst(lc($gname));
	$gname =~ s/[Dd]na/DNA/;
	$gname =~ s/[Rr]na/RNA/;
	$gname =~ s/[Cc]pg/CpG/;
	$gname =~ s/Hmm/HMM/i;
	$gdesc =~ s/[Dd]na/DNA/;
	$gdesc =~ s/[Rr]na/RNA/;
	$gdesc =~ s/[Cc]pg/CpG/;
	$gdesc =~ s/Hmm/HMM/i;
	$grpdef{$gname} = $gdesc;
    }
}
close GRPSTD;

$docdir = "$cvsdoc/master/emboss/apps";
$sfdocdir = "$sfdoctop/apps/cvs";

open ( SUM, ">g.g") || die "cannot open temporary groups summary file";

header1(SUM);
print SUM "Application Groups";
header2(SUM);


print SUM "
<table border cellpadding=4 bgcolor=\"#FFFFF0\">

<tr><th>Group</th><th>Description</th></tr>

";

foreach $g (sort (keys %groups)) {
# change the capitalisation on a few group names - most are lowercase
    $name = $g;
    $name =~ s/_/ /g;
    $name = ucfirst(lc($name));
    $name =~ s/[Dd]na/DNA/;
    $name =~ s/[Rr]na/RNA/;
    $name =~ s/Cpg/CpG/i;
    $name =~ s/Hmm/HMM/i;
    if(!defined($grpdef{$name})){
	print STDERR "Unknown group '$name'\n";
	$grpdef{$name} = $name;
    }
    $desc = $grpdef{$name};

# this group's name is too long for the Makefile 
    $filename = $g;
    $filename =~ s/restriction_enzymes/re/;


    print SUM "<tr>
<td><A HREF=\"$filename\_group.html\">$name</A></td>
<td>$desc</td>
</tr>\n";
# print "$filename '$groups{$g}' '$grpnames{$g}'\n";

    open ( GRP, ">y.y") || die "cannot open temporary group file";

    header1 (GRP);
    print GRP "$grpnames{$g}";
    header2 (GRP);

    print GRP "
$desc
<p>

<table border cellpadding=4 bgcolor=\"#FFFFF0\">

<tr><th>Program name</th><th>Description</th></tr>
";

    foreach $p (split (/\s+/, $groups{$g})) {
#   print "$g : '$p'\n";
	if ($progdir{$p}) {
	    print GRP "
<tr>
<td><a href=\"../embassy/$progdir{$p}/$p.html\">$p</a></td>
<td>
$progs{$p}
</td>
</tr>
";

	}
	else {
	    print GRP "
<tr>
<td><a href=\"$p.html\">$p</a></td>
<td>
$progs{$p}
</td>
</tr>
";
	}
    }

    print GRP "

</table>

";

    footer (GRP);

    close GRP;

    filediff ("$docdir/$filename\_group.html", "y.y");

# check to see if the CVS tree copy of the html program group documentation
# needs updating
    $status = htmlsource("$filename\_group.html","$cvsdoc/master/emboss/apps");
#	$status = system "lynx -source $url/$filename\_group.html > x.x";
    if (!$status) {
	$badsrc++;
	print "htmlsource error $status $url/$filename\_group.html";
    }
    else {
# change ../emboss_icon.jpg and ../index.html to current directory
	system "perl -p -i -e 's#\.\.\/index.html#index.html#g;' x.x";
	if ($embassy ne "") {
	    system "perl -p -i -e 's#\/images/emboss_icon.jpg#emboss_icon.jpg#g;' x.x";
	}
	filediff ("$cvsdoc/html/$filename\_group.html", "x.x");
    }
}

print SUM "

</table>
";

footer(SUM);

close SUM;

filediff("$docdir/groups.html", "g.g");

# check to see if the CVS tree copy of the html group documentation needs updating
$status = htmlsource("groups.html","$cvsdoc/master/emboss/apps");
#    $status = system "lynx -source $url/groups.html > x.x";
if (!$status) {
    $badsrc++;
    print "htmlsource error $status $url/groups.html";
}
else {
# change ../emboss_icon.jpg and ../index.html to current directory
    system "perl -p -i -e 's#\.\.\/index.html#index.html#g;' x.x";
    system "perl -p -i -e 's#\/images/emboss_icon.jpg#emboss_icon.jpg#g;' x.x";
    filediff ("$cvsdoc/html/groups.html", "x.x");
}

######################################################################
# OK - we have updated all our files, now CVS add and CVS commit them 
######################################################################

chdir "$cvsdoc/html";

if ($cvsdochtmladd ne "") {
    print "cvs add -m'documentation added' $cvsdochtmladd\n";
    print STDERR "cvs add -m'documentation added' $cvsdochtmladd\n";
    if ($cvscommit) {
	system "cvs add -m'documentation added' $cvsdochtmladd";
    }
}
if ($cvsdochtmlcommit ne "") {
    print "cvs commit -m'documentation committed' $cvsdochtmlcommit\n";
    print STDERR "cvs commit -m'documentation committed' $cvsdochtmlcommit\n";
    if ($cvscommit) {
	system "cvs commit -m'documentation committed' $cvsdochtmlcommit";
    }
}
else {
    print STDERR "HTML docs unchanged\n";
}

chdir "$cvsdoc/text";

if ($cvsdoctextadd ne "") {
    print "cvs add -m'documentation added' $cvsdoctextadd\n";
    print STDERR "cvs add -m'documentation added' $cvsdoctextadd\n";
    if ($cvscommit) {
	system "cvs add -m'documentation added' $cvsdoctextadd";
    }
}
if ($cvsdoctextcommit ne "") {
    print "cvs commit -m'documentation committed' $cvsdoctextcommit\n";
    print STDERR "cvs commit -m'documentation committed' $cvsdoctextcommit\n";
    if ($cvscommit) {
	system "cvs commit -m'documentation committed' $cvsdoctextcommit";
    }
}
else {
    print STDERR "TEXT docs unchanged\n";
}

# No need to make these makefiles ... now they use wildcards
#print "Create make files\n";
#system("$scripts/makeMake.pl");	       # no parameter == do text
#system("$scripts/makeMake.pl html");   # any parameter == do html

print "\n";
print LOG "\n";
print "==================================\n";
print LOG "==================================\n";
print "Lynx errors: $badlynx\n";
print LOG "Lynx errors: $badlynx\n";
print "HTML source errors: $badsrc\n";
print LOG "HTML source errors: $badsrc\n";
foreach $x (sort(keys(%missingdoc))) {
    print "Missing: $missingdoc{$x}/$x.html\n";
    print LOG "Missing: $missingdoc{$x}/$x.html\n";
}