[BACK]Return to list2html.pl CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / htdocs

Annotation of htdocs/list2html.pl, Revision 1.64

1.1       abs         1: #!/usr/bin/env perl
                      2: #
1.64    ! dent        3: # $NetBSD: list2html.pl,v 1.63 2001/02/21 23:46:10 dent Exp $
1.3       abs         4: # Process *.list files into indexed *.html files. (abs)
1.1       abs         5: # Looks for these compulsary tags:
                      6: #      <LIST>                  Include generated list of entries here.
1.28      abs         7: #      <SECTION>Text           Introduces new section
1.39      abs         8: #      </LIST>                 Mark end of all special entries
1.1       abs         9: #
1.3       abs        10: # Plus these optional tags: (You will probably want to use <DATE> or <ENTRY>)
1.2       abs        11: #      <DATE>tag date Text     Change entry, expanded to title & added to list
                     12: #      <ENTRY>tag Text         New entry, expanded to title and added to list
1.58      dent       13: #      <LISTLINK>url Text      Link added to list, removed from main text
                     14: #      <ENTRYLINK>url Text     Link added to list and main text
1.1       abs        15: #      <HEADING>Text           Standard heading at top of document
1.51      dent       16: #      <DEVHEADING>Text        Standard heading at top of developer docs
1.11      abs        17: #      <TROW>Text: Text        Table row, with two text fields
1.39      abs        18: #                              NOTE: <TROW> will automatically continue
                     19: #                              until a link containing </table>
                     20: #      <HOMELINK>              Add flag link to NetBSD home page
                     21: #      <DOCLINK>               Add flag links to NetBSD home page & docs top
1.40      abs        22: #      <DEVLINK>               Add flag links to NetBSD home page & developers
1.47      dent       23: #      <PORTLINK>              Add flag links to NetBSD home page & ports top
1.48      dent       24: #      <GALLINK>               Add flag links to NetBSD home page & gallery
1.1       abs        25: # Continuation lines are understood (useful for the special tags)
1.6       abs        26: #
                     27: # Additional links:
1.34      abs        28: #      ([\w.+]+)\((\d)\)       -> manpages             eg: ls(1)
                     29: #      <([-\w.]+@[-\w.]+)>     -> email address        eg: <user@host>
                     30: #      <PKGSRC>category/name   -> link to pkgsrc README.html
1.36      abs        31: #      <CURRENTSRC>path        -> link to source file/dir in -current
1.38      abs        32: #      <URL>[^\s<]+[^<\s.]     -> Insert link to URL
1.61      itojun     33: #      <RFC>RFC[0-9]+          -> link to RFC (www.normos.org)
1.36      abs        34: #
                     35: # NOTE: Update htdocs/developers/htdocs.list when adding features.
1.9       abs        36: #
1.35      abs        37: #   (c) 1999, 2000 DKBrownlee. All rights reserved. This file may be used to
                     38: #      update the information on the NetBSD website. If you want to use it
                     39: #      for any other purpose, ask me first.. abs@mono.org
1.9       abs        40: #
1.1       abs        41:
                     42: use strict;
1.21      abs        43: use Getopt::Std;
1.42      abs        44: $^W = 1;
1.43      abs        45: my($verbose, %extras, $months_previous, $list_date_links);
1.42      abs        46: my($version, %opt, %pkgname);
1.31      abs        47:
                     48: # List of pkgsrc names to 'human preferred' forms
                     49: %pkgname = qw(kde KDE gimp GIMP gnome GNOME xsane XSane);
1.1       abs        50:
1.45      abs        51: $months_previous = 9;  # Previous months to display for DATE entries
1.63      dent       52: $list_date_links = 6;  # List the first N date entries on stdout
1.8       abs        53:
1.64    ! dent       54: $version = '$Revision: 1.63 $';
1.42      abs        55: $version =~ /([\d.]+)/ && ($version = $1);
1.5       abs        56:
1.42      abs        57: if (!&getopts('a:m:hV', \%opt) || $opt{'h'} || ( !$opt{'V'} && @ARGV != 2) )
1.5       abs        58:     {
                     59:     print "list2html.pl [opts] infile outfile
                     60: [opts] -a xxx  Define 'arch=xxx' when linking to manpages
1.8       abs        61:        -m xxx  Set months to display for <DATE> (default $months_previous)
1.5       abs        62:        -h      This help.
1.21      abs        63:        -V      Display version and exit ($version - David Brownlee/abs)
1.5       abs        64:
1.25      abs        65: list2html.pl processes .list files into .html, parsing various special tags.
1.5       abs        66: .list files are intended to reduce the effort required to maintain files such
                     67: as FAQs, and change logs. More details given at the start of list2html.pl.
                     68: ";
                     69:     exit;
                     70:     }
1.21      abs        71: if ($opt{'V'})
                     72:     { print "$version\n"; exit; }
1.5       abs        73:
1.42      abs        74: $verbose = 1;
1.21      abs        75: if ($opt{'m'})
1.42      abs        76:     { $months_previous = $opt{'m'}; }
                     77: $months_previous = &get_minmonth($months_previous);
1.1       abs        78:
1.42      abs        79: %extras = (
1.39      abs        80:
1.60      dent       81: '<HEADING>\s*(.*)',
                     82: '<table><tr><td>
                     83:     <a href="$HOME/Misc/daemon-copy.html"><img
                     84:      align="middle" src="$HOME/images/BSD-daemon.jpg" border="0"
                     85:      width=146 height=129 alt="BSD daemon"></a>
                     86:   </td><td align=center>
                     87:     <h1>NetBSD Documentation:</h1>
                     88:     <h1>$SUB1</h1>
                     89: </td></tr></table>
                     90: <p>'
                     91: ,
                     92:
                     93: '<DEVHEADING>\s*(.*)',
                     94: '<table><tr><td>
                     95:     <a href="$HOME/Misc/daemon-copy.html"><img
                     96:      align="middle" src="$HOME/images/BSD-daemon.jpg" border="0"
                     97:      width=146 height=129 alt="BSD daemon"></a>
                     98:   </td><td align=center>
                     99:     <h1>NetBSD Developer Documentation:</h1>
                    100:     <h1>$SUB1</h1>
1.51      dent      101: </td></tr></table>
1.60      dent      102: <p>'
                    103: ,
1.51      dent      104:
1.60      dent      105: '<HOMELINK>',
                    106: '<table><tr><td>
1.57      dent      107:     <a href="$HOME/"><img
1.59      dent      108:        src="$HOME/images/NetBSD-flag.gif" border="0"
1.56      dent      109:        width="91" height="42" alt=""></a>
1.39      abs       110:   </td><td>
1.57      dent      111:     <a href="$HOME/"><img
1.59      dent      112:        src="$HOME/images/empty.gif" border="0"
1.56      dent      113:        width="1" height="1" alt="NetBSD ">Home Page</a>
1.60      dent      114: </td></tr></table>'
                    115: ,
1.39      abs       116:
1.60      dent      117: '<DEVLINK>',
                    118: '<table width="100%"><tr><td>
1.56      dent      119:   <table><tr><td>
1.57      dent      120:     <a href="$HOME/"><img
1.59      dent      121:        src="$HOME/images/NetBSD-flag.gif" border="0"
1.56      dent      122:        width="91" height="42" alt=""></a>
                    123:   </td><td>
1.57      dent      124:     <a href="$HOME/"><img
                    125:        src="$HOME/images/empty.gif" border="0"
1.56      dent      126:        width="1" height="1" alt="NetBSD ">Home Page</a>
                    127:   </td></tr></table>
1.40      abs       128: </td><td>
1.56      dent      129:   <table><tr><td>
1.57      dent      130:     <a href="$DEVELOPERS"><img
1.59      dent      131:        src="$HOME/images/NetBSD-flag.gif" border="0"
1.56      dent      132:        width="91" height="42" alt=""></a>
                    133:   </td><td>
1.57      dent      134:     <a href="$DEVELOPERS"><img
                    135:        src="$HOME/images/empty.gif" border="0"
1.56      dent      136:        width="1" height="1" alt="NetBSD ">Developer Documentation</a>
                    137:   </td></tr></table>
1.60      dent      138: </td></tr></table>'
                    139: ,
1.40      abs       140:
1.60      dent      141: '<DOCLINK>',
                    142: '<table width="100%"><tr><td>
1.56      dent      143:   <table><tr><td>
1.57      dent      144:     <a href="$HOME/"><img
1.59      dent      145:        src="$HOME/images/NetBSD-flag.gif" border="0"
1.56      dent      146:        width="91" height="42" alt=""></a>
                    147:   </td><td>
1.57      dent      148:     <a href="$HOME/"><img
                    149:        src="$HOME/images/empty.gif" border="0"
1.56      dent      150:        width="1" height="1" alt="NetBSD ">Home Page</a>
                    151:   </td></tr></table>
1.39      abs       152: </td><td>
1.56      dent      153:   <table><tr><td>
1.57      dent      154:     <a href="$DOCS"><img
1.59      dent      155:        src="$HOME/images/NetBSD-flag.gif" border="0"
1.56      dent      156:        width="91" height="42" alt=""></a>
1.60      dent      157:   </td><td>
1.57      dent      158:     <a href="$DOCS"><img
                    159:        src="$HOME/images/empty.gif" border="0"
1.56      dent      160:        width="1" height="1" alt="NetBSD ">Documentation top level</a>
                    161:   </td></tr></table>
1.60      dent      162: </td></tr></table>'
                    163: ,
1.47      dent      164:
1.60      dent      165: '<PORTLINK>',
                    166: '<table width="100%"><tr><td>
1.56      dent      167:   <table><tr><td>
1.57      dent      168:     <a href="$HOME/"><img
1.59      dent      169:        src="$HOME/images/NetBSD-flag.gif" border="0"
1.56      dent      170:        width="91" height="42" alt=""></a>
                    171:   </td><td>
1.57      dent      172:     <a href="$HOME/"><img
                    173:        src="$HOME/images/empty.gif" border="0"
1.56      dent      174:        width="1" height="1" alt="NetBSD ">Home Page</a>
                    175:   </td></tr></table>
1.47      dent      176: </td><td>
1.56      dent      177:   <table><tr><td>
1.57      dent      178:     <a href="$PORTS"><img
1.59      dent      179:        src="$HOME/images/NetBSD-flag.gif" border="0"
1.56      dent      180:        width="91" height="42" alt=""></a>
1.60      dent      181:   </td><td>
1.57      dent      182:     <a href="$PORTS"><img
                    183:        src="$HOME/images/empty.gif" border="0"
1.56      dent      184:        width="1" height="1" alt="NetBSD ">Supported Architectures</a>
                    185:   </td></tr></table>
1.60      dent      186: </td></tr></table>'
                    187: ,
1.48      dent      188:
1.60      dent      189: '<GALLINK>',
                    190: '<table width="100%"><tr><td>
1.56      dent      191:   <table><tr><td>
1.57      dent      192:     <a href="$HOME/"><img
1.59      dent      193:        src="$HOME/images/NetBSD-flag.gif" border="0"
1.56      dent      194:        width="91" height="42" alt=""></a>
                    195:   </td><td>
1.57      dent      196:     <a href="$HOME/"><img
                    197:        src="$HOME/images/empty.gif" border="0"
1.56      dent      198:        width="1" height="1" alt="NetBSD ">Home Page</a>
                    199:   </td></tr></table>
1.48      dent      200: </td><td>
1.56      dent      201:   <table><tr><td>
1.57      dent      202:     <a href="$GALLERY"><img
1.59      dent      203:        src="$HOME/images/NetBSD-flag.gif" border="0"
1.56      dent      204:        width="91" height="42" alt=""></a>
                    205:   </td><td>
1.57      dent      206:     <a href="$GALLERY"><img
                    207:        src="$HOME/images/empty.gif" border="0"
1.56      dent      208:        width="1" height="1" alt="NetBSD ">Gallery page</a>
                    209:   </td></tr></table>
1.60      dent      210: </td></tr></table>'
1.39      abs       211:
1.1       abs       212: );
                    213:
                    214: # XXX Should DTRT with faqs not under Documentation
                    215:
1.42      abs       216: &makelist(@ARGV, &extras_generate(%extras));
1.1       abs       217: exit;
                    218:
1.5       abs       219: sub check_date
                    220:     {
1.42      abs       221:     my($date) = @_;
                    222:     my($month, $when);
                    223:     my(%months) = ('Jan' => 1, 'Feb' => 2,     'Mar' => 3,
                    224:                   'Apr' => 4,  'May' => 5,     'Jun' => 6,
                    225:                   'Jul' => 7,  'Aug' => 8,     'Sep' => 9,
                    226:                   'Oct' => 10, 'Nov' => 11,    'Dec' => 12 );
1.5       abs       227:
                    228:     if ($date !~ /(\S+)\s*(\d+)/)
                    229:        { &fail("Unable to parse date '$date'"); }
1.42      abs       230:     if (!defined($month = $months{$1}))
1.5       abs       231:        {
                    232:        &warn("Unable to parse month '$1'");
1.42      abs       233:        $month = 12;
1.5       abs       234:        }
1.42      abs       235:     $when = sprintf("%04d%02d", $2, $month);
1.5       abs       236:     ( $when>$months_previous );
                    237:     }
                    238:
1.24      abs       239: sub extract_tags
                    240:     {
1.42      abs       241:     my($file, @tags) = @_;
                    242:     my($tag, %map);
1.24      abs       243:
1.42      abs       244:     if (!open(FILE, $file))
1.28      abs       245:        { return; }
1.24      abs       246:     while (<FILE>)
                    247:        {
                    248:        foreach $tag (@tags)
                    249:            {
                    250:            if ( /($tag)/ )
1.42      abs       251:                { $map{$tag} = $1; }
1.24      abs       252:            }
                    253:        }
                    254:     close(FILE);
                    255:     %map;
                    256:     }
                    257:
