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