44 * Displays available options under grand unified configuration scheme
55 *
66 * The purpose of this option is to list, sort, and make searchable, all
7- * runtime options available to Postgresql, by their description and grouping.
8- *
9- * Valid command-line options to this program:
10- *
11- *none: All available variables are sorted by group and name
12- * and formatted nicely. ( for human consumption )
13- *<string>: list all the variables whose name matches this string
14- *-g <string> : list all the variables whose group matches this string
15- *-l: lists all currently defined groups and terminates
16- *-G: no sort by groups (you get strict name order, instead)
17- *-m: output the list in Machine friendly format, with a header row
18- *-M: same as m, except no header
19- *-h: help
7+ * runtime options available to PostgreSQL, by their description and grouping.
208 *
219 * Options whose flag bits are set to GUC_NO_SHOW_ALL, GUC_NOT_IN_SAMPLE,
2210 * or GUC_DISALLOW_IN_FILE are not displayed, unless the user specifically
2513 * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
2614 *
2715 * IDENTIFICATION
28- * $Header: /cvsroot/pgsql/src/backend/utils/misc/help_config.c,v 1.6 2003/09/25 06:58:06 petere Exp $
16+ * $Header: /cvsroot/pgsql/src/backend/utils/misc/help_config.c,v 1.7 2003/09/27 09:29:31 petere Exp $
2917 *
3018 *-------------------------------------------------------------------------
3119 */
@@ -52,40 +40,33 @@ extern char *optarg;
5240 * The following char constructs provide the different formats the variables
5341 * can be outputted in.
5442 */
55- enum outputFormat
56- {
57- HUMAN_OUTPUT ,
58- MACHINE_OUTPUT
59- };
43+ #define HUMAN_OUTPUT 0
44+ #define MACHINE_OUTPUT 1
6045
6146static const char * const GENERIC_FORMAT []= {
62- gettext_noop ("Name: %-20s\nContext: %-20s\nGroup: %-20s\n" ),
47+ gettext_noop ("Name: %-20s\nContext: %-20s\nGroup: %-20s\n" ),
6348"%s\t%s\t%s\t"
6449};
6550static const char * const GENERIC_DESC []= {
66- gettext_noop ("Description: %s\n%s\n" ),
51+ gettext_noop ("Description: %s\n%s\n" ),
6752"%s\t%s\n"
6853};
6954static const char * const BOOL_FORMAT []= {
70- gettext_noop ("Type: Boolean\nReset value: %-s\n" ),
55+ gettext_noop ("Type: Boolean\nDefault value: %-s\n" ),
7156"BOOL\t%s\t\t\t"
7257};
7358static const char * const INT_FORMAT []= {
74- gettext_noop ("Type: integer\nReset value: %-20d\nMin value: %-20d\nMax value: %-20d\n" ),
59+ gettext_noop ("Type: integer\nDefault value: %-20d\nMin value: %-20d\nMax value: %-20d\n" ),
7560"INT\t%d\t%d\t%d\t"
7661};
7762static const char * const REAL_FORMAT []= {
78- gettext_noop ("Type: real\nReset value: %-20g\nMin value: %-20g\nMax value: %-20g\n" ),
63+ gettext_noop ("Type: real\nDefault value: %-20g\nMin value: %-20g\nMax value: %-20g\n" ),
7964"REAL\t%g\t%g\t%g\t"
8065};
8166static const char * const STRING_FORMAT []= {
82- gettext_noop ("Type: string\nReset value: %-s\n" ),
67+ gettext_noop ("Type: string\nDefault value: %-s\n" ),
8368"STRING\t%s\t\t\t"
8469};
85- static const char * const COLUMN_HEADER []= {
86- "" ,
87- gettext_noop ("NAME\tCONTEXT\tGROUP\tTYPE\tRESET_VALUE\tMIN\tMAX\tSHORT_DESCRIPTION\tLONG_DESCRIPTION\n" )
88- };
8970static const char * const ROW_SEPARATOR []= {
9071"------------------------------------------------------------\n" ,
9172""
@@ -95,12 +76,8 @@ static const char *const ROW_SEPARATOR[] = {
9576 * Variables loaded from the command line
9677 */
9778static char * nameString = NULL ;/* The var name pattern to match */
98- static bool nameRegexBool = false;/* Match the name pattern as a
99- * regex */
10079static char * groupString = NULL ;/* The var group pattern to match */
101- static bool groupRegexBool = false;/* Match the group pattern as a
102- * regex */
103- static enum outputFormat outFormat = HUMAN_OUTPUT ;
80+ static int outFormat = HUMAN_OUTPUT ;
10481static bool suppressAllHeaders = false;/* MACHINE_OUTPUT output, no
10582 * column headers */
10683static bool groupResults = true;/* sort result list by groups */
@@ -124,8 +101,7 @@ typedef union
124101static bool varMatches (mixedStruct * structToTest );
125102static int compareMixedStructs (const void * ,const void * );
126103static mixedStruct * * varsToDisplay (int * resultListSize );
127- static const char * usageErrMsg (void );
128- static void helpMessage (void );
104+ static void helpMessage (const char * progname );
129105static void listAllGroups (void );
130106static void printGenericHead (struct config_generic structToPrint );
131107static void printGenericFoot (struct config_generic structToPrint );
@@ -145,16 +121,13 @@ GucInfoMain(int argc, char *argv[])
145121int c ;
146122int i ;
147123
148- while ((c = getopt (argc ,argv ,"g:rGmMlh " ))!= -1 )
124+ while ((c = getopt (argc - 1 ,argv + 1 ,"g:GmMlh " ))!= -1 )
149125{
150126switch (c )
151127{
152128case 'g' :
153129groupString = optarg ;
154130break ;
155- case 'r' :/* not actually implemented yet */
156- nameRegexBool = true;
157- break ;
158131case 'G' :
159132groupResults = false;
160133break ;
@@ -169,17 +142,17 @@ GucInfoMain(int argc, char *argv[])
169142listAllGroups ();
170143exit (0 );
171144case 'h' :
172- helpMessage ();
145+ helpMessage (argv [ 0 ] );
173146exit (0 );
174147
175148default :
176- fprintf (stderr ,gettext ("%s\n Try -h forfurther details \n" ),usageErrMsg () );
149+ fprintf (stderr ,gettext ("Try \" %s--help-config -h\" formore information. \n" ),argv [ 0 ] );
177150exit (1 );
178151}
179152}
180153
181- if (optind < argc )
182- nameString = argv [optind ];
154+ if (optind < argc - 1 )
155+ nameString = argv [optind + 1 ];
183156
184157/* get the list of variables that match the user's specs. */
185158varList = varsToDisplay (& resultListSize );
@@ -191,12 +164,12 @@ GucInfoMain(int argc, char *argv[])
191164sizeof (mixedStruct * ),compareMixedStructs );
192165
193166/* output the results */
194- if (!suppressAllHeaders )
195- printf (gettext ( COLUMN_HEADER [ outFormat ]) );
167+ if (outFormat == MACHINE_OUTPUT && !suppressAllHeaders )
168+ printf ("NAME\tCONTEXT\tGROUP\tTYPE\tDEFAULT_VALUE\tMIN\tMAX\tSHORT_DESCRIPTION\tLONG_DESCRIPTION\n" );
196169
197170for (i = 0 ;varList [i ]!= NULL ;i ++ )
198171{
199- printf (gettext ( ROW_SEPARATOR [outFormat ]) );
172+ printf (ROW_SEPARATOR [outFormat ]);
200173printMixedStruct (varList [i ]);
201174}
202175
@@ -299,7 +272,7 @@ varMatches(mixedStruct *structToTest)
299272 * searched for a variable in
300273 * particular. */
301274
302- if (nameString != NULL && ! nameRegexBool )
275+ if (nameString != NULL )
303276{
304277if (strstr (structToTest -> generic .name ,nameString )!= NULL )
305278{
@@ -308,12 +281,7 @@ varMatches(mixedStruct *structToTest)
308281}
309282}
310283
311- if (nameString != NULL && nameRegexBool )
312- {
313- /* We do not support this option yet */
314- }
315-
316- if (groupString != NULL && !groupRegexBool )
284+ if (groupString != NULL )
317285{
318286if (strstr (config_group_names [structToTest -> generic .group ],groupString )!= NULL )
319287{
@@ -326,11 +294,6 @@ varMatches(mixedStruct *structToTest)
326294matches = false;
327295}
328296
329- if (groupString != NULL && groupRegexBool )
330- {
331- /* We do not support this option yet */
332- }
333-
334297/* return all variables */
335298if (nameString == NULL && groupString == NULL )
336299matches = true;
@@ -355,9 +318,14 @@ printMixedStruct(mixedStruct *structToPrint)
355318{
356319
357320case PGC_BOOL :
358- printf (gettext (BOOL_FORMAT [outFormat ]),
359- (structToPrint -> bool .reset_val == 0 ) ?
360- gettext ("FALSE" ) :gettext ("TRUE" ));
321+ if (outFormat == HUMAN_OUTPUT )
322+ printf (gettext (BOOL_FORMAT [outFormat ]),
323+ (structToPrint -> bool .reset_val == 0 ) ?
324+ gettext ("false" ) :gettext ("true" ));
325+ else
326+ printf (gettext (BOOL_FORMAT [outFormat ]),
327+ (structToPrint -> bool .reset_val == 0 ) ?
328+ "FALSE" :"TRUE" );
361329break ;
362330
363331case PGC_INT :
@@ -380,7 +348,7 @@ printMixedStruct(mixedStruct *structToPrint)
380348break ;
381349
382350default :
383- printf (gettext ( "Unrecognized variable type! \n") );
351+ printf ("Internal error: unrecognized run-time parameter type\n" );
384352break ;
385353}
386354
@@ -409,40 +377,29 @@ listAllGroups(void)
409377{
410378int i ;
411379
412- printf (gettext ("All currently defined groups\n" ));
413- printf (gettext ("----------------------------\n" ));
414380for (i = 0 ;config_group_names [i ]!= NULL ;i ++ )
415- printf (gettext ("%s\n" ),gettext (config_group_names [i ]));
416- }
417-
418- static const char *
419- usageErrMsg (void )
420- {
421- return gettext ("Usage for --help-config option: [-h] [-g <group>] [-l] [-G] [-m] [-M] [string]\n" );
381+ printf ("%s\n" ,gettext (config_group_names [i ]));
422382}
423383
424384static void
425- helpMessage (void )
385+ helpMessage (const char * progname )
426386{
427- printf (gettext ("Description:\n"
428- "--help-config displays all the runtime options available in PostgreSQL.\n"
429- "It groups them by category and sorts them by name. If available, it will\n"
430- "present a short description, default, max and min values as well as other\n"
431- "information about each option.\n\n"
432- "With no options specified, it will output all available runtime options\n"
433- "in human friendly format, grouped by category and sorted by name.\n\n"
434-
435- "%s\n"
436-
437- "General Options:\n"
438- " [string]All options with names that match this string\n"
439- " -g GROUPAll options in categories that match GROUP\n"
440- " -l Prints list of all groups / subgroups\n"
441- " -h Prints this help message\n"
442- "\nOutput Options:\n"
443- " -G Do not group by category\n"
444- " -m Machine friendly format: tab separated fields\n"
445- " -M Same as m, except header with column names is suppressed\n" ),
446- usageErrMsg ()
447- );
387+ printf (gettext ("%s --help-config displays information about the\n"
388+ "run-time configuration parameters available in the PostgreSQL server.\n\n" ),
389+ progname );
390+ printf (gettext ("Usage:\n %s --help-config [OPTION]... [NAME]\n\n" ),progname );
391+ printf (gettext ("General Options:\n" ));
392+ printf (gettext (" NAME output information about parameters matching this name\n" ));
393+ printf (gettext (" -g GROUP output information about parameters matching this group\n" ));
394+ printf (gettext (" -l list available parameter groups\n" ));
395+ printf (gettext (" -h show this help, then exit\n" ));
396+ printf (gettext ("\nOutput Options:\n" ));
397+ printf (gettext (" -G do not group by category\n" ));
398+ printf (gettext (" -m machine-friendly format: tab separated fields\n" ));
399+ printf (gettext (" -M same as -m, but header with column names is suppressed\n" ));
400+ printf (gettext ("\n"
401+ "If no parameter name is specified, all parameters are shown. By default,\n"
402+ "parameters are grouped by category, sorted by name, and output in a human-\n"
403+ "friendly format. Available information about run-time parameters includes\n"
404+ "a short description, default value, maximum and minimum values.\n" ));
448405}