/
Rdindex.in
147 lines (126 loc) · 3.62 KB
/
Rdindex.in
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
#! @PERL@
# Extract R object INDEX information from Rd files.
# Usage: R CMD Rdindex [options] files
# The titles are nicely formatted between two columns (defaults are 25
# and 72, respectively).
# Copyright (C) 1997-2000 The R Core Development 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 Getopt::Long;
use R::Utils;
use R::Rd;
my $revision = ' $Revision: 1.10.2.1 $ ';
my $version;
my $name;
$revision =~ / ([\d\.]*) /;
$version = $1;
($name = $0) =~ s|.*/||;
sub usage {
print STDERR <<END;
Usage: R CMD Rdindex [options] FILES
Create an index table from the R documentation sources specified by
FILES, by either giving the paths to the files, or the path to a
directory with the sources of a package. The titles are nicely
formatted between two column positions (defaults are 25 and 72,
respectively).
Options:
-h, --help print short help message and exit
-v, --version print version info and exit
-l, --left=X make X the left column for title formatting
-r, --right=Y make Y the right column for title formatting
-d, --data include only data documentation files if a
directory was specified
--os=NAME use OS subdir \`NAME\' (unix, mac or windows)
--OS=NAME the same as \`--os\'.
Email bug reports to <r-bugs\@r-project.org>.
END
exit 0;
}
my $OSdir = "unix";
my @knownoptions = ("h|help", "v|version", "l|left=s", "r|right=s",
"d|data", "os|OS:s");
GetOptions(@knownoptions) || &usage();
&R_version($name, $version) if $opt_v;
&usage() if $opt_h;
$opt_l = 25 unless $opt_l;
$opt_r = 72 unless $opt_r;
$OSdir = $opt_os if $opt_os;
my $l1 = $opt_l - 2;
my $l2 = $opt_r - $opt_l;
my $cmd = "format short =\n";
$cmd .= "@" . rep("<", $l1) . " ^" . rep("<", $l2) . "\n";
$cmd .= "\$name, \$desc\n";
$cmd .= ".\n";
eval($cmd);
$cmd = "format long =\n";
$cmd .= "@" . rep("<", $opt_r) . "\n";
$cmd .= "\$name\n";
$cmd .= ".\n";
eval($cmd);
$cmd = "format cont =\n";
$cmd .= "~" . rep(" ", $l1) . " ^" . rep("<", $l2) . "\n";
$cmd .= "\$desc\n";
$cmd .= ".\n";
eval($cmd);
my $dir;
if ($#ARGV == 0 && -d $ARGV[0]) {
$dir = $ARGV[0];
if (-d "$dir/man") {
$dir = "$dir/man";
}
@Rdfiles = sort(glob("$dir/*.[Rr]d"), glob("$dir/$OSdir/*.[Rr]d"));
if ($opt_d) {
my @tmp = ();
foreach $f (@Rdfiles) {
@tmp = (@tmp, `grep -l '\\\\keyword{datasets}' $f`);
}
@Rdfiles = @tmp;
}
} else {
@Rdfiles = ();
foreach $arg (@ARGV) {
@Rdfiles = (@Rdfiles, glob($arg));
}
}
undef $/;
foreach $file (@Rdfiles) {
my $rdinfo = R::Rd->info($file);
$name = $rdinfo->{"name"};
my $l = length($name);
if ($l <= $l1) {
$~ = short;
}
else {
$~ = long;
}
$desc = $rdinfo->{"title"};
write;
$~ = cont;
while ($desc) {
write;
}
}
sub rep {
my $retval = "";
for($k=0; $k<$_[1]; $k++) {
$retval .= $_[0];
}
$retval;
}
### Local Variables: ***
### mode: perl ***
### perl-indent-level: 4 ***
### End: ***