annotate src/fftw-3.3.5/doc/FAQ/bfnnconv.pl @ 84:08ae793730bd

Add null config files
author Chris Cannam
date Mon, 02 Mar 2020 14:03:47 +0000
parents 2cd0e3b3e1fd
children
rev   line source
Chris@42 1 #!/usr/bin/perl --
Chris@42 2 # Copyright (C) 1993-1995 Ian Jackson.
Chris@42 3
Chris@42 4 # This file is free software; you can redistribute it and/or modify
Chris@42 5 # it under the terms of the GNU General Public License as published by
Chris@42 6 # the Free Software Foundation; either version 2, or (at your option)
Chris@42 7 # any later version.
Chris@42 8
Chris@42 9 # It is distributed in the hope that it will be useful,
Chris@42 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@42 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@42 12 # GNU General Public License for more details.
Chris@42 13
Chris@42 14 # You should have received a copy of the GNU General Public License
Chris@42 15 # along with GNU Emacs; see the file COPYING. If not, write to
Chris@42 16 # the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Chris@42 17 # Boston, MA 02111-1307, USA.
Chris@42 18
Chris@42 19 # (Note: I do not consider works produced using these BFNN processing
Chris@42 20 # tools to be derivative works of the tools, so they are NOT covered
Chris@42 21 # by the GPL. However, I would appreciate it if you credited me if
Chris@42 22 # appropriate in any documents you format using BFNN.)
Chris@42 23
Chris@42 24 @outputs=('ascii','info','html');
Chris@42 25
Chris@42 26 while ($ARGV[0] =~ m/^\-/) {
Chris@42 27 $_= shift(@ARGV);
Chris@42 28 if (m/^-only/) {
Chris@42 29 @outputs= (shift(@ARGV));
Chris@42 30 } else {
Chris@42 31 warn "unknown option `$_' ignored";
Chris@42 32 }
Chris@42 33 }
Chris@42 34
Chris@42 35 $prefix= $ARGV[0];
Chris@42 36 $prefix= 'stdin' unless length($prefix);
Chris@42 37 $prefix =~ s/\.bfnn$//;
Chris@42 38
Chris@42 39 if (open(O,"$prefix.xrefdb")) {
Chris@42 40 @xrefdb= <O>;
Chris@42 41 close(O);
Chris@42 42 } else {
Chris@42 43 warn "no $prefix.xrefdb ($!)";
Chris@42 44 }
Chris@42 45
Chris@42 46 $section= -1;
Chris@42 47 for $thisxr (@xrefdb) {
Chris@42 48 $_= $thisxr;
Chris@42 49 chop;
Chris@42 50 if (m/^Q (\w+) ((\d+)\.(\d+)) (.*)$/) {
Chris@42 51 $qrefn{$1}= $2;
Chris@42 52 $qreft{$1}= $5;
Chris@42 53 $qn2ref{$3,$4}= $1;
Chris@42 54 $maxsection= $3;
Chris@42 55 $maxquestion[$3]= $4;
Chris@42 56 } elsif (m/^S (\d+) /) {
Chris@42 57 $maxsection= $1;
Chris@42 58 $sn2title{$1}=$';
Chris@42 59 }
Chris@42 60 }
Chris@42 61
Chris@42 62 open(U,">$prefix.xrefdb-new");
Chris@42 63
Chris@42 64 for $x (@outputs) { require("m-$x.pl"); }
Chris@42 65
Chris@42 66 &call('init');
Chris@42 67
Chris@42 68 while (<>) {
Chris@42 69 chop;
Chris@42 70 next if m/^\\comment\b/;
Chris@42 71 if (!m/\S/) {
Chris@42 72 &call('endpara');
Chris@42 73 next;
Chris@42 74 }
Chris@42 75 if (s/^\\section +//) {
Chris@42 76 $line= $_;
Chris@42 77 $section++; $question=0;
Chris@42 78 print U "S $section $line\n";
Chris@42 79 $|=1; print "S$section",' 'x10,"\r"; $|=0;
Chris@42 80 &call('endpara');
Chris@42 81 &call('startmajorheading',"$section",
Chris@42 82 "Section $section",
Chris@42 83 $section<$maxsection ? "Section ".($section+1) : '',
Chris@42 84 $section>1 ? 'Section '.($section-1) : 'Top');
Chris@42 85 &text($line);
Chris@42 86 &call('endmajorheading');
Chris@42 87 if ($section) {
Chris@42 88 &call('endpara');
Chris@42 89 &call('startindex');
Chris@42 90 for $thisxr (@xrefdb) {
Chris@42 91 $_= $thisxr;
Chris@42 92 chop;
Chris@42 93 if (m/^Q (\w+) (\d+)\.(\d+) (.*)$/) {
Chris@42 94 $ref= $1; $num1= $2; $num2= $3; $text= $4;
Chris@42 95 next unless $num1 == $section;
Chris@42 96 &call('startindexitem',$ref,"Q$num1.$num2","Question $num1.$num2");
Chris@42 97 &text($text);
Chris@42 98 &call('endindexitem');
Chris@42 99 }
Chris@42 100 }
Chris@42 101 &call('endindex');
Chris@42 102 }
Chris@42 103 } elsif (s/^\\question \d{2}[a-z]{3}((:\w+)?) +//) {
Chris@42 104 $line= $_;
Chris@42 105 $question++;
Chris@42 106 $qrefstring= $1;
Chris@42 107 $qrefstring= "q_${section}_$question" unless $qrefstring =~ s/^://;
Chris@42 108 print U "Q $qrefstring $section.$question $line\n";
Chris@42 109 $|=1; print "Q$section.$question",' 'x10,"\r"; $|=0;
Chris@42 110 &call('endpara');
Chris@42 111 &call('startminorheading',$qrefstring,
Chris@42 112 "Question $section.$question",
Chris@42 113 $question < $maxquestion[$section] ? "Question $section.".($question+1) :
Chris@42 114 $section < $maxsection ? "Question ".($section+1).".1" : '',
Chris@42 115 $question > 1 ? "Question $section.".($question-1) :
Chris@42 116 $section > 1 ? "Question ".($section-1).'.'.($maxquestion[$section-1]) :
Chris@42 117 'Top',
Chris@42 118 "Section $section");
Chris@42 119 &text("Question $section.$question. $line");
Chris@42 120 &call('endminorheading');
Chris@42 121 } elsif (s/^\\only +//) {
Chris@42 122 @saveoutputs= @outputs;
Chris@42 123 @outputs=();
Chris@42 124 for $x (split(/\s+/,$_)) {
Chris@42 125 push(@outputs,$x) if grep($x eq $_, @saveoutputs);
Chris@42 126 }
Chris@42 127 } elsif (s/^\\endonly$//) {
Chris@42 128 @outputs= @saveoutputs;
Chris@42 129 } elsif (s/^\\copyto +//) {
Chris@42 130 $fh= $';
Chris@42 131 while(<>) {
Chris@42 132 last if m/^\\endcopy$/;
Chris@42 133 while (s/^([^\`]*)\`//) {
Chris@42 134 print $fh $1;
Chris@42 135 m/([^\\])\`/ || warn "`$_'";
Chris@42 136 $_= $';
Chris@42 137 $cmd= $`.$1;
Chris@42 138 $it= `$cmd`; chop $it;
Chris@42 139 print $fh $it;
Chris@42 140 }
Chris@42 141 print $fh $_;
Chris@42 142 }
Chris@42 143 } elsif (m/\\index$/) {
Chris@42 144 &call('startindex');
Chris@42 145 for $thisxr (@xrefdb) {
Chris@42 146 $_= $thisxr;
Chris@42 147 chop;
Chris@42 148 if (m/^Q (\w+) (\d+\.\d+) (.*)$/) {
Chris@42 149 $ref= $1; $num= $2; $text= $3;
Chris@42 150 &call('startindexitem',$ref,"Q$num","Question $num");
Chris@42 151 &text($text);
Chris@42 152 &call('endindexitem');
Chris@42 153 } elsif (m/^S (\d+) (.*)$/) {
Chris@42 154 $num= $1; $text= $2;
Chris@42 155 next unless $num;
Chris@42 156 &call('startindexmainitem',"s_$num",
Chris@42 157 "Section $num.","Section $num");
Chris@42 158 &text($text);
Chris@42 159 &call('endindexitem');
Chris@42 160 } else {
Chris@42 161 warn $_;
Chris@42 162 }
Chris@42 163 }
Chris@42 164 &call('endindex');
Chris@42 165 } elsif (m/^\\call-(\w+) +(\w+)\s*(.*)$/) {
Chris@42 166 $fn= $1.'_'.$2;
Chris@42 167 eval { &$fn($3); };
Chris@42 168 warn $@ if length($@);
Chris@42 169 } elsif (m/^\\call +(\w+)\s*(.*)$/) {
Chris@42 170 eval { &call($1,$2); };
Chris@42 171 warn $@ if length($@);
Chris@42 172 } elsif (s/^\\set +(\w+)\s*//) {
Chris@42 173 $svalue= $'; $svari= $1;
Chris@42 174 eval("\$user_$svari=\$svalue"); $@ && warn "setting $svalue failed: $@\n";
Chris@42 175 } elsif (m/^\\verbatim$/) {
Chris@42 176 &call('startverbatim');
Chris@42 177 while (<>) {
Chris@42 178 chop;
Chris@42 179 last if m/^\\endverbatim$/;
Chris@42 180 &call('verbatim',$_);
Chris@42 181 }
Chris@42 182 &call('endverbatim');
Chris@42 183 } else {
Chris@42 184 s/\.$/\. /;
Chris@42 185 &text($_." ");
Chris@42 186 }
Chris@42 187 }
Chris@42 188
Chris@42 189 print ' 'x25,"\r";
Chris@42 190 &call('finish');
Chris@42 191 rename("$prefix.xrefdb-new","$prefix.xrefdb") || warn "rename xrefdb: $!";
Chris@42 192 exit 0;
Chris@42 193
Chris@42 194
Chris@42 195 sub text {
Chris@42 196 local($in,$rhs,$word,$refn,$reft,$fn,$style);
Chris@42 197 $in= "$holdover$_[0]";
Chris@42 198 $holdover= '';
Chris@42 199 while ($in =~ m/\\/) {
Chris@42 200 #print STDERR ">$`##$'\n";
Chris@42 201 $rhs=$';
Chris@42 202 &call('text',$`);
Chris@42 203 $_= $rhs;
Chris@42 204 if (m/^\w+ $/) {
Chris@42 205 $holdover= "\\$&";
Chris@42 206 $in= '';
Chris@42 207 } elsif (s/^fn\s+([^\s\\]*\w)//) {
Chris@42 208 $in= $_;
Chris@42 209 $word= $1;
Chris@42 210 &call('courier');
Chris@42 211 &call('text',$word);
Chris@42 212 &call('endcourier');
Chris@42 213 } elsif (s/^tab\s+(\d+)\s+//) {
Chris@42 214 $in= $_; &call('tab',$1);
Chris@42 215 } elsif (s/^nl\s+//) {
Chris@42 216 $in= $_; &call('newline');
Chris@42 217 } elsif (s/^qref\s+(\w+)//) {
Chris@42 218 $refn= $qrefn{$1};
Chris@42 219 $reft= $qreft{$1};
Chris@42 220 if (!length($refn)) {
Chris@42 221 warn "unknown question `$1'";
Chris@42 222 }
Chris@42 223 $in= "$`\\pageref:$1:$refn:$reft\\endpageref.$_";
Chris@42 224 } elsif (s/^pageref:(\w+):([^:\n]+)://) {
Chris@42 225 $in= $_;
Chris@42 226 &call('pageref',$1,$2);
Chris@42 227 } elsif (s/^endpageref\.//) {
Chris@42 228 $in= $_; &call('endpageref');
Chris@42 229 } elsif (s/^(\w+)\{//) {
Chris@42 230 $in= $_; $fn= $1;
Chris@42 231 eval { &call("$fn"); };
Chris@42 232 if (length($@)) { warn $@; $fn= 'x'; }
Chris@42 233 push(@styles,$fn);
Chris@42 234 } elsif (s/^\}//) {
Chris@42 235 $in= $_;
Chris@42 236 $fn= pop(@styles);
Chris@42 237 if ($fn ne 'x') { &call("end$fn"); }
Chris@42 238 } elsif (s/^\\//) {
Chris@42 239 $in= $_;
Chris@42 240 &call('text',"\\");
Chris@42 241 } elsif (s,^(\w+)\s+([-A-Za-z0-9.\@:/]*\w),,) {
Chris@42 242 #print STDERR "**$&**$_\n";
Chris@42 243 $in= $_;
Chris@42 244 $style=$1; $word= $2;
Chris@42 245 &call($style);
Chris@42 246 &call('text',$word);
Chris@42 247 &call("end$style");
Chris@42 248 } else {
Chris@42 249 warn "unknown control `\\$_'";
Chris@42 250 $in= $_;
Chris@42 251 }
Chris@42 252 }
Chris@42 253 &call('text',$in);
Chris@42 254 }
Chris@42 255
Chris@42 256
Chris@42 257 sub call {
Chris@42 258 local ($fnbase, @callargs) = @_;
Chris@42 259 local ($coutput);
Chris@42 260 for $coutput (@outputs) {
Chris@42 261 if ($fnbase eq 'text' && eval("\@${coutput}_cmds")) {
Chris@42 262 #print STDERR "special handling text (@callargs) for $coutput\n";
Chris@42 263 $evstrg= "\$${coutput}_args[\$#${coutput}_args].=\"\@callargs\"";
Chris@42 264 eval($evstrg);
Chris@42 265 length($@) && warn "call adding for $coutput (($evstrg)): $@";
Chris@42 266 } else {
Chris@42 267 $fntc= $coutput.'_'.$fnbase;
Chris@42 268 &$fntc(@callargs);
Chris@42 269 }
Chris@42 270 }
Chris@42 271 }
Chris@42 272
Chris@42 273
Chris@42 274 sub recurse {
Chris@42 275 local (@outputs) = $coutput;
Chris@42 276 local ($holdover);
Chris@42 277 &text($_[0]);
Chris@42 278 }
Chris@42 279
Chris@42 280
Chris@42 281 sub arg {
Chris@42 282 #print STDERR "arg($_[0]) from $coutput\n";
Chris@42 283 $cmd= $_[0];
Chris@42 284 eval("push(\@${coutput}_cmds,\$cmd); push(\@${coutput}_args,'')");
Chris@42 285 length($@) && warn "arg setting up for $coutput: $@";
Chris@42 286 }
Chris@42 287
Chris@42 288 sub endarg {
Chris@42 289 #print STDERR "endarg($_[0]) from $coutput\n";
Chris@42 290 $evstrg= "\$${coutput}_cmd= \$cmd= pop(\@${coutput}_cmds); ".
Chris@42 291 "\$${coutput}_arg= \$arg= pop(\@${coutput}_args); ";
Chris@42 292 eval($evstrg);
Chris@42 293 length($@) && warn "endarg extracting for $coutput (($evstrg)): $@";
Chris@42 294 #print STDERR ">call $coutput $cmd $arg< (($evstrg))\n";
Chris@42 295 $evstrg= "&${coutput}_do_${cmd}(\$arg)";
Chris@42 296 eval($evstrg);
Chris@42 297 length($@) && warn "endarg running ${coutput}_do_${cmd} (($evstrg)): $@";
Chris@42 298 }