@@ -46,6 +46,9 @@ sub Catalogs
46
46
47
47
open (INPUT_FILE, ' <' , $input_file ) || die " $input_file : $! " ;
48
48
49
+ my ($filename ) = ($input_file =~ m / (\w +)\. h$ / );
50
+ my $natts_pat = " Natts_$filename " ;
51
+
49
52
# Scan the input file.
50
53
while (<INPUT_FILE>)
51
54
{
@@ -70,8 +73,15 @@ sub Catalogs
70
73
s /\s +/ / g ;
71
74
72
75
# Push the data into the appropriate data structure.
73
- if (/ ^DATA\( insert(\s +OID\s +=\s +(\d +))?\s +\(\s *(.*)\s *\)\s *\) $ / )
76
+ if (/ $natts_pat \s +(\d +)/ )
77
+ {
78
+ $catalog {natts } = $1 ;
79
+ }
80
+ elsif (/ ^DATA\( insert(\s +OID\s +=\s +(\d +))?\s +\(\s *(.*)\s *\)\s *\) $ / )
74
81
{
82
+ check_natts($filename , $catalog {natts }, $3 ,
83
+ $input_file , INPUT_FILE-> input_line_number);
84
+
75
85
push @{ $catalog {data } }, { oid => $2 , bki_values => $3 };
76
86
}
77
87
elsif (/ ^DESCR\(\" (.*)\"\) $ / )
@@ -216,4 +226,20 @@ sub RenameTempFile
216
226
rename ($temp_name , $final_name ) || die " rename: $temp_name : $! " ;
217
227
}
218
228
229
+ # verify the number of fields in the passed-in bki structure
230
+ sub check_natts
231
+ {
232
+ my ($catname , $natts , $bki_val , $file , $line ) = @_ ;
233
+ die " Could not find definition for Natts_${catname} before start of DATA() in $file \n "
234
+ unless defined $natts ;
235
+
236
+ # we're working with a copy and need to count the fields only, so collapse
237
+ $bki_val =~ s / "[^"]*?"/ xxx/ g ;
238
+ my @atts = split /\s +/, $bki_val ;
239
+
240
+ die sprintf
241
+ " Wrong number of attributes in DATA() entry at %s :%d (expected %d but got %d )\n " ,
242
+ $file , $line , $natts , scalar @atts
243
+ unless $natts == @atts ;
244
+ }
219
245
1;
0 commit comments