Age Owner Branch data TLA Line data Source code
1 : : /*-------------------------------------------------------------------------
2 : : * help_config.c
3 : : *
4 : : * Displays available options under grand unified configuration scheme
5 : : *
6 : : * Options whose flag bits are set to GUC_NO_SHOW_ALL, GUC_NOT_IN_SAMPLE,
7 : : * or GUC_DISALLOW_IN_FILE are not displayed, unless the user specifically
8 : : * requests that variable by name
9 : : *
10 : : * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
11 : : *
12 : : * IDENTIFICATION
13 : : * src/backend/utils/misc/help_config.c
14 : : *
15 : : *-------------------------------------------------------------------------
16 : : */
17 : : #include "postgres.h"
18 : :
19 : : #include <limits.h>
20 : : #include <unistd.h>
21 : :
22 : : #include "utils/guc_tables.h"
23 : : #include "utils/help_config.h"
24 : :
25 : :
26 : : /*
27 : : * This union allows us to mix the numerous different types of structs
28 : : * that we are organizing.
29 : : */
30 : : typedef union
31 : : {
32 : : struct config_generic generic;
33 : : struct config_bool _bool;
34 : : struct config_real real;
35 : : struct config_int integer;
36 : : struct config_string string;
37 : : struct config_enum _enum;
38 : : } mixedStruct;
39 : :
40 : :
41 : : static void printMixedStruct(mixedStruct *structToPrint);
42 : : static bool displayStruct(mixedStruct *structToDisplay);
43 : :
44 : :
45 : : void
8046 peter_e@gmx.net 46 :UBC 0 : GucInfoMain(void)
47 : : {
48 : : struct config_generic **guc_vars;
49 : : int numOpts;
50 : :
51 : : /* Initialize the GUC hash table */
8152 tgl@sss.pgh.pa.us 52 : 0 : build_guc_variables();
53 : :
1110 54 : 0 : guc_vars = get_guc_variables(&numOpts);
55 : :
25 peter@eisentraut.org 56 [ # # ]:UNC 0 : for (int i = 0; i < numOpts; i++)
57 : : {
7825 bruce@momjian.us 58 :UBC 0 : mixedStruct *var = (mixedStruct *) guc_vars[i];
59 : :
8046 peter_e@gmx.net 60 [ # # ]: 0 : if (displayStruct(var))
61 : 0 : printMixedStruct(var);
62 : : }
63 : :
4873 64 : 0 : exit(0);
65 : : }
66 : :
67 : :
68 : : /*
69 : : * This function will return true if the struct passed to it
70 : : * should be displayed to the user.
71 : : */
72 : : static bool
8117 bruce@momjian.us 73 : 0 : displayStruct(mixedStruct *structToDisplay)
74 : : {
8046 peter_e@gmx.net 75 : 0 : return !(structToDisplay->generic.flags & (GUC_NO_SHOW_ALL |
76 : : GUC_NOT_IN_SAMPLE |
77 : : GUC_DISALLOW_IN_FILE));
78 : : }
79 : :
80 : :
81 : : /*
82 : : * This function prints out the generic struct passed to it. It will print out
83 : : * a different format, depending on what the user wants to see.
84 : : */
85 : : static void
8117 bruce@momjian.us 86 : 0 : printMixedStruct(mixedStruct *structToPrint)
87 : : {
8046 peter_e@gmx.net 88 : 0 : printf("%s\t%s\t%s\t",
89 : : structToPrint->generic.name,
90 : : GucContext_Names[structToPrint->generic.context],
91 : : _(config_group_names[structToPrint->generic.group]));
92 : :
8152 tgl@sss.pgh.pa.us 93 [ # # # # : 0 : switch (structToPrint->generic.vartype)
# # ]
94 : : {
95 : :
96 : 0 : case PGC_BOOL:
8046 peter_e@gmx.net 97 [ # # ]: 0 : printf("BOOLEAN\t%s\t\t\t",
98 : : (structToPrint->_bool.reset_val == 0) ?
99 : : "FALSE" : "TRUE");
8152 tgl@sss.pgh.pa.us 100 : 0 : break;
101 : :
102 : 0 : case PGC_INT:
8046 peter_e@gmx.net 103 : 0 : printf("INTEGER\t%d\t%d\t%d\t",
104 : : structToPrint->integer.reset_val,
105 : : structToPrint->integer.min,
106 : : structToPrint->integer.max);
8152 tgl@sss.pgh.pa.us 107 : 0 : break;
108 : :
109 : 0 : case PGC_REAL:
8046 peter_e@gmx.net 110 : 0 : printf("REAL\t%g\t%g\t%g\t",
111 : : structToPrint->real.reset_val,
112 : : structToPrint->real.min,
113 : : structToPrint->real.max);
8152 tgl@sss.pgh.pa.us 114 : 0 : break;
115 : :
116 : 0 : case PGC_STRING:
8046 peter_e@gmx.net 117 [ # # ]: 0 : printf("STRING\t%s\t\t\t",
118 : : structToPrint->string.boot_val ? structToPrint->string.boot_val : "");
8152 tgl@sss.pgh.pa.us 119 : 0 : break;
120 : :
6434 magnus@hagander.net 121 : 0 : case PGC_ENUM:
122 : 0 : printf("ENUM\t%s\t\t\t",
123 : : config_enum_lookup_by_value(&structToPrint->_enum,
124 : : structToPrint->_enum.boot_val));
125 : 0 : break;
126 : :
8152 tgl@sss.pgh.pa.us 127 : 0 : default:
7796 128 : 0 : write_stderr("internal error: unrecognized run-time parameter type\n");
8152 129 : 0 : break;
130 : : }
131 : :
8046 peter_e@gmx.net 132 [ # # # # ]: 0 : printf("%s\t%s\n",
133 : : (structToPrint->generic.short_desc == NULL) ? "" : _(structToPrint->generic.short_desc),
134 : : (structToPrint->generic.long_desc == NULL) ? "" : _(structToPrint->generic.long_desc));
8152 tgl@sss.pgh.pa.us 135 : 0 : }
|