1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
|
#!/usr/bin/perl
eval "exec /usr/bin/perl -S $0 $*"
if $running_under_some_shell;
# this emulates #! processing on NIH machines.
# (remove #! line above if indigestible)
eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift;
# process any FOO=bar switches
#
# explain - extract on-line documentation from elisp function definitions
#
# Input is expected to be a concatenation of .el files, each starting with
# an RCS "Id" line supplying the original filename. Output is written to
# corresponding .texinfo files. Variable references are written to
# variables.texinfo. These can be incorporated into documentation
# using @include statements.
#
# $Id: explain,v 1.1 1996/12/31 03:02:00 jrv Exp jrv $
#
$[ = 1; # set array base to 1
$, = ' '; # set output field separator
$\ = "\n"; # set output record separator
if (($#ARGV+1) != 2) {
print 'usage: explain elisp-file';
}
$file_name = 'DUMMY.texinfo';
$variable_file = 'variables.texinfo';
$func_file = $ARGV[1];
line: while (<>) {
chop; # strip record separator
@Fld = split(' ', $_, 9999);
if (/define-key *emacspeak-keymap/ ||
/define-key *emacspeak-eterm-keymap/ ||
/define-key *emacspeak-dtk-submap/) {
# parse a key definition that looks like this:
# (define-key emacspeak-keymap "\C-a"
# 'emacspeak-toggle-auditory-icons )
$text = $_;
if ($#Fld < 4) {
# print "wrapped line:",text;
$_ = &Getline0();
$text = $text . $_;
# print " becomes:",text;
;
}
# if ($_ ~ /\'\[003 *[a-zA-Z]*\]/) {
# $_ ~= s//[/;
# }
@b = split(' ', $text);
$keymap = $b[2];
if (index($b[3], "'") == 1) {
$key = substr($b[3], 2, 999999);
$func_name = $b[4];
}
else { # key sequence includes a space
$key = substr($text, index($text, "\"") + 1, 999999);
$func_name = $key;
$key = substr($key, 1, index($key, "\"") - 1);
$key =~ s/^ $/[space]/;
}
$key =~ s/^\\//; # eliminate leading `\' on key sequence
$key =~ s/\@$/@@/; # escape the `@' for texinfo
$key =~ s/^\%s$/1/; # special case - substitute example
# add appropriate prefix
if ($keymap =~ /emacspeak-keymap/) {
$key = 'C-e ' . $key;
}
elsif ($keymap =~ /emacspeak-dtk-submap/) {
$key = 'C-e d ' . $key;
}
elsif ($keymap =~ /emacspeak-eterm-keymap/) {
$key = 'C-t ' . $key;
}
# if ($func_name =~ /emacspeak-eterm-maybe-send-raw/) {
# $key = 'C-r C-r'; # special case - insert proper key sequence
# }
if (!($i = index($func_name, "'"))) {
print $.,': @c bad function name:', $func_name;
next;
}
$func_name =~ s/^.*'//;
$func_name =~ s/ *\).*$//;
$Keys{$func_name} = $key;
}
}
&Pick('>', $variable_file) &&
(print $fh '@table @samp');
while (($_ = &Getline2($func_file),$getline_ok)) {
if ($_ =~ /\$Id:/) { # found start of a new source code file
# -- open new output file to match
if ($definitions_found) {
&Pick('>', $file_name) &&
(print $fh "\@end table\n");
}
if ($collected) {
&dump_unbound($file_name);
}
delete $opened{$file_name} && close($file_name);
$definitions_found = 0;
@t = split(' ', $_);
$file_name = $t[3];
$file_name =~ s/\..*$/.texinfo/;
$file_name =~ s/emacspeak.texinfo/emacspeak-main.texinfo/;
}
elsif ($_ =~ /^ *\(defun/ ||
# $_ =~ /^ *\(defadvice/ ||
$_ =~ /^ *\(defsubst/) {
$func_name = $Fld[2];
# print "found definition of",$func_name;
$func_name =~ s/ *\(.*$//;
$_ = &Getline2($func_file);
$interactive = $_ =~ /[^a-zA-Z0-9-]interactive/;
if ($_ !~ /^[ \t]*\"/) {
if(/^[ \t]*$/) {next;}
if ($interactive) {
print $.,": ",$_, "not the docs";
print "interactive =", $interactive;
}
$_ = &Getline2($func_file);
}
if ($_ !~ /^[ \t]*\"/) {
next;
}
# print $_, "is start of docs";
s/"//;
$text = '';
while (1) {
$i = index($_, "\"");
# print "quote at offset",i," of ",$0
if ($i) {
last; # break after finding closing quote
}
$text = $text . $_ . "\n";
$err = ($_ = &Getline2($func_file),$getline_ok);
if ($err == 0 || $err == -1) {
&Pick('>', 'explain.log') &&
(print $fh 'error on input file');
exit 1;
}
}
$text = $text . substr($_, 1, $i - 1) . "\n";
# document only interactive functions
if (!$interactive) {
$err = ($_ = &Getline2($func_file),$getline_ok);
if ($err == 0 || $err == -1) {
&Pick('>', 'explain.log') &&
(print $fh 'error on input file');
exit 1;
}
if ($_ =~ /^$/) {$_ = &Getline2($func_file);}
if (!($_ =~ /[^a-zA-Z0-9-]interactive/)) {
next;
}
}
if (defined $Keys{$func_name}) {
if (!$definitions_found) {
&Pick('>', $file_name) &&
(print $fh '@table @samp');
}
$definitions_found++;
$key = $Keys{$func_name};
delete $Keys{$func_name};
&Pick('>', $file_name) &&
(print $fh '@item', $key);
&Pick('>', $file_name) &&
(print $fh '@kindex', $key);
&Pick('>', $file_name) &&
(print $fh '@itemx M-x', $func_name);
&Pick('>', $file_name) &&
(print $fh '@findex', $func_name);
&Pick('>', $file_name) &&
(print $fh $text);
}
elsif ($collected) {
&Pick('>', $file_name) &&
(print $fh '@c no key binding for', $func_name);
# print "with usage:",text >file_name;
$unbound{$func_name} = $text;
$cnt_unbound++;
$unbound_file{$func_name} = $file_name;
}
else {
if (!$definitions_found) {
&Pick('>', $file_name) &&
(print $fh '@table @samp');
}
$definitions_found++;
$text =~ s/dfined/defined/; # fix spelling
$text =~ s/contnets/contents/; # fix spelling
&Pick('>', $file_name) &&
(print $fh '@c no key binding for', $func_name);
&Pick('>', $file_name) &&
(print $fh '@item M-x', $func_name);
&Pick('>', $file_name) &&
(print $fh '@findex', $func_name);
&Pick('>', $file_name) &&
(print $fh $text);
}
}
elsif ($_ =~ /^\(defvar/) {
$var_name = $Fld[2];
# print "found definition of",$var_name;
$var_name =~ s/ *\(.*$//;
$_ = &Getline2($func_file);
if ($_ !~ /^[ \t]*\"/) {
$_ = &Getline2($func_file);
}
if ($_ !~ /^[ \t]*\"/) {
next;
}
s/"//;
if ($_ =~ /^[ \t]*\@/) {
next;
}
$text = '';
while (1) {
$i = index($_, "\"");
# print "quote at offset",i," of ",$0
if ($i) {
last;
}
$text = $text . $_ . "\n";
$err = ($_ = &Getline2($func_file),$getline_ok);
if ($err == 0 || $err == -1) {
&Pick('>', 'explain.log') &&
(print $fh 'error on input file');
exit 1;
}
}
$text = $text . substr($_, 1, $i - 1) . "\n";
# $text =~ s/dfined/defined/g;
if ($text =~ /(\\\\\{([-a-zA-Z]*)\})/) {
# The documentation includes an entire key binding table.
# We delete the request.
$text =~ s/(\\\\\{([-a-zA-Z]*)\})//;
}
if ($text =~ /(\\\\\[([-a-zA-Z]*)\])/) {
# The documentation refers to the key binding of a command.
# We must substitute the key binding.
# print "This documentation: ",$text;
# print "contains this sequence:", $1;
# print "which includes this command:", $2;
if( defined $Keys{$2}) {
# print "which is bound to: ", $Keys{$2};
$s_ = '@kbd{'.($Keys{$2}).'}';
$s_ =~ s/&/\$&/g,
# $s_ =~ s/(\W)/\\$1/g;
# $text =~ s/$1/eval $s_/e;
$text =~ s/(\\\\\[([-a-zA-Z]*)\])/$s_/;
# print "resulting docs:",$text;
}
else { print $., ":", $text, $2, "is not bound to any key"; }
}
&Pick('>', $variable_file) &&
(print $fh '@item', $var_name);
&Pick('>', $variable_file) &&
(print $fh '@vindex', $var_name);
$text =~ s/t\!\@\#\$/t!\@\@#\$/g;
&Pick('>', $variable_file) &&
(print $fh $text);
}
}
if ($definitions_found) {
&Pick('>', $file_name) &&
(print $fh '@end table');
}
foreach $name (keys %Keys) {
print '@c no explanation for', $Keys{$name}, $name;
}
# dump_unbound("unbound.texinfo");
&Pick('>', $variable_file) &&
(print $fh '@end table');
exit $ExitValue;
sub dump_unbound {
local($file_name) = @_;
if ($cnt_unbound) {
&Pick('>', $file_name) &&
(print $fh "These functions are not bound to a key.\n");
&Pick('>', $file_name) &&
(print $fh '@table @samp');
foreach $name (keys %unbound) {
&Pick('>', $file_name) &&
(print $fh '@item M-x', $name);
&Pick('>', $file_name) &&
(print $fh '@findex', $name);
&Pick('>', $file_name) &&
(print $fh '@c from:', $unbound_file{$name});
&Pick('>', $file_name) &&
(print $fh $unbound{$name});
delete $unbound{$name};
$cnt_unbound--;
}
&Pick('>', $file_name) &&
(print $fh '@end table');
}
}
sub Getline0 {
if ($getline_ok = (($_ = <>) ne '')) {
chop; # strip record separator
@Fld = split(' ', $_, 9999);
}
$_;
}
sub Getline2 {
&Pick('',@_);
if ($getline_ok = (($_ = <$fh>) ne '')) {
chop; # strip record separator
@Fld = split(' ', $_, 9999);
}
$_;
}
sub Pick {
local($mode,$name,$pipe) = @_;
$fh = $name;
open($name,$mode.$name.$pipe) unless $opened{$name}++;
}
|