Skip to content

Commit e05147e

Browse files
committed
You can't NLS-enable a program component by just putting gettext() around
every string, especially if some of the output should be fixed-format machine-readable. This needs to be more carefully sorted out. Also, make the help message generated by --help-config -h be more similar in style to the others.
1 parent 4af19a5 commit e05147e

File tree

3 files changed

+57
-99
lines changed

3 files changed

+57
-99
lines changed

src/backend/main/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.63 2003/09/25 06:57:59 petere Exp $
16+
* $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.64 2003/09/27 09:29:31 petere Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -227,7 +227,7 @@ main(int argc, char *argv[])
227227
* the arguments passed on to GucInfoMain.
228228
*/
229229
if (argc > 1 && strcmp(new_argv[1], "--help-config") == 0)
230-
exit(GucInfoMain(argc - 1, new_argv + 1));
230+
exit(GucInfoMain(argc, new_argv));
231231

232232
/*
233233
* Otherwise we're a standalone backend. Invoke PostgresMain,

src/backend/tcop/postgres.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.365 2003/09/25 06:58:02 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.366 2003/09/27 09:29:31 petere Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -1991,7 +1991,8 @@ usage(char *progname)
19911991
printf(" -P disable system indexes\n");
19921992
printf(" -s show statistics after each query\n");
19931993
printf(" -S SORT-MEM set amount of memory for sorts (in kbytes)\n");
1994-
printf(" --help-config show configuration options, then exit. Details: --help-config -h\n");
1994+
printf(" --help-config show configuration parameters, then exit;\n"
1995+
" details: --help-config -h\n");
19951996
printf(" --help show this help, then exit\n");
19961997
printf(" --version output version information, then exit\n");
19971998
printf("\nDeveloper options:\n");
@@ -2661,7 +2662,7 @@ PostgresMain(int argc, char *argv[], const char *username)
26612662
if (!IsUnderPostmaster)
26622663
{
26632664
puts("\nPOSTGRES backend interactive interface ");
2664-
puts("$Revision: 1.365 $ $Date: 2003/09/25 06:58:02 $\n");
2665+
puts("$Revision: 1.366 $ $Date: 2003/09/27 09:29:31 $\n");
26652666
}
26662667

26672668
/*

src/backend/utils/misc/help_config.c

Lines changed: 51 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,7 @@
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
@@ -25,7 +13,7 @@
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

6146
static 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
};
6550
static 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
};
6954
static 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
};
7358
static 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
};
7762
static 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
};
8166
static 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-
};
8970
static 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
*/
9778
static char *nameString = NULL; /* The var name pattern to match */
98-
static bool nameRegexBool = false; /* Match the name pattern as a
99-
* regex */
10079
static 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;
10481
static bool suppressAllHeaders = false; /* MACHINE_OUTPUT output, no
10582
* column headers */
10683
static bool groupResults = true; /* sort result list by groups */
@@ -124,8 +101,7 @@ typedef union
124101
static bool varMatches(mixedStruct *structToTest);
125102
static int compareMixedStructs(const void *, const void *);
126103
static mixedStruct **varsToDisplay(int *resultListSize);
127-
static const char *usageErrMsg(void);
128-
static void helpMessage(void);
104+
static void helpMessage(const char *progname);
129105
static void listAllGroups(void);
130106
static void printGenericHead(struct config_generic structToPrint);
131107
static void printGenericFoot(struct config_generic structToPrint);
@@ -145,16 +121,13 @@ GucInfoMain(int argc, char *argv[])
145121
int c;
146122
int i;
147123

148-
while ((c = getopt(argc, argv, "g:rGmMlh")) != -1)
124+
while ((c = getopt(argc - 1, argv + 1, "g:GmMlh")) != -1)
149125
{
150126
switch (c)
151127
{
152128
case 'g':
153129
groupString = optarg;
154130
break;
155-
case 'r': /* not actually implemented yet */
156-
nameRegexBool = true;
157-
break;
158131
case 'G':
159132
groupResults = false;
160133
break;
@@ -169,17 +142,17 @@ GucInfoMain(int argc, char *argv[])
169142
listAllGroups();
170143
exit(0);
171144
case 'h':
172-
helpMessage();
145+
helpMessage(argv[0]);
173146
exit(0);
174147

175148
default:
176-
fprintf(stderr, gettext("%s \n Try -h for further details\n"), usageErrMsg());
149+
fprintf(stderr, gettext("Try \"%s --help-config -h\" for more information.\n"), argv[0]);
177150
exit(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. */
185158
varList = varsToDisplay(&resultListSize);
@@ -191,12 +164,12 @@ GucInfoMain(int argc, char *argv[])
191164
sizeof(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

197170
for (i = 0; varList[i] != NULL; i++)
198171
{
199-
printf(gettext(ROW_SEPARATOR[outFormat]));
172+
printf(ROW_SEPARATOR[outFormat]);
200173
printMixedStruct(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
{
304277
if (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
{
318286
if (strstr(config_group_names[structToTest->generic.group], groupString) != NULL)
319287
{
@@ -326,11 +294,6 @@ varMatches(mixedStruct *structToTest)
326294
matches = false;
327295
}
328296

329-
if (groupString != NULL && groupRegexBool)
330-
{
331-
/* We do not support this option yet */
332-
}
333-
334297
/* return all variables */
335298
if (nameString == NULL && groupString == NULL)
336299
matches = true;
@@ -355,9 +318,14 @@ printMixedStruct(mixedStruct *structToPrint)
355318
{
356319

357320
case 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");
361329
break;
362330

363331
case PGC_INT:
@@ -380,7 +348,7 @@ printMixedStruct(mixedStruct *structToPrint)
380348
break;
381349

382350
default:
383-
printf(gettext("Unrecognized variable type!\n"));
351+
printf("Internal error: unrecognized run-time parameter type\n");
384352
break;
385353
}
386354

@@ -409,40 +377,29 @@ listAllGroups(void)
409377
{
410378
int i;
411379

412-
printf(gettext("All currently defined groups\n"));
413-
printf(gettext("----------------------------\n"));
414380
for (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

424384
static 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 GROUP All 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
}

0 commit comments

Comments
 (0)