annotate src/fftw-3.3.3/doc/FAQ/bfnnconv.pl @ 168:ceec0dd9ec9c

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