The R Project SVN R

Rev

Rev 11515 | Rev 14341 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2195 hornik 1
#! @PERL@
2
#-*- perl -*- (for Rdconv.in ..)
3
 
11515 hornik 4
## Convert R documentation into HTML, LaTeX and text format
2195 hornik 5
 
6
# Copyright (C) 1997 Friedrich Leisch
11515 hornik 7
# Copyright (C) 2000 The R Core Development Team
2195 hornik 8
#
9
# This program is free software; you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation; either version 2, or (at your option)
12
# any later version.
13
#
14
# This program is distributed in the hope that it will be useful, but
15
# WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the GNU
17
# General Public License for more details.
18
#
19
# A copy of the GNU General Public License is available via WWW at
20
# http://www.gnu.org/copyleft/gpl.html.	 You can also obtain it by
5458 ripley 21
# writing to the Free Software Foundation, Inc., 59 Temple Place,
22
# Suite 330, Boston, MA  02111-1307  USA.
2195 hornik 23
 
11515 hornik 24
# Send any bug reports to r-bugs@r-project.org.
2195 hornik 25
 
26
use Getopt::Long;
10481 ripley 27
use R::Rdconv;
11515 hornik 28
use R::Utils;
2195 hornik 29
 
11684 leisch 30
my $revision = ' $Revision: 1.19 $ ';
7380 hornik 31
my $version;
32
my $name;
7329 ripley 33
 
7380 hornik 34
$revision =~ / ([\d\.]*) /;
35
$version = $1;
36
($name = $0) =~ s|.*/||;
37
 
38
sub usage {
39
  print STDERR <<END;
8244 leisch 40
Usage: R CMD Rdconv [options] FILE
7380 hornik 41
 
42
Convert R documentation in FILE to other formats such as plain text,
43
HTML or LaTeX.
44
 
45
Options:
46
  -h, --help		print short help message and exit
47
  -v, --version		print version info and exit
48
  -d, --debug		turn on debugging (increase verbosity)
49
  -t, --type=TYPE	convert to format TYPE
11515 hornik 50
  -o, --output=OUT	use \`OUT\' as the output file
51
      --os=NAME		use OS subdir \`NAME\' (unix, mac or windows)
52
      --OS=NAME		the same as \`--os\'.
7380 hornik 53
 
11515 hornik 54
Possible format specifications are \`txt\' (plain text), \`html\',
55
\`latex\', \`Sd\' (S documentation format), and \`example\' (extract R
56
code in the examples).
9271 ripley 57
 
11515 hornik 58
The default is to send output to stdout, which is also given by \`-o -\'.
59
Using \`-o \"\"\' will choose an output filename by removing a \`.Rd\'
60
extension from FILE and adding a suitable extension.
7380 hornik 61
 
10633 hornik 62
Email bug reports to <r-bugs\@r-project.org>.
7380 hornik 63
END
64
  exit 0;
65
}
66
 
9940 pd 67
$OSdir ="unix";
7380 hornik 68
 
9271 ripley 69
@knownoptions = ("debug|d", "type|t:s", "h|help", "v|version", 
11515 hornik 70
		 "o|output:s", "os|OS:s");
7380 hornik 71
GetOptions (@knownoptions) || &usage();
11515 hornik 72
&R_version($name, $version) if $opt_v;
7380 hornik 73
&usage() if $opt_h;
2195 hornik 74
 
7329 ripley 75
$OSdir = $opt_os if $opt_os;
9271 ripley 76
$out = 0;
77
if(defined $opt_o) {
78
    if(length($opt_o)) { $out = $opt_o; }
11684 leisch 79
    else { $out = $ARGV[0]; $out =~ s/.Rd$//i; }
9271 ripley 80
}
81
$out = 0 if $out eq "-";
7329 ripley 82
 
2195 hornik 83
usage() if $opt_help;
84
 
85
if($opt_type =~ /html/i){
9271 ripley 86
    if(defined $opt_o && length($opt_o) == 0) { $out = $out . ".html"; }
87
    Rdconv($ARGV[0],$opt_type,$opt_debug, $out);
2195 hornik 88
}
7304 ripley 89
elsif($opt_type =~ /txt/i){
9271 ripley 90
    Rdconv($ARGV[0],$opt_type,$opt_debug, $out);
7304 ripley 91
}
2195 hornik 92
elsif($opt_type =~ /Sd/i){
9271 ripley 93
    if(defined $opt_o && length($opt_o) == 0) { $out = $out . ".d"; }
94
    Rdconv($ARGV[0],$opt_type,$opt_debug, $out);
2195 hornik 95
}
96
elsif($opt_type =~ /latex/i){
9271 ripley 97
    if(defined $opt_o && length($opt_o) == 0) { $out = $out . ".tex"; }
98
    Rdconv($ARGV[0],$opt_type,$opt_debug, $out);
2195 hornik 99
}
9271 ripley 100
elsif($opt_type =~ /example/i){
101
    if(defined $opt_o && length($opt_o) == 0) { $out = $out . ".R"; }
102
    Rdconv($ARGV[0],$opt_type,$opt_debug, $out);
103
} else {
104
    print STDERR "Unknown type: options are txt, html, latex, Sd, example\n";
2281 maechler 105
}