diff --git a/bin/gendobj b/bin/gendobj index bd3ace606..fcc376511 100755 --- a/bin/gendobj +++ b/bin/gendobj @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -# $Id: gendobj,v 1.1 2002/02/08 22:41:22 mdb Exp $ +# $Id: gendobj,v 1.2 2002/02/08 23:08:39 mdb Exp $ # # gendobj is used to generate DObject source file definitons basded on # abbreviated declarations. Because DObject fields all have standard @@ -29,6 +29,14 @@ while ($source = shift) { next; } + # if the destination file is newer than the source file, do nothing + my $dmtime = (stat($dest))[9]; + my $smtime = (stat($source))[9]; + if ((defined $dmtime) && ($dmtime > $smtime)) { + warn "Skipping $source as source is newer.\n" if ($verbose); + next; + } + if (!open(IN, "$source")) { warn "Unable to open $source for reading: $!\n"; next; @@ -72,6 +80,7 @@ while ($source = shift) { # check to see if we're seeing a DObject field declaration if (/^\s*public ([A-Za-z]+(\[\])*) ([A-Za-z]+)( = .*)?;\s*$/) { + print "Matched field [type=$1, field=$3]\n" if ($verbose); push (@fields, [$1, $3]); } } @@ -79,28 +88,31 @@ while ($source = shift) { close(IN); - print join("", @preamble); - print join("", @classdecl); + # generate the output file + if (!open(OUT, ">$dest")) { + warn "Unable to open $dest for writing: $!\n"; + next; + } + + print "Writing output to $dest...\n" if ($verbose); + + print OUT join("", @preamble); + print OUT join("", @classdecl); my $field; foreach $field (@fields) { print_dobj_constant($field->[0], $field->[1]); } - print join("", @classbody); + print OUT join("", @classbody); foreach $field (@fields) { print_dobj_setters($field->[0], $field->[1]); } - print "}\n"; + print OUT "}\n"; - # generate the output file -# if (!open(OUT, ">$dest")) { -# warn "Unable to open $dest for writing: $!\n"; -# next; -# } -# close(OUT); + close(OUT); } sub print_dobj_constant @@ -112,7 +124,7 @@ sub print_dobj_constant $fcode =~ s/([A-Z])/_$1/g; $fcode =~ tr/a-z/A-Z/; - print <$field field. */ public static final String $fcode = "$field"; @@ -131,9 +143,25 @@ sub print_dobj_setters my $cfield = $field; $cfield =~ s/(\w)/\U$1/; + # we may need to wrap the field for certain types + my $dobjval = $field; + if ($type eq "boolean") { + $dobjval = "new Boolean($field)"; + } elsif ($type eq "byte") { + $dobjval = "new Byte($field)"; + } elsif ($type eq "int") { + $dobjval = "new Integer($field)"; + } elsif ($type eq "long") { + $dobjval = "new Long($field)"; + } elsif ($type eq "float") { + $dobjval = "new Float($field)"; + } elsif ($type eq "double") { + $dobjval = "new Double($field)"; + } + # some known types have special setters if ($type eq "DSet") { - print <$field field be set to the specified @@ -194,7 +222,7 @@ EOF */ public void set$cfield ($type $field) { - requestAttributeChange($fcode, $field); + requestAttributeChange($fcode, $dobjval); } /** @@ -206,7 +234,7 @@ EOF public void set${cfield}Immediate ($type $field) { this.$field = $field; - requestAttributeChange($fcode, $field); + requestAttributeChange($fcode, $dobjval); } EOF }