2008-07-03 11:45:32 -07:00
|
|
|
#!/usr/bin/perl -w
|
2008-07-03 11:55:17 -07:00
|
|
|
# vim: set et sts=4 sw=4:
|
2008-07-03 11:45:32 -07:00
|
|
|
|
|
|
|
package CG;
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
# Code generator for C struct definitions
|
|
|
|
|
2008-07-09 08:02:10 -07:00
|
|
|
my $filename = "";
|
|
|
|
my $outfile = "";
|
|
|
|
my $startTpl = "";
|
|
|
|
|
2008-07-03 11:55:06 -07:00
|
|
|
sub printStructFieldType
|
2008-07-03 11:45:32 -07:00
|
|
|
{
|
2008-07-03 14:51:23 -07:00
|
|
|
my ($output, $field) = @_;
|
2008-07-03 11:45:32 -07:00
|
|
|
|
2008-07-03 11:55:06 -07:00
|
|
|
$_ = ${$field}{"type"};
|
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
if (/count/) { $$output .= "unsigned int "; }
|
2008-07-11 14:53:10 -07:00
|
|
|
elsif (/([US]D?WORD|[US]BYTE)/) { $$output .= "$1 "; } # "transition" type
|
2008-07-11 07:48:39 -07:00
|
|
|
elsif (/string/) { $$output .= "char* "; }
|
2008-07-03 14:51:23 -07:00
|
|
|
elsif (/real/) { $$output .= "float "; }
|
|
|
|
elsif (/bool/) { $$output .= "bool "; }
|
|
|
|
elsif (/set/) { $$output .= "bool "; }
|
2008-07-10 13:43:26 -07:00
|
|
|
elsif (/enum/) { $$output .= "${${$field}{\"enum\"}}{\"name\"} "; }
|
2008-07-12 14:39:49 -07:00
|
|
|
elsif (/struct/)
|
|
|
|
{
|
|
|
|
my $name;
|
|
|
|
my $prefix = "";
|
|
|
|
my $suffix = "";
|
|
|
|
|
|
|
|
getStructName(\$name, ${$field}{"struct"}, \$prefix, \$suffix);
|
|
|
|
|
|
|
|
$$output .= "${prefix}${name}${suffix}* ";
|
|
|
|
}
|
2008-07-03 16:21:45 -07:00
|
|
|
elsif (/IMD_model/) { $$output .= "iIMDShape* "; }
|
2008-07-09 13:47:17 -07:00
|
|
|
elsif (/C-only-field/) { $$output .= "${$field}{\"ctype\"} "; }
|
2008-07-11 15:14:09 -07:00
|
|
|
else { die "error:$filename:${$field}{\"line\"}: UKNOWN TYPE: $_"; }
|
2008-07-03 11:45:32 -07:00
|
|
|
}
|
|
|
|
|
2008-07-03 11:55:17 -07:00
|
|
|
sub preProcessField
|
2008-07-03 11:45:32 -07:00
|
|
|
{
|
2008-07-03 11:55:06 -07:00
|
|
|
my ($field, $comments) = @_;
|
2008-07-03 11:45:32 -07:00
|
|
|
|
2008-07-04 05:50:58 -07:00
|
|
|
if (grep(/unique/, @{${$field}{"qualifiers"}}))
|
2008-07-03 11:45:32 -07:00
|
|
|
{
|
2008-07-03 11:55:06 -07:00
|
|
|
# Separate this notice from the rest of the comment if there's any
|
|
|
|
push @{$comments}, "" if @{$comments};
|
2008-07-03 11:45:32 -07:00
|
|
|
|
2008-07-03 11:55:06 -07:00
|
|
|
push @{$comments}, " Unique across all instances";
|
2008-07-03 11:45:32 -07:00
|
|
|
}
|
2008-07-03 11:55:17 -07:00
|
|
|
|
2008-07-04 05:51:09 -07:00
|
|
|
if (grep(/optional/, @{${$field}{"qualifiers"}}))
|
|
|
|
{
|
|
|
|
# Separate this notice from the rest of the comment if there's any
|
|
|
|
push @{$comments}, "" if @{$comments};
|
|
|
|
|
|
|
|
push @{$comments}, " This field is optional and can be NULL to indicate that it has no value";
|
|
|
|
}
|
|
|
|
|
2008-07-03 11:55:17 -07:00
|
|
|
$_ = ${$field}{"type"};
|
|
|
|
$_ = "" unless $_;
|
|
|
|
|
|
|
|
if (/set/)
|
2008-07-03 11:45:32 -07:00
|
|
|
{
|
2008-07-03 11:55:06 -07:00
|
|
|
# Separate this notice from the rest of the comment if there's any
|
|
|
|
push @{$comments}, "" if @{$comments};
|
2008-07-03 11:45:32 -07:00
|
|
|
|
2008-07-03 11:55:06 -07:00
|
|
|
push @{$comments}, " \@see ${$field}{\"enum\"} for the meaning of index values";
|
2008-07-03 11:45:32 -07:00
|
|
|
}
|
2008-07-03 11:55:06 -07:00
|
|
|
}
|
2008-07-03 11:45:32 -07:00
|
|
|
|
2008-07-03 11:55:17 -07:00
|
|
|
sub postProcessField
|
2008-07-03 11:55:06 -07:00
|
|
|
{
|
2008-07-03 14:51:23 -07:00
|
|
|
my ($output, $field, $enumMap) = @_;
|
2008-07-03 11:55:17 -07:00
|
|
|
$_ = ${$field}{"type"};
|
2008-07-03 11:55:06 -07:00
|
|
|
$_ = "" unless $_;
|
2008-07-03 11:45:32 -07:00
|
|
|
|
2008-07-03 11:55:06 -07:00
|
|
|
if (/set/)
|
2008-07-03 11:45:32 -07:00
|
|
|
{
|
2008-07-09 05:16:55 -07:00
|
|
|
my $enum = ${$field}{"enum"};
|
2008-07-03 11:55:06 -07:00
|
|
|
my $enumSize = @{${$enum}{"values"}};
|
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
$$output .= "\[${enumSize}]" if (/set/);
|
2008-07-03 11:45:32 -07:00
|
|
|
}
|
2008-07-03 11:55:06 -07:00
|
|
|
}
|
2008-07-03 11:45:32 -07:00
|
|
|
|
2008-07-03 11:55:06 -07:00
|
|
|
sub printComments
|
|
|
|
{
|
2008-07-03 14:51:23 -07:00
|
|
|
my ($output, $comments, $indent) = @_;
|
2008-07-03 11:45:32 -07:00
|
|
|
|
2008-07-03 11:55:06 -07:00
|
|
|
return unless @{$comments};
|
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
$$output .= "\t" if $indent;
|
|
|
|
$$output .= "/**\n";
|
2008-07-03 11:55:06 -07:00
|
|
|
|
|
|
|
foreach my $comment (@{$comments})
|
|
|
|
{
|
2008-07-03 14:51:23 -07:00
|
|
|
$$output .= "\t" if $indent;
|
|
|
|
$$output .= " *${comment}\n";
|
2008-07-03 11:45:32 -07:00
|
|
|
}
|
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
$$output .= "\t" if $indent;
|
|
|
|
$$output .= " */\n";
|
2008-07-03 11:45:32 -07:00
|
|
|
}
|
|
|
|
|
2008-07-03 11:55:06 -07:00
|
|
|
sub printStructFields
|
2008-07-03 11:45:32 -07:00
|
|
|
{
|
2008-07-03 14:51:23 -07:00
|
|
|
my $output = $_[0];
|
|
|
|
my @fields = @{${$_[1]}{"fields"}};
|
|
|
|
my $enumMap = $_[2];
|
2008-07-03 11:45:32 -07:00
|
|
|
|
2008-07-03 11:55:06 -07:00
|
|
|
while (@fields)
|
|
|
|
{
|
|
|
|
my $field = shift(@fields);
|
|
|
|
my @comments = @{${$field}{"comment"}};
|
2008-07-03 11:45:32 -07:00
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
preProcessField($field, \@comments);
|
2008-07-03 11:45:32 -07:00
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
printComments($output, \@comments, 1);
|
2008-07-03 11:45:32 -07:00
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
$$output .= "\t";
|
|
|
|
printStructFieldType($output, $field);
|
|
|
|
$$output .= ${$field}{"name"};
|
2008-07-03 11:45:32 -07:00
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
postProcessField($output, $field, $enumMap);
|
|
|
|
$$output .= ";\n";
|
2008-07-03 11:55:06 -07:00
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
$$output .= "\n" if @fields;
|
2008-07-03 11:55:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-09 06:59:23 -07:00
|
|
|
sub getStructName
|
2008-07-03 11:55:06 -07:00
|
|
|
{
|
2008-07-12 14:39:49 -07:00
|
|
|
my ($name, $struct, $prefix, $suffix) = @_;
|
2008-07-03 11:55:06 -07:00
|
|
|
|
|
|
|
foreach (keys %{${$struct}{"qualifiers"}})
|
2008-07-03 11:45:32 -07:00
|
|
|
{
|
2008-07-03 11:55:06 -07:00
|
|
|
$$prefix = ${${$struct}{"qualifiers"}}{$_} if /prefix/ and not $$prefix;
|
2008-07-10 14:11:24 -07:00
|
|
|
$$suffix = ${${$struct}{"qualifiers"}}{$_} if /suffix/ and not $$suffix;
|
2008-07-03 11:55:06 -07:00
|
|
|
|
2008-07-12 14:39:49 -07:00
|
|
|
getStructName($name, ${${$struct}{"qualifiers"}}{"inherit"}, $prefix, $suffix) if /inherit/;
|
2008-07-09 06:59:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
$$name = ${$struct}{"name"};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub printStructContent
|
|
|
|
{
|
|
|
|
my ($output, $struct, $structMap, $enumMap) = @_;
|
|
|
|
|
|
|
|
foreach (keys %{${$struct}{"qualifiers"}})
|
|
|
|
{
|
2008-07-03 11:55:06 -07:00
|
|
|
if (/inherit/)
|
2008-07-03 11:45:32 -07:00
|
|
|
{
|
2008-07-08 04:37:23 -07:00
|
|
|
my $inheritStruct = ${${$struct}{"qualifiers"}}{"inherit"};
|
|
|
|
my $inheritName = ${$inheritStruct}{"name"};
|
2008-07-03 11:55:06 -07:00
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
$$output .= "\t/* BEGIN of inherited \"$inheritName\" definition */\n";
|
2008-07-09 06:59:23 -07:00
|
|
|
printStructContent($output, $inheritStruct, $structMap, $enumMap);
|
2008-07-03 14:51:23 -07:00
|
|
|
$$output .= "\t/* END of inherited \"$inheritName\" definition */\n";
|
2008-07-03 11:45:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
printStructFields($output, $struct, $enumMap);
|
2008-07-03 11:55:06 -07:00
|
|
|
}
|
2008-07-03 11:45:32 -07:00
|
|
|
|
2008-07-11 06:30:25 -07:00
|
|
|
sub printLoadFunc
|
|
|
|
{
|
|
|
|
my ($output, $struct) = @_;
|
|
|
|
|
|
|
|
$$output .= "/* Forward declaration to allow pointers to this type */\n"
|
|
|
|
. "struct sqlite3;\n"
|
|
|
|
. "\n"
|
|
|
|
. "/** Load the contents of the ${$struct}{\"name\"} table from the given SQLite database.\n"
|
|
|
|
. " *\n"
|
|
|
|
. " * \@param db represents the database to load from\n"
|
|
|
|
. " *\n"
|
|
|
|
. " * \@return true if we succesfully loaded all available rows from the table,\n"
|
|
|
|
. " * false otherwise.\n"
|
|
|
|
. " */\n"
|
|
|
|
. "extern bool\n"
|
|
|
|
. "#line ${${${$struct}{\"qualifiers\"}}{\"loadFunc\"}}{\"line\"} \"$filename\"\n"
|
|
|
|
. "${${${$struct}{\"qualifiers\"}}{\"loadFunc\"}}{\"name\"}\n";
|
|
|
|
|
|
|
|
my $count = $$output =~ s/\n/\n/sg;
|
|
|
|
$count += 2;
|
|
|
|
$$output .= "#line $count \"$outfile\"\n"
|
|
|
|
. "\t(struct sqlite3* db);\n\n";
|
|
|
|
}
|
|
|
|
|
2008-07-11 07:02:17 -07:00
|
|
|
sub getMacroName
|
|
|
|
{
|
|
|
|
my ($name, $struct, $prefix, $suffix) = @_;
|
|
|
|
|
|
|
|
foreach (keys %{${$struct}{"qualifiers"}})
|
|
|
|
{
|
|
|
|
if (/macro/)
|
|
|
|
{
|
|
|
|
foreach (keys %{${${$struct}{"qualifiers"}}{"macro"}})
|
|
|
|
{
|
|
|
|
$$prefix = ${${${$struct}{"qualifiers"}}{"macro"}}{$_} if /prefix/ and not $$prefix;
|
|
|
|
$$suffix = ${${${$struct}{"qualifiers"}}{"macro"}}{$_} if /suffix/ and not $$suffix;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getMacroName($name, ${${$struct}{"qualifiers"}}{"inherit"}, $prefix, $suffix) if /inherit/;
|
|
|
|
}
|
|
|
|
|
|
|
|
$$name = "${$prefix}${$struct}{\"name\"}${$suffix}";
|
|
|
|
}
|
|
|
|
|
|
|
|
sub printMacroStructFields
|
|
|
|
{
|
|
|
|
my ($output, $struct, $enumMap, $first) = @_;
|
|
|
|
|
|
|
|
foreach (keys %{${$struct}{"qualifiers"}})
|
|
|
|
{
|
|
|
|
printMacroStructFields($output, ${${$struct}{"qualifiers"}}{"inherit"}, $enumMap, 0) if /inherit/;
|
|
|
|
}
|
|
|
|
|
|
|
|
my @fields = @{${$struct}{"fields"}};
|
|
|
|
while (@fields)
|
|
|
|
{
|
|
|
|
my $field = shift(@fields);
|
|
|
|
|
|
|
|
$$output .= "\t";
|
|
|
|
printStructFieldType($output, $field);
|
|
|
|
$$output .= ${$field}{"name"};
|
|
|
|
|
|
|
|
postProcessField($output, $field, $enumMap);
|
|
|
|
$$output .= "; \\" if @fields or not $first;
|
|
|
|
$$output .= "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$$output .= "\n" if $first;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub printMacro
|
|
|
|
{
|
|
|
|
my ($output, $struct, $enumMap) = @_;
|
|
|
|
|
|
|
|
my $prefix = "";
|
|
|
|
my $suffix = "";
|
|
|
|
my $macroName;
|
|
|
|
|
|
|
|
getMacroName(\$macroName, $struct, \$prefix, \$suffix);
|
|
|
|
|
|
|
|
$$output .= "#define $macroName \\\n";
|
|
|
|
|
|
|
|
printMacroStructFields($output, $struct, $enumMap, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub hasMacro
|
|
|
|
{
|
|
|
|
my ($struct) = @_;
|
|
|
|
|
2008-07-11 09:41:59 -07:00
|
|
|
return ${${${$struct}{"qualifiers"}}{"macro"}}{"has"} if exists(${${${$struct}{"qualifiers"}}{"macro"}}{"has"});
|
2008-07-11 07:02:17 -07:00
|
|
|
|
|
|
|
foreach (keys %{${$struct}{"qualifiers"}})
|
|
|
|
{
|
|
|
|
return hasMacro(${${$struct}{"qualifiers"}}{"inherit"}) if /inherit/;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-07-03 12:10:36 -07:00
|
|
|
sub printEnum()
|
2008-07-03 11:55:06 -07:00
|
|
|
{
|
2008-07-03 14:51:23 -07:00
|
|
|
my ($output, $enum) = @_;
|
2008-07-03 11:45:32 -07:00
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
printComments($output, ${$enum}{"comment"}, 0);
|
2008-07-03 11:55:06 -07:00
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
# Start printing the enum
|
2008-07-09 06:59:23 -07:00
|
|
|
$$output .= "typedef enum ${$enum}{\"name\"}\n{\n";
|
2008-07-03 11:55:06 -07:00
|
|
|
|
2008-07-03 12:10:36 -07:00
|
|
|
my @values = @{${$enum}{"values"}};
|
2008-07-03 11:55:06 -07:00
|
|
|
|
2008-07-11 06:06:02 -07:00
|
|
|
my $valprefix = "";
|
2008-07-10 14:24:39 -07:00
|
|
|
$valprefix = ${${$enum}{"qualifiers"}}{"valprefix"} if exists(${${$enum}{"qualifiers"}}{"valprefix"});
|
2008-07-11 04:17:08 -07:00
|
|
|
my $valsuffix = "";
|
|
|
|
$valsuffix = ${${$enum}{"qualifiers"}}{"valsuffix"} if exists(${${$enum}{"qualifiers"}}{"valsuffix"});
|
2008-07-10 14:24:39 -07:00
|
|
|
|
2008-07-11 06:06:02 -07:00
|
|
|
$valprefix = "${$enum}{\"name\"}_" if not exists(${${$enum}{"qualifiers"}}{"valprefix"}) and not exists(${${$enum}{"qualifiers"}}{"valsuffix"});
|
|
|
|
|
2008-07-03 12:10:36 -07:00
|
|
|
while (@values)
|
|
|
|
{
|
|
|
|
my $value = shift(@values);
|
|
|
|
my $name = ${$value}{"name"};
|
2008-07-03 11:55:06 -07:00
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
printComments($output, ${$value}{"comment"}, 1);
|
2008-07-03 11:55:06 -07:00
|
|
|
|
2008-07-11 04:17:08 -07:00
|
|
|
$$output .= "\t${valprefix}${name}${valsuffix},\n";
|
2008-07-03 11:45:32 -07:00
|
|
|
|
2008-07-10 14:02:58 -07:00
|
|
|
$$output .= "\n" if @values or exists(${${$enum}{"qualifiers"}}{"max"});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exists(${${$enum}{"qualifiers"}}{"max"}))
|
|
|
|
{
|
|
|
|
$$output .= "\t/**\n"
|
|
|
|
. "\t * The number of enumerators in this enum.\n"
|
|
|
|
. "\t */\n"
|
2008-07-11 04:13:01 -07:00
|
|
|
. "\t${${$enum}{\"qualifiers\"}}{\"max\"},\n";
|
2008-07-03 11:55:06 -07:00
|
|
|
}
|
2008-07-03 12:10:36 -07:00
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
# Finish printing the enum
|
|
|
|
$$output .= "} ${$enum}{\"name\"};\n\n";
|
2008-07-03 11:45:32 -07:00
|
|
|
}
|
|
|
|
|
2008-07-03 12:10:36 -07:00
|
|
|
sub printStruct()
|
2008-07-03 11:45:32 -07:00
|
|
|
{
|
2008-07-03 14:51:23 -07:00
|
|
|
my ($output, $struct, $structMap, $enumMap) = @_;
|
2008-07-03 11:55:06 -07:00
|
|
|
|
2008-07-03 12:10:36 -07:00
|
|
|
my $name;
|
|
|
|
my $prefix = "";
|
2008-07-10 14:11:24 -07:00
|
|
|
my $suffix = "";
|
2008-07-03 11:55:06 -07:00
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
printComments($output, ${$struct}{"comment"}, 0);
|
2008-07-03 11:55:06 -07:00
|
|
|
|
2008-07-12 14:39:49 -07:00
|
|
|
getStructName(\$name, $struct, \$prefix, \$suffix);
|
2008-07-09 06:59:23 -07:00
|
|
|
|
2008-07-03 12:10:36 -07:00
|
|
|
# Start printing the structure
|
2008-07-10 14:11:24 -07:00
|
|
|
$$output .= "typedef struct ${prefix}${name}${suffix}\n{\n";
|
2008-07-03 11:55:06 -07:00
|
|
|
|
2008-07-09 06:59:23 -07:00
|
|
|
printStructContent($output, $struct, $structMap, $enumMap);
|
2008-07-03 11:55:06 -07:00
|
|
|
|
2008-07-03 12:10:36 -07:00
|
|
|
# Finish printing the structure
|
2008-07-10 14:11:24 -07:00
|
|
|
$$output .= "} ${prefix}${name}${suffix};\n\n";
|
2008-07-09 08:25:42 -07:00
|
|
|
|
2008-07-11 06:30:25 -07:00
|
|
|
printLoadFunc($output, $struct) if exists(${${$struct}{"qualifiers"}}{"loadFunc"});
|
2008-07-11 07:02:17 -07:00
|
|
|
|
|
|
|
printMacro($output, $struct, $enumMap) if hasMacro($struct);
|
2008-07-03 11:45:32 -07:00
|
|
|
}
|
|
|
|
|
2008-07-03 12:04:00 -07:00
|
|
|
sub printHdrGuard
|
|
|
|
{
|
2008-07-03 14:51:23 -07:00
|
|
|
my ($output, $name) = @_;
|
2008-07-03 12:04:00 -07:00
|
|
|
|
2008-07-09 10:45:56 -07:00
|
|
|
$name =~ tr/\./_/;
|
|
|
|
$name =~ tr/-/_/;
|
2008-07-03 12:04:00 -07:00
|
|
|
$name = uc($name);
|
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
$$output .= "__INCLUDED_DB_TEMPLATE_SCHEMA_STRUCTDEF_${name}_H__";
|
2008-07-03 12:04:00 -07:00
|
|
|
}
|
|
|
|
|
2008-07-09 05:46:53 -07:00
|
|
|
sub processCmdLine()
|
|
|
|
{
|
2008-07-09 06:57:26 -07:00
|
|
|
my ($argv) = @_;
|
|
|
|
|
|
|
|
$startTpl = shift(@$argv) if @$argv > 1;
|
2008-07-09 05:46:53 -07:00
|
|
|
}
|
|
|
|
|
2008-07-03 12:04:00 -07:00
|
|
|
sub startFile()
|
|
|
|
{
|
2008-07-09 09:05:41 -07:00
|
|
|
my ($output, $name, $outputfile) = @_;
|
2008-07-03 12:04:00 -07:00
|
|
|
|
2008-07-09 08:02:10 -07:00
|
|
|
$filename = $name;
|
2008-07-09 09:05:41 -07:00
|
|
|
if ($outputfile)
|
|
|
|
{
|
|
|
|
$outfile = $outputfile;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$outfile = $name;
|
|
|
|
# Replace the extension with ".h" so that we can use it to #include the header
|
|
|
|
$outfile =~ s/\.[^.]*$/.h/;
|
|
|
|
}
|
2008-07-09 08:02:10 -07:00
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
$$output .= "/* This file is generated automatically, do not edit, change the source ($name) instead. */\n\n";
|
2008-07-03 12:04:00 -07:00
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
$$output .= "#ifndef ";
|
2008-07-09 09:05:41 -07:00
|
|
|
printHdrGuard($output, $outfile);
|
2008-07-03 14:51:23 -07:00
|
|
|
$$output .= "\n";
|
2008-07-03 12:04:00 -07:00
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
$$output .= "#define ";
|
2008-07-09 09:05:41 -07:00
|
|
|
printHdrGuard($output, $outfile);
|
2008-07-03 14:51:23 -07:00
|
|
|
$$output .= "\n\n";
|
2008-07-09 06:57:26 -07:00
|
|
|
|
2008-07-10 03:58:13 -07:00
|
|
|
return unless $startTpl;
|
|
|
|
|
2008-07-09 06:57:26 -07:00
|
|
|
$$output .= "#line 1 \"$startTpl\"\n";
|
|
|
|
open (TEMPL, $startTpl);
|
|
|
|
while (<TEMPL>)
|
|
|
|
{
|
|
|
|
s/\$name\b/$name/g;
|
2008-07-09 08:02:10 -07:00
|
|
|
s/\$header\b/$outfile/g;
|
2008-07-09 06:57:26 -07:00
|
|
|
$$output .= $_;
|
|
|
|
}
|
|
|
|
close (TEMPL);
|
|
|
|
|
|
|
|
my $count = $$output =~ s/\n/\n/sg;
|
|
|
|
$count += 2;
|
2008-07-09 08:02:10 -07:00
|
|
|
$$output .= "#line $count \"$outfile\"\n"
|
|
|
|
. "\n";
|
2008-07-03 12:04:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
sub endFile()
|
|
|
|
{
|
2008-07-03 14:51:23 -07:00
|
|
|
my ($output, $name) = @_;
|
2008-07-03 12:04:00 -07:00
|
|
|
|
2008-07-03 14:51:23 -07:00
|
|
|
$$output .= "#endif // ";
|
|
|
|
printHdrGuard($output, $name);
|
|
|
|
$$output .= "\n";
|
2008-07-03 12:04:00 -07:00
|
|
|
}
|
|
|
|
|
2008-07-03 11:45:32 -07:00
|
|
|
1;
|