PostgreSQL Source Code  git master
help_config.c
Go to the documentation of this file.
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-2017, 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 <float.h>
20 #include <limits.h>
21 #include <unistd.h>
22 
23 #include "utils/guc_tables.h"
24 #include "utils/help_config.h"
25 
26 
27 /*
28  * This union allows us to mix the numerous different types of structs
29  * that we are organizing.
30  */
31 typedef union
32 {
33  struct config_generic generic;
34  struct config_bool _bool;
35  struct config_real real;
36  struct config_int integer;
38  struct config_enum _enum;
39 } mixedStruct;
40 
41 
42 static void printMixedStruct(mixedStruct *structToPrint);
43 static bool displayStruct(mixedStruct *structToDisplay);
44 
45 
46 void
48 {
49  struct config_generic **guc_vars;
50  int numOpts,
51  i;
52 
53  /* Initialize the guc_variables[] array */
55 
56  guc_vars = get_guc_variables();
57  numOpts = GetNumConfigOptions();
58 
59  for (i = 0; i < numOpts; i++)
60  {
61  mixedStruct *var = (mixedStruct *) guc_vars[i];
62 
63  if (displayStruct(var))
64  printMixedStruct(var);
65  }
66 
67  exit(0);
68 }
69 
70 
71 /*
72  * This function will return true if the struct passed to it
73  * should be displayed to the user.
74  */
75 static bool
76 displayStruct(mixedStruct *structToDisplay)
77 {
78  return !(structToDisplay->generic.flags & (GUC_NO_SHOW_ALL |
81 }
82 
83 
84 /*
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.
87  */
88 static void
90 {
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]));
95 
96  switch (structToPrint->generic.vartype)
97  {
98 
99  case PGC_BOOL:
100  printf("BOOLEAN\t%s\t\t\t",
101  (structToPrint->_bool.reset_val == 0) ?
102  "FALSE" : "TRUE");
103  break;
104 
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;
111 
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;
118 
119  case PGC_STRING:
120  printf("STRING\t%s\t\t\t",
121  structToPrint->string.boot_val ? structToPrint->string.boot_val : "");
122  break;
123 
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;
129 
130  default:
131  write_stderr("internal error: unrecognized run-time parameter type\n");
132  break;
133  }
134 
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));
138 }
void build_guc_variables(void)
Definition: guc.c:4227
static bool displayStruct(mixedStruct *structToDisplay)
Definition: help_config.c:76
const char * long_desc
Definition: guc_tables.h:150
double reset_val
Definition: guc_tables.h:219
struct config_int integer
Definition: help_config.c:36
struct config_bool _bool
Definition: help_config.c:34
const char * name
Definition: guc_tables.h:146
void GucInfoMain(void)
Definition: help_config.c:47
const char * short_desc
Definition: guc_tables.h:149
const char * boot_val
Definition: guc_tables.h:228
#define write_stderr(str)
Definition: parallel.c:182
struct config_generic ** get_guc_variables(void)
Definition: guc.c:4215
const char * config_enum_lookup_by_value(struct config_enum *record, int val)
Definition: guc.c:5645
struct config_real real
Definition: help_config.c:35
static void printMixedStruct(mixedStruct *structToPrint)
Definition: help_config.c:89
struct config_enum _enum
Definition: help_config.c:38
struct config_generic generic
Definition: help_config.c:33
#define GUC_NO_SHOW_ALL
Definition: guc.h:206
const char *const GucContext_Names[]
Definition: guc.c:529
const char *const config_group_names[]
Definition: guc.c:566
char string[11]
Definition: preproc-type.c:46
#define GUC_NOT_IN_SAMPLE
Definition: guc.h:209
enum config_type vartype
Definition: guc_tables.h:153
struct config_string string
Definition: help_config.c:37
double max
Definition: guc_tables.h:214
#define GUC_DISALLOW_IN_FILE
Definition: guc.h:210
double min
Definition: guc_tables.h:213
int i
enum config_group group
Definition: guc_tables.h:148
int GetNumConfigOptions(void)
Definition: guc.c:8367
bool reset_val
Definition: guc_tables.h:187
#define _(x)
Definition: elog.c:84
GucContext context
Definition: guc_tables.h:147
int reset_val
Definition: guc_tables.h:203