File: cvs2html

package info (click to toggle)
cvs2html 1.98-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 120 kB
  • ctags: 14
  • sloc: perl: 1,287; makefile: 6
file content (1852 lines) | stat: -rwxr-xr-x 60,868 bytes parent folder | download | duplicates (2)
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
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
#!/usr/bin/perl
#
# Perl program to transform the 'cvs log' output to HTML
#
# Perl program to transform the 'cvs log' output to HTML.
# The HTML output will show the revision log history,
# differences between versions and enable a flexible
# configuration of the amount of information the user
# like to see from the CVS repository.
# cvs2html can be used for any type of cvs archive.

#
# ** Note that the first line might be wrong depending **
# ** on the location of your perl program.             **
# ** The program requires:                             **
# **             perl version 5.003 or newer           **
#
# cvs2html should run on any Unix compatible machine
# with the above programs.
# Test machine: Linux RedHat 7.2 with Perl 5.6.0
#
# Usage :
#
#  type cvs2html with no arguments to display basic help
#  or type cvs2html -h to get more help

# Changelog
# Ver  Date        Who did it            What happened
# -------------------------------------------------------------------------
# 1.98 2007-07-09  Henrik Carlqvist      Times of modification is presented as 
#                                        localtime instead of UTC time.
#                                        Switch which allows skipping of some files 
#                                        handled by cvs.
#                                        Comparison between first revision on branch 
#                                        with originating revision on main trunk. 
#
# 1.97 2004-11-29  Kim Schulz            Misc changes
#
# 1.96 2002-11-09  Lloyd Parkes          Patch for when -l and -R are used 
#                                        at the same time. 
#
# 1.95 2002-07-24  Holger L. Bille       Patch against problem with empty
#                                        log-entries.
#
# 1.94 2002-06-25  Magnus Ahlman	 Added a option argument -R CVS Reposity
#					 specified in the cvsweb.conf
#					 so you can integrate with cvsweb
#
# 1.93 2002-05-25  John Hardin           Patch against freezing problem
#                                        with cvs log would report "nothing
#                                        known about"
#
# 1.92 2002-03-25  Anna Jonna            Typos removed
#                  Armannsdottir       
#
# 1.91 2002-01-13  Jacob Sparre Andersen Major overhaul of the code
#                  and Peter Toft        in order to generate HTML 4.0
#                                        compliant code. Many bugs corrected.
#
# 1.90 2001-09-07  Stefan Kost           A few "cosmetical" corrections.
#
# 1.89 2001-09-06  Stefan Kost           * "back to main" links in chronofile
#                                          only if frames==1
#                                        * subs html_header/html_footer
#                                        * $cvs2html_diff is now called $diffdirname
#                                          (in preparation for more subdirs)
#                                          and defaults to just "diff"
#                                        * sub cvsrootinfo (with extended infos)
#                                        * the ususal cosmetical fixes here and there
#                                        * both halfs of diff output are now
#                                          delimited by a small gap
#                                        * entries in __rf-files are now sorted
#
# 1.88 2001-09-04  Peter Toft            Kim Schulz means that that 
#                                        text in line 748 (previously 744) 
#                                        was adequite. Updated.
#
# 1.87 2001-08-30  Laurent Besson        Bagged two bugs!!
#                  Stefan Kost           * fixed empty output
#                                        * copyright footer looks the same
#                                          for all pages
#                                        * chrono-file back-links go to
#                                          "top" frame
#
# 1.86 2001-08-26  Stefan Kost           Handling of verbosity level update
#
# 1.85 2001-08-24  Stefan Kost           * handles "cvs connection refused"
#                                        * find_alldirs, find_subdirs do not
#                                          follow symlinks
#                                        * new option -V <verbosity level>
#                                        * cleaned up code indentation
#                                        * more comments
#
# 1.84 2001-07-14  Peter Toft            Added links in the cronological file
#                                        to the main page and removed a
#                                        debug-printout statement.
#
# 1.83 2001-06-28  Grzegorz Pawelczak    Patch to handle branches (fix)
#
# 1.82 2001-06-22  Grzegorz Pawelczak    Patch to handle branches
#
# 1.81 2001-06-18  David Carson          Minor update - added support
#                                        for underscore in author-field
#
# 1.80 2001-05-31  Peter V. Pretsch      Fixed the problem with missing
#                                        right frames
#
# 1.79 2000-12-27  Peter Toft            Peter made error in the Changelog :-)
#
# 1.78 2000-12-27  Peter Toft            Error in making diff-directories
#                                        corrected. Example included in help-
#                                        description.
#                                        Changed mkdir to perl-command.
#
# 1.77 2000-12-15  Peter Toft            Hack to avoid generating the
#                                        same diff-files over and over again.
#                                        Renaming of the diff-files.
#                                        Dumping the diff-files in a
#                                        separate subdir.
#
# 1.76 2000-11-30  Jody Lewis            Typo; The parent links in the
#                                        lower left frame were incorrect
#
# 1.75 2000-11-04  Kirby Vandivort       URL of cvs2html changed
#
# 1.73 2000-11-02  Peter Toft            Clean up - deleted an old status line
#
# 1.72 2000-10-28  Peter Toft            If basename() or dirname() adds
#                                        a \n code, then cvs2html malfunctions
#                                        This should solve the problem.
#
# 1.71 2000-10-26  Peter Toft            Minor clean-up
#
# 1.70 2000-10-26  Jon Berndt            Documentation problem -L option
#                  Peter Toft            -L/-E option was not working
#                                        Redefined -L and dumped the -E option
#
# 1.69 2000-09-29  Robert Merkle         Support for users with 0-9
#                                        in name
#
# 1.68 2000-09-20  Wolfgang Bangerth     Patch to avoid HTML syntax
#                                        problems and link error.
#
# 1.67 2000-08-21  Kirby Vandivort       Update to cvs2html to fix html
#                                        markup display in cvs comments
#
# 1.66 2000-08-11  Kirby Vandivort       Added support for an
#                                        parameter -P controlled location
#                                        of cvs
#
# 1.65 2000-06-24  Peter Toft            Added support for filenames
#                                        containing whitespaces -
#                                        requested by John Stone
#
# 1.64 2000-06-11  Peter Toft            Better documentation in the start
#                                        of the program
#
# ---- ----------  --------------------  -------------------------------
#
# This program is protected by the GPL, and all modifications of
# general interest can be emailed to Peter Toft <pto@sslug.dk>
#
# The GPL can be found at http://www.gnu.org/copyleft/gpl.html
#
# Other people that have contributed directly or indirectly to cvs2html
#  Holger L. Bille <hlb@vitesse.com>
#  Henner Zeller <zeller@think.de>
#  Henning Niss <hniss@diku.dk>
#  Henrik Carlquist <Henrik.Carlqvist@dynamics.saab.se>
#  Tim Bradshaw <tfb@cley.com>
#  David Miller
#  Parkes, Lloyd <lloyd.parkes@eds.com>
#  David Carson <DCarson@extremenetworks.com>
#  Finn Aarup Nielsen <fn@imm.dtu.dk>
#  Michael Krause <mkrause@teuto.net>
#  Jim Phillips <jim@ks.uiuc.edu>
#  Jon S. Berndt <jsb@hal-pc.org>
#  Edward S. Marshall <emarshal@logic.net>
#  Curtis L. Olson <curt@me.umn.edu>
#  Aubrey Jaffer <jaffer@colorage.com>
#  Mark Cooke <mpc@star.sr.bham.ac.uk>
#  Carlo Wood <carlo@runaway.xs4all.nl>
#  Kirby Vandivort <kvandivo@ks.uiuc.edu>
#  Dag Br�ck <dag@Dynasim.se>
#  Wolfgang Bangerth <wolfgang.bangerth@iwr.uni-heidelberg.de>
#  Robert Merkle <r.merkle@siep.shell.com>
#  Jody Lewis <jody.lewis@philips.com>
#  Peter V. Pretsch <pvp@pe.dk>
#  Grzegorz Pawelczak <gpawel@adlex.com>
#  Stefan Kost <st_kost@gmx.de>
#  Anna Jonna Armannsdottir <a@sleepy.dk>
#  John Hardin <johnh@aproposretail.com>
#  Magnus Ahlman <magnus.ahlman@eds.com>

#
# Copyright under GPL 1997 - 2002 by
# Peter Toft (pto@sslug.dk) + the persons above
#
# Join the cvs2html mailing list <sslug-cvs2html@sslug.dk>
# by sending an email to <sslug-cvs2html-subscribe@sslug.dk>,
# the contents of this mails is of no matter.
# You will receive an email than you need to reply to.
#
# If you want to unsubscribe from the list - write a mail to
# <sslug-cvs2html-unsubscribe@sslug.dk>, and reply to the mail you get.
# In case of problems contact <pto@sslug.dk>
#
# The URL of cvs2html is:

$URL = "http://cvs.sslug.dk/cvs2html";

