2007-04-17: Added functionality for CDEFS. Still needs changes to dbToRecordtypeH.
This commit is contained in:
@@ -161,6 +161,10 @@ sub parse_recordtype {
|
||||
$dbd->add($rtyp);
|
||||
popContext("recordtype($name)");
|
||||
return;
|
||||
}
|
||||
elsif (m/\G % (.*) \n/oxgc) {
|
||||
print " Recordtype-Cdef: $1\n" if $debug;
|
||||
$rtyp->add_cdef($1);
|
||||
} else {
|
||||
m/\G (.*) $/moxgc or dieContext("Unexpected end of input");
|
||||
dieContext("Syntax error in '$1'");
|
||||
|
||||
@@ -11,6 +11,7 @@ sub init {
|
||||
$this->{FIELD_INDEX} = {};
|
||||
$this->{DEVICE_LIST} = [];
|
||||
$this->{DEVICE_INDEX} = {};
|
||||
$this->{CDEFS} = [];
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -72,6 +73,15 @@ sub device {
|
||||
return $this->{DEVICE_INDEX}->{$choice};
|
||||
}
|
||||
|
||||
sub add_cdef {
|
||||
my ($this, $cdef) = @_;
|
||||
push @{$this->{CDEFS}}, $cdef;
|
||||
}
|
||||
|
||||
sub cdefs {
|
||||
return @{shift->{CDEFS}};
|
||||
}
|
||||
|
||||
sub toDeclaration {
|
||||
my $this = shift;
|
||||
my @fields = map {
|
||||
@@ -79,7 +89,8 @@ sub toDeclaration {
|
||||
} $this->fields;
|
||||
my $name = $this->name;
|
||||
$name .= "Record" unless $name eq "dbCommon";
|
||||
return "typedef struct $name {\n" .
|
||||
my $cdefs = join("\n", $this->cdefs);
|
||||
return "$cdefs\ntypedef struct $name {\n" .
|
||||
join("\n", @fields) .
|
||||
"\n} $name;\n";
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use Test::More tests => 14;
|
||||
use Test::More tests => 17;
|
||||
|
||||
use DBD::Recordtype;
|
||||
use DBD::Recfield;
|
||||
@@ -46,3 +46,9 @@ is_deeply \@devices, [$dev1], 'Device list';
|
||||
|
||||
is $rtyp->device('test device'), $dev1, 'Device name lookup';
|
||||
|
||||
is $rtyp->cdefs, 0, 'No cdefs yet';
|
||||
$rtyp->add_cdef("cdef");
|
||||
is $rtyp->cdefs, 1, 'First cdef added';
|
||||
|
||||
my @cdefs = $rtyp->cdefs;
|
||||
is_deeply \@cdefs, ["cdef"], 'cdef list';
|
||||
|
||||
Reference in New Issue
Block a user