The R Project SVN R

Rev

Rev 18013 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 18013 Rev 19010
Line 1... Line 1...
1
#! @PERL@
1
#! @PERL@
2
#-*- perl -*- (for Rdconv.in ..)
-
 
3
 
2
 
4
## Convert R documentation into HTML, LaTeX and text format
3
## Convert R documentation into HTML, LaTeX and text format
5
 
4
 
6
# Copyright (C) 1997 Friedrich Leisch
5
# Copyright (C) 1997 Friedrich Leisch
7
# Copyright (C) 2000 The R Core Development Team
6
# Copyright (C) 2000, 2002 The R Core Development Team
8
#
7
#
9
# This program is free software; you can redistribute it and/or modify
8
# 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
9
# 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)
10
# the Free Software Foundation; either version 2, or (at your option)
12
# any later version.
11
# any later version.
Line 24... Line 23...
24
# Send any bug reports to r-bugs@r-project.org.
23
# Send any bug reports to r-bugs@r-project.org.
25
 
24
 
26
use Getopt::Long;
25
use Getopt::Long;
27
use R::Rdconv;
26
use R::Rdconv;
28
use R::Utils;
27
use R::Utils;
-
 
28
use R::Vars;
29
 
29
 
30
my $revision = ' $Revision: 1.22 $ ';
30
my $revision = ' $Revision: 1.23 $ ';
31
my $version;
31
my $version;
32
my $name;
32
my $name;
33
 
33
 
34
$revision =~ / ([\d\.]*) /;
34
$revision =~ / ([\d\.]*) /;
35
$version = $1;
35
$version = $1;
36
($name = $0) =~ s|.*/||;
36
($name = $0) =~ s|.*/||;
37
 
37
 
-
 
38
## <NOTE>
-
 
39
## Used in Rdconv.pm and Rdlists.pm ...
-
 
40
my $OSdir = $R::Vars::OSTYPE;
-
 
41
## </NOTE>
-
 
42
 
-
 
43
my @knownoptions = ("debug|d", "type|t:s", "h|help", "v|version", 
-
 
44
		    "o|output:s", "os|OS=s" => \$OSdir);
-
 
45
GetOptions (@knownoptions) || &usage();
-
 
46
&R_version($name, $version) if $opt_v;
-
 
47
&usage() if $opt_h;
-
 
48
 
-
 
49
my $out = 0;
-
 
50
if(defined $opt_o) {
-
 
51
    if(length($opt_o)) {
-
 
52
	$out = $opt_o;
-
 
53
    }
-
 
54
    else {
-
 
55
	$out = $ARGV[0];
-
 
56
	$out =~ s/.Rd$//i;
-
 
57
    }
-
 
58
}
-
 
59
$out = 0 if $out eq "-";
-
 
60
 
-
 
61
my %types_and_exts = ("txt", "",
-
 
62
		      "html", ".html",
-
 
63
		      "latex", ".tex",		      
-
 
64
		      "Sd", ".d",
-
 
65
		      "Ssgm", ".sgml",
-
 
66
		      "example", ".R");
-
 
67
 
-
 
68
my $opt_type_ok = 0;
-
 
69
 
-
 
70
foreach my $type (keys(%types_and_exts)) {
-
 
71
    if($opt_type =~ /$type/i) {
-
 
72
	if(defined $opt_o && length($opt_o) == 0) {
-
 
73
	    $out .= $types_and_exts{$type};
-
 
74
	}
-
 
75
	Rdconv($ARGV[0], $opt_type, $opt_debug, $out);
-
 
76
	$opt_type_ok = 1;
-
 
77
	last;
-
 
78
    }
-
 
79
}
-
 
80
 
-
 
81
if(!$opt_type_ok) {
-
 
82
    print STDERR "Unknown type: options are " .
-
 
83
	join(", ", sort(keys(%types_and_exts))) . ".\n";
-
 
84
}
-
 
85
 
38
sub usage {
86
sub usage {
39
  print STDERR <<END;
87
  print STDERR <<END;
40
Usage: R CMD Rdconv [options] FILE
88
Usage: R CMD Rdconv [options] FILE
41
 
89
 
42
Convert R documentation in FILE to other formats such as plain text,
90
Convert R documentation in FILE to other formats such as plain text,
Line 45... Line 93...
45
Options:
93
Options:
46
  -h, --help		print short help message and exit
94
  -h, --help		print short help message and exit
47
  -v, --version		print version info and exit
95
  -v, --version		print version info and exit
48
  -d, --debug		turn on debugging (increase verbosity)
96
  -d, --debug		turn on debugging (increase verbosity)
49
  -t, --type=TYPE	convert to format TYPE
97
  -t, --type=TYPE	convert to format TYPE
50
  -o, --output=OUT	use \`OUT\' as the output file
98
  -o, --output=OUT	use 'OUT' as the output file
51
      --os=NAME		use OS subdir \`NAME\' (unix, mac or windows)
99
      --os=NAME		use OS subdir 'NAME' (unix, mac or windows)
52
      --OS=NAME		the same as \`--os\'.
100
      --OS=NAME		the same as '--os'
53
 
101
 
54
Possible format specifications are \`txt\' (plain text), \`html\',
102
Possible format specifications are 'txt' (plain text), 'html', 'latex',
55
\`latex\', \`Sd\' (old S documentation format), \`Ssgm\' 
103
'Sd' (old S documentation format), 'Ssgm' (new S documentation format),
56
(new S documentation format) and \`example\' (extract R code in the examples).
104
and 'example' (extract R code in the examples).
57
 
105
 
58
The default is to send output to stdout, which is also given by \`-o -\'.
106
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\'
107
Using '-o ""' will choose an output filename by removing a '.Rd'
60
extension from FILE and adding a suitable extension.
108
extension from FILE and adding a suitable extension.
61
  
109
  
62
Email bug reports to <r-bugs\@r-project.org>.
110
Email bug reports to <r-bugs\@r-project.org>.
63
END
111
END
64
  exit 0;
112
  exit 0;
65
}
113
}
66
 
114
 
67
## <FIXME>
-
 
68
## Currently, R_OSTYPE is always set on Unix/Windows.
-
 
69
my $OSdir = R_getenv("R_OSTYPE", "mac");
-
 
70
## </FIXME>
-
 
71
 
-
 
72
@knownoptions = ("debug|d", "type|t:s", "h|help", "v|version", 
-
 
73
		 "o|output:s", "os|OS:s");
115
### Local Variables: ***
74
GetOptions (@knownoptions) || &usage();
-
 
75
&R_version($name, $version) if $opt_v;
-
 
76
&usage() if $opt_h;
-
 
77
 
-
 
78
$OSdir = $opt_os if $opt_os;
-
 
79
$out = 0;
-
 
80
if(defined $opt_o) {
116
### mode: perl ***
81
    if(length($opt_o)) { $out = $opt_o; }
-
 
82
    else { $out = $ARGV[0]; $out =~ s/.Rd$//i; }
-
 
83
}
-
 
84
$out = 0 if $out eq "-";
117
### perl-indent-level: 4 ***
85
 
-
 
86
usage() if $opt_help;
-
 
87
 
-
 
88
if($opt_type =~ /html/i){
-
 
89
    if(defined $opt_o && length($opt_o) == 0) { $out = $out . ".html"; }
-
 
90
    Rdconv($ARGV[0],$opt_type,$opt_debug, $out);
-
 
91
}
-
 
92
elsif($opt_type =~ /txt/i){
-
 
93
    Rdconv($ARGV[0],$opt_type,$opt_debug, $out);
-
 
94
}
-
 
95
elsif($opt_type =~ /Sd/i){
-
 
96
    if(defined $opt_o && length($opt_o) == 0) { $out = $out . ".d"; }
-
 
97
    Rdconv($ARGV[0],$opt_type,$opt_debug, $out);
-
 
98
}
-
 
99
elsif($opt_type =~ /Ssgm/i){
-
 
100
    if(defined $opt_o && length($opt_o) == 0) { $out = $out . ".sgml"; }
-
 
101
    Rdconv($ARGV[0],$opt_type,$opt_debug, $out);
-
 
102
}
-
 
103
elsif($opt_type =~ /latex/i){
-
 
104
    if(defined $opt_o && length($opt_o) == 0) { $out = $out . ".tex"; }
-
 
105
    Rdconv($ARGV[0],$opt_type,$opt_debug, $out);
-
 
106
}
-
 
107
elsif($opt_type =~ /example/i){
-
 
108
    if(defined $opt_o && length($opt_o) == 0) { $out = $out . ".R"; }
-
 
109
    Rdconv($ARGV[0],$opt_type,$opt_debug, $out);
-
 
110
} else {
118
### End: ***
111
    print STDERR "Unknown type: options are txt, html, latex, Sd, example\n";
-
 
112
}
-