#!/bin/perl die "Usage: armpi_ext1 \n" if ($#ARGV); %sw = ('WEND', '#endr', '[', '#if', '|', '#else', ']', '#endif'); while (<>) { if (/^-- (\w+) -+\n$/o) { push @r, $current if (($current = $1) ne 'MAIN'); while (($_ = <>) !~ /^-+\n$/o) { if (($sr,$param) = /^\w*\s+<(\w+)>\s*(.*?)(;.*)?\n$/o) { if (($tmp = $rout{$sr}) eq '') { $! = 1; die "Unknown routine $1\n" } if (/^(\w+)/o) { $rout{$current} .= "$1\n" } while ($param ne '') { ($a,$b,$c,$param) = $param =~ /(\w+)=(\w+)(,\s*)?(.*)/o; $tmp =~ s/([^%])\b$a\b/$1%$b/g; } $tmp =~ s/%//g; $rout{$current} .= "; routine $sr (begin)\n$tmp" ."; routine $sr (end)\n"; } else { if (/^(\w+)\s+(RN|SETA)\s+(.+\n)$/o) { $_ = "\t\t#set\t$1 = $3" } elsif (/^(\w*)\s+WHILE\s+(.*?)\s+>=\s*0\s/o) { $_ = ($1 eq '' ? '' : "$1\n")."\t\t#rept\t1 + $2\n" } elsif (/^(\w*)\s+(WEND|\[|\||])(\s.*\n?)$/o) { $_ = ($1 eq '' ? '' : "$1\n")."\t\t$sw{$2}$3" } $rout{$current} .= $_ unless (/^\w*\s+GBLA\s/); } } } } print "\t\t#set\tLR = 14\n$rout{MAIN}";