Fix oversight in previous error-reporting patch; mustn't pfree path string
[PostgreSQL.git] / src / backend / utils / misc / help_config.c
blobd83db146e864e6bffab48a0e17c562d489fd6ab2
1 /*-------------------------------------------------------------------------
2 * help_config.c
4 * Displays available options under grand unified configuration scheme
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
10 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
12 * IDENTIFICATION
13 * $PostgreSQL$
15 *-------------------------------------------------------------------------
17 #include "postgres.h"
19 #include <float.h>
20 #include <limits.h>
21 #include <unistd.h>
23 #include "utils/guc_tables.h"
24 #include "utils/help_config.h"
28 * This union allows us to mix the numerous different types of structs
29 * that we are organizing.
31 typedef union
33 struct config_generic generic;
34 struct config_bool bool;
35 struct config_real real;
36 struct config_int integer;
37 struct config_string string;
38 struct config_enum _enum;
39 } mixedStruct;
42 static void printMixedStruct(mixedStruct *structToPrint);
43 static bool displayStruct(mixedStruct *structToDisplay);
46 int
47 GucInfoMain(void)
49 struct config_generic **guc_vars;
50 int numOpts,
53 /* Initialize the guc_variables[] array */
54 build_guc_variables();
56 guc_vars = get_guc_variables();
57 numOpts = GetNumConfigOptions();
59 for (i = 0; i < numOpts; i++)
61 mixedStruct *var = (mixedStruct *) guc_vars[i];
63 if (displayStruct(var))
64 printMixedStruct(var);
67 return 0;
72 * This function will return true if the struct passed to it
73 * should be displayed to the user.
75 static bool
76 displayStruct(mixedStruct *structToDisplay)
78 return !(structToDisplay->generic.flags & (GUC_NO_SHOW_ALL |
79 GUC_NOT_IN_SAMPLE |
80 GUC_DISALLOW_IN_FILE));
85 * This function prints out the generic struct passed to it. It will print out
86 * a different format, depending on what the user wants to see.
88 static void
89 printMixedStruct(mixedStruct *structToPrint)
91 printf("%s\t%s\t%s\t",
92 structToPrint->generic.name,
93 GucContext_Names[structToPrint->generic.context],
94 _(config_group_names[structToPrint->generic.group]));
96 switch (structToPrint->generic.vartype)
99 case PGC_BOOL:
100 printf("BOOLEAN\t%s\t\t\t",
101 (structToPrint->bool.reset_val == 0) ?
102 "FALSE" : "TRUE");
103 break;
105 case PGC_INT:
106 printf("INTEGER\t%d\t%d\t%d\t",
107 structToPrint->integer.reset_val,
108 structToPrint->integer.min,
109 structToPrint->integer.max);
110 break;
112 case PGC_REAL:
113 printf("REAL\t%g\t%g\t%g\t",
114 structToPrint->real.reset_val,
115 structToPrint->real.min,
116 structToPrint->real.max);
117 break;
119 case PGC_STRING:
120 printf("STRING\t%s\t\t\t",
121 structToPrint->string.boot_val ? structToPrint->string.boot_val : "");
122 break;
124 case PGC_ENUM:
125 printf("ENUM\t%s\t\t\t",
126 config_enum_lookup_by_value(&structToPrint->_enum,
127 structToPrint->_enum.boot_val));
128 break;
130 default:
131 write_stderr("internal error: unrecognized run-time parameter type\n");
132 break;
135 printf("%s\t%s\n",
136 (structToPrint->generic.short_desc == NULL) ? "" : _(structToPrint->generic.short_desc),
137 (structToPrint->generic.long_desc == NULL) ? "" : _(structToPrint->generic.long_desc));