<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#-*- perl -*-

## Copyright (C) 2000, 2001 R Development Core Team
##
## This program 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.
##
## Send any bug reports to r-bugs@r-project.org

use Getopt::Long;
use R::Rdtools;
use R::Utils;

my $revision = ' $Revision: 1.8 $ ';
my $version;
my $name;

$revision =~ / ([\d\.]*) /;
$version = $1;
($name = $0) =~ s|.*/||;

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

Extract usage information for use by codoc from the Rd source files
listed in FILE, writing results to OUT.

Options:
  -h, --help            print short help message and exit
  -v, --version         print version info and exit
      --mode=MODE       use operation mode MODE (codoc, args or style)
      --os=NAME         use OS subdir \`NAME\' (unix, mac or windows)
      --OS=NAME         the same as \`--os\'.

Email bug reports to &lt;r-bugs\@r-project.org&gt;.
END
  exit 0;
}

## &lt;FIXME&gt;
## Currently, R_OSTYPE is always set on Unix/Windows.
my $OSdir = R_getenv("R_OSTYPE", "mac");
## &lt;/FIXME&gt;
my $opt_mode = "codoc";
my $opt_v;

GetOptions("h|help"    =&gt; \&amp;usage,
	   "v|version" =&gt; \$opt_v,
	   "os|OS:s"   =&gt; \$OSdir,
	   "mode=s"    =&gt; \$opt_mode
	  ) or &amp;usage();

&amp;R_version($name, $version) if $opt_v;

open(INFILE, "&lt; $ARGV[0]") or die "Can't open input file";
open(OUTFILE, "&gt; $ARGV[1]") or die "Can't open output file";

while (&lt;INFILE&gt;) {
    chomp;
    open RDFILE, "&lt; $_";
    ## &lt;NOTE&gt;
    ## This is really dangerous ...
    my @chunks = split(/\\name/, &amp;Rdpp($_, $OSdir));
    ## &lt;/NOTE&gt;
    foreach my $text (@chunks) {
	next if($text !~ /^\s*{\s*([^}]*[^}\s])\s*}.*/);
	print OUTFILE "# usages in documentation object $1\n";
	print OUTFILE "# arglist: ", join(" ", get_arglist($text)), "\n"
	  unless ($opt_mode eq "codoc");

	## Put \name back in front as get_usages() needs it.  Could also
	## pass on the name we just determined ...
	$text = "\\name" . $text;

	{
	    local $/;		# unset for get_usages()
	    %usages = get_usages($text, $opt_mode);
	}

	foreach my $key (keys(%usages)){
	    $usages{$key} =~ s/ *\\.?dots/ .../g;
	    if ($key !~ /^&lt;/) {
		print OUTFILE "$key &lt;- function$usages{$key} NULL\n";
	    }
	}

	print OUTFILE "\n";
    }
}
</pre></body></html>