Commit e05147e5 authored by Peter Eisentraut's avatar Peter Eisentraut

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.
parent 4af19a57
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.63 2003/09/25 06:57:59 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.64 2003/09/27 09:29:31 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -227,7 +227,7 @@ main(int argc, char *argv[]) ...@@ -227,7 +227,7 @@ main(int argc, char *argv[])
* the arguments passed on to GucInfoMain. * the arguments passed on to GucInfoMain.
*/ */
if (argc > 1 && strcmp(new_argv[1], "--help-config") == 0) if (argc > 1 && strcmp(new_argv[1], "--help-config") == 0)
exit(GucInfoMain(argc - 1, new_argv + 1)); exit(GucInfoMain(argc, new_argv));
/* /*
* Otherwise we're a standalone backend. Invoke PostgresMain, * Otherwise we're a standalone backend. Invoke PostgresMain,
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.365 2003/09/25 06:58:02 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.366 2003/09/27 09:29:31 petere Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -1991,7 +1991,8 @@ usage(char *progname) ...@@ -1991,7 +1991,8 @@ usage(char *progname)
printf(" -P disable system indexes\n"); printf(" -P disable system indexes\n");
printf(" -s show statistics after each query\n"); printf(" -s show statistics after each query\n");
printf(" -S SORT-MEM set amount of memory for sorts (in kbytes)\n"); printf(" -S SORT-MEM set amount of memory for sorts (in kbytes)\n");
printf(" --help-config show configuration options, then exit. Details: --help-config -h\n"); printf(" --help-config show configuration parameters, then exit;\n"
" details: --help-config -h\n");
printf(" --help show this help, then exit\n"); printf(" --help show this help, then exit\n");
printf(" --version output version information, then exit\n"); printf(" --version output version information, then exit\n");
printf("\nDeveloper options:\n"); printf("\nDeveloper options:\n");
...@@ -2661,7 +2662,7 @@ PostgresMain(int argc, char *argv[], const char *username) ...@@ -2661,7 +2662,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
puts("\nPOSTGRES backend interactive interface "); puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.365 $ $Date: 2003/09/25 06:58:02 $\n"); puts("$Revision: 1.366 $ $Date: 2003/09/27 09:29:31 $\n");
} }
/* /*
......
...@@ -4,19 +4,7 @@ ...@@ -4,19 +4,7 @@
* Displays available options under grand unified configuration scheme * Displays available options under grand unified configuration scheme
* *
* The purpose of this option is to list, sort, and make searchable, all * The purpose of this option is to list, sort, and make searchable, all
* runtime options available to Postgresql, by their description and grouping. * runtime options available to PostgreSQL, by their description and grouping.
*
* Valid command-line options to this program:
*
* none : All available variables are sorted by group and name
* and formatted nicely. ( for human consumption )
* <string> : list all the variables whose name matches this string
* -g <string> : list all the variables whose group matches this string
* -l : lists all currently defined groups and terminates
* -G : no sort by groups (you get strict name order, instead)
* -m : output the list in Machine friendly format, with a header row
* -M : same as m, except no header
* -h : help
* *
* Options whose flag bits are set to GUC_NO_SHOW_ALL, GUC_NOT_IN_SAMPLE, * Options whose flag bits are set to GUC_NO_SHOW_ALL, GUC_NOT_IN_SAMPLE,
* or GUC_DISALLOW_IN_FILE are not displayed, unless the user specifically * or GUC_DISALLOW_IN_FILE are not displayed, unless the user specifically
...@@ -25,7 +13,7 @@ ...@@ -25,7 +13,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/misc/help_config.c,v 1.6 2003/09/25 06:58:06 petere Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/misc/help_config.c,v 1.7 2003/09/27 09:29:31 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -52,40 +40,33 @@ extern char *optarg; ...@@ -52,40 +40,33 @@ extern char *optarg;
* The following char constructs provide the different formats the variables * The following char constructs provide the different formats the variables
* can be outputted in. * can be outputted in.
*/ */
enum outputFormat #define HUMAN_OUTPUT 0
{ #define MACHINE_OUTPUT 1
HUMAN_OUTPUT,
MACHINE_OUTPUT
};
static const char *const GENERIC_FORMAT[] = { static const char *const GENERIC_FORMAT[] = {
gettext_noop("Name: %-20s\nContext: %-20s\nGroup: %-20s\n"), gettext_noop("Name: %-20s\nContext: %-20s\nGroup: %-20s\n"),
"%s\t%s\t%s\t" "%s\t%s\t%s\t"
}; };
static const char *const GENERIC_DESC[] = { static const char *const GENERIC_DESC[] = {
gettext_noop("Description: %s\n%s\n"), gettext_noop("Description: %s\n%s\n"),
"%s\t%s\n" "%s\t%s\n"
}; };
static const char *const BOOL_FORMAT[] = { static const char *const BOOL_FORMAT[] = {
gettext_noop("Type: Boolean\nReset value: %-s\n"), gettext_noop("Type: Boolean\nDefault value: %-s\n"),
"BOOL\t%s\t\t\t" "BOOL\t%s\t\t\t"
}; };
static const char *const INT_FORMAT[] = { static const char *const INT_FORMAT[] = {
gettext_noop("Type: integer\nReset value: %-20d\nMin value: %-20d\nMax value: %-20d\n"), gettext_noop("Type: integer\nDefault value: %-20d\nMin value: %-20d\nMax value: %-20d\n"),
"INT\t%d\t%d\t%d\t" "INT\t%d\t%d\t%d\t"
}; };
static const char *const REAL_FORMAT[] = { static const char *const REAL_FORMAT[] = {
gettext_noop("Type: real\nReset value: %-20g\nMin value: %-20g\nMax value: %-20g\n"), gettext_noop("Type: real\nDefault value: %-20g\nMin value: %-20g\nMax value: %-20g\n"),
"REAL\t%g\t%g\t%g\t" "REAL\t%g\t%g\t%g\t"
}; };
static const char *const STRING_FORMAT[] = { static const char *const STRING_FORMAT[] = {
gettext_noop("Type: string\nReset value: %-s\n"), gettext_noop("Type: string\nDefault value: %-s\n"),
"STRING\t%s\t\t\t" "STRING\t%s\t\t\t"
}; };
static const char *const COLUMN_HEADER[] = {
"",
gettext_noop("NAME\tCONTEXT\tGROUP\tTYPE\tRESET_VALUE\tMIN\tMAX\tSHORT_DESCRIPTION\tLONG_DESCRIPTION\n")
};
static const char *const ROW_SEPARATOR[] = { static const char *const ROW_SEPARATOR[] = {
"------------------------------------------------------------\n", "------------------------------------------------------------\n",
"" ""
...@@ -95,12 +76,8 @@ static const char *const ROW_SEPARATOR[] = { ...@@ -95,12 +76,8 @@ static const char *const ROW_SEPARATOR[] = {
* Variables loaded from the command line * Variables loaded from the command line
*/ */
static char *nameString = NULL; /* The var name pattern to match */ static char *nameString = NULL; /* The var name pattern to match */
static bool nameRegexBool = false; /* Match the name pattern as a
* regex */
static char *groupString = NULL; /* The var group pattern to match */ static char *groupString = NULL; /* The var group pattern to match */
static bool groupRegexBool = false; /* Match the group pattern as a static int outFormat = HUMAN_OUTPUT;
* regex */
static enum outputFormat outFormat = HUMAN_OUTPUT;
static bool suppressAllHeaders = false; /* MACHINE_OUTPUT output, no static bool suppressAllHeaders = false; /* MACHINE_OUTPUT output, no
* column headers */ * column headers */
static bool groupResults = true; /* sort result list by groups */ static bool groupResults = true; /* sort result list by groups */
...@@ -124,8 +101,7 @@ typedef union ...@@ -124,8 +101,7 @@ typedef union
static bool varMatches(mixedStruct *structToTest); static bool varMatches(mixedStruct *structToTest);
static int compareMixedStructs(const void *, const void *); static int compareMixedStructs(const void *, const void *);
static mixedStruct **varsToDisplay(int *resultListSize); static mixedStruct **varsToDisplay(int *resultListSize);
static const char *usageErrMsg(void); static void helpMessage(const char *progname);
static void helpMessage(void);
static void listAllGroups(void); static void listAllGroups(void);
static void printGenericHead(struct config_generic structToPrint); static void printGenericHead(struct config_generic structToPrint);
static void printGenericFoot(struct config_generic structToPrint); static void printGenericFoot(struct config_generic structToPrint);
...@@ -145,16 +121,13 @@ GucInfoMain(int argc, char *argv[]) ...@@ -145,16 +121,13 @@ GucInfoMain(int argc, char *argv[])
int c; int c;
int i; int i;
while ((c = getopt(argc, argv, "g:rGmMlh")) != -1) while ((c = getopt(argc - 1, argv + 1, "g:GmMlh")) != -1)
{ {
switch (c) switch (c)
{ {
case 'g': case 'g':
groupString = optarg; groupString = optarg;
break; break;
case 'r': /* not actually implemented yet */
nameRegexBool = true;
break;
case 'G': case 'G':
groupResults = false; groupResults = false;
break; break;
...@@ -169,17 +142,17 @@ GucInfoMain(int argc, char *argv[]) ...@@ -169,17 +142,17 @@ GucInfoMain(int argc, char *argv[])
listAllGroups(); listAllGroups();
exit(0); exit(0);
case 'h': case 'h':
helpMessage(); helpMessage(argv[0]);
exit(0); exit(0);
default: default:
fprintf(stderr, gettext("%s \n Try -h for further details\n"), usageErrMsg()); fprintf(stderr, gettext("Try \"%s --help-config -h\" for more information.\n"), argv[0]);
exit(1); exit(1);
} }
} }
if (optind < argc) if (optind < argc - 1)
nameString = argv[optind]; nameString = argv[optind + 1];
/* get the list of variables that match the user's specs. */ /* get the list of variables that match the user's specs. */
varList = varsToDisplay(&resultListSize); varList = varsToDisplay(&resultListSize);
...@@ -191,12 +164,12 @@ GucInfoMain(int argc, char *argv[]) ...@@ -191,12 +164,12 @@ GucInfoMain(int argc, char *argv[])
sizeof(mixedStruct *), compareMixedStructs); sizeof(mixedStruct *), compareMixedStructs);
/* output the results */ /* output the results */
if (!suppressAllHeaders) if (outFormat == MACHINE_OUTPUT && !suppressAllHeaders)
printf(gettext(COLUMN_HEADER[outFormat])); printf("NAME\tCONTEXT\tGROUP\tTYPE\tDEFAULT_VALUE\tMIN\tMAX\tSHORT_DESCRIPTION\tLONG_DESCRIPTION\n");
for (i = 0; varList[i] != NULL; i++) for (i = 0; varList[i] != NULL; i++)
{ {
printf(gettext(ROW_SEPARATOR[outFormat])); printf(ROW_SEPARATOR[outFormat]);
printMixedStruct(varList[i]); printMixedStruct(varList[i]);
} }
...@@ -299,7 +272,7 @@ varMatches(mixedStruct *structToTest) ...@@ -299,7 +272,7 @@ varMatches(mixedStruct *structToTest)
* searched for a variable in * searched for a variable in
* particular. */ * particular. */
if (nameString != NULL && !nameRegexBool) if (nameString != NULL)
{ {
if (strstr(structToTest->generic.name, nameString) != NULL) if (strstr(structToTest->generic.name, nameString) != NULL)
{ {
...@@ -308,12 +281,7 @@ varMatches(mixedStruct *structToTest) ...@@ -308,12 +281,7 @@ varMatches(mixedStruct *structToTest)
} }
} }
if (nameString != NULL && nameRegexBool) if (groupString != NULL)
{
/* We do not support this option yet */
}
if (groupString != NULL && !groupRegexBool)
{ {
if (strstr(config_group_names[structToTest->generic.group], groupString) != NULL) if (strstr(config_group_names[structToTest->generic.group], groupString) != NULL)
{ {
...@@ -326,11 +294,6 @@ varMatches(mixedStruct *structToTest) ...@@ -326,11 +294,6 @@ varMatches(mixedStruct *structToTest)
matches = false; matches = false;
} }
if (groupString != NULL && groupRegexBool)
{
/* We do not support this option yet */
}
/* return all variables */ /* return all variables */
if (nameString == NULL && groupString == NULL) if (nameString == NULL && groupString == NULL)
matches = true; matches = true;
...@@ -355,9 +318,14 @@ printMixedStruct(mixedStruct *structToPrint) ...@@ -355,9 +318,14 @@ printMixedStruct(mixedStruct *structToPrint)
{ {
case PGC_BOOL: case PGC_BOOL:
printf(gettext(BOOL_FORMAT[outFormat]), if (outFormat == HUMAN_OUTPUT)
(structToPrint->bool.reset_val == 0) ? printf(gettext(BOOL_FORMAT[outFormat]),
gettext("FALSE") : gettext("TRUE")); (structToPrint->bool.reset_val == 0) ?
gettext("false") : gettext("true"));
else
printf(gettext(BOOL_FORMAT[outFormat]),
(structToPrint->bool.reset_val == 0) ?
"FALSE" : "TRUE");
break; break;
case PGC_INT: case PGC_INT:
...@@ -380,7 +348,7 @@ printMixedStruct(mixedStruct *structToPrint) ...@@ -380,7 +348,7 @@ printMixedStruct(mixedStruct *structToPrint)
break; break;
default: default:
printf(gettext("Unrecognized variable type!\n")); printf("Internal error: unrecognized run-time parameter type\n");
break; break;
} }
...@@ -409,40 +377,29 @@ listAllGroups(void) ...@@ -409,40 +377,29 @@ listAllGroups(void)
{ {
int i; int i;
printf(gettext("All currently defined groups\n"));
printf(gettext("----------------------------\n"));
for (i = 0; config_group_names[i] != NULL; i++) for (i = 0; config_group_names[i] != NULL; i++)
printf(gettext("%s\n"), gettext(config_group_names[i])); printf("%s\n", gettext(config_group_names[i]));
}
static const char *
usageErrMsg(void)
{
return gettext("Usage for --help-config option: [-h] [-g <group>] [-l] [-G] [-m] [-M] [string]\n");
} }
static void static void
helpMessage(void) helpMessage(const char *progname)
{ {
printf(gettext("Description:\n" printf(gettext("%s --help-config displays information about the\n"
"--help-config displays all the runtime options available in PostgreSQL.\n" "run-time configuration parameters available in the PostgreSQL server.\n\n"),
"It groups them by category and sorts them by name. If available, it will\n" progname);
"present a short description, default, max and min values as well as other\n" printf(gettext("Usage:\n %s --help-config [OPTION]... [NAME]\n\n"), progname);
"information about each option.\n\n" printf(gettext("General Options:\n"));
"With no options specified, it will output all available runtime options\n" printf(gettext(" NAME output information about parameters matching this name\n"));
"in human friendly format, grouped by category and sorted by name.\n\n" printf(gettext(" -g GROUP output information about parameters matching this group\n"));
printf(gettext(" -l list available parameter groups\n"));
"%s\n" printf(gettext(" -h show this help, then exit\n"));
printf(gettext("\nOutput Options:\n"));
"General Options:\n" printf(gettext(" -G do not group by category\n"));
" [string] All options with names that match this string\n" printf(gettext(" -m machine-friendly format: tab separated fields\n"));
" -g GROUP All options in categories that match GROUP\n" printf(gettext(" -M same as -m, but header with column names is suppressed\n"));
" -l Prints list of all groups / subgroups\n" printf(gettext("\n"
" -h Prints this help message\n" "If no parameter name is specified, all parameters are shown. By default,\n"
"\nOutput Options:\n" "parameters are grouped by category, sorted by name, and output in a human-\n"
" -G Do not group by category\n" "friendly format. Available information about run-time parameters includes\n"
" -m Machine friendly format: tab separated fields\n" "a short description, default value, maximum and minimum values.\n"));
" -M Same as m, except header with column names is suppressed\n"),
usageErrMsg()
);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment