The R Project SVN R

Rev

Rev 26719 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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