Header And Logo

PostgreSQL
| The world's most advanced open source database.

help_config.c

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  * help_config.c
00003  *
00004  * Displays available options under grand unified configuration scheme
00005  *
00006  * Options whose flag bits are set to GUC_NO_SHOW_ALL, GUC_NOT_IN_SAMPLE,
00007  * or GUC_DISALLOW_IN_FILE are not displayed, unless the user specifically
00008  * requests that variable by name
00009  *
00010  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00011  *
00012  * IDENTIFICATION
00013  *    src/backend/utils/misc/help_config.c
00014  *
00015  *-------------------------------------------------------------------------
00016  */
00017 #include "postgres.h"
00018 
00019 #include <float.h>
00020 #include <limits.h>
00021 #include <unistd.h>
00022 
00023 #include "utils/guc_tables.h"
00024 #include "utils/help_config.h"
00025 
00026 
00027 /*
00028  * This union allows us to mix the numerous different types of structs
00029  * that we are organizing.
00030  */
00031 typedef union
00032 {
00033     struct config_generic generic;
00034     struct config_bool bool;
00035     struct config_real real;
00036     struct config_int integer;
00037     struct config_string string;
00038     struct config_enum _enum;
00039 } mixedStruct;
00040 
00041 
00042 static void printMixedStruct(mixedStruct *structToPrint);
00043 static bool displayStruct(mixedStruct *structToDisplay);
00044 
00045 
00046 void
00047 GucInfoMain(void)
00048 {
00049     struct config_generic **guc_vars;
00050     int         numOpts,
00051                 i;
00052 
00053     /* Initialize the guc_variables[] array */
00054     build_guc_variables();
00055 
00056     guc_vars = get_guc_variables();
00057     numOpts = GetNumConfigOptions();
00058 
00059     for (i = 0; i < numOpts; i++)
00060     {
00061         mixedStruct *var = (mixedStruct *) guc_vars[i];
00062 
00063         if (displayStruct(var))
00064             printMixedStruct(var);
00065     }
00066 
00067     exit(0);
00068 }
00069 
00070 
00071 /*
00072  * This function will return true if the struct passed to it
00073  * should be displayed to the user.
00074  */
00075 static bool
00076 displayStruct(mixedStruct *structToDisplay)
00077 {
00078     return !(structToDisplay->generic.flags & (GUC_NO_SHOW_ALL |
00079                                                GUC_NOT_IN_SAMPLE |
00080                                                GUC_DISALLOW_IN_FILE));
00081 }
00082 
00083 
00084 /*
00085  * This function prints out the generic struct passed to it. It will print out
00086  * a different format, depending on what the user wants to see.
00087  */
00088 static void
00089 printMixedStruct(mixedStruct *structToPrint)
00090 {
00091     printf("%s\t%s\t%s\t",
00092            structToPrint->generic.name,
00093            GucContext_Names[structToPrint->generic.context],
00094            _(config_group_names[structToPrint->generic.group]));
00095 
00096     switch (structToPrint->generic.vartype)
00097     {
00098 
00099         case PGC_BOOL:
00100             printf("BOOLEAN\t%s\t\t\t",
00101                    (structToPrint->bool.reset_val == 0) ?
00102                    "FALSE" : "TRUE");
00103             break;
00104 
00105         case PGC_INT:
00106             printf("INTEGER\t%d\t%d\t%d\t",
00107                    structToPrint->integer.reset_val,
00108                    structToPrint->integer.min,
00109                    structToPrint->integer.max);
00110             break;
00111 
00112         case PGC_REAL:
00113             printf("REAL\t%g\t%g\t%g\t",
00114                    structToPrint->real.reset_val,
00115                    structToPrint->real.min,
00116                    structToPrint->real.max);
00117             break;
00118 
00119         case PGC_STRING:
00120             printf("STRING\t%s\t\t\t",
00121                    structToPrint->string.boot_val ? structToPrint->string.boot_val : "");
00122             break;
00123 
00124         case PGC_ENUM:
00125             printf("ENUM\t%s\t\t\t",
00126                    config_enum_lookup_by_value(&structToPrint->_enum,
00127                                              structToPrint->_enum.boot_val));
00128             break;
00129 
00130         default:
00131             write_stderr("internal error: unrecognized run-time parameter type\n");
00132             break;
00133     }
00134 
00135     printf("%s\t%s\n",
00136            (structToPrint->generic.short_desc == NULL) ? "" : _(structToPrint->generic.short_desc),
00137            (structToPrint->generic.long_desc == NULL) ? "" : _(structToPrint->generic.long_desc));
00138 }