<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># Copyright (C) 1997-2002 R Development Core Team
#
# This document is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# A copy of the GNU General Public License is available via WWW at
# http://www.gnu.org/copyleft/gpl.html.  You can also obtain it by
# writing to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA  02111-1307  USA.

use File::Basename;
use Getopt::Long;
use R::Rd;
use R::Rdtools;
use R::Utils;
use R::Vars;

my $OS_type = $R::Vars::OSTYPE;

my @known_options = ("o|output:s", "os|OS:s");
GetOptions (@known_options) || &amp;usage();

$OS_type = $opt_os if $opt_os;

my $out = 0;
$out = $opt_o if(defined $opt_o &amp;&amp; length($opt_o));

my $pkg;

$ARGV[0] =~ /([^\/]*)$/;
$pkg = $1;


my $outfile;
if($out) {
    open(OUTFILE, "&gt; $out") or die "Cannot write to '$out'";
    $outfile = OUTFILE;
} else {
    $outfile = STDOUT;
}

my @Rdfiles =
    &amp;list_files_with_type(&amp;file_path($ARGV[0], "man"),
			  "docs",
			  $OS_type);

foreach my $rdfile (@Rdfiles) {
    my $file = basename($rdfile, (".Rd", ".rd"));
    my $rdinfo = R::Rd-&gt;info($rdfile, $OS_type);
    print $outfile "Entry: " . $rdinfo-&gt;{"name"} . "\n";
    print $outfile "Aliases: " .
	join(" ", @{$rdinfo-&gt;{"aliases"}}) . "\n";
    print $outfile "Keywords: " .
	join(" ", @{$rdinfo-&gt;{"keywords"}}) . "\n";
    print $outfile "Description: " . $rdinfo-&gt;{"title"} . "\n";

    ## &lt;FIXME&gt;
    ## This has extension 'html' hard-wired.
    print $outfile "URL: ../../../library/$pkg/html/$file.html\n\n";
    ## &lt;/FIXME&gt;
}


sub usage {
  print STDERR &lt;&lt;END;
Usage: [R CMD] perl /path/to/Rd2contents.pl [options] FILE

Prepare the CONTENTS file for a directory.

Options:
  -o, --output=OUT	use 'OUT' as the output file
      --os=NAME		use OS type 'NAME' (unix, mac or windows)
      --OS=NAME		the same as '--os'.
END
  exit 0;
}
</pre></body></html>