The R Project SVN R

Rev

Rev 47602 | Rev 49122 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 47602 Rev 49121
Line 1... Line 1...
1
#! @PERL@
1
# ${R_HOME}/bin/Rdconv -*- sh -*- for installing add-on packages
2
 
2
 
-
 
3
args=
-
 
4
while test -n "${1}"; do
3
## Convert R documentation into HTML, LaTeX and text format
5
  ## quote each argument here, unquote in R code.
-
 
6
  args="${args}nextArg${1}"
-
 
7
  shift
-
 
8
done
4
 
9
 
5
# Copyright (C) 1997 Friedrich Leisch
-
 
6
# Copyright (C) 2000-8 The R Core Development Team
-
 
7
#
-
 
8
# This program is free software; you can redistribute it and/or modify
-
 
9
# it under the terms of the GNU General Public License as published by
-
 
10
# the Free Software Foundation; either version 2, or (at your option)
-
 
11
# any later version.
-
 
12
#
-
 
13
# This program is distributed in the hope that it will be useful, but
-
 
14
# WITHOUT ANY WARRANTY; without even the implied warranty of
-
 
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the GNU
-
 
16
# General Public License for more details.
-
 
17
#
-
 
18
# A copy of the GNU General Public License is available at
10
## NB: Apple's ICU needs LC_COLLATE set when R is started.
19
# http://www.r-project.org/Licenses/
-
 
20
 
-
 
21
# Send any bug reports to r-bugs@r-project.org.
-
 
22
 
-
 
23
use Getopt::Long;
-
 
24
use R::Rdconv;
-
 
25
use R::Utils;
-
 
26
use R::Vars;
-
 
27
 
-
 
28
my $revision = ' $Rev: 47602 $ ';
-
 
29
my $version;
-
 
30
my $name;
-
 
31
 
-
 
32
## switch on autoflushing for STDOUT.  We want this as we
-
 
33
## write to both STDERR (warnings) and STDOUT.
-
 
34
$| = 1;
-
 
35
 
-
 
36
$revision =~ / ([\d\.]*) /;
-
 
37
$version = $1;
-
 
38
($name = $0) =~ s|.*/||;
-
 
39
 
-
 
40
## <NOTE>
-
 
41
## Used in Rdconv.pm and Rdlists.pm via $main::OSdir, and hence must not
11
echo 'tools:::.Rdconv()' | R_DEFAULT_PACKAGES= LC_COLLATE=C "${R_HOME}/bin/R" --vanilla --slave --args ${args}
42
## be lexical.  Argh.
-
 
43
$OSdir = $R::Vars::OSTYPE;
-
 
44
## </NOTE>
-
 
45
 
-
 
46
my @knownoptions = ("debug|d", "type|t:s", "h|help", "v|version",
-
 
47
		    "o|output:s", "os|OS=s" => \$OSdir, "encoding=s",
-
 
48
		    "package=s", "version=s");
-
 
49
GetOptions (@knownoptions) || &usage();
-
 
50
&R_version($name, $version) if $opt_v;
-
 
51
&usage() if $opt_h;
-
 
52
 
-
 
53
my $out = 0;
-
 
54
if(defined $opt_o) {
-
 
55
    if(length($opt_o)) {
-
 
56
	$out = $opt_o;
-
 
57
    }
-
 
58
    else {
-
 
59
	$out = $ARGV[0];
-
 
60
	$out =~ s/.Rd$//i;
-
 
61
    }
-
 
62
}
-
 
63
$out = 0 if $out eq "-";
-
 
64
my $enc = "unknown";
-
 
65
$enc = $opt_encoding if $opt_encoding;
-
 
66
my $pkg = "unknown";
-
 
67
$pkg = $opt_package if $opt_package;
-
 
68
my $ver = "";
-
 
69
$ver = $opt_version if $opt_version;
-
 
70
 
-
 
71
my %types_and_exts = ("txt", "",
-
 
72
		      "html", ".html",
-
 
73
		      "latex", ".tex",
-
 
74
		      "example", ".R");
-
 
75
 
-
 
76
my $opt_type_ok = 0;
-
 
77
 
-
 
78
foreach my $type (keys(%types_and_exts)) {
-
 
79
    if($opt_type =~ /$type/i) {
-
 
80
	if(defined $opt_o && length($opt_o) == 0) {
-
 
81
	    $out .= $types_and_exts{$type};
-
 
82
	}
-
 
83
	Rdconv($ARGV[0], $opt_type, $opt_debug, $out, $pkg, $ver, $enc);
-
 
84
	$opt_type_ok = 1;
-
 
85
	last;
-
 
86
    }
-
 
87
}
-
 
88
 
-
 
89
if(!$opt_type_ok) {
-
 
90
    print STDERR "Unknown type: options are " .
-
 
91
	join(", ", sort(keys(%types_and_exts))) . ".\n";
-
 
92
}
-
 
93
 
-
 
94
sub usage {
-
 
95
  print <<END;
-
 
96
Usage: R CMD Rdconv [options] FILE
-
 
97
 
-
 
98
Convert R documentation in FILE to other formats such as plain text,
-
 
99
HTML or LaTeX.
-
 
100
 
-
 
101
Options:
-
 
102
  -h, --help		print short help message and exit
-
 
103
  -v, --version		print version info and exit
-
 
104
  -d, --debug		turn on debugging (increase verbosity)
-
 
105
  -t, --type=TYPE	convert to format TYPE
-
 
106
  --encoding=enc        use 'enc' as the default encoding
-
 
107
  --package=pkg         use 'pkg' as the package name
-
 
108
  --version=version     use 'version' as the package version
-
 
109
  -o, --output=OUT	use 'OUT' as the output file
-
 
110
      --os=NAME		use OS subdir 'NAME' (unix or windows)
-
 
111
      --OS=NAME		the same as '--os'
-
 
112
 
-
 
113
Possible format specifications are 'txt' (plain text), 'html', 'latex',
-
 
114
and 'example' (extract R code in the examples).
-
 
115
 
-
 
116
The default is to send output to stdout, which is also given by '-o -'.
-
 
117
Using '-o ""' will choose an output filename by removing a '.Rd'
-
 
118
extension from FILE and adding a suitable extension.
-
 
119
 
-
 
120
Report bugs to <r-bugs\@r-project.org>.
-
 
121
END
-
 
122
  exit 0;
-
 
123
}
-
 
124
 
-
 
125
### Local Variables: ***
-
 
126
### mode: perl ***
-
 
127
### perl-indent-level: 4 ***
-
 
128
### End: ***
-