Add file headers and leaders to generated files

Give the code generators the opportunity to print something at the start and the end of the file. E.g. header guards for C files, and some notice about the file being automatically generated for all types.

git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@5363 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2008-07-03 19:04:00 +00:00
parent 309517fc95
commit 0814e56caa
3 changed files with 48 additions and 1 deletions

View File

@ -183,4 +183,38 @@ sub printStructs()
}
}
sub printHdrGuard
{
my ($name) = @_;
$name =~ s/\./_/g;
$name = uc($name);
print "__INCLUDED_DB_TEMPLATE_SCHEMA_STRUCTDEF_${name}_H__";
}
sub startFile()
{
my ($name) = @_;
print "/* This file is generated automatically, do not edit, change the source ($name) instead. */\n\n";
print "#ifndef ";
printHdrGuard($name);
print "\n";
print "#define ";
printHdrGuard($name);
print "\n\n";
}
sub endFile()
{
my ($name) = @_;
print "\n#endif // ";
printHdrGuard($name);
print "\n";
}
1;

View File

@ -119,7 +119,7 @@ sub parseStruct
my @curComment = ();
# Read and parse the file
my $name;
my $name = $ARGV[0];
while (<>)
{
chomp;
@ -134,5 +134,7 @@ while (<>)
else { print "Unmatched line: $_\n"; }
}
CG::startFile($name);
CG::printEnums(\@enumList);
CG::printStructs(\@structList, \%structMap, \%enumMap);
CG::endFile($name);

View File

@ -144,4 +144,15 @@ sub printStructs()
}
}
sub startFile()
{
my ($name) = @_;
print "-- This file is generated automatically, do not edit, change the source ($name) instead.\n\n";
}
sub endFile()
{
}
1;