]> granicus.if.org Git - postgresql/blob - src/backend/utils/misc/help_config.c
Cleanup on --help-config: Now called --describe-config, no further options,
[postgresql] / src / backend / utils / misc / help_config.c
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-2003, PostgreSQL Global Development Group
11  *
12  * IDENTIFICATION
13  *        $Header: /cvsroot/pgsql/src/backend/utils/misc/help_config.c,v 1.8 2003/10/18 22:59:09 petere Exp $
14  *
15  *-------------------------------------------------------------------------
16  */
17 #include "postgres.h"
18
19 #include <float.h>
20 #include <limits.h>
21 #include <unistd.h>
22
23 #include "utils/guc.h"
24 #include "utils/guc_tables.h"
25 #include "utils/help_config.h"
26
27
28 /*
29  * This union allows us to mix the numerous different types of structs
30  * that we are organizing.
31  */
32 typedef union
33 {
34         struct config_generic generic;
35         struct config_bool bool;
36         struct config_real real;
37         struct config_int integer;
38         struct config_string string;
39 } mixedStruct;
40
41
42 static void printMixedStruct(mixedStruct *structToPrint);
43 static bool displayStruct(mixedStruct *structToDisplay);
44
45
46 int
47 GucInfoMain(void)
48 {
49         int                     i;
50
51         /* Initialize the guc_variables[] array */
52         build_guc_variables();
53
54         for (i = 0; i < num_guc_variables; i++)
55         {
56                 mixedStruct *var = (mixedStruct *) guc_variables[i];
57
58                 if (displayStruct(var))
59                         printMixedStruct(var);
60         }
61
62         return 0;
63 }
64
65
66 /*
67  * This function will return true if the struct passed to it
68  * should be displayed to the user.
69  */
70 static bool
71 displayStruct(mixedStruct *structToDisplay)
72 {
73         return !(structToDisplay->generic.flags & (GUC_NO_SHOW_ALL |
74                                                                                            GUC_NOT_IN_SAMPLE |
75                                                                                            GUC_DISALLOW_IN_FILE));
76 }
77
78
79 /*
80  * This function prints out the generic struct passed to it. It will print out
81  * a different format, depending on what the user wants to see.
82  */
83 static void
84 printMixedStruct(mixedStruct *structToPrint)
85 {
86         printf("%s\t%s\t%s\t",
87                    structToPrint->generic.name,
88                    GucContext_Names[structToPrint->generic.context],
89                    gettext(config_group_names[structToPrint->generic.group]));
90
91         switch (structToPrint->generic.vartype)
92         {
93
94                 case PGC_BOOL:
95                         printf("BOOLEAN\t%s\t\t\t",
96                                    (structToPrint->bool.reset_val == 0) ?
97                                    "FALSE" : "TRUE");
98                         break;
99
100                 case PGC_INT:
101                         printf("INTEGER\t%d\t%d\t%d\t",
102                                    structToPrint->integer.reset_val,
103                                    structToPrint->integer.min,
104                                    structToPrint->integer.max);
105                         break;
106
107                 case PGC_REAL:
108                         printf("REAL\t%g\t%g\t%g\t",
109                                    structToPrint->real.reset_val,
110                                    structToPrint->real.min,
111                                    structToPrint->real.max);
112                         break;
113
114                 case PGC_STRING:
115                         printf("STRING\t%s\t\t\t",
116                                    structToPrint->string.boot_val);
117                         break;
118
119                 default:
120                         fprintf(stderr, "internal error: unrecognized run-time parameter type\n");
121                         break;
122         }
123
124         printf("%s\t%s\n",
125                    (structToPrint->generic.short_desc == NULL) ? "" : gettext(structToPrint->generic.short_desc),
126                    (structToPrint->generic.long_desc == NULL) ? "" : gettext(structToPrint->generic.long_desc));
127 }