The R Project SVN R

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2195 hornik 1
#! @PERL@
2
 
11515 hornik 3
## Convert R documentation into HTML, LaTeX and text format
2195 hornik 4
 
5
# Copyright (C) 1997 Friedrich Leisch
28128 ripley 6
# Copyright (C) 2000-4 The R Core Development Team
2195 hornik 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 via WWW at
19
# http://www.gnu.org/copyleft/gpl.html.	 You can also obtain it by
5458 ripley 20
# writing to the Free Software Foundation, Inc., 59 Temple Place,
21
# Suite 330, Boston, MA  02111-1307  USA.
2195 hornik 22
 
11515 hornik 23
# Send any bug reports to r-bugs@r-project.org.
2195 hornik 24
 
25
use Getopt::Long;
10481 ripley 26
use R::Rdconv;
11515 hornik 27
use R::Utils;
19010 hornik 28
use R::Vars;
2195 hornik 29
 
29659 hornik 30
my $revision = ' $Revision: 1.27 $ ';
7380 hornik 31
my $version;
32
my $name;
7329 ripley 33
 
7380 hornik 34
$revision =~ / ([\d\.]*) /;
35
$version = $1;
36
($name = $0) =~ s|.*/||;
37
 
29659 hornik 38
## <NOTE>
25260 hornik 39
## Used in Rdconv.pm and Rdlists.pm via $main::OSdir, and hence must not
40
## be lexical.  Argh.
41
$OSdir = $R::Vars::OSTYPE;
29659 hornik 42
## </NOTE>
19010 hornik 43
 
44
my @knownoptions = ("debug|d", "type|t:s", "h|help", "v|version", 
45
		    "o|output:s", "os|OS=s" => \$OSdir);
46
GetOptions (@knownoptions) || &usage();
47
&R_version($name, $version) if $opt_v;
48
&usage() if $opt_h;
49
 
50
my $out = 0;
51
if(defined $opt_o) {
52
    if(length($opt_o)) {
53
	$out = $opt_o;
54
    }
55
    else {
56
	$out = $ARGV[0];
57
	$out =~ s/.Rd$//i;
58
    }
59
}
60
$out = 0 if $out eq "-";
61
 
62
my %types_and_exts = ("txt", "",
63
		      "html", ".html",
64
		      "latex", ".tex",		      
65
		      "Sd", ".d",
66
		      "Ssgm", ".sgml",
67
		      "example", ".R");
68
 
69
my $opt_type_ok = 0;
70
 
71
foreach my $type (keys(%types_and_exts)) {
72
    if($opt_type =~ /$type/i) {
73
	if(defined $opt_o && length($opt_o) == 0) {
74
	    $out .= $types_and_exts{$type};
75
	}
28128 ripley 76
	Rdconv($ARGV[0], $opt_type, $opt_debug, $out, "unknown");
19010 hornik 77
	$opt_type_ok = 1;
78
	last;
79
    }
80
}
81
 
82
if(!$opt_type_ok) {
83
    print STDERR "Unknown type: options are " .
84
	join(", ", sort(keys(%types_and_exts))) . ".\n";
85
}
86
 
7380 hornik 87
sub usage {
88
  print STDERR <<END;
8244 leisch 89
Usage: R CMD Rdconv [options] FILE
7380 hornik 90
 
91
Convert R documentation in FILE to other formats such as plain text,
92
HTML or LaTeX.
93
 
94
Options:
95
  -h, --help		print short help message and exit
31770 ripley 96
  -v, --version		print Rdconv version info and exit
7380 hornik 97
  -d, --debug		turn on debugging (increase verbosity)
98
  -t, --type=TYPE	convert to format TYPE
19010 hornik 99
  -o, --output=OUT	use 'OUT' as the output file
26719 ripley 100
      --os=NAME		use OS subdir 'NAME' (unix or windows)
19010 hornik 101
      --OS=NAME		the same as '--os'
7380 hornik 102
 
19010 hornik 103
Possible format specifications are 'txt' (plain text), 'html', 'latex',
104
'Sd' (old S documentation format), 'Ssgm' (new S documentation format),
105
and 'example' (extract R code in the examples).
9271 ripley 106
 
19010 hornik 107
The default is to send output to stdout, which is also given by '-o -'.
108
Using '-o ""' will choose an output filename by removing a '.Rd'
11515 hornik 109
extension from FILE and adding a suitable extension.
7380 hornik 110
 
10633 hornik 111
Email bug reports to <r-bugs\@r-project.org>.
7380 hornik 112
END
113
  exit 0;
114
}
115
 
19010 hornik 116
### Local Variables: ***
117
### mode: perl ***
118
### perl-indent-level: 4 ***
119
### End: ***