$cvs2html_version='$Id: cvs2html,v 1.98 2007/07/08 22:21:44 pto Exp $';

require 'getopts.pl';
require 'ctime.pl';

use File::Basename;
use File::Find;

if($cvs2html_version =~ /^\$Id\: (\w+?),v (\d+?\.\d+?) /i) {
  $version=$2;
}
else {
  $version="?.?";
}

# get options from cfgfile

# now get the options. The ones with a colon means the an extra argument follows.
# all options given will override the ones specified in cfgfile
&Getopts('R:r:abc:C:d:efhkl:n:N:s:vo:D:E:L:O:w:i:pP:V:x:');

###############################################################
# graphic related default variables that you can change
###############################################################

# Default width of the left frame in pixels. Also changed by -w option
$leftframewidth = 150;

# Default splitratio of the left frame in percent. Also changed by -s option
$leftsplitratio = "70%";

# Default cell color
$cellcolor = "#c7c7c7";

# Default filename cell color
$filenamecellcolor = "#7777FF";

# Default background color gray
$backcolor = "#AAAAAA";

# Default background for the difference cells
$differencebackground = "#BBBBBB";

# Colors and font to show the diff type of code changes when using -a
$diffcolorHeading    ='#999999';     # color of 'Line'-heading of each diffed file
$diffcolorEmpty      ='#999999';     # color of 'empty' lines
$diffcolorNormal     ='#BBBBBB';     # color of 'unchanged' ('equal') lines
$diffcolorRemove     ='#FF9999';     # Removed line(s) (left)  (empty)
$diffcolorChange     ='#99FF99';     # Added line(s)   (empty) (right)
$diffcolorDarkChange ='#77AA77';     # lines, which are empty on the left/right
$diffcolorAdd        ='#AAAAFF';     # Changed line(s) (     both    )
# just uncomment if you don't want any font-changes
#$difffontface        ="Arial,Helvetica";
$difffontface        ="Courier,Courier New";
$difffontsize        ="-1";

###############################################################
# other default variables that you can change
###############################################################

# Set $kkon ="-kk" if you permanently want to hide keyword substitutions
# when making diff-files.
$kkon = "";

# Set $whitespace = "-w" if you want to ignore white space changes
# in diff
$whitespace="-w";

# The timedifference in seconds which we consider as the same
# commit time
$commit_smalltimedifference = 10;

# default CVS location (default assumes in path)
$cvsLocation="cvs";

# warnings if omitting generating of diff-files
$diffwarning = 0;

# sub dir name for diff-files
$diffdirname = "diff";

###############################################################
# Subfunctions
###############################################################

#html helper
sub html_footer {
  my ($stradd)=@_;

  if(!defined($stradd)){ $stradd=""; }
  (undef,$min,$hour,$mday,$mon,$year,undef,undef,undef) = localtime(time);
  $struser=getlogin;
  $strdate=sprintf "%4d-%02d-%02d %2d:%02d",$year+1900, $mon+1, $mday,$hour,$min;

  $ret="<hr>\n";
  $ret.="<center><font size=\"-1\">\n";
  $ret.="File made using version $version of ";
  $ret.="<a href=\"$URL\" target=\"_new\">cvs2html</a> by ";
  $ret.="$struser at $strdate  $revisionlimitertext $stradd";
  $ret.="</font></center>\n";
  return($ret);
}

sub html_header {
  my ($title)=@_;

  $ret="<\!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n
<html>\n<head>\n<title>";
  if(defined($title) && length($title)>0) {
	$ret.="$title";
  }
  else {
	$ret.="cvs2html";
  }
  $ret.="</title>\n</head>\n";
  if ($opt_i) {
	$ret.="<body background=\"$opt_i\">\n";
  } else {
	$ret.="<body bgcolor=\"$backcolor\">\n";
  }
  if(defined($title) && length($title)>0) {
	$ret.="<h2 align=\"center\">$title</h2>\n<hr>\n";
  }
  return($ret);
}

sub cvsrootinfo {
  # the two tables are needed for proper layout
  $ret="<table border=\"0\" cellpadding=\"1\" cellspacing=\"1\" align=\"center\" bgcolor=\"$cellcolor\" width=\"100%\">\n";
  $ret.="<tr>\n";
  $ret.="<td width=\"15%\" align=\"right\"><b>Protocol:</b></td><td width=\"35%\">$protocol</td>\n";
  $ret.="<td width=\"15%\" align=\"right\"><b>    User:</b></td><td width=\"35%\">$cvsuser</td>\n";
  $ret.="</tr>\n<tr>\n";
  $ret.="<td width=\"15%\" align=\"right\"><b> Machine:</b></td><td width=\"35%\">$machine</td>\n";
  $ret.="<td width=\"15%\" align=\"right\"><b> CVSROOT:</b></td><td width=\"35%\">$cvsroot</td>\n";
  $ret.="</tr>\n";
  $ret.="</table><hr>\n";
  return($ret);
}

#function to help sort
sub sorter{
  $chronotimesince0[$a] <=> $chronotimesince0[$b];
}

#Function to close the main file
sub closemainfile {
  # Print date & copyright info in the last part of the HTML document
  $stradd="";
  if ($cutdate>"00000000") {
    $stradd.=" leaving out any log message prior to $cutyearformat2";
  }
  if (($opt_n>0) && ($opt_a)) {
    $stradd.=" and only showing the $opt_n latest version differences";
  }
  print OUTFILE html_footer($stradd);

  # Lets wrap up OUTFILE
  print OUTFILE "</body>\n";
  print OUTFILE "</html>\n";

  close(OUTFILE);
}

# Function to show how the function is used. Called if no options are given.
sub shorthelp {
  print "*** CVS2HTML ***\nA Perl program to transform the 'cvs log' output to HTML.\n";

  print "Usage of cvs2html\n\n";
  print "cvs2html [-a [-b][-k]] [-n NUMDIF] [-l/-L FTPHOME]\n";
  print "         [-e] [-f] [-d \"MMM DD [YYYY]\"] [-D DD] [-i IMAGE] [-h]\n";
  print "         [-v] [-w FRAMEWIDTH] [-s PERCENTAGE] [-N MAXCHRONO]\n";
  print "         [-rREV1:REV2] [-c/-C CFILENAME] -O/o HTMLNAME\n";
  print "         [-P CVSPATH] [-V VERBOSITY] [-x SKIPFILENAME]\n";
  print "         [-R CVSWEB ROOT]";

  print "\n\nTry: cvs2html -help\n";
}

sub showhelp {
  print "\n";

  print " cvs2html -O foo\n";
  print " outputs html files foo.html and alike for each subdirectory\n";
  print " Note that if foo is a directory the files are stored there\n";
  print " using the name of the repository as the base filename.\n";
  print "\n";

  print " cvs2html -O foo -v\n";
  print " which outputs a html file to the file foo.html including\n";
  print " information about the CVSROOT setting.\n";
  print "\n";

  print " Using -o instead of -O, frames will be made for easy control.\n";
  print "\n";

  print " If -e is specified the log messages are printed\n";
  print " in courier (non-proportional) font.\n";
  print "\n";

  print " If -c CFILENAME is specified a chronological sorted list of all log\n";
  print " entries will be saved in CFILENAME (CFILENAME is a full html filename)\n";
  print " Use -C CFILENAME instead of -c to do reverse sort of the log file.\n";
  print " Add -p to include cvs log information into the CFILENAME.\n\n";

  print " If -a is specified additional fields and files are generated\n";
  print " containing differences betweeen versions\n";
  print " in a xdiff-like side by side manner.\n";
  print " The -n NUMDIF will only output the lastest NUMDIF diff files.\n";
  print " The -N MAXCHRONO will only show the last MAXCHRONO file changes\n";
  print " in the chronological list of changes.\n";
  print "\n";

  print " if -b is specified in addition to diff-mode\n";
  print " spcaces are used as breakpoint to wrap the text\n";
  print " so the two columns don't exceed the total width\n";
  print " If -k is specified in addition to diff-mode\n";
  print " changes in lines caused by CVS-keyword substition\n";
  print " are ignored.\n";

  print " If an option -l ftphome is given links to the files relative\n";
  print " to the URL ftphome is made. Use -L ftphtmlhome to do the same as\n";
  print " -l, but substitutes file extension with .html\n";
  print "\n";

  print " If an option -d \"month day year\" is given (year optional) any\n";
  print " log message prior to that date is omitted. The three first \n";
  print " letters of the name of the month is used, e.g., Jun 5.\n";
  print " A -D DD option will drop any log DD days ago or earlier\n";
  print "\n";

  print " If an option -rREVISIONTAG1:REVISIONTAG2 is given, then\n";
  print " the log messages are only shown between those revision\n";
  print " REVISIONTAG1 and REVISIONTAG2. If a file was not tagged\n";
  print " then the whole revision story of the file will be shown.\n";
  print "\n";

  print " If -o and -w FRAMEWIDTH is used the left frame will have\n";
  print " FRAMEWIDTH pixels. Add -f when using the -o option to \n";
  print " generate individual log files for each file.\n";
  print " Use -s PERCENTAGE to set width of the fraction of the left\n";
  print " bar in percentage.\n";
  print "\n";

  print " Use -i IMAGE to replace the background with file specified as IMAGE\n";
  print "\n";

  print " Use -P CVSPATH to specify an explicit location cvs.  The\n";
  print " default value is simply 'cvs', which means that cvs is in your\n";
  print " path.\n";
  print "\n";

  print " Use -V VERBOSITY to make cvs2html report what it is doing. A\n";
  print " value of 0 means be quiet and bigger numbers means more output.\n";
  print " This is especially useful, when something went wrong.\n";
  print "\n";

  print " Use -R CVSWEBROOT to make reports intergrated with cvsweb.\n";
  print " The argument should be the symbolic_name in cvsweb.conf.\n";
  print "\n";

  print " Use -x SKIPFILENAME to to exclude all information about files\n";
  print " with that name.\n";
  print "\n";

  print " The html file also contains anchors, if a file foo.html\n";
  print " containing a file e.g., foofoo.m is generated then it is\n";
  print " possible to search http://CORRECT_URL/foo.html#foofoo.m\n";
  print "\n";

  print " Example :\n";
  print " cvs2html  -l http://cvs.sslug.dk/linuxbog -f -p \\\\ \n";
  print "   -o cvs2html/index.html -v -a -b -n 6 -C crono.html\n";
  print " makes cvs2html/ with individual log data for each file \n";
  print " with links relative to \"http://cvs.sslug.dk/linuxbog\"\n";
  print " and creates a chronological log file \"crono.html\".\n";
  print "\n";

  print " cvs2html with no arguments displays this help\n";
  print " Peter Toft et al, Technical University of Denmark, 1997\n";
  exit(0);
}