1.5       abs       258: sub extras_generate
                    259:     {
1.42      abs       260:     my(%extras) = @_;
1.48      dent      261:     my($pathtodoc, $pathtodev, $pathtoports, $pathtogal, $str, $home);
1.5       abs       262:
1.28      abs       263:     if ($0 !~ m#(.*)/[^/]+.pl#)
1.5       abs       264:        { &fail("Unable to extract path from '$0'"); }
1.42      abs       265:     $home = "$1";
1.46      dent      266:     $pathtodoc = "$home/Documentation/";
                    267:     $pathtodev = "$home/developers/";
1.47      dent      268:     $pathtoports = "$home/Ports/";
1.48      dent      269:     $pathtogal = "$home/gallery/";
1.5       abs       270:     foreach $str ( keys %extras )
                    271:        {
1.39      abs       272:        $extras{$str} =~ s#\$HOME#$home#g;
1.40      abs       273:        $extras{$str} =~ s#\$DEVELOPERS#$pathtodev#g;
1.56      dent      274:        $extras{$str} =~ s#\$DOCS#$pathtodoc#g;
1.47      dent      275:        $extras{$str} =~ s#\$PORTS#$pathtoports#g;
1.48      dent      276:         $extras{$str} =~ s#\$GALLERY#$pathtogal#g;
1.5       abs       277:        }
                    278:     (%extras);
                    279:     }
                    280:
                    281: sub extras_process
                    282:     {
1.42      abs       283:     my($data, %extras) = @_;
1.39      abs       284:     my($key, $sub1, $sub2, $value);
1.5       abs       285:
                    286:     foreach $key ( keys %extras )
                    287:        {
1.42      abs       288:        $value = $extras{$key};
1.28      abs       289:        if ($data =~ /$key/)
1.5       abs       290:            {
1.39      abs       291:            ($sub1, $sub2) = ($1, $2);
                    292:            if (defined($sub1))
1.42      abs       293:                { $value =~ s#\$SUB1#$sub1#g; }
1.39      abs       294:            if (defined($sub2))
1.42      abs       295:                { $value =~ s#\$SUB2#$sub2#g; }
                    296:            $data =~ s/$key.*/$value/;
1.5       abs       297:            }
                    298:        }
                    299:     $data;
                    300:     }
                    301:
                    302: sub fail
                    303:     {
1.42      abs       304:     print STDERR "ABORTING: ", @_, "\n";
1.5       abs       305:     exit 3
                    306:     }
                    307:
1.8       abs       308: sub get_minmonth
                    309:     {
1.42      abs       310:     my($monthsback) = @_;
                    311:     my($year, $month);
1.8       abs       312:
1.42      abs       313:     ($month, $year) = (localtime(time))[4, 5];
1.8       abs       314:
                    315:     ++$month;
1.42      abs       316:     $month -= $monthsback;
1.28      abs       317:     while ($month<1)
1.8       abs       318:        {
1.42      abs       319:        $month += 12;
1.8       abs       320:        --$year;
                    321:        }
1.42      abs       322:     sprintf("%04d%02d", $year+1900, $month);
1.8       abs       323:     }
                    324:
1.17      abs       325: # Collect $list containing forward links as we go. In general each entry will
                    326: # generate something in $list and some expanded data in the main $data.
                    327: #
1.3       abs       328: sub makelist
1.1       abs       329:     {
1.42      abs       330:     my($infile, $outfile, %extras) = @_;
                    331:     my($data, $section, $href, $header, $list, $pre, %tags, $date_month);
1.43      abs       332:     my($date_num, $date_num_used, $entry_num, $ignore, @date_links);
                    333:     my($in_entry, $in_section, $endlist);
1.18      abs       334:     my($title_font) = "<font face=\"helvetica, arial, sans-serif\">";
                    335:     my($end_title_font) = "</font>";
1.42      abs       336:     my(%rcsmap) = &extract_tags($outfile, '\$NetBSD.*\$');
1.39      abs       337:     my($rcstag, $in_trow);
1.1       abs       338:
1.42      abs       339:     $list = '';
1.1       abs       340:
1.42      abs       341:     $data = $date_month = '';
                    342:     $entry_num = $date_num = $date_num_used = 0;
                    343:     open(FILE, $infile) || die("Unable to open '$infile': $!");
1.1       abs       344:     foreach( <FILE> )
                    345:        {
1.24      abs       346:        foreach $rcstag (%rcsmap)
                    347:            { s/$rcstag/$rcsmap{$rcstag}/; }
1.28      abs       348:        if (defined($pre))              # Handle continuation lines
1.42      abs       349:            { $_ = $pre.$_; $pre = undef; }
1.2       abs       350:
1.42      abs       351:        if (substr($_, -2) eq "\\\n")   # Handle continuation lines
1.1       abs       352:            {
                    353:            s/\\\n$//;
1.42      abs       354:            $pre = $_;
1.1       abs       355:            next;
                    356:            }
                    357:
1.28      abs       358:        if (m#^<DATE>\s*(.+\S)#)        # Changes
1.1       abs       359:            {
1.42      abs       360:            my($year, $month, $link);
1.1       abs       361:
1.2       abs       362:            if ($in_entry)
                    363:                {
1.53      dent      364:                $data .= "</dd></dl>\n";
1.42      abs       365:                $in_entry = undef;
1.2       abs       366:                }
1.42      abs       367:            $ignore = undef;
1.1       abs       368:            ++$date_num;
1.42      abs       369:            $header = $1;
1.28      abs       370:            if ($header !~ /^([-a-z0-9_.+]+)\s+(\d+) (\S+) (\d+) - (\S.*)/)
1.1       abs       371:                { &fail("'$header' not in expected 'date - event' format"); }
1.42      abs       372:            $href = $1;
                    373:            $header = "$5 ($2 $3)";
                    374:            $month = "$3 $4";
                    375:            $link = $5;
1.28      abs       376:            if (defined($tags{$href}))
1.1       abs       377:                { &fail("Duplicate name tag '$href'"); }
1.42      abs       378:            $tags{$href} = 1;
1.1       abs       379:            if (!&check_date($month))
1.42      abs       380:                { $ignore = 1; }
1.1       abs       381:            else
                    382:                {
1.42      abs       383:                $_ = '';
1.1       abs       384:                ++$date_num_used;
1.28      abs       385:                if ($month ne $date_month)
1.1       abs       386:                    {
1.28      abs       387:                    if ($date_month ne '')
1.53      dent      388:                        { $list .= "</ul>\n"; }
                    389:                    $list .= "<h3>$month</h3>\n<ul>\n";
1.42      abs       390:                    $_ .= "<hr><h2>$month</h2><hr>\n";
                    391:                    $date_month = $month;
1.1       abs       392:                    }
                    393:
1.54      dent      394:                $_.= "<p><h3>\n$title_font".
1.53      dent      395:                        "<a name=\"$href\">$header</a>$end_title_font\n".
                    396:                        "<font size=\"-1\">".
                    397:                        "(<a href=\"#top\">top</a>)</font>\n".
                    398:                        "</h3><dl><dt><dd>\n";
                    399:                $list .= "<li>$title_font\n<a href=\"#$href\">$link</a>".
                    400:                        "$end_title_font</li>\n";
1.43      abs       401:                if (@date_links < $list_date_links)
                    402:                    {
1.63      dent      403:                    push(@date_links, "<li><font face=\"helvetica, arial\" size=\"-1\">\n".
                    404:                                      "<a href=\"Changes/#$href\">\n".
                    405:                                      "    $link</a>\n".
                    406:                                      "</font></li>\n");
1.43      abs       407:                    }
1.42      abs       408:                $in_entry = 1;
1.1       abs       409:                }
                    410:            }
1.2       abs       411:
1.39      abs       412:        if (m#^<ENTRY>\s*(.+\S)#)
1.1       abs       413:            {
1.29      abs       414:            if (! $in_section )
1.53      dent      415:                { $list .= "<ul>\n"; }  # Start title list
1.28      abs       416:
1.2       abs       417:            if ($in_entry)
                    418:                {
1.53      dent      419:                $data .= "</dd></dl>\n";
1.42      abs       420:                $in_entry = undef;
1.2       abs       421:                }
1.25      abs       422:
1.42      abs       423:            $ignore = undef;
1.1       abs       424:            ++$entry_num;
1.42      abs       425:            $_ = $1;
1.28      abs       426:            if (! /^([-a-z0-9_.+,]+)\s+(.*)/)
1.20      abs       427:                { &fail("Invalid <ENTRY> ($_), not ([-a-z0-9_.+,]+)\s+(.*)"); }
1.42      abs       428:            $href = $1;
                    429:            $header = $2;
1.28      abs       430:            if (defined($tags{$href}))
1.2       abs       431:                { &fail("Duplicate name tag '$href'"); }
1.42      abs       432:            $tags{$href} = 1;
1.1       abs       433:
1.53      dent      434:            $_ = "<p><h3>\n$title_font".
                    435:                    "<a name=\"$href\">$header</a>$end_title_font\n".
                    436:                    "<font size=\"-1\">".
                    437:                    "(<a href=\"#top\">top</a>)</font>\n".
                    438:                    "</h3><dl><dt><dd>\n";
                    439:            $list .= "<li>$title_font\n<a href=\"#$href\">$header</a>".
                    440:                    "$end_title_font</li>\n";
1.29      abs       441:            $in_entry = $in_section = 1;
1.1       abs       442:            &verbose("\t$href\n");
                    443:            }
1.2       abs       444:
1.58      dent      445:        if (m#^<LISTLINK>\s*(.+\S)#)
1.1       abs       446:            {
1.29      abs       447:            if ( ! $in_section )
1.53      dent      448:                { $list .= "<ul>\n"; }  # Start title list
1.29      abs       449:
1.42      abs       450:            $ignore = undef;
1.1       abs       451:            ++$entry_num;
1.42      abs       452:            $_ = $1;
1.28      abs       453:            if (! m#^(\S+)\s+(.*)#)
1.58      dent      454:                { &fail("Invalid <LISTLINK> ($_), not (\S+)\s+(.*)"); }
1.42      abs       455:            $href = $1;
                    456:            $header = $2;
1.2       abs       457:            $_ = '';
1.58      dent      458:            $list .= "<li>$title_font\n<a href=\"$href\">$header</a>".
1.53      dent      459:                    "$end_title_font</li>\n";
1.29      abs       460:            $in_section = 1;
1.1       abs       461:            &verbose("\t$href\n");
                    462:            }
1.58      dent      463:
                    464:         if (m#^<ENTRYLINK>\s*(.+\S)#)
                    465:             {
                    466:             if ( ! $in_section )
                    467:                 { $list .= "<ul>\n"; }  # Start title list
                    468:
                    469:             if ($in_entry)
                    470:                 {
                    471:                 $data .= "</dd></dl>\n";
                    472:                 $in_entry = undef;
                    473:                 }
                    474:
                    475:             $ignore = undef;
                    476:             ++$entry_num;
                    477:             $_ = $1;
                    478:             if (! m#^(\S+)\s+(.*)#)
                    479:                 { &fail("Invalid <ENTRYLINK> ($_), not (\S+)\s+(.*)"); }
                    480:             $href = $1;
                    481:             $header = $2;
                    482:             $_ = "<p><h3>\n$title_font".
                    483:                     "<a href=\"$href\">$header</a>$end_title_font\n".
                    484:                     "<font size=\"-1\">".
                    485:                     "(<a href=\"#top\">top</a>)</font>\n".
                    486:                     "</h3><dl><dt><dd>\n";
                    487:             $list .= "<li>$title_font\n<a href=\"$href\">$header</a>".
                    488:                     "$end_title_font</li>\n";
                    489:             $in_entry = $in_section = 1;
                    490:             &verbose("\t$href\n");
                    491:             }
1.2       abs       492:
1.39      abs       493:        if (m#^<SECTION>\s*(.+\S)#)
1.1       abs       494:            {
1.2       abs       495:            if ($in_entry)
                    496:                {
1.53      dent      497:                $data .= "</dd></dl>\n";
1.42      abs       498:                $in_entry = undef;
1.2       abs       499:                }
1.7       abs       500:            else # In case no entries
                    501:                { $data =~ s#<hr>\n<h2>.*</h2><hr>\n*$##; }
1.42      abs       502:            $ignore = undef;
1.28      abs       503:            if (defined($section))
1.16      abs       504:                {
1.53      dent      505:                $list .= "</ul>\n";
1.42      abs       506:                $section = $1;
                    507:                $list .= "<h2>$section</h2>\n";
1.53      dent      508:                $list .= "<ul>\n";      # Start title list
1.16      abs       509:                }
                    510:            else
1.17      abs       511:                {       # If we have never seen <SECTION> remember top link!
1.42      abs       512:                $section = $1;
                    513:                $list .= "<h2><a name=\"top\">$section</a></h2>\n".
1.53      dent      514:                        "<ul>\n";
1.16      abs       515:                }
1.42      abs       516:            $_ = "<hr>\n<h2>$section</h2><hr>";
1.29      abs       517:            $in_section = 1;
1.1       abs       518:            &verbose("    $section\n");
1.11      abs       519:            }
1.39      abs       520:
                    521:        if (m#^<TROW>\s*(.*)#)
1.11      abs       522:            {
1.42      abs       523:            $_ = $1;
1.28      abs       524:            if (! m#^([^:]+:)\s+(.*)#)
1.11      abs       525:                { &fail("<TROW> should match ([^:]+:)\s+(.*)"); }
1.42      abs       526:            $ignore = undef;
1.39      abs       527:            $_ = "<tr><th valign=top align=right>$1</th>\n  <td>$2</td></tr>\n";
                    528:            $in_trow = 1;
                    529:            }
                    530:        elsif ($in_trow)
                    531:            {
                    532:            if (m#</table>#i)
                    533:                { $in_trow = 0; }
                    534:            else
                    535:                {                       # Append to last <TROW>
                    536:                substr($data, -11, 0) = ' '.&sub_external_links($_);
                    537:                $_ = '';
                    538:                }
1.1       abs       539:            }
1.2       abs       540:
1.39      abs       541:        if (m#^</LIST>#)
1.1       abs       542:            {
1.2       abs       543:            if ($in_entry)
                    544:                {
1.53      dent      545:                $data .= "</dd></dl>\n";
1.42      abs       546:                $in_entry = undef;
1.2       abs       547:                }
                    548:            if ($endlist)
1.39      abs       549:                { &fail("Duplicate </LIST>"); }
1.42      abs       550:            $endlist = 1;
                    551:            $ignore = undef;
                    552:            $_ = "<hr>\n";
1.1       abs       553:            }
1.2       abs       554:
1.28      abs       555:        if (! $ignore)
1.42      abs       556:            { $data .= &sub_external_links($_); }
1.1       abs       557:        }
                    558:
                    559:     close(FILE);
1.53      dent      560:     $list .= "</ul>\n";
1.2       abs       561:     if (!$endlist)
1.28      abs       562:        { &fail("Missing </LIST> tag"); }
1.2       abs       563:     if ($data !~ s/<LIST>/$list/)
1.1       abs       564:        { &fail("Unable to locate <LIST> tag"); }
1.42      abs       565:     $_ = "\n\n<!-- DO NOT EDIT THIS FILE. EDIT '$infile' AND RUN 'make' -->\n";
1.7       abs       566:     if ($data !~ s/(<head[^>]*>)/$1$_/i)
                    567:        { &fail("Unable to locate <head> tag"); }
                    568:
1.42      abs       569:     open(FILE, ">$outfile") || die("Unable to write '$outfile': $!");
                    570:     print FILE &extras_process($data, %extras);
1.1       abs       571:     close(FILE);
1.28      abs       572:     if ($date_num)
1.1       abs       573:        {
1.42      abs       574:        print "$date_num date entr", ($date_num == 1)?'y':'ies';
1.1       abs       575:        if ($date_num_used != $date_num)
                    576:            { print " ($date_num_used used)"; }
                    577:        print ".\n";
1.43      abs       578:        if (@date_links)
                    579:            {
1.63      dent      580:            print "First $list_date_links date links (for main index.html):\n",
1.43      abs       581:                                                                @date_links;
                    582:            }
1.1       abs       583:        }
1.28      abs       584:     if ($entry_num)
1.42      abs       585:        { print "$entry_num entr", ($entry_num == 1)?'y':'ies', ".\n"; }
1.1       abs       586:     }
                    587:
1.5       abs       588: sub sub_external_links
1.1       abs       589:     {
1.42      abs       590:     my($text) = @_;
1.1       abs       591:
1.44      abs       592:     # Man page references. As of 1.4 matches every page except '[' and 'w'.
                    593:     #
                    594:     $_ = $text;        # Output text include match string, so handle in sections
                    595:     $text = '';
1.64    ! dent      596:     while ( m#([a-zA-Z_][-\w.+]*[\w+])\((\d)\)# )
1.44      abs       597:        {
1.64    ! dent      598:        my($page, $section, $link);
1.44      abs       599:
1.64    ! dent      600:        ($page, $section) = ($1, $2);
1.44      abs       601:
1.64    ! dent      602:        $link = 'http://www.tac.eu.org/cgi-bin/man-cgi?';
1.1       abs       603:
1.64    ! dent      604:        $link .= "$page+$section";
1.44      abs       605:
                    606:        $text .= $` . "<a href=\"$link\">$page($section)</a>";
                    607:        $_ = $';
                    608:        }
                    609:     $text .= $_;
1.34      abs       610:
                    611:     # Expand <CURRENTSRC>path
                    612:     #
1.61      itojun    613:     while ($text =~ m#<CURRENTSRC>([^\s<>]+\w)#)
1.35      abs       614:        {
                    615:         my($path);
                    616:
                    617:        $path = $1;
1.36      abs       618:        $path =~ s#^/##;
1.37      abs       619:        $path =~ s#^usr/##;
                    620:        $path =~ s#^src/##;
1.36      abs       621:        if ($path =~ m#^(sys|share|gnu)#)
                    622:            { $path = $1."src/$path"; }
1.35      abs       623:        elsif ($path !~ m#^(doc|xsrc)#)
1.36      abs       624:            { $path = "basesrc/$path"; }
1.53      dent      625:        $text =~ s#<CURRENTSRC>([^\s<>]+\w)#<a href="http://cvsweb.netbsd.org/bsdweb.cgi/$path?rev=HEAD&amp;content-type=text/x-cvsweb-markup">$1</a>#;
1.35      abs       626:        }
1.38      abs       627:
                    628:     # Expand <URL>[^\s<]+[^<\s.]
                    629:     $text =~ s#<URL>([^\s<]+[^<\s.])#<a href="$1">$1</a>#g;
1.25      abs       630:
1.27      soren     631:     # Expand <PKGSRC>category/name entries
1.25      abs       632:     #
1.61      itojun    633:     while ($text =~ m#<PKGSRC>((\w+/|)([^\s<>]+\w))#)
1.31      abs       634:        {
                    635:         my($n) = $3;
                    636:        if (defined($pkgname{$n}))
                    637:            { $n = $pkgname{$n}; }
1.32      abs       638:         $text =~ s#<PKGSRC>((\w+/|)([^\s<>]+\w))#<a href="ftp://ftp.netbsd.org/pub/NetBSD/packages/pkgsrc/$1/README.html">$n</a>#;
1.61      itojun    639:        }
                    640:
                    641:     # Expand <RFC>RFCxxxx entries
                    642:     #
                    643:     while ($text =~ m#<RFC>([^\s<>]+\w)#)
                    644:        {
                    645:         my($o, $n);
                    646:        $o = $n = $1;
                    647:        $n =~ s#^rfc##i;
                    648:        if ($n =~ /^\d+$/)
                    649:            {
                    650:            $text =~ s#<RFC>$o#<a href="http://www.normos.org/ietf/rfc/rfc$n.txt">$o</a>#;
                    651:            }
                    652:            else
                    653:            {
                    654:            $text =~ s#<RFC>$o#$o#;
                    655:            }
1.31      abs       656:        }
1.25      abs       657:
1.10      abs       658:     # Expand <user@host> email addresses
                    659:     #
1.13      abs       660:     $text =~ s#<([-\w.]+@[-\w.]+)>#<a href="mailto:$1">&lt;$1&gt;</a>#g;
1.25      abs       661:
1.5       abs       662:     $text;
1.1       abs       663:     }
                    664:
                    665: sub verbose
                    666:     { $verbose && print @_; }
1.8       abs       667:
                    668: sub warn
1.42      abs       669:     { print "WARNING: ", @_; }

CVSweb <webmaster@jp.NetBSD.org>