| 1 |
#!/usr/bin/perl |
| 2 |
## usage: makecm <cmfiles ...> |
| 3 |
## |
| 4 |
## This script looks at a CM file like MLRISC.cm and updates the export list. |
| 5 |
## It changes the file in place. |
| 6 |
## |
| 7 |
|
| 8 |
if ($#ARGV == -1) |
| 9 |
{ open(HELP,"$0"); |
| 10 |
while (<HELP>) |
| 11 |
{ print $1, "\n" if /^## (.*)/; |
| 12 |
} |
| 13 |
exit (1); |
| 14 |
} |
| 15 |
|
| 16 |
foreach $file (@ARGV) |
| 17 |
{ makecm($file); |
| 18 |
} |
| 19 |
|
| 20 |
sub makecm |
| 21 |
{ my($cmfile) = @_; |
| 22 |
$error = 0; |
| 23 |
open(MLRISC,$cmfile) || (print STDERR ("$!: $cmfile\n"), $error = 1); |
| 24 |
@HEADER=(); |
| 25 |
@FOOTER=(); |
| 26 |
@SIGS=(); |
| 27 |
@FCTS=(); |
| 28 |
@STRS=(); |
| 29 |
while (<MLRISC>) |
| 30 |
{ next if /^\s*(functor|signature|structure) .*$/; |
| 31 |
if (/^\s*is\s*$/) |
| 32 |
{ goto NEXT; |
| 33 |
} |
| 34 |
push @HEADER, $_; |
| 35 |
} |
| 36 |
|
| 37 |
NEXT: |
| 38 |
|
| 39 |
while (<MLRISC>) |
| 40 |
{ push @FOOTER, $_; |
| 41 |
next if $_ =~ /\(\*.*\*\)/; |
| 42 |
($comment=1, next) if $_ =~ /^\s*\(\*.*/; |
| 43 |
($comment=0, next) if $_ =~ /^.*\*\)/; |
| 44 |
next if $comment; |
| 45 |
if ($_ =~ /^.*\.(sml|sig)/) |
| 46 |
{ open (F,$_) || (print STDERR ("$!: $cmfile: $_"), $error = 1); |
| 47 |
while (<F>) |
| 48 |
{ if (/^(signature)\s+([a-zA-Z0-9_]+)/) |
| 49 |
{ push @SIGS, "\t$1 $2\n"; |
| 50 |
} |
| 51 |
if (/^(functor)\s+([a-zA-Z0-9_]+)/) |
| 52 |
{ push @FCTS, "\t$1 $2\n"; |
| 53 |
} |
| 54 |
if (/^(structure)\s+([a-zA-Z0-9_]+)/) |
| 55 |
{ push @STRS, "\t$1 $2\n"; |
| 56 |
} |
| 57 |
} |
| 58 |
close F |
| 59 |
} |
| 60 |
} |
| 61 |
close(MLRISC); |
| 62 |
if ($error) { exit 1; } |
| 63 |
#system("/bin/mv -f $cmfile $cmfile.bak"); |
| 64 |
open(MLRISC,">$cmfile") || die("$!: $cmfile"); |
| 65 |
for (@HEADER) |
| 66 |
{ print MLRISC $_; |
| 67 |
} |
| 68 |
for (sort @SIGS) { print MLRISC $_; } |
| 69 |
for (sort @STRS) { print MLRISC $_; } |
| 70 |
for (sort @FCTS) { print MLRISC $_; } |
| 71 |
print MLRISC "is\n"; |
| 72 |
for (@FOOTER) |
| 73 |
{ print MLRISC $_; |
| 74 |
} |
| 75 |
print "[New $cmfile created]\n"; |
| 76 |
} |