Attached is another update.
New features/bugs:
*) now also attempts to get non-quoted object names within SEEALSO
sections to have a LANG(LINK(...)) around them
*) parentheses are now ALWAYS quoted, to prevent the rdoc2... scripts
from choking on unbalanced ones (e.g., "x in the range (0, 1]")
*) blank lines are mapped into PARA so that e.g. reference sections come
out better
*) comments are mapped into comments :-)
Please have a try.
-k
************************************************************************
#!/usr/bin/perl -w
$VERSION = "0.1-1";
$\ = "\n";
$parenLevel = 0;
$inSeeAlso = 0;
$doprint = 1;
$needArg = 1;
$needVal = 0;
$output = "";
while (<>) {
chop;
&substitute unless /^\./;
@word = split;
if (/^\s*$/) { &output("PARA"); }
if (/^[^.]/) { &output($_); }
if (/^\.AG/) {
if ($needArg) {
§ion(0, "ARGUMENTS(");
$needArg = 0;
}
§ion(1, "ARG($word[1] @@");
}
if (/^\.CS/) { §ion(0, "USAGE("); }
if (/^\.DN/) { $doprint = 0; }
if (/^\.DT/) { §ion(0, "DESCRIPTION("); }
if (/^\.EX/) { §ion(0, "EXAMPLES("); }
if (/^\.FN/) { $fun = $word[1]; }
if (/^\.(IP|PP)/) { &output("PARA"); }
if (/^\.KW/) {
if ($parenLevel > 0) {
§ion(0, "");
$parenLevel = 0;
}
&output("COMMENT(KEYWORD($word[1]))");
}
if (/^\.RC/) {
if ($needVal) {
$needVal = 0;
§ion(0, "VALUES(\n$output\n@@");
$doprint = 1;
}
§ion(1, "ARG($word[1] @@");
}
if (/^\.RT/) {
$needVal = 1;
$doprint = 0;
$output = "";
}
if (/^\.SA/) {
§ion(0, "SEEALSO(");
$inSeeAlso = 1;
}
if (/^\.SE/) { ¶graph("SIDE EFFECTS"); }
if (/^\.SH/) {
if ($word[1] =~ /REFERENCE/) {
§ion(0, "REFERENCES(");
} else {
¶graph($word[1]);
}
}
if (/^\.sp/) { output("BLANK"); }
if (/^\.TL/) { §ion(0, "TITLE($fun @@"); }
if (/^\.WR/) {
§ion(0, "");
print("COMMENT(Converted by sd2rd version $VERSION.)");
}
if (/^\.AO/) {
output("Arguments for function LANG($word[1]()) can also be");
output("supplied to this function.");
}
if (/^\.GE/) {
output("This is a generic function.");
output("Functions with names beginning in LANG($fun.) will be");
output("methods for this function.");
}
if (/^\.GR/) {
output("Graphical parameters (see LANG(LINK(par)) may also be");
output("supplied as arguments to this function.");
}
if (/^\.ME/) {
output("This function is a method for the generic function");
output("LANG($word[1]()) for class LANG($word[2]).");
output("It can be invoked by calling LANG($word[1](x)) for an");
output("object LANG(x) of the appropriate class, or directly by");
output("calling LANG($word[1].$word[2](x)) regardless of the");
output("class of the object.");
}
if (/^\.NA/) { output("Missing values (LANG(NA)s) are allowed.");
}
if (/^\.Tl/) {
output("In addition, the high-level graphics control arguments");
output("described under LANG(LINK(par)) and the arguments to");
output("LANG(LINK(title)) may be supplied to this function.");
}
}
sub substitute {
s/\(/\\\(/g;
s/\)/\\\)/g;
s/\.\.\./DOTS/g;
s/\\fB/BOLD\(/g;
s/\\fR/\)/g;
s/\\\.(.*)$/COMMENT($1)/g;
if ($inSeeAlso) {
s/\`?([\.\w]*\w+)\'?/LANG(LINK($1))/g;
} else {
s/\`([^\']*)\'/LANG($1)/g;
}
}
sub section {
local($level, $text) = @_;
$n = $parenLevel - $level;
print(")" x $n) if ($n > 0);
if ($needVal) {
print("VALUE(\n$output\n)");
$needVal = 0;
}
print("$text") if $text;
$parenLevel = $level + 1;
$doprint = 1;
$inSeeAlso = 0;
}
sub paragraph {
local($name) = @_;
&output("PARA\nBOLD($name): ");
}
sub output {
local($text) = @_;
if ($doprint) {
print($text);
} elsif ($output) {
$output .= "\n$text";
} else {
$output = $text;
}
}
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To:
r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-