-
Notifications
You must be signed in to change notification settings - Fork 315
/
Rdconv.in
119 lines (99 loc) · 3.16 KB
/
Rdconv.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
#! @PERL@
## Convert R documentation into HTML, LaTeX and text format
# Copyright (C) 1997 Friedrich Leisch
# Copyright (C) 2000, 2002 The R Core Development 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::Rdconv;
use R::Utils;
use R::Vars;
my $revision = ' $Revision: 1.24 $ ';
my $version;
my $name;
$revision =~ / ([\d\.]*) /;
$version = $1;
($name = $0) =~ s|.*/||;
## <FIXME>
## Used in Rdconv.pm and Rdlists.pm via $main::OSdir, and hence must not
## be lexical. Argh.
$OSdir = $R::Vars::OSTYPE;
## </FIXME>
my @knownoptions = ("debug|d", "type|t:s", "h|help", "v|version",
"o|output:s", "os|OS=s" => \$OSdir);
GetOptions (@knownoptions) || &usage();
&R_version($name, $version) if $opt_v;
&usage() if $opt_h;
my $out = 0;
if(defined $opt_o) {
if(length($opt_o)) {
$out = $opt_o;
}
else {
$out = $ARGV[0];
$out =~ s/.Rd$//i;
}
}
$out = 0 if $out eq "-";
my %types_and_exts = ("txt", "",
"html", ".html",
"latex", ".tex",
"Sd", ".d",
"Ssgm", ".sgml",
"example", ".R");
my $opt_type_ok = 0;
foreach my $type (keys(%types_and_exts)) {
if($opt_type =~ /$type/i) {
if(defined $opt_o && length($opt_o) == 0) {
$out .= $types_and_exts{$type};
}
Rdconv($ARGV[0], $opt_type, $opt_debug, $out);
$opt_type_ok = 1;
last;
}
}
if(!$opt_type_ok) {
print STDERR "Unknown type: options are " .
join(", ", sort(keys(%types_and_exts))) . ".\n";
}
sub usage {
print STDERR <<END;
Usage: R CMD Rdconv [options] FILE
Convert R documentation in FILE to other formats such as plain text,
HTML or LaTeX.
Options:
-h, --help print short help message and exit
-v, --version print version info and exit
-d, --debug turn on debugging (increase verbosity)
-t, --type=TYPE convert to format TYPE
-o, --output=OUT use 'OUT' as the output file
--os=NAME use OS subdir 'NAME' (unix, mac or windows)
--OS=NAME the same as '--os'
Possible format specifications are 'txt' (plain text), 'html', 'latex',
'Sd' (old S documentation format), 'Ssgm' (new S documentation format),
and 'example' (extract R code in the examples).
The default is to send output to stdout, which is also given by '-o -'.
Using '-o ""' will choose an output filename by removing a '.Rd'
extension from FILE and adding a suitable extension.
Email bug reports to <r-bugs\@r-project.org>.
END
exit 0;
}
### Local Variables: ***
### mode: perl ***
### perl-indent-level: 4 ***
### End: ***