# This function will set the date after which the log info is shown.
# Any log info before the date is NOT shown.
sub date_control {
  %months= (
            'Jan','01',
            'Feb','02',
            'Mar','03',
            'Apr','04',
            'May','05',
            'Jun','06',
            'Jul','07',
            'Aug','08',
            'Sep','09',
            'Oct','10',
            'Nov','11',
            'Dec','12',
            );


  &ctime(time) =~/^(\w+) (\w+) (\d+) (\d+):(\d+):(\d+) (\d+)$/;

  $currentyear=$7;

  if (($opt_d)||($opt_D)) {
    if ($opt_d) {
      ($cutmonthtxt,$cutdatetxt,$cutyeartxt)= $opt_d =~ /^(\w+) (\d+) (\d+)$/;
    }
    if ($opt_D) {
      $cd = localtime(time-3600*24*$opt_D);
      $cd =~ /^(\w+) (\w+)[ ]*(\d+)[ ]*(\d+):(\d+):(\d+) (\d+)$/;
      $cutyeartxt = $7;
      $cutmonthtxt = $2;
      $cutdatetxt = $3;
    }

    if (length($cutyeartxt)==0) {
      ($cutmonthtxt,$cutdatetxt)= $opt_d =~ /^(\w+) (\d+)$/;
      $cutyeartxt=$currentyear;
    }
    $cutyearformat2="$cutmonthtxt $cutdatetxt $cutyeartxt";
	
    if (length($cutdatetxt)==1) {
      $cutdatetxt="0".$cutdatetxt;
    }
    $m=$months{$cutmonthtxt};
    if (length($m)==0) {
      print "The option -d \"month day [year]\" was used with a wrong month ($cutmonthtxt).\n";
      print "First three letters is used\n";
      exit(0);
    }
    $cutdate = $cutyeartxt.$m.$cutdatetxt;
  }
  else {
    $cutdate = "00000000";
  }
  # Anything before year 0000 - I dont think so...........
}

# Function to read the next line from cvslogarray
sub getnextline {
  $lineno++;
  if($lineno<=scalar(@cvslogarray)) {
	# DEBUG
	#print STDOUT "    cvslogarray[$lineno]=$cvslogarray[$lineno]";
	# DEBUG
	return($cvslogarray[$lineno]);
  }
  else {
	return(undef);
  }
}

sub flush_diff_rows ($$$$) {
    local $j;
    my ($leftColRef,$rightColRef,$leftRow,$rightRow) = @_;
    if ($state eq "PreChangeRemove") {          # we just got remove-lines before
      for ($j = 0 ; $j < $leftRow; $j++) {
          print DIFFFILE "<tr><td bgcolor=\"$diffcolorRemove\">@$leftColRef[$j]</td>";
		  print DIFFFILE "<td bgcolor=\"$backcolor\">&nbsp;</td>";
          print DIFFFILE "<td bgcolor=\"$diffcolorEmpty\">&nbsp;</td></tr>\n";
      }
    }
    elsif ($state eq "PreChange") {             # state eq "PreChange"
      # we got removes with subsequent adds
      for ($j = 0; $j < $leftRow || $j < $rightRow ; $j++) {  # dump out both cols
          print DIFFFILE "<tr>";
          if ($j < $leftRow) { print DIFFFILE "<td bgcolor=\"$diffcolorChange\">@$leftColRef[$j]</td>"; }
          else { print DIFFFILE "<td bgcolor=\"$diffcolorDarkChange\">&nbsp;</td>"; }
		  print DIFFFILE "<td bgcolor=\"$backcolor\">&nbsp;</td>";
          if ($j < $rightRow) { print DIFFFILE "<td bgcolor=\"$diffcolorChange\">@$rightColRef[$j]</td>"; }
          else { print DIFFFILE "<td bgcolor=\"$diffcolorDarkChange\">&nbsp;</td>"; }
          print DIFFFILE "</tr>\n";
      }
    }
}
# Function to generate diff-files
sub generate_diff_file {
  local ( $ii,$difftxt,@diffar );
  $diffname = $outdirname.'/'.$diffdirname.'/'."diff$convdir\_$filename\_$oldrevnumber\_$revnumber.html";

  stat($diffname);
  if (-e _) {
    if ($diffwarning == 1) {
      print "WARNING; cvs2html does not generate $diffname\n";
    }
  }
  else {
    @listhtmlnames = (@listhtmlnames,$diffname);
    open(DIFFFILE,">$diffname") or die "Error: Could not open ; $diffname";
    print DIFFFILE html_header("Difference for $currentdir/$filename from version $revnumber to $oldrevnumber");
    if ($opt_k) {
      $kkon = "-kk";
    }
    @diffar = `$cvsLocation diff $kkon $whitespace -u -r $revnumber -r $oldrevnumber \"$currentdir/$filename\"\n`;

    print DIFFFILE "<table border=0 cellspacing=0 cellpadding=0 width=\"100%\">\n";
    print DIFFFILE "<tr bgcolor=\"#ffffff\"><th width=\"50%\">version $revnumber</th><th bgcolor=\"$backcolor\">&nbsp;</th><th width=\"50%\">version $oldrevnumber</th></tr>";

	$fs="<font";
	if(defined($difffontface) && length($difffontface)>0) {
	  $fs.=" face=\"$difffontface\"";
	}
	if(defined($difffontsize) && length($difffontsize)>0) {
	  $fs.=" size=\"$difffontsize\"";
	}
	$fs.=">";
    $fe="</font>";

    $leftRow = 0;
    $rightRow = 0;

    # the first 8 lines are garbage for us
    for ($ii=8;$ii<=$#diffar;$ii++) {
      chop($difftxt = $diffar[$ii]);
      if ($difftxt =~ /^@@/) {
        ($oldline,$newline) = $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@/;
        print DIFFFILE "<tr bgcolor=\"$diffcolorHeading\"><td width=\"50%\">";
        print DIFFFILE "<table width=\"100%\" border=0 cellpadding=5><tr><td><b>Line $oldline</b></td></tr></table>";
        print DIFFFILE "</td><td bgcolor=\"$backcolor\">&nbsp;</td><td width=\"50%\">";
        print DIFFFILE "<table width=\"100%\" border=0 cellpadding=5><tr><td><b>Line $newline</b></td></tr></table>";
        print DIFFFILE "</td></tr>\n";
        $state = "dump";
        $leftRow = 0;
        $rightRow = 0;
      }
      else {
        ($diffcode,$rest) = $difftxt =~ /^([-+ ])(.*)/;
        $_= $rest;
########
# quote special characters
# according to RFC 1866,Hypertext Markup Language 2.0,
# 9.7.1. Numeric and Special Graphic Entity Set
# (Hen)
#######
		s/&/&amp;/g;
		s/\"/&quot;/g;
		s/</&lt;/g;
		s/>/&gt;/g;

		# replace <tab> and <space>
		if ($opt_b) {
		  # make every other space 'breakable'
		  s/        /&nbsp; &nbsp; &nbsp; &nbsp; /g;    # <tab>
		  s/   /&nbsp; &nbsp;/g;                        # 3 * <space>
		  s/  /&nbsp; /g;                               # 2 * <space>
		  # leave single space as it is
		}
		else {
		  s/        /&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/g;
		  s/ /&nbsp;/g;
		}

		# Add fontface, size
		$_ = "$fs&nbsp;$_$fe";

		#########
		# little state machine to parse unified-diff output (Hen, zeller@think.de)
		# in order to get some nice 'ediff'-mode output
		# states:
		#  "dump"             - just dump the value
		#  "PreChangeRemove"  - we began with '-' .. so this could be the start of a 'change' area or just remove
		#  "PreChange"        - okey, we got several '-' lines and moved to '+' lines -> this is a change block
		##########

		if ($diffcode eq '+') {
		  if ($state eq "dump") {  # 'change' never begins with '+': just dump out value
			print DIFFFILE "<tr><td bgcolor=\"$diffcolorEmpty\">&nbsp;</td><td bgcolor=\"$backcolor\">&nbsp;</td><td bgcolor=\"$diffcolorAdd\">$_</td></tr>\n";
		  }
		  else {                   # we got minus before
			$state = "PreChange";
			$rightCol[$rightRow++] = $_;
		  }
		}
		elsif ($diffcode eq '-') {
		  $state = "PreChangeRemove";
		  $leftCol[$leftRow++] = $_;
		}
        else {  # empty diffcode
		  flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
		  print DIFFFILE "<tr><td bgcolor=\"$diffcolorNormal\">$_</td><td bgcolor=\"$backcolor\">&nbsp;</td><td bgcolor=\"$diffcolorNormal\">$_</td></tr>\n";
		  $state = "dump";
		  $leftRow = 0;
		  $rightRow = 0;
		}
      }
    }
    flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
    print DIFFFILE "</table>";

    # print legend
    print DIFFFILE "<br><hr><table border=0><tr><td>";
    print DIFFFILE "Legend:<br><table border=0 cellspacing=0 cellpadding=1>\n";
    print DIFFFILE "<tr><td align=center bgcolor=\"$diffcolorRemove\">$fs"."line(s) removed in v.$revnumber"."$fe</td><td bgcolor=\"$diffcolorEmpty\">$fs"."&nbsp;"."$fe</td></tr>";
    print DIFFFILE "<tr bgcolor=\"$diffcolorChange\"><td align=center colspan=2>$fs"."line(s) changed"."$fe</td></tr>";
    print DIFFFILE "<tr><td bgcolor=\"$diffcolorEmpty\">$fs"."&nbsp;"."$fe</td><td align=center bgcolor=\"$diffcolorAdd\">$fs"."line(s) added in v.$oldrevnumber"."$fe</td></tr>";
    print DIFFFILE "</table></td></tr></table>\n";

    print DIFFFILE html_footer("");
    print DIFFFILE "</body>\n</html>\n";
    close(DIFFFILE);
  }
}

sub find_alldirs {
  my @dirs = ();
  find(
       sub {
         if (-d && ! -l && ! /CVS$/) {
           if ($File::Find::dir eq "." && $_ eq ".") {
             push @dirs, "./";
           }
           else {
             push @dirs, "$File::Find::dir/$_";
           }
         }
       }, '.'
	  );

  @dirs = map { $_ . "\n" } @dirs;

  return @dirs;
}

sub find_subdirs {
  my $currentdir = shift;

  my @dirs = ();
  finddepth(
            sub {
              if (-d && ! -l && ! /CVS$/ && $File::Find::dir eq $currentdir) {
                if ( ! ($File::Find::dir eq $currentdir && $_ eq ".") ) {
                  push @dirs, "$File::Find::dir/$_";
                }
              }
            }, $currentdir
		   );

  @dirs = map { $_ . "\n" } @dirs;

  return @dirs;
}

sub kill_log_header {
  @llcvslog = ();
  $headerstill = -1;
  foreach $ii (0 .. ($#lcvslog-1)) {
    if ($headerstill == 0) {
      @llcvslog = (@llcvslog,$lcvslog[$ii]);
    }
    else {
      $headerstill = $headerstill - 1;
      if ($lcvslog[$ii] =~ '----------------------------') {
		$headerstill = 2;
      }
    }
  }
}

#############################################################
# Lets set up the basics
#############################################################

# Always enforce restrictions on dates. If no date is given
# a very early one is used.
date_control;

# Set the width of the left frame.
# Default value has been set above.
if ($opt_w) {
  $leftframewidth = $opt_w;
}

# Set the splitratio of the left frame.
# Default value has been set above.
if ($opt_s) {
  $leftsplitratio = $opt_s;
}

# I want help!
if ($opt_h) {
  shorthelp;
  showhelp;
  exit(0);
}

# The user must give a filename for the HTML-file(s)
if ((!(($opt_O) || ($opt_o))) || (($opt_O) && ($opt_o))) {
  shorthelp;
  print "\nMade by Peter Toft (pto\@sslug.dk).\ncvs2html is protected by the GPL.\n";
  exit(0);
}

$dochrono="";
if($opt_c) {
  $dochrono=$opt_c;
}
if($opt_C) {
  $dochrono=$opt_C;
}


# Is -c followed by a "valid" filename ?
if (length($dochrono)>5) {
  $chronooutname = $dochrono;
}
else {
  $chronooutname = "cvs2html_chrono_log.html";
}

# Want to write to a file with frames?
if ($opt_o) {
  $frames = 1;
  $outname = $opt_o;
}

# Do you want to limit to certain revisions
$revisionlimiter="";
$revisionlimitertext="";
$starttag="";
if ($opt_r) {
  $revisionlimiter = "-r".$opt_r;
  $revisionlimitertext=" and only showing data between revisions $opt_r";
  if ($opt_r =~ /^(\S*):(\S*)/) {
    $starttag=$1;
    $endtag=$2;
  }
  $revisionlimiter_end = "-r:".$endtag;
  $revisionlimiter_startonly = "-r".$starttag;
}

# Want to write to a file without frames?
if ($opt_O) {
  $frames = 0;
  $outname = $opt_O;
}

$linkrel = "";
# Want to link to external file
if ($opt_l) {
  $linkrel = $opt_l;
}

# Explicit path to cvs
if ($opt_P) {
  $cvsLocation = $opt_P;
}

# Files which should not be presented
if ($opt_x) {
  $skipfile=$opt_x;
}

# Get the environment variable CVSROOT for this CVS repository
open(INFILE,"<./CVS/Root") or die "Error: The file ./CVS/Root is missing  - this directory does not seem to be under CVS-control.";
($fullcvsroot) = <INFILE> =~/^(.*)$/;
close INFILE;

# Split CVSROOT in machine and dir if possible.
@spl = split(':',$fullcvsroot);
if ($#spl == 3) {
# @spl[0] is empty because client/server root starts with ':' -> ":pserver" or ":ext"
    $protocol =$spl[1]; # client/server
    ($cvsuser,$machine) = split('@',$spl[2]);
    $cvsroot = $spl[3];
}
elsif ($#spl == 1) {
    $protocol = "rsh/ssh";
    ($cvsuser,$machine) = split('@',$spl[0]);
    $cvsroot = $spl[1];
}
else {
    $protocol = "local";
    $cvsuser = "";
    $machine =  "localhost";
    $cvsroot = $spl[0];
}

# Get the name of the repository
open(INFILE,"<./CVS/Repository")  or die "Error: The file ./CVS/Repository is missing.";

#($rootdir) = <INFILE> =~/^\Q$fullcvsroot\E(.*)$/;
($rootdir) = <INFILE>;
$rootdir = basename($rootdir);
($rootdir) = $rootdir =~ /^(.*)$/;

close INFILE;

# Strip a .html from the outname if any (pasted on later)
($outnamem) = $outname =~ /^(.*)\.html$/;
if (length($outnamem)>0) {
  $outname = $outnamem;
}

# If an outputname is a directory a file named after the repository
# is generated (and others if using frames).
if (-d $outname) {
  $outname = $outname."/".$rootdir;
}

# Split the outname from a possible directory full path
$outfilename = basename($outname);
$outdirname = dirname($outname);

($outfilename) = $outfilename =~ /^(.*)$/;
($outdirname) = $outdirname =~ /^(.*)$/;
$fulldiffdirname = $outdirname."/".$diffdirname;

mkdir($outdirname,0775);
mkdir($fulldiffdirname,0775);

if(defined($opt_V) && $opt_V>0) { print STDOUT "Processing \#1 $currentdir\n"; }

# Get all dirs to search
@entirealldirs = find_alldirs();

# Only pass along subdirectories that are under version control
@alldirs = ();
foreach $dir (@entirealldirs) {
    chop($dir);
    if ( -d "$dir/CVS" ) {
        if(defined($opt_V) && $opt_V>1) { print STDOUT "  $dir\n"; }
        push(@alldirs, "$dir\n");
    }
}

if ($frames == 1) {
  # Write the start of the left lower frame if more than one dir
  if (($#alldirs > 0) || ($dochrono)) {
    $llname = $outdirname.'/'.$outfilename."__lfl.html";
    open(OUTFILE3,">$llname") or die "Error: The file $llname could not be opened.";
    @listhtmlnames = (@listhtmlnames,$llname);
	print OUTFILE3 html_header("");

    if ($dochrono) {
      print OUTFILE3 "<table border=0 cellspacing=1 cellpadding=3 bgcolor=\"$cellcolor\" width=\"100%\">\n";
      $coutref = $outdirname."/".$chronooutname;
      print OUTFILE3 '<tr><td><a href="'.$chronooutname.'" target="rf"><FONT SIZE="-1">Chronological Log'."</font></a></td></tr>\n";
      print OUTFILE3 "</table><br>\n";
    }

    print OUTFILE3 "<h3 align=center>Dirs</h3>\n";
    print OUTFILE3 "<table border=0 cellspacing=1 cellpadding=3 bgcolor=\"$cellcolor\" width=\"100%\">";

    for ($ii=0;$ii<=$#alldirs;$ii++) {
      $alldirs[$ii] =~ /^\.(.*)$/;
      $dir = $1;
      $showdir = "[$rootdir]$dir";
      $refname = $dir;

      $refname =~ tr/\//_/;

      if (length($refname) == 1) {
        $refname = $outfilename;
      }
      else {
        $refname = $outfilename.$refname;
      }
      print OUTFILE3 '<tr><td><a href="'.$refname.'.html" target="_top"><FONT SIZE="-1">'.$showdir."</font></a></td></tr>\n";
    }
    print OUTFILE3 "</table>\n";
    print OUTFILE3 "</body>\n";
    print OUTFILE3 "</html>\n";

    close(OUTFILE3);
  }
}

if ($dochrono) {
  $chronocounter = -1;
  @chronoindex=();
  @chronoauthor=();
  @chrononame=();
  @chronotimesince0=();
  @chronoversion=();
  @chronoshowtime=();
  @chronolinknames=();
}

#############################################################
# Lets go for each of the directories
#############################################################
for ($dd=0;$dd<=$#alldirs;$dd++) {
  # Initialization
  @otherdnames = ();
  $lineno = -1;
  $foundbadone = 0;
  $fnumber = 1;

  # Where are we ?
  # $convdir is the current dir where all / are converted to _
  ($currentdir) = $alldirs[$dd] =~ /^\.\/(.*)$/;
  $convdir = $currentdir;
  $convdir =~ tr/\//_/;
  if (length($currentdir)==0) {
    $currentdirformat2 ="";
    $currentdir='.';
    $convdir = "";
  }
  else {
    $currentdirformat2 = $currentdir."/";
    $convdir = '_'.$convdir;
  }
  if(defined($opt_V) && $opt_V>0) { print STDOUT "Processing \#2 $currentdir\n"; }

  @entiresubdirs = find_subdirs($currentdir);
  @subdirs = ();
  foreach $dir (@entiresubdirs) {
    chop($dir);
    if ( -d "$dir/CVS" ) {
	  if(defined($opt_V) && $opt_V>1) { print STDOUT "  $dir\n"; }
	  push(@subdirs, "$dir\n");
	}
  }

  if ($frames == 1) {
	$llname = $outdirname.'/'.$outfilename.$convdir."__lfl.html";
	open(OUTFILE3,">$llname") or die "Error: The file $llname could not be opened.";
	@listhtmlnames = (@listhtmlnames,$llname);
	print OUTFILE3 html_header("");
	
	if ($dochrono) {
	  print OUTFILE3 "<table border=0 cellspacing=1 cellpadding=3 bgcolor=\"$cellcolor\" width=\"100%\">";
	  $coutref = $outdirname."/".$chronooutname;
	  print OUTFILE3 '<tr><td><a href="'.$chronooutname.'" target="rf"><font size="-1">Chronological Log'."</font></a></td></tr>\n";
	  print OUTFILE3 "</table><br>\n";
	}
	
	if ($#subdirs>=0 || $currentdir ne '.') {
	  print OUTFILE3 "<h3 align=center>Sub Dirs</h3>\n";
	  print OUTFILE3 "<table border=0 cellspacing=1 cellpadding=3 bgcolor=\"$cellcolor\" width=\"100%\">";

	  if($currentdir eq '.') {
		# No parent directory to top
	  }
	  else {
		$showdir = ".. Parent Dir";
		$up = dirname ($currentdir);
		($up) = $up =~ /^(.*)$/;

		if ($up eq ".") {
		  $refname = "/";
		}
		else {
		  $refname = "/$up";
		}
		$refname =~ tr/\//_/;
		if (length($refname) == 1) {
		  $refname = $outfilename;
		}
		else {
		  $refname = $outfilename.$refname;
		}
		print OUTFILE3 '<tr><td><a href="'.$refname.'.html" target="_top"><FONT SIZE="-1">'.$showdir."</font></a></td></tr>\n";
	  }
	  for ($ii=0;$ii<=$#subdirs;$ii++) {
		$subdirs[$ii] =~ /^\.(.*)$/;
		$dir = $1;
		$up = dirname ($subdirs[$ii]);
		($up) = $up =~ /^(.*)$/;
		$up = basename ($up);
		($up) = $up =~ /^(.*)$/;
		$down = basename ($subdirs[$ii]);
		($down) = $down =~ /^(.*)$/;
		$dir = "/$down";
		if ($up eq ".\n") {
		  $showdir = "[$rootdir]$dir";
		}
		else {
		  $showdir = "[$up]$dir";
		}

		if($currentdir eq '.') {
		  $refname = $dir;
		}
		else {
		  $refname = "/$currentdir$dir";
		}
		$refname =~ tr/\//_/;
		if (length($refname) == 1) {
		  $refname = $outfilename;
		}
		else {
		  $refname = $outfilename.$refname;
		}

		print OUTFILE3 '<tr><td><a href="'.$refname.'.html"  target="_top"><FONT SIZE="-1">'.$showdir."</font></a></td></tr>\n";
	  }
	  print OUTFILE3 "</TABLE><br>\n";
	}
	print OUTFILE3 "</body>\n";
	print OUTFILE3 "</html>\n";

	close(OUTFILE3);
  }

  # Should the output have frames then make left lower frame.
  if ($frames == 1) {
    # Write the start of the left upper frame
    $luname = $outdirname.'/'.$outfilename.$convdir."__lfu.html";
    open(OUTFILE2,">$luname") or die "Error: The file $luname could not be opened.";
    @listhtmlnames = (@listhtmlnames,$luname);
	print OUTFILE2 html_header("");
 	print OUTFILE2 "<h3 align=\"center\">Log History</h3>\n";
    print OUTFILE2 "<table border=0 cellspacing=1 cellpadding=3 bgcolor=\"$cellcolor\" width=\"100%\">";
	%outfile2lines=();
  }

  # Should the output have frames ?
  if ($frames == 1) {
    $mainname = $outdirname.'/'.$outfilename.$convdir.".html";

    # Write the start of the main html file
    open(OUTFILE4,">$mainname") or die "Error: The file $mainname could not be opened.";
    @listhtmlnames = (@listhtmlnames,$mainname);
    print OUTFILE4 "<\!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">\n<html>\n";
    print OUTFILE4 "<head><title>CVS2HTML</title></head>\n";
    print OUTFILE4 "<frameset cols=\"$leftframewidth,*\">\n";
    # only do the left lower frame if subdirs found

    if (($#alldirs > 0)  || ($dochrono)) {
      print OUTFILE4 "<frameset rows=\"".$leftsplitratio.",*\">\n";
      print OUTFILE4 "<frame scrolling=auto src=\"".$outfilename.$convdir."__lfu.html\" name=\"lfu\">\n";
      print OUTFILE4 "<frame scrolling=auto src=\"".$outfilename.$convdir."__lfl.html\" name=\"lfl\">\n";
#      print OUTFILE4 "<frame scrolling=auto src=\"$outfilename"."__lfl.html\" name=\"lfl\">\n";
      print OUTFILE4 "</frameset>\n";
    }
    else {
      print OUTFILE4 "<frame scrolling=auto src=\"$outfilename".$convdir."__lfu.html\" name=\"lfu\">\n";
    }
    # Do right frame link
    print OUTFILE4 "<frame scrolling=auto src=\"$outfilename".$convdir."__rf.html\" name=\"rf\">\n";
    print OUTFILE4 "<noframes>\n";
    print OUTFILE4 "<h2 align=center>CVS Directories</h2>\n<hr>\n<br>\n";
  }

  if(defined($opt_V) && $opt_V>0) { print STDOUT "Getting cvs-entries\n"; }

  $cvsnames = "";
  @cvsnameslist = ();
  $Entryfilename = $currentdir."/CVS/Entries";

  open(NAMEFILE,"<$Entryfilename");
  $contin = 1;
  $nooffiles = 0;
  while ($contin ==1) {
    $namlin = <NAMEFILE>;
    ($readnameline) = $namlin =~ /^\/([ a-zA-Z0-9-+_\.(...)]*)\/.*$/;
    $_ = $readnameline;
    s/ /~/g;
    $readnameline = $_;
    if (length($namlin)>0) {
      if (length($readnameline)>0) {
	if($readnameline ne $skipfile) {
	  $nooffiles++;
	  $cvsnames = $cvsnames." ".quotemeta($currentdir.'/'.$readnameline);
	  push @cvsnameslist, quotemeta($currentdir.'/'.$readnameline);
	}
      }
    }
    else {
      $contin=0;
    }
  }
  close(NAMEFILE);

  # Check for an empty Log (if, e.g., the directory does not contain files
  # registered with CVS).
  if (length ($cvsnames) <= 0) {
	print STDERR "Error 4 : Doing $currentdir: Log is empty.\n";
	# We really should make a file here I think
	if ($frames == 1) {
	  $rfoutname = $outdirname.'/'.$outfilename.$convdir."__rf.html";
	  open(OUTFILE,">$rfoutname") or die "Error: Could not open $rfoutname\n.";
	  @listhtmlnames = (@listhtmlnames,$rfoutname);
	}
	$fnumber=2;
	if (length($currentdir)==1) {
	  print OUTFILE html_header("--- $rootdir ---");
	}
	else {
	  print OUTFILE html_header("--- $rootdir/$currentdir ---");
	}
	
	if ($opt_v) { print OUTFILE cvsrootinfo(); }
	print OUTFILE html_footer("");
	print OUTFILE "</body></html>\n";
	
	# Lets open the main file and process
	if ($frames == 1) {
	  $rfoutname = $outdirname.'/'.$outfilename.$convdir.$fname."__rf.html";
	  open(OUTFILE,">$rfoutname") or die "Error: Could not open $rfoutname\n.";
	  @listhtmlnames = (@listhtmlnames,$rfoutname);
	}
	else {
	  $mainoutname = $outdirname.'/'.$outfilename.$convdir.$fname.".html";
	  open(OUTFILE,">$mainoutname") or die "Error: Could not open $mainoutname\n.";
	  @listhtmlnames = (@listhtmlnames,$mainoutname);
	}
	$fnumber=2;
	if (length($currentdir)==1) {
	  print OUTFILE html_header("--- $rootdir ---");
	}
	else {
	  print OUTFILE html_header("--- $rootdir/$currentdir ---");
	}
	print OUTFILE "<center>This directory is empty</center>\n";
	closemainfile;
  }
  next if (length ($cvsnames) <= 0); # Log is empty so proceed to next directory

  if(defined($opt_V) && $opt_V>0) { print STDOUT "Retrieving logdata\n"; }

  $_ = join ('" "', sort (split ' ', $cvsnames));
  s/~/ /g;
  $cvsnames = '"'.$_.'"';
  @cvslogarray = ();

# it would be nice to have just one cvs log <file_1> <file_2> ... <file_n>
# the filter out invalid branch blocs and re-request them
# for this I would need to know how this message looks like

  foreach $cvsnamesentry (@cvsnameslist) {
	if(defined($opt_V) && $opt_V>1) { print STDOUT "  $cvsnamesentry\n"; }
    @cvslogarray_sub = `$cvsLocation log $revisionlimiter $cvsnamesentry 2>&1 `;
    if ($cvslogarray_sub[0] =~ /connection refused/i) {
	  print STDERR "Error 3 : connection to cvs refused for \"$cvsnamesentry\"\n";
	  @cvslogarray_sub = ();
	  last;
	}
    if ($cvslogarray_sub[0] =~ /invalid branch or revision pair/i) {
      # the end tag was probably the first rev in a branch and "cvs log"
      # does not tolerate such combination, it needs special handling
      # retry with '-r:endtag'
      print "retrying with $revisionlimiter_end\n";
      @cvslogarray_sub_branch = `$cvsLocation log $revisionlimiter_end $cvsnamesentry`;
      @cvslogarray_sub_trunk = `$cvsLocation log $revisionlimiter_startonly $cvsnamesentry`;
      # find index of log entry separator line in @cvslogarray_sub_trunk
      $trunk_log_line = 0;
      while ( $trunk_log_line <=  $#cvslogarray_sub_trunk and
			  ! ($cvslogarray_sub_trunk[$trunk_log_line] =~ /^--------*$/) ){
		$trunk_log_line++;
      }
      # combine both logs
      @cvslogarray_sub = (@cvslogarray_sub_branch[0 .. $#cvslogarray_sub_branch-1],
						  @cvslogarray_sub_trunk[$trunk_log_line .. $#cvslogarray_sub_trunk]);
    }
    push @cvslogarray, @cvslogarray_sub;
  }

  if(defined($opt_V) && $opt_V>0) { print STDOUT "Processing logdata\n"; }

  $line = getnextline;

  # skip lines starting with "?"
  while ($line =~ /^\? (.*)$/) {
    $foundbadone = 1 ;
    $line = getnextline;
  }

  while ($line) {
    if ($opt_n>0) {
      $nodiff = $opt_n;
    }
    else {
      $nodiff = -1;
    }
    $oldrevnumber=0;
    if ($line =~ /^\? (.*)/) {
      print STDERR "The file \"$1\" is not part of cvs\n";
      $line = getnextline;
    }
    $line = getnextline;

	# skip lines starting with "?"
    while ($line =~ /^\? (.*)$/) {
      $foundbadone = 1 ;
      $line = getnextline;
    }

	# skip empty lines
    while ($line =~ /^( *)$/) {
      $line = getnextline;
    }

	# found a filename (ends on ",v")
    if ($line =~ /^.*: (.*),v$/) {
      $line = getnextline;
      ($lfilename) = $line =~ /^.*: (.*)$/;

      ($filename) = $lfilename =~ (/^.*\/([ a-zA-Z0-9-+_\.(...)]*)$/);
      if (length($filename) == 0) {
        $filename = $lfilename;
      }

      if (length($filename) == 0) {
        print STDERR "Error 2 in processing the output of cvs log in $currentdir\n";
        print STDERR $line;
      }
	  else {
		if(defined($opt_V) && $opt_V>1) { print STDOUT "  $filename\n"; }
	  }
      $printfilename = 0;
      $onlist = 0;
    }
    else  {
      print STDERR "Error 1 in processing the output of cvs log in $currentdir\n";
      print STDERR $line;
      print STDERR "\n";
      if ($line =~ /nothing known about/) {
        print STDERR "No log info for file.\n";
        last;
      }
    }

    # Find the next separator...
    while ($line and !($line =~ /^symbolic names:/) and !($line =~ /^--------*$/) and !($line =~ /^========*$/)) {
      $line = getnextline;
    }

    # Find the revision of the startrevision if any:
    $startrevision="";
    if ($line =~ /^symbolic names:/) {
      $line = getnextline;
      while (!($line =~ /^[a-z]/)) {
		if ($line =~ /[ 	]*(\S*): (\S*)$/) {
		  if ($1 eq $starttag) {
			$startrevision=$2;
		  }
		}
        $line = getnextline;
      }
      # Find the next separator...
      while (!($line =~ /^--------*$/) and !($line =~ /^========*$/)) {
		$line = getnextline;
      }
    }

    $newfile=0;

    # If the separator is a new file separator, flag it.
    if ($line =~ /^========*$/) {
      $newfile = 1;
      # FIXME: We still need to create a index~<filename>__rf.html
	  if ($frames == 1) {
		$rfoutname = $outdirname.'/'.$outfilename.$convdir."__rf.html";
		open(OUTFILE,">$rfoutname") or die "Error: Could not open $rfoutname\n.";
		@listhtmlnames = (@listhtmlnames,$rfoutname);
	  }
	  $fnumber=2;
	  if (length($currentdir)==1) {
		print OUTFILE html_header("--- $rootdir ---");
	  }
	  else {
		print OUTFILE html_header("--- $rootdir/$currentdir ---");
	  }
	  if ($opt_v) { print OUTFILE cvsrootinfo(); }
	  print OUTFILE html_footer("");
	  print OUTFILE "</body></html>\n";

      # This just skips over this file.
    }

	if(defined($opt_V) && $opt_V>2) { print STDOUT "    Getting metadata\n"; }

    $leftfill = 0;
    $line = getnextline;

    while ($newfile==0) {
      if ($line =~ /revision (\S*)/) {
        $revnumber=$1;
      }
      else {
        $revnumber = "[Error_in_revnumber]";
      }

      $line = getnextline;

      if ($line =~ /date: (...................)/) {
        $revdate = `date -d \"$1 UTC\" +\"%Y/%m/%d %H:%M:%S\"`;
      }
      else {
        $revdate = "[Error_in_revdate]";
      }

      if ($line =~ /author: ([a-zA-Z0-9_]*);/) {
        $author = $1;
      }
      else {
        $author = "[Error_in_author]";
      }

      if ($line =~ /lines: ([+\-0-9 ]*)$/) {
        $changelines = $1;
      }
      else {
        $changelines = "None";
      }

      $line = getnextline;

      if ($line =~ /branches: (.*)/) {
        $line = getnextline;
      }

      ($rd1,$rd2,$rd3,$rdrest) = $revdate =~ /^(\d+)\/(\d+)\/(\d+) (.*)$/;
      $revdateformat2 = $rd1.$rd2.$rd3;
      ($rt1,$rt2,$rt3) = $rdrest =~/(\d+)\:(\d+)\:(\d+)/;

      $revdateformat3 = 3600*$rt1+60*$rt2+$rt3+86400*$revdateformat2;
      $printfilename = $printfilename + 1;

      $fname="";
      if ($opt_f) {
        $fname = '~'.$filename;
      }
      if ((($fnumber == 1) || ($opt_f)) && ($printfilename==1)) {
        if (($opt_f) && ($fnumber==1)){
          $rfoutname = $outdirname.'/'.$outfilename.$convdir."__rf.html";
          open(OUTFILE,">$rfoutname") or die "Error: Could not open $rfoutname\n.";
          @listhtmlnames = (@listhtmlnames,$rfoutname);
		  if (length($currentdir)==1) {
			print OUTFILE html_header("--- $rootdir ---");
		  }
		  else {
			print OUTFILE html_header("--- $rootdir/$currentdir ---");
		  }
          print OUTFILE "<h3>Select entries from the left panel to get to the cvs log information for the files</h3>\n";
		  print OUTFILE html_footer("");
          print OUTFILE "</body>\n</html>\n";
          close(OUTFILE);
        }

        # Lets open the main file and process
        if ($frames == 1) {
          $rfoutname = $outdirname.'/'.$outfilename.$convdir.$fname."__rf.html";
          open(OUTFILE,">$rfoutname") or die "Error: Could not open $rfoutname\n.";
          @listhtmlnames = (@listhtmlnames,$rfoutname);
        }
        else {
          $mainoutname = $outdirname.'/'.$outfilename.$convdir.$fname.".html";
          open(OUTFILE,">$mainoutname") or die "Error: Could not open $mainoutname\n.";
          @listhtmlnames = (@listhtmlnames,$mainoutname);
        }
        $fnumber=2;
		if (length($currentdir)==1) {
		  print OUTFILE html_header("--- $rootdir ---");
		}
		else {
		  print OUTFILE html_header("--- $rootdir/$currentdir ---");
		}
		if ($opt_v) { print OUTFILE cvsrootinfo(); }
      }

      $needthisrevision = 0;
      if (($revdateformat2 >= $cutdate) and ($revnumber ne $startrevision)) {
        $needthisrevision = 1;
      }

      if ( $needthisrevision or $needthisdiffonly ) {
		if (($onlist == 0) && ($printfilename == 1)) {
		  print OUTFILE "<a name=\"$filename\">\n</a>\n";
		  print OUTFILE "<table border=0 cellspacing=1 cellpadding=3 bgcolor=\"$cellcolor\" width=\"100%\">\n";
		  print OUTFILE "<tr>\n";
		  print OUTFILE "<td colspan=4 bgcolor=\"$filenamecellcolor\"><b><font size=\"+1\">\n";

		  $cdir = "";
		  if (length($currentdir)>1) {
			$cdir = '/'.$currentdir;
		  }

		  $Ls = "";
		  $Le = "";
		  if ($opt_L) {
			($flname,$ext) = $filename =~ /^([a-zA-Z0-9+-_]*)\.([a-zA-Z0-9]*)$/;
			if (length($ext)==0) {
			  $flname = $filename;
			}
			$Ls = "<a href=\"$opt_L$cdir/$flname".".html\" target=\"_top\">";
			$Le = "</a>\n";
		  }
		  print OUTFILE $Ls."Filename".$Le.": ";

		  $Ls = "";
		  $Le = "";
		  if (($opt_l) && ($opt_R)) {
			$Ls = "<a href=\"$opt_l$cdir/$filename\?cvsroot\=$opt_R\">";
		   	$Le = "</a>\n";
		  } elsif (($opt_l) && (! opt_R)) {
			$Ls = "<a href=\"$opt_l$cdir/$filename\">";
			$Le = "</a>\n";
		  }
			
		  print OUTFILE $Ls.$filename.$Le;
		  print OUTFILE "</font></B><br></td></tr>\n";
		}
        $onlist = 1;
        if (($opt_o) && ($leftfill == 0)) {
          if ($opt_f) {
            $chronolinker = $outfilename.$convdir.'~'.$filename.'__rf.html';
          }
          else {
            $chronolinker = $outfilename.$convdir.'__rf.html#'.$filename;
          }
		  # justcollect, we'll output them sorted on filename
		  $outfile2lines{$filename}="<tr><td><a href=\"$chronolinker\" target=\"rf\"><font size=\"-1\">$filename</font></a></td></tr>\n";
          $leftfill=2;
        }
        if (($opt_a) && ($oldrevnumber!=0) && ($nodiff!=0)) {
	  # Comparing first revision on a branch with revision on origin trunk
	  if($oldrevnumber =~ /[0-9]+\.[0-9]+\.[0-9]+\.1$/) {
	    $savedrevnumber=$revnumber;
	    $revnumber=$oldrevnumber;
	    $revnumber =~ s/\.[0-9]+\.1$//;
	  }
	  if($oldrevnumber eq '1.1' ) {
	    print OUTFILE "<tr><td colspan=4 bgcolor=\"$differencebackground\"><i>First version</i></tr>\n";
	  }
 	  else {
	    print OUTFILE "<tr><td colspan=4 bgcolor=\"$differencebackground\"><i>Show difference between <a href=\"$diffdirname/diff$convdir\_$filename\_$oldrevnumber\_$revnumber.html\">Revision $revnumber and $oldrevnumber </a></i></tr>\n";
	    generate_diff_file;
	  }
          $nodiff--;
	  # Comparing first revision on a branch with revision on origin trunk
	  if($oldrevnumber =~ /[0-9]+\.[0-9]+\.[0-9]+\.1$/) {
	    $revnumber=$savedrevnumber;
	  }
        }
        $oldrevnumber=$revnumber;
		if ( $needthisrevision==0 ) {
		  $needthisdiffonly = 0;
		}
		if ( $needthisrevision!=0 ) {
		  if (($opt_a) && ($nodiff!=0)) {
			$needthisdiffonly = 1;
		  }
		  print OUTFILE "<tr><td><b>Revision $revnumber</b><td>$author\n";
		  print OUTFILE "<td>$revdate";
		  if (length($changelines)<2) {
			print OUTFILE "<td>None\n";
		  }
		  else {
			print OUTFILE "<td>$changelines\n";
		  }
		  print OUTFILE "<tr><td colspan=4>\n";
		  if ($dochrono) {
	 		$chronocounter++;
 			$nams = $currentdirformat2.$filename;
			@chronoindex = (@chronoindex,$chronocounter);
			@chrononame = (@chrononame,$nams);
			@chronoauthor = (@chronoauthor,$author);
			@chronoversion = (@chronoversion,$revnumber);
			@chronoshowtime = (@chronoshowtime,$revdate);
			@chronotimesince0 = (@chronotimesince0,$revdateformat3);
			@chronolinknames = (@chronolinknames,$chronolinker);
		  }
		}
      }

      # While more log read and process
      $morelog=1;
      while ($morelog==1) {
        if ($line =~ /^----------*$/) {
          $morelog=0;
        }
        else {
          if ($line =~ /^========*$/) {
            $newfile=1;
            $morelog=0;
          }
          else {
            $_=$line;
            s/&/&amp;/g;
            s/\"/&quot;/g;
            s/</&lt;/g;
            s/>/&gt;/g;
            $line=$_;
            if ($line =~ /^(.*)$/) {
              if (($revdateformat2 >= $cutdate) and ($revnumber ne $startrevision)) {
                if ($opt_e) {
                  print OUTFILE "<code>$1</code><br>\n";
                }
                else {
                  print OUTFILE "$1<br>\n";
                }
              }
            }
          }
        }
        $line = getnextline;
      }
      print OUTFILE "\n";
    }

    # Comparing first revision on a branch with revision on origin trunk
    if($oldrevnumber =~ /[0-9]+\.[0-9]+\.[0-9]+\.1$/) {
      $savedrevnumber=$revnumber;
      $revnumber=$oldrevnumber;
      $revnumber =~ s/\.[0-9]+\.1$//;
    }
    if($oldrevnumber eq '1.1') {
      print OUTFILE "<tr><td colspan=4 bgcolor=\"$differencebackground\"><i>First version</i></tr>\n";
    }
    else {
      print OUTFILE "<tr><td colspan=4 bgcolor=\"$differencebackground\"><i>Show difference between <a href=\"$diffdirname/diff$convdir\_$filename\_$oldrevnumber\_$revnumber.html\">Revision $revnumber and $oldrevnumber </a></i></tr>\n";
      generate_diff_file;
    }
    if($oldrevnumber =~ /[0-9]+\.[0-9]+\.[0-9]+\.1$/) {
      $revnumber=$savedrevnumber;
    }
    
    if ($onlist==1) {
      print OUTFILE "</table><br>\n";
    }
    if ($onlist==0) {
      @otherdnames = (@otherdnames,$filename);
    }
    if ($opt_f) {
      closemainfile;
    }
  }

  if (!$opt_f) {
    closemainfile;
  }

  if ($opt_o) {
	# output all filenames sorted
	foreach $key (sort { lc($a) cmp lc($b) } keys %outfile2lines) {
	  print OUTFILE2 $outfile2lines{$key}
	}
    print OUTFILE2 "</table><br>\n";
  }
  if (($opt_o) && ($nooffiles == $#otherdnames+1)) {
    print OUTFILE2 "No file revisions.<br>\n";
  }
  if (($#otherdnames>=0) && ($opt_o)) {
    print OUTFILE2 "<br><hr><h3 align=center>Unchanged</h3>\n";
    if ($#otherdnames>=0) {
      print OUTFILE2 "<table border=0 cellspacing=1 cellpadding=3 bgcolor=\"$cellcolor\" width=\"100%\">\n";
      for ($ii=0;$ii<=$#otherdnames;$ii++) {
		print OUTFILE2 "<tr><td><font size=\"-1\">$otherdnames[$ii]</font></td></tr>\n";
      }
      print OUTFILE2 "</table><br>\n";
	}
    else {
      print OUTFILE2 "All files have revisions.<br>\n";
    }
  }

  # Lets wrap up OUTFILE2
  if ($opt_o) {
    print OUTFILE2 "</body>\n";
    print OUTFILE2 "</html>\n";
    close(OUTFILE2);
  }

  # Found a bad one....... This should NOT happen
  if ($foundbadone == 1) {
    print STDERR "\ncvs2html found some files that was no part of CVS\n\n";
  }

  if ($frames == 1) {
    print OUTFILE4 "<table border=0 cellspacing=1 cellpadding=3 bgcolor=\"$cellcolor\" width=\"100%\">\n";

    for ($ddd=0;$ddd<=$#alldirs;$ddd++) {
      ($currentdir) = $alldirs[$ddd] =~ /^\.\/(.*)$/;
      $convdir = $currentdir;
      $convdir =~ tr/\//_/;
      if (length($currentdir)==0) {
        $currentdir='.';
        $convdir = "";
      }
      else {
        $convdir = '_'.$convdir;
      }

      chop($ldir = $alldirs[$ddd]);
      if (length($ldir) == 2) {
        $ldir ="";
      }
      print OUTFILE4 "<tr><td><a href=\"".$outfilename.$convdir."__lfu.html\">[$rootdir]$ldir</a></td></tr>\n";
    }
    print OUTFILE4 "</table><br>\n";
  }

  print OUTFILE4 html_footer("");
  print OUTFILE4 "</noframes>\n";
  print OUTFILE4 "</frameset>\n";
  print OUTFILE4 "</html>\n";
  close(OUTFILE4);
}

if ($dochrono) {
  $coutref = $outdirname."/".$chronooutname;
  open(CHRONOFILE,">$coutref");

  if(defined($opt_V) && $opt_V>0) { print STDOUT "Generate chrono file\n"; }

  print CHRONOFILE html_header("CVS time sorted logs");
  if ($frames == 0) {
	print CHRONOFILE '<a href="'.$outfilename.'.html" target="_top">Back to main page</a><p>';
  }


  #print "Sorting the logfiles\r";
  @cindex = sort sorter @chronoindex;
  #print "Done sorting the logfiles\n";

  if ($frames == 1) {
    print CHRONOFILE "<table border=\"0\" width=\"100%\" bgcolor=\"$cellcolor\" cellspacing=\"1\" cellpadding=\"3\">";
    printf(CHRONOFILE "<tr><td><b>%s</b></td> <td><b>%s</b></td> <td><b>%s</b></td>  <td><b>%s</b></td></tr>\n","Time       ","Revision","Author","Filename");
  }
  else {
    printf(CHRONOFILE "<br><tr><br>\n%20s %8s %10s %s<br><hr>\n","Time       ","Revision","Author","Filename");
  }

  $cclim = $chronocounter;
  $cindexlow=0;
  if ($opt_N>0) {
    if ($opt_N-1<$chronocounter) {
      $cclim = $opt_N-1;
      $cindexlow = $chronocounter+1-$opt_N;
      $cctxt = " and only the last $opt_N changes are shown.";
    }
  }

  if ($cindexlow<0) {
    $cindexlow=0;
  }

  if ($opt_p) {
    for ($ii=$cindexlow;$ii<=$chronocounter;$ii++) {
      if ($opt_c) {
		$cind = $ii;
      }
      else {
		$cind = $chronocounter-$ii+$cindexlow;
      }
      $index = $cindex[$cind];

	  if(defined($opt_V) && $opt_V>1) { print STDOUT "  $chrononame[$index]\n"; }

      @lcvslog = `$cvsLocation log -N -r$chronoversion[$index] "$chrononame[$index]"`;
      @llcvslog = ();
      $headerstill = -1;
      foreach $jj (0 .. ($#lcvslog-1)) {
		if ($headerstill == 0) {
		  $_=$lcvslog[$jj];
		  s/&/&amp;/g;
		  s/\"/&quot;/g;
		  s/</&lt;/g;
		  s/>/&gt;/g;
		  @llcvslog = (@llcvslog,$_);
		}
		else {
		  $headerstill = $headerstill - 1;
		  if ($lcvslog[$jj] =~ '----------------------------') {
			$headerstill = 2;
		  }
		}
      }
      $lcvslogar[$index] = join('<br>',@llcvslog);
      if (length($lcvslogar[$index])<2) {
		$lcvslogar[$index] = "<i>(Empty log)</i>";
      }
    }
  }
  for ($ii=$cindexlow;$ii<=$chronocounter;$ii++) {
    if ($opt_c) {
      $cind = $ii;
      $cind2 = $ii+1;
    }
    else {
      $cind = $chronocounter-$ii+$cindexlow;
      $cind2 = $cind-1;
    }
    $index = $cindex[$cind];
    $index2 = $cindex[$cind2];
    $ccc = '<A HREF="'.$chronolinknames[$index].'">'.$chrononame[$index]."</a>";
    if ($frames==0) {
      printf(CHRONOFILE "%20s %8s %10s %s<br>\n",$chronoshowtime[$index],$chronoversion[$index],$chronoauthor[$index],$ccc);
    }
    else {
      printf(CHRONOFILE "<tr><td><b>%s</b></td> <td>%s</td> <td>%s</td> <td>%s</td></tr>\n",$chronoshowtime[$index],$chronoversion[$index],$chronoauthor[$index],$ccc);
      if ($opt_p) {
	if ($ii == $chronocounter){
	  printf(CHRONOFILE "<tr><td COLSPAN=4>\n");
	  print CHRONOFILE  $lcvslogar[$index];
	  printf(CHRONOFILE "</td></tr>\n");
	}
	elsif (($lcvslogar[$index] ne $lcvslogar[$index2]) || (abs($chronotimesince0[$index]-$chronotimesince0[$index2]))>$commit_smalltimedifference) {
	  printf(CHRONOFILE "<tr><td COLSPAN=4>\n");
	  print CHRONOFILE  $lcvslogar[$index];
	  printf(CHRONOFILE "</td></tr>\n");
	}
      }
    }
  }

  if ($frames == 1) {
    print CHRONOFILE "</table>\n";
  }
  else {
    print CHRONOFILE "<hr>\n";
  }

  if ($frames == 0) {
	print CHRONOFILE '<p><a href="'.$outfilename.'.html" target="_top">Back to main page</a><p>';
  }


  $stradd="";
  if ($cutdate>"00000000") {
    $stradd.=" leaving out any log message prior to $cutyearformat2 $revisionlimitertext";
  }
  print CHRONOFILE html_footer($stradd.$cctxt);
  #Wrap up the file
  print CHRONOFILE "\n</body>\n</html>\n";

  close(CHRONOFILE);
# We must report that a new file has been made
  @listhtmlnames = (@listhtmlnames,$coutref);
}

# Print status about which files have been generated
#  all diffs are under *_diff/ directory
#  files ending on "__rf" are those displayed in the right frame (the ones showing the revision history)
#  files ending on "__lfu" are those displayed in the upper part of the left frame
#  files ending on "__lfl" are those displayed in the lower part of the left frame
#
if(defined($opt_V) && $opt_V>0) {
  print STDOUT "cvs2html has generated the following files :\n";
  @ll=sort(@listhtmlnames);
  for ($ff=0;$ff<=$#listhtmlnames;$ff++) {
	print "  $ll[$ff]\n";
  }
  print "\n";
}