|
22 | 22 | my @input_files; |
23 | 23 | my $output_path = ''; |
24 | 24 | my $major_version; |
| 25 | +my $include_path; |
25 | 26 |
|
26 | 27 | # Process command line switches. |
27 | 28 | while (@ARGV) |
|
31 | 32 | { |
32 | 33 | push @input_files, $arg; |
33 | 34 | } |
| 35 | + elsif ($arg =~ /^-I/) |
| 36 | + { |
| 37 | + $include_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV; |
| 38 | + } |
34 | 39 | elsif ($arg =~ /^-o/) |
35 | 40 | { |
36 | 41 | $output_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV; |
|
50 | 55 | # Sanity check arguments. |
51 | 56 | die "No input files.\n" if !@input_files; |
52 | 57 | die "--set-version must be specified.\n" if !defined $major_version; |
| 58 | +die "-I, the header include path, must be specified.\n" if !$include_path; |
53 | 59 |
|
54 | 60 | # Make sure output_path ends in a slash. |
55 | 61 | if ($output_path ne '' && substr($output_path, -1) ne '/') |
|
133 | 139 | # While duplicate OIDs would only cause a failure if they appear in |
134 | 140 | # the same catalog, our project policy is that manually assigned OIDs |
135 | 141 | # should be globally unique, to avoid confusion. |
136 | | -# |
137 | | -# Also use the loop to determine the maximum explicitly assigned oid |
138 | | -# found in the data file, we'll use that for default oid assignments. |
139 | 142 | my $found = 0; |
140 | | -my $maxoid = 0; |
141 | 143 | foreach my $oid (keys %oidcounts) |
142 | 144 | { |
143 | | - if ($oid > $maxoid) |
144 | | - { |
145 | | - $maxoid = $oid; |
146 | | - } |
147 | 145 | next unless $oidcounts{$oid} > 1; |
148 | 146 | print STDERR "Duplicate OIDs detected:\n" if !$found; |
149 | 147 | print STDERR "$oid\n"; |
150 | 148 | $found++; |
151 | 149 | } |
152 | 150 | die "found $found duplicate OID(s) in catalog data\n" if $found; |
153 | 151 |
|
| 152 | + |
| 153 | +# Oids not specified in the input files are automatically assigned, |
| 154 | +# starting at FirstGenbkiObjectId. |
| 155 | +my $FirstGenbkiObjectId = |
| 156 | + Catalog::FindDefinedSymbol('access/transam.h', $include_path, |
| 157 | + 'FirstGenbkiObjectId'); |
| 158 | +my $GenbkiNextOid = $FirstGenbkiObjectId; |
| 159 | + |
| 160 | + |
154 | 161 | # Fetch some special data that we will substitute into the output file. |
155 | 162 | # CAUTION: be wary about what symbols you substitute into the .bki file here! |
156 | 163 | # It's okay to substitute things that are expected to be really constant |
|
418 | 425 | # Assign oid if oid column exists and no explicit assignment in row |
419 | 426 | if ($attname eq "oid" and not defined $bki_values{$attname}) |
420 | 427 | { |
421 | | - $bki_values{$attname} = $maxoid; |
422 | | - $maxoid++; |
| 428 | + $bki_values{$attname} = $GenbkiNextOid; |
| 429 | + $GenbkiNextOid++; |
423 | 430 | } |
424 | 431 |
|
425 | 432 | # Substitute constant values we acquired above. |
@@ -858,6 +865,7 @@ sub usage |
858 | 865 | Usage: genbki.pl [options] header... |
859 | 866 |
|
860 | 867 | Options: |
| 868 | + -I include path |
861 | 869 | -o output path |
862 | 870 | --set-version PostgreSQL version number for initdb cross-check |
863 | 871 |
|
|
0 commit comments