@@ -33,185 +33,186 @@ sub ParseHeader
33
33
' TransactionId' => ' xid' ,
34
34
' XLogRecPtr' => ' pg_lsn' );
35
35
36
- my %catalog ;
37
- my $declaring_attributes = 0;
38
- my $is_varlen = 0;
39
- my $is_client_code = 0;
36
+ my %catalog ;
37
+ my $declaring_attributes = 0;
38
+ my $is_varlen = 0;
39
+ my $is_client_code = 0;
40
40
41
- $catalog {columns } = [];
42
- $catalog {toasting } = [];
43
- $catalog {indexing } = [];
44
- $catalog {client_code } = [];
41
+ $catalog {columns } = [];
42
+ $catalog {toasting } = [];
43
+ $catalog {indexing } = [];
44
+ $catalog {client_code } = [];
45
45
46
- open (my $ifh , ' <' , $input_file ) || die " $input_file : $! " ;
46
+ open (my $ifh , ' <' , $input_file ) || die " $input_file : $! " ;
47
47
48
- # Scan the input file.
49
- while (<$ifh >)
50
- {
48
+ # Scan the input file.
49
+ while (<$ifh >)
50
+ {
51
51
52
- # Set appropriate flag when we're in certain code sections.
53
- if (/ ^#/ )
52
+ # Set appropriate flag when we're in certain code sections.
53
+ if (/ ^#/ )
54
+ {
55
+ $is_varlen = 1 if / ^#ifdef\s +CATALOG_VARLEN/ ;
56
+ if (/ ^#ifdef\s +EXPOSE_TO_CLIENT_CODE/ )
54
57
{
55
- $is_varlen = 1 if / ^#ifdef\s +CATALOG_VARLEN/ ;
56
- if (/ ^#ifdef\s +EXPOSE_TO_CLIENT_CODE/ )
57
- {
58
- $is_client_code = 1;
59
- next ;
60
- }
61
- next if !$is_client_code ;
58
+ $is_client_code = 1;
59
+ next ;
62
60
}
61
+ next if !$is_client_code ;
62
+ }
63
63
64
- if (!$is_client_code )
64
+ if (!$is_client_code )
65
+ {
66
+ # Strip C-style comments.
67
+ s ;/\*(.|\n)*\*/;;g;
68
+ if (m ; /\* ; )
65
69
{
66
- # Strip C-style comments.
67
- s ;/\*(.|\n)*\*/;;g;
68
- if (m ; /\* ; )
69
- {
70
-
71
- # handle multi-line comments properly.
72
- my $next_line = <$ifh >;
73
- die " $input_file : ends within C-style comment\n "
74
- if !defined $next_line ;
75
- $_ .= $next_line ;
76
- redo ;
77
- }
78
70
79
- # Strip useless whitespace and trailing semicolons.
80
- chomp ;
81
- s / ^\s +// ;
82
- s / ;\s *$// ;
83
- s /\s +/ / g ;
71
+ # handle multi-line comments properly.
72
+ my $next_line = <$ifh >;
73
+ die " $input_file : ends within C-style comment\n "
74
+ if !defined $next_line ;
75
+ $_ .= $next_line ;
76
+ redo ;
84
77
}
85
78
86
- # Push the data into the appropriate data structure.
87
- if (/ ^DECLARE_TOAST\(\s *(\w +),\s *(\d +),\s *(\d +)\) / )
79
+ # Strip useless whitespace and trailing semicolons.
80
+ chomp ;
81
+ s / ^\s +// ;
82
+ s / ;\s *$// ;
83
+ s /\s +/ / g ;
84
+ }
85
+
86
+ # Push the data into the appropriate data structure.
87
+ if (/ ^DECLARE_TOAST\(\s *(\w +),\s *(\d +),\s *(\d +)\) / )
88
+ {
89
+ my ($toast_name , $toast_oid , $index_oid ) = ($1 , $2 , $3 );
90
+ push @{ $catalog {toasting } },
91
+ " declare toast $toast_oid $index_oid on $toast_name \n " ;
92
+ }
93
+ elsif (/ ^DECLARE_(UNIQUE_)?INDEX\(\s *(\w +),\s *(\d +),\s *(.+)\) / )
94
+ {
95
+ my ($is_unique , $index_name , $index_oid , $using ) =
96
+ ($1 , $2 , $3 , $4 );
97
+ push @{ $catalog {indexing } },
98
+ sprintf (
99
+ " declare %sindex %s %s %s \n " ,
100
+ $is_unique ? ' unique ' : ' ' ,
101
+ $index_name , $index_oid , $using );
102
+ }
103
+ elsif (/ ^BUILD_INDICES/ )
104
+ {
105
+ push @{ $catalog {indexing } }, " build indices\n " ;
106
+ }
107
+ elsif (/ ^CATALOG\( (\w +),(\d +),(\w +)\) / )
108
+ {
109
+ $catalog {catname } = $1 ;
110
+ $catalog {relation_oid } = $2 ;
111
+ $catalog {relation_oid_macro } = $3 ;
112
+
113
+ $catalog {bootstrap } = /BKI_BOOTSTRAP/ ? ' bootstrap' : ' ' ;
114
+ $catalog {shared_relation } =
115
+ / BKI_SHARED_RELATION/ ? ' shared_relation' : ' ' ;
116
+ $catalog {without_oids } =
117
+ / BKI_WITHOUT_OIDS/ ? ' without_oids' : ' ' ;
118
+ if (/ BKI_ROWTYPE_OID\( (\d +),(\w +)\) / )
88
119
{
89
- my ( $toast_name , $toast_oid , $index_oid ) = ( $1 , $2 , $3 ) ;
90
- push @{ $catalog {toasting } },
91
- " declare toast $toast_oid $index_oid on $toast_name \n " ;
120
+ $catalog { rowtype_oid } = $1 ;
121
+ $catalog {rowtype_oid_clause } = " rowtype_oid $1 " ;
122
+ $catalog { rowtype_oid_macro } = $2 ;
92
123
}
93
- elsif ( / ^DECLARE_(UNIQUE_)?INDEX \(\s *( \w +), \s *( \d +), \s *(.+) \) / )
124
+ else
94
125
{
95
- my ($is_unique , $index_name , $index_oid , $using ) =
96
- ($1 , $2 , $3 , $4 );
97
- push @{ $catalog {indexing } },
98
- sprintf (
99
- " declare %sindex %s %s %s \n " ,
100
- $is_unique ? ' unique ' : ' ' ,
101
- $index_name , $index_oid , $using );
126
+ $catalog {rowtype_oid } = ' ' ;
127
+ $catalog {rowtype_oid_clause } = ' ' ;
128
+ $catalog {rowtype_oid_macro } = ' ' ;
102
129
}
103
- elsif (/ ^BUILD_INDICES/ )
130
+ $catalog {schema_macro } = /BKI_SCHEMA_MACRO/ ? 1 : 0;
131
+ $declaring_attributes = 1;
132
+ }
133
+ elsif ($is_client_code )
134
+ {
135
+ if (/ ^#endif/ )
104
136
{
105
- push @{ $catalog { indexing } }, " build indices \n " ;
137
+ $is_client_code = 0 ;
106
138
}
107
- elsif ( / ^CATALOG \( ( \w +),( \d +),( \w +) \) / )
139
+ else
108
140
{
109
- $catalog {catname } = $1 ;
110
- $catalog {relation_oid } = $2 ;
111
- $catalog {relation_oid_macro } = $3 ;
112
-
113
- $catalog {bootstrap } = /BKI_BOOTSTRAP/ ? ' bootstrap' : ' ' ;
114
- $catalog {shared_relation } =
115
- / BKI_SHARED_RELATION/ ? ' shared_relation' : ' ' ;
116
- $catalog {without_oids } =
117
- / BKI_WITHOUT_OIDS/ ? ' without_oids' : ' ' ;
118
- if (/ BKI_ROWTYPE_OID\( (\d +),(\w +)\) / )
119
- {
120
- $catalog {rowtype_oid } = $1 ;
121
- $catalog {rowtype_oid_clause } = " rowtype_oid $1 " ;
122
- $catalog {rowtype_oid_macro } = $2 ;
123
- }
124
- else
125
- {
126
- $catalog {rowtype_oid } = ' ' ;
127
- $catalog {rowtype_oid_clause } = ' ' ;
128
- $catalog {rowtype_oid_macro } = ' ' ;
129
- }
130
- $catalog {schema_macro } = /BKI_SCHEMA_MACRO/ ? 1 : 0;
131
- $declaring_attributes = 1;
141
+ push @{ $catalog {client_code } }, $_ ;
132
142
}
133
- elsif ($is_client_code )
143
+ }
144
+ elsif ($declaring_attributes )
145
+ {
146
+ next if (/ ^{|^$ / );
147
+ if (/ ^}/ )
134
148
{
135
- if (/ ^#endif/ )
136
- {
137
- $is_client_code = 0;
138
- }
139
- else
140
- {
141
- push @{ $catalog {client_code } }, $_ ;
142
- }
149
+ $declaring_attributes = 0;
143
150
}
144
- elsif ( $declaring_attributes )
151
+ else
145
152
{
146
- next if (/ ^{|^$ / );
147
- if (/ ^}/ )
153
+ my %column ;
154
+ my @attopts = split /\s +/, $_ ;
155
+ my $atttype = shift @attopts ;
156
+ my $attname = shift @attopts ;
157
+ die " parse error ($input_file )"
158
+ unless ($attname and $atttype );
159
+
160
+ if (exists $RENAME_ATTTYPE {$atttype })
148
161
{
149
- $declaring_attributes = 0 ;
162
+ $atttype = $RENAME_ATTTYPE { $atttype } ;
150
163
}
151
- else
164
+
165
+ # If the C name ends with '[]' or '[digits]', we have
166
+ # an array type, so we discard that from the name and
167
+ # prepend '_' to the type.
168
+ if ($attname =~ / (\w +)\[\d *\] / )
152
169
{
153
- my %column ;
154
- my @attopts = split /\s +/, $_ ;
155
- my $atttype = shift @attopts ;
156
- my $attname = shift @attopts ;
157
- die " parse error ($input_file )"
158
- unless ($attname and $atttype );
159
-
160
- if (exists $RENAME_ATTTYPE {$atttype })
170
+ $attname = $1 ;
171
+ $atttype = ' _' . $atttype ;
172
+ }
173
+
174
+ $column {type } = $atttype ;
175
+ $column {name } = $attname ;
176
+ $column {is_varlen } = 1 if $is_varlen ;
177
+
178
+ foreach my $attopt (@attopts )
179
+ {
180
+ if ($attopt eq ' BKI_FORCE_NULL' )
161
181
{
162
- $atttype = $RENAME_ATTTYPE { $atttype } ;
182
+ $column { forcenull } = 1 ;
163
183
}
164
-
165
- # If the C name ends with '[]' or '[digits]', we have
166
- # an array type, so we discard that from the name and
167
- # prepend '_' to the type.
168
- if ($attname =~ / (\w +)\[\d *\] / )
184
+ elsif ($attopt eq ' BKI_FORCE_NOT_NULL' )
169
185
{
170
- $attname = $1 ;
171
- $atttype = ' _' . $atttype ;
186
+ $column {forcenotnull } = 1;
172
187
}
173
188
174
- $column {type } = $atttype ;
175
- $column {name } = $attname ;
176
- $column {is_varlen } = 1 if $is_varlen ;
189
+ # We use quotes for values like \0 and \054, to
190
+ # make sure all compilers and syntax highlighters
191
+ # can recognize them properly.
192
+ elsif ($attopt =~ / BKI_DEFAULT\( ['"]?([^'"]+)['"]?\) / )
193
+ {
194
+ $column {default } = $1 ;
195
+ }
196
+ elsif ($attopt =~ / BKI_LOOKUP\( (\w +)\) / )
197
+ {
198
+ $column {lookup } = $1 ;
199
+ }
200
+ else
201
+ {
202
+ die
203
+ " unknown column option $attopt on column $attname " ;
204
+ }
177
205
178
- foreach my $attopt ( @attopts )
206
+ if ( $column { forcenull } and $column { forcenotnull } )
179
207
{
180
- if ($attopt eq ' BKI_FORCE_NULL' )
181
- {
182
- $column {forcenull } = 1;
183
- }
184
- elsif ($attopt eq ' BKI_FORCE_NOT_NULL' )
185
- {
186
- $column {forcenotnull } = 1;
187
- }
188
- # We use quotes for values like \0 and \054, to
189
- # make sure all compilers and syntax highlighters
190
- # can recognize them properly.
191
- elsif ($attopt =~ / BKI_DEFAULT\( ['"]?([^'"]+)['"]?\) / )
192
- {
193
- $column {default } = $1 ;
194
- }
195
- elsif ($attopt =~ / BKI_LOOKUP\( (\w +)\) / )
196
- {
197
- $column {lookup } = $1 ;
198
- }
199
- else
200
- {
201
- die
202
- " unknown column option $attopt on column $attname " ;
203
- }
204
-
205
- if ($column {forcenull } and $column {forcenotnull })
206
- {
207
- die " $attname is forced both null and not null" ;
208
- }
208
+ die " $attname is forced both null and not null" ;
209
209
}
210
- push @{ $catalog {columns } }, \%column ;
211
210
}
211
+ push @{ $catalog {columns } }, \%column ;
212
212
}
213
213
}
214
- close $ifh ;
214
+ }
215
+ close $ifh ;
215
216
return \%catalog ;
216
217
}
217
218
@@ -228,7 +229,7 @@ sub ParseData
228
229
$input_file =~ / (\w +)\. dat$ /
229
230
or die " Input file $input_file needs to be a .dat file.\n " ;
230
231
my $catname = $1 ;
231
- my $data = [];
232
+ my $data = [];
232
233
233
234
# Scan the input file.
234
235
while (<$ifd >)
@@ -311,8 +312,9 @@ sub AddDefaultValues
311
312
{
312
313
$row -> {$attname } = $column -> {default };
313
314
}
314
- elsif ($catname eq ' pg_proc' && $attname eq ' pronargs' &&
315
- defined ($row -> {proargtypes }))
315
+ elsif ($catname eq ' pg_proc'
316
+ && $attname eq ' pronargs'
317
+ && defined ($row -> {proargtypes }))
316
318
{
317
319
# pg_proc.pronargs can be derived from proargtypes.
318
320
my @proargtypes = split /\s +/, $row -> {proargtypes };
@@ -328,7 +330,7 @@ sub AddDefaultValues
328
330
if (@missing_fields )
329
331
{
330
332
die sprintf " missing values for field(s) %s in %s .dat line %s \n " ,
331
- join (' , ' , @missing_fields ), $catname , $row -> {line_number };
333
+ join (' , ' , @missing_fields ), $catname , $row -> {line_number };
332
334
}
333
335
}
334
336
@@ -379,7 +381,7 @@ sub FindDefinedSymbol
379
381
sub FindDefinedSymbolFromData
380
382
{
381
383
my ($data , $symbol ) = @_ ;
382
- foreach my $row (@{ $data })
384
+ foreach my $row (@{$data })
383
385
{
384
386
if ($row -> {oid_symbol } eq $symbol )
385
387
{
0 commit comments