The R Project SVN R

Rev

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

Rev 7222 Rev 7357
Line 1... Line 1...
1
#! @PERL@
1
#! @PERL@
-
 
2
#
-
 
3
# ${R_HOME}/bin/Sd2Rd for converting S documentation to Rd format
2
 
4
 
3
# Convert S documentation to R documentation format
-
 
4
# Usage: Sd2Rd [-n] [-x] file
-
 
5
# The option `-x' makes the program greedily interpret all single-quoted
-
 
6
# names intended as code names.
-
 
7
# The option `-n' renders examples non-executable by wrapping them into
-
 
8
# a \dontrun{} environment.
-
 
9
 
-
 
10
# Copyright (C) 1997, 1998, 1999 Kurt Hornik
5
# Copyright (C) 1997, 1998, 1999, 2000 Kurt Hornik
11
#
6
#
12
# This document is free software; you can redistribute it and/or modify
7
# This document is free software; you can redistribute it and/or modify
13
# it under the terms of the GNU General Public License as published by
8
# it under the terms of the GNU General Public License as published by
14
# the Free Software Foundation; either version 2, or (at your option)
9
# the Free Software Foundation; either version 2, or (at your option)
15
# any later version.
10
# any later version.
Line 22... Line 17...
22
# A copy of the GNU General Public License is available via WWW at
17
# A copy of the GNU General Public License is available via WWW at
23
# http://www.gnu.org/copyleft/gpl.html.  You can also obtain it by
18
# http://www.gnu.org/copyleft/gpl.html.  You can also obtain it by
24
# writing to the Free Software Foundation, Inc., 59 Temple Place,
19
# writing to the Free Software Foundation, Inc., 59 Temple Place,
25
# Suite 330, Boston, MA  02111-1307  USA.
20
# Suite 330, Boston, MA  02111-1307  USA.
26
 
21
 
27
# Bug reports to Kurt.Hornik@ci.tuwien.ac.at
22
use Getopt::Long;
28
 
23
 
29
$REVISION = '$Revision: 1.5 $';
24
my $revision = ' $Revision: 1.6 $ ';
-
 
25
my $version;
-
 
26
my $name;
-
 
27
 
30
$REVISION =~ / ([\d\.]*) /;
28
$revision =~ / ([\d\.]*) /;
31
$VERSION = $1;
29
$version = $1;
32
($NAME = $0) =~ s|.*/||;
30
($name = $0) =~ s|.*/||;
33
 
31
 
34
$\ = "\n";
32
sub version {
35
 
-
 
36
$braceLevel = 0;
33
  print STDERR <<END;
37
$inVerbatim = 0;
34
Sd2Rd $version
38
$inSeeAlso = 0;
35
Copyright (C) 1997-2000 Kurt Hornik.
-
 
36
This is free software; see the GNU General Public Licence version 2
39
$doprint = 1;
37
or later for copying conditions.  There is NO warranty.    
40
$needArg = 1;
38
END
41
$needVal = 0;
39
  exit 0;
42
$output = "";
40
}
43
 
41
 
-
 
42
sub usage {
-
 
43
  print STDERR <<END;
44
use Getopt::Long;
44
Usage: $name [options] FILE
-
 
45
 
-
 
46
Convert S documentation in FILE to R documentation format.
-
 
47
 
-
 
48
Options:
-
 
49
  -h, --help		print short help message and exit
-
 
50
  -v, --version		print version info and exit
-
 
51
  -n			render examples non-executable by wrapping them
-
 
52
			into a \\dontrun{} environment
-
 
53
  -x			interpret all single-quoted names as code names
-
 
54
 
-
 
55
Email bug reports to <r-bugs\@lists.r-project.org>.
-
 
56
END
-
 
57
  exit 0; 
-
 
58
}
-
 
59
 
45
GetOptions(("n", "x")) || &usage();
60
GetOptions(("v|version", "h|help", "n", "x")) || &usage();
-
 
61
&version() if $opt_v;
-
 
62
&usage() if $opt_h;
-
 
63
 
-
 
64
my $braceLevel = 0;
-
 
65
my $inVerbatim = 0;
-
 
66
my $inSeeAlso = 0;
-
 
67
my $doprint = 1;
-
 
68
my $needArg = 1;
-
 
69
my $needVal = 0;
-
 
70
my $output = "";
46
 
71
 
47
while (<>) {
72
while (<>) {
48
  chop;
73
  chop;
49
  &substitute unless /^\./;
74
  &substitute unless /^\./;
50
  @word = split;
75
  my @word = split;
51
  
76
  
52
  if (/^\s*$/) { &output("\n"); }
77
  if (/^\s*$/) { &output("\n"); }
53
  if (/^[^.]/) { &output($_); }
78
  if (/^[^.]/) { &output($_); }
54
 
79
 
55
  ## Added by BDR 1998/08/27
80
  ## Added by BDR 1998/08/27
Line 219... Line 244...
219
    s/\`([^\']*)\'/\\code{$1}/g;
244
    s/\`([^\']*)\'/\\code{$1}/g;
220
  }
245
  }
221
}
246
}
222
 
247
 
223
sub section {
248
sub section {
224
  local($level, $text) = @_;
249
  my($level, $text) = @_;
225
  $n = $braceLevel - $level;
250
  $n = $braceLevel - $level;
226
  print("\}" x $n) if ($n > 0);
251
  print("\}" x $n) if ($n > 0);
227
  if ($needVal) {
252
  if ($needVal) {
228
    print("\\value\{\n$output\n\}");
253
    print("\\value\{\n$output\n\}");
229
    $needVal = 0;
254
    $needVal = 0;
Line 234... Line 259...
234
  $inSeeAlso = 0;
259
  $inSeeAlso = 0;
235
  $doprint = 1;    
260
  $doprint = 1;    
236
}
261
}
237
 
262
 
238
sub paragraph {
263
sub paragraph {
239
  local($name) = @_;
264
  my($name) = @_;
240
  &output("\n\\bold\{$name.\} ");
265
  &output("\n\\bold\{$name.\} ");
241
}
266
}
242
    
267
    
243
sub output {
268
sub output {
244
  local($text) = @_;
269
  my($text) = @_;
245
  if ($doprint) {
270
  if ($doprint) {
246
    print($text);
271
    print($text);
247
  } elsif ($output) {
272
  } elsif ($output) {
248
    $output .= "\n$text";
273
    $output .= "\n$text";
249
  } else {
274
  } else {
250
    $output = $text;
275
    $output = $text;
251
  }
276
  }
252
}
277
}
253
 
278
 
254
sub usage {
-
 
255
  print("\n$NAME version $VERSION\n\nusage:  $NAME [-n] [-x] file\n");
-
 
256
  print("options:");
-
 
257
  print("  -x      interpret all single-quoted names as code names");
-
 
258
  print("  -n      render examples non-executable");
-
 
259
  exit;
-
 
260
}
-
 
261
 
-
 
262
### Local Variables: ***
279
### Local Variables: ***
263
### mode: perl ***
280
### mode: perl ***
264
### perl-indent-level: 2 ***
281
### perl-indent-level: 2 ***
265
### End: ***
282
### End: ***