#!/usr/bin/perl -w
#
# Converting MOF-files to .mo-files, Step 1
#
# Author: Christian Schiller
# Date: 08/15/98
#
# output filename
$filename = "_$ARGV[0]";
print STDERR "output will be written to $filename\n";
open(OUTPUT, ">$filename");
$squarebracket = 0; # indicates whether square brackets
# have been opened but not closed yet
$qualifier = 0; # indicates that a qualifier definition is
# spanning multiple lines
$abstract = 0; # indicates whether an abstract
# qualifier is active
$association = 0; # indicates whether an association qualifier
# is active
while (<>) {
# skip comments and pragmas
if (/\/\/|^#/) {
next;
}
# skip qualifier definitions
if (/^Qualifier/i) {
if (/;/) {
next;
} else {
$qualifier = 1;
}
while ($qualifier) {
$_ = <>;
/;/ && do { $qualifier = 0; }
}
next;
}
# skip qualifiers
if (/\[/) {
$abstract = 0;
/abstract/i && do { $abstract = 1; };
/Association/ && do { $association = 1};
if (/\[.*\]/) {
next;
} else {
$squarebracket = 1;
}
while ($squarebracket){
$_ = <>;
/abstract/i && do { $abstract = 1; };
/Association/ && do { $association = 1};
/\]/ && do { $squarebracket = 0; }
}
next;
}
# skip associations
if ($association) {
while(! eof) {
/}\s*;/ && last;
$_ = <>;
}
}
if ($association) {
$association = 0;
next;
}
# mark abstract classes
if ($abstract) {
s/class/abstract class/;
}
# add 'public abstract' in front of methods;
# methods are recognized by scanning for '()'
s/(\s*)(\w.*)\(\);/$1public abstract $2\(\);/;
print OUTPUT;
}