|
| 1 | +#!/usr/bin/perl |
| 2 | +#---------------------------------------------------------------------- |
| 3 | +# |
| 4 | +# Generate guc_tables.c from guc_parameters.dat. |
| 5 | +# |
| 6 | +# Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group |
| 7 | +# Portions Copyright (c) 1994, Regents of the University of California |
| 8 | +# |
| 9 | +# src/backend/utils/misc/gen_guc_tables.pl |
| 10 | +# |
| 11 | +#---------------------------------------------------------------------- |
| 12 | + |
| 13 | +use strict; |
| 14 | +use warnings FATAL => 'all'; |
| 15 | + |
| 16 | +use FindBin; |
| 17 | +use lib "$FindBin::RealBin/../../catalog"; |
| 18 | +use Catalog; |
| 19 | + |
| 20 | +die "Usage: $0 INPUT_FILE OUTPUT_FILE\n" unless @ARGV == 2; |
| 21 | +my ($input_fname, $output_fname) = @ARGV; |
| 22 | + |
| 23 | +my $parse = Catalog::ParseData($input_fname); |
| 24 | + |
| 25 | +open my $ofh, '>', $output_fname or die; |
| 26 | + |
| 27 | +print_boilerplate($ofh, $output_fname, 'GUC tables'); |
| 28 | +foreach my $type (qw(bool int real string enum)) |
| 29 | +{ |
| 30 | + print_one_table($ofh, $type); |
| 31 | +} |
| 32 | + |
| 33 | +close $ofh; |
| 34 | + |
| 35 | + |
| 36 | +# Adds double quotes and escapes as necessary for C strings. |
| 37 | +sub dquote |
| 38 | +{ |
| 39 | + my ($s) = @_; |
| 40 | + |
| 41 | + return q{"} . $s =~ s/"/\\"/gr . q{"}; |
| 42 | +} |
| 43 | + |
| 44 | +# Print GUC table for one type. |
| 45 | +sub print_one_table |
| 46 | +{ |
| 47 | + my ($ofh, $type) = @_; |
| 48 | + my $Type = ucfirst $type; |
| 49 | + |
| 50 | + print $ofh "\n\n"; |
| 51 | + print $ofh "struct config_${type} ConfigureNames${Type}[] =\n"; |
| 52 | + print $ofh "{\n"; |
| 53 | + |
| 54 | + foreach my $entry (@{$parse}) |
| 55 | + { |
| 56 | + next if $entry->{type} ne $type; |
| 57 | + |
| 58 | + print $ofh "#ifdef $entry->{ifdef}\n" if $entry->{ifdef}; |
| 59 | + print $ofh "\t{\n"; |
| 60 | + printf $ofh "\t\t{%s, %s, %s,\n", |
| 61 | + dquote($entry->{name}), |
| 62 | + $entry->{context}, |
| 63 | + $entry->{group}; |
| 64 | + printf $ofh "\t\t\tgettext_noop(%s),\n", dquote($entry->{short_desc}); |
| 65 | + if ($entry->{long_desc}) |
| 66 | + { |
| 67 | + printf $ofh "\t\t\tgettext_noop(%s)", dquote($entry->{long_desc}); |
| 68 | + } |
| 69 | + else |
| 70 | + { |
| 71 | + print $ofh "\t\t\tNULL"; |
| 72 | + } |
| 73 | + if ($entry->{flags}) |
| 74 | + { |
| 75 | + print $ofh ",\n\t\t\t$entry->{flags}\n"; |
| 76 | + } |
| 77 | + else |
| 78 | + { |
| 79 | + print $ofh "\n"; |
| 80 | + } |
| 81 | + print $ofh "\t\t},\n"; |
| 82 | + print $ofh "\t\t&$entry->{variable},\n"; |
| 83 | + print $ofh "\t\t$entry->{boot_val},"; |
| 84 | + print $ofh " $entry->{min}," |
| 85 | + if $entry->{type} eq 'int' || $entry->{type} eq 'real'; |
| 86 | + print $ofh " $entry->{max}," |
| 87 | + if $entry->{type} eq 'int' || $entry->{type} eq 'real'; |
| 88 | + print $ofh " $entry->{options}," |
| 89 | + if $entry->{type} eq 'enum'; |
| 90 | + print $ofh "\n"; |
| 91 | + printf $ofh "\t\t%s, %s, %s\n", |
| 92 | + ($entry->{check_hook} || 'NULL'), |
| 93 | + ($entry->{assign_hook} || 'NULL'), |
| 94 | + ($entry->{show_hook} || 'NULL'); |
| 95 | + print $ofh "\t},\n"; |
| 96 | + print $ofh "#endif\n" if $entry->{ifdef}; |
| 97 | + print $ofh "\n"; |
| 98 | + } |
| 99 | + |
| 100 | + print $ofh "\t/* End-of-list marker */\n"; |
| 101 | + print $ofh "\t{{0}}\n"; |
| 102 | + print $ofh "};\n"; |
| 103 | + |
| 104 | + return; |
| 105 | +} |
| 106 | + |
| 107 | +sub print_boilerplate |
| 108 | +{ |
| 109 | + my ($fh, $fname, $descr) = @_; |
| 110 | + printf $fh <<EOM, $fname, $descr; |
| 111 | +/*------------------------------------------------------------------------- |
| 112 | + * |
| 113 | + * %s |
| 114 | + * %s |
| 115 | + * |
| 116 | + * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group |
| 117 | + * Portions Copyright (c) 1994, Regents of the University of California |
| 118 | + * |
| 119 | + * NOTES |
| 120 | + * ****************************** |
| 121 | + * *** DO NOT EDIT THIS FILE! *** |
| 122 | + * ****************************** |
| 123 | + * |
| 124 | + * It has been GENERATED by src/backend/utils/misc/gen_guc_tables.pl |
| 125 | + * |
| 126 | + *------------------------------------------------------------------------- |
| 127 | + */ |
| 128 | +EOM |
| 129 | + |
| 130 | + return; |
| 131 | +} |
0 commit comments