Modified script not to generate new destination file unless the source

file is newer.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@966 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-02-08 23:08:39 +00:00
parent 8a6f656111
commit d71d2c3a91
+45 -17
View File
@@ -1,6 +1,6 @@
#!/usr/bin/perl -w #!/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 # gendobj is used to generate DObject source file definitons basded on
# abbreviated declarations. Because DObject fields all have standard # abbreviated declarations. Because DObject fields all have standard
@@ -29,6 +29,14 @@ while ($source = shift) {
next; 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")) { if (!open(IN, "$source")) {
warn "Unable to open $source for reading: $!\n"; warn "Unable to open $source for reading: $!\n";
next; next;
@@ -72,6 +80,7 @@ while ($source = shift) {
# check to see if we're seeing a DObject field declaration # check to see if we're seeing a DObject field declaration
if (/^\s*public ([A-Za-z]+(\[\])*) ([A-Za-z]+)( = .*)?;\s*$/) { if (/^\s*public ([A-Za-z]+(\[\])*) ([A-Za-z]+)( = .*)?;\s*$/) {
print "Matched field [type=$1, field=$3]\n" if ($verbose);
push (@fields, [$1, $3]); push (@fields, [$1, $3]);
} }
} }
@@ -79,28 +88,31 @@ while ($source = shift) {
close(IN); close(IN);
print join("", @preamble); # generate the output file
print join("", @classdecl); 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; my $field;
foreach $field (@fields) { foreach $field (@fields) {
print_dobj_constant($field->[0], $field->[1]); print_dobj_constant($field->[0], $field->[1]);
} }
print join("", @classbody); print OUT join("", @classbody);
foreach $field (@fields) { foreach $field (@fields) {
print_dobj_setters($field->[0], $field->[1]); print_dobj_setters($field->[0], $field->[1]);
} }
print "}\n"; print OUT "}\n";
# generate the output file close(OUT);
# if (!open(OUT, ">$dest")) {
# warn "Unable to open $dest for writing: $!\n";
# next;
# }
# close(OUT);
} }
sub print_dobj_constant sub print_dobj_constant
@@ -112,7 +124,7 @@ sub print_dobj_constant
$fcode =~ s/([A-Z])/_$1/g; $fcode =~ s/([A-Z])/_$1/g;
$fcode =~ tr/a-z/A-Z/; $fcode =~ tr/a-z/A-Z/;
print <<EOF; print OUT <<EOF;
/** The field name of the <code>$field</code> field. */ /** The field name of the <code>$field</code> field. */
public static final String $fcode = "$field"; public static final String $fcode = "$field";
@@ -131,9 +143,25 @@ sub print_dobj_setters
my $cfield = $field; my $cfield = $field;
$cfield =~ s/(\w)/\U$1/; $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 # some known types have special setters
if ($type eq "DSet") { if ($type eq "DSet") {
print <<EOF; print OUT <<EOF;
/** /**
* Requests that the specified element be added to the * Requests that the specified element be added to the
@@ -164,7 +192,7 @@ sub print_dobj_setters
EOF EOF
} elsif ($type eq "OidList") { } elsif ($type eq "OidList") {
print <<EOF; print OUT <<EOF;
/** /**
* Requests that the specified oid be added to the * Requests that the specified oid be added to the
@@ -186,7 +214,7 @@ EOF
EOF EOF
} else { } else {
print <<EOF; print OUT <<EOF;
/** /**
* Requests that the <code>$field</code> field be set to the specified * Requests that the <code>$field</code> field be set to the specified
@@ -194,7 +222,7 @@ EOF
*/ */
public void set$cfield ($type $field) public void set$cfield ($type $field)
{ {
requestAttributeChange($fcode, $field); requestAttributeChange($fcode, $dobjval);
} }
/** /**
@@ -206,7 +234,7 @@ EOF
public void set${cfield}Immediate ($type $field) public void set${cfield}Immediate ($type $field)
{ {
this.$field = $field; this.$field = $field;
requestAttributeChange($fcode, $field); requestAttributeChange($fcode, $dobjval);
} }
EOF EOF
} }