Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit040e1ce

Browse files
committed
Make the messages and the options parsing a bit more standard.
1 parent4f581e0 commit040e1ce

File tree

1 file changed

+41
-52
lines changed

1 file changed

+41
-52
lines changed

‎src/bin/initdb/initdb.c

Lines changed: 41 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* Portions Copyright (c) 1994, Regents of the University of California
4444
* Portions taken from FreeBSD.
4545
*
46-
* $Header: /cvsroot/pgsql/src/bin/initdb/initdb.c,v 1.12 2003/11/2321:41:30 petere Exp $
46+
* $Header: /cvsroot/pgsql/src/bin/initdb/initdb.c,v 1.13 2003/11/2322:17:59 petere Exp $
4747
*
4848
*-------------------------------------------------------------------------
4949
*/
@@ -56,6 +56,7 @@
5656
#include<unistd.h>
5757
#include<locale.h>
5858
#include<signal.h>
59+
#include<errno.h>
5960

6061
#include"libpq/pqsignal.h"
6162
#include"mb/pg_wchar.h"
@@ -94,8 +95,6 @@ char *username = "";
9495
boolpwprompt= false;
9596
booldebug= false;
9697
boolnoclean= false;
97-
boolshow_help= false;
98-
boolshow_version= false;
9998
boolshow_setting= false;
10099

101100

@@ -250,7 +249,7 @@ xmalloc(size_t size)
250249
result=malloc(size);
251250
if (!result)
252251
{
253-
fputs(_("malloc failure - bailing out\n"),stderr);
252+
fprintf(stderr,_("%s: out of memory\n"),progname);
254253
exit(1);
255254
}
256255
returnresult;
@@ -264,7 +263,7 @@ xstrdup(const char *s)
264263
result=strdup(s);
265264
if (!result)
266265
{
267-
fputs(_("strdup failure - bailing out\n"),stderr);
266+
fprintf(stderr,_("%s: out of memory\n"),progname);
268267
exit(1);
269268
}
270269
returnresult;
@@ -395,7 +394,8 @@ readfile(char *path)
395394

396395
if ((infile=fopen(path,"r"))==NULL)
397396
{
398-
fprintf(stderr,_("could not read %s\n"),path);
397+
fprintf(stderr,_("%s: could not open file \"%s\" for reading: %s\n"),
398+
progname,path,strerror(errno));
399399
exit_nicely();
400400
}
401401

@@ -453,7 +453,8 @@ writefile(char *path, char **lines)
453453
;
454454
if ((out_file=fopen(path,PG_BINARY_W))==NULL)
455455
{
456-
fprintf(stderr,_("could not write %s\n"),path);
456+
fprintf(stderr,_("%s: could not open file \"%s\" for writing: %s\n"),
457+
progname,path,strerror(errno));
457458
exit_nicely();
458459
}
459460
for (line=lines;*line!=NULL;line++)
@@ -2009,23 +2010,23 @@ usage(const char *progname)
20092010
printf(_(" [-D, --pgdata=]DATADIR location for this database cluster\n"));
20102011
printf(_(" -E, --encoding=ENCODING set default encoding for new databases\n"));
20112012
printf(_(" --locale=LOCALE initialize database cluster with given locale\n"));
2012-
printf(_(" --lc-collate, --lc-ctype, --lc-messages=LOCALE\n"));
2013-
printf(_(" --lc-monetary, --lc-numeric, --lc-time=LOCALE\n"));
2014-
printf(_(" initialize database cluster with given locale\n"));
2015-
printf(_(" in the respective category (default taken from\n"));
2016-
printf(_(" environment)\n"));
2013+
printf(_(" --lc-collate, --lc-ctype, --lc-messages=LOCALE\n"
2014+
" --lc-monetary, --lc-numeric, --lc-time=LOCALE\n"
2015+
" initialize database cluster with given locale\n"
2016+
" in the respective category (default taken from\n"
2017+
" environment)\n"));
20172018
printf(_(" --no-locale equivalent to --locale=C\n"));
20182019
printf(_(" -U, --username=NAME database superuser name\n"));
20192020
printf(_(" -W, --pwprompt prompt for a password for the new superuser\n"));
20202021
printf(_(" -?, --help show this help, then exit\n"));
20212022
printf(_(" -V, --version output version information, then exit\n"));
2022-
printf(_("\nLess commonly used options:\n"));
2023+
printf(_("\nLess commonly used options:\n"));
20232024
printf(_(" -d, --debug generate lots of debugging output\n"));
20242025
printf(_(" -s, --show show internal settings\n"));
20252026
printf(_(" -L DIRECTORY where to find the input files\n"));
20262027
printf(_(" -n, --noclean do not clean up after errors\n"));
2027-
printf(_("\nIf the data directory is not specified, the environment variable PGDATA\n"));
2028-
printf(_("is used.\n"));
2028+
printf(_("\nIf the data directory is not specified, the environment variable PGDATA\n"
2029+
"is used.\n"));
20292030
printf(_("\nReport bugs to <pgsql-bugs@postgresql.org>.\n"));
20302031
}
20312032

@@ -2115,20 +2116,24 @@ main(int argc, char *argv[])
21152116
self_path=NULL;
21162117
}
21172118

2119+
if (argc>1)
2120+
{
2121+
if (strcmp(argv[1],"--help")==0||strcmp(argv[1],"-?")==0)
2122+
{
2123+
usage(progname);
2124+
exit(0);
2125+
}
2126+
if (strcmp(argv[1],"--version")==0||strcmp(argv[1],"-V")==0)
2127+
{
2128+
puts("initdb (PostgreSQL) "PG_VERSION);
2129+
exit(0);
2130+
}
2131+
}
2132+
21182133
/* process command-line options */
21192134

2120-
while (1)
2135+
while ((c=getopt_long(argc,argv,"dD:E:L:nU:W",long_options,&option_index))!=-1)
21212136
{
2122-
/*
2123-
* a : as the first option char here lets us use ? as a short
2124-
* option
2125-
*/
2126-
c=getopt_long(argc,argv,":D:E:WU:?sVdnL:",
2127-
long_options,&option_index);
2128-
2129-
if (c==-1)
2130-
break;
2131-
21322137
switch (c)
21332138
{
21342139
case'D':
@@ -2178,20 +2183,14 @@ main(int argc, char *argv[])
21782183
case8:
21792184
locale="C";
21802185
break;
2181-
case'?':
2182-
show_help= true;
2183-
break;
21842186
case's':
21852187
show_setting= true;
21862188
break;
2187-
case'V':
2188-
show_version= true;
2189-
break;
21902189
default:
2191-
show_help= true;
2192-
printf(_("Unrecognized option: %c\n"),c);
2190+
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),
2191+
progname);
2192+
exit(1);
21932193
}
2194-
21952194
}
21962195

21972196
/* Non-option argument specifies data directory */
@@ -2202,19 +2201,11 @@ main(int argc, char *argv[])
22022201
}
22032202

22042203
if (optind<argc)
2205-
show_help= true;
2206-
2207-
if (show_version)
22082204
{
2209-
/* hard coded name here, in case they rename executable */
2210-
printf("initdb (PostgreSQL) %s\n",PG_VERSION);
2211-
exit(0);
2212-
}
2213-
2214-
if (show_help)
2215-
{
2216-
usage(progname);
2217-
exit(0);
2205+
fprintf(stderr,_("%s: too many command-line arguments (first is \"%s\")\n"),
2206+
progname,argv[optind+1]);
2207+
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),
2208+
progname);
22182209
}
22192210

22202211
if (strlen(pg_data)==0)
@@ -2229,11 +2220,9 @@ main(int argc, char *argv[])
22292220
{
22302221
fprintf(stderr,
22312222
_("%s: no data directory specified\n"
2232-
"You must identify the directory where the data "
2233-
"for this database system\n"
2234-
"will reside. Do this with either the invocation "
2235-
"option -D or the\n"
2236-
"environment variable PGDATA.\n"),
2223+
"You must identify the directory where the data for this database system\n"
2224+
"will reside. Do this with either the invocation option -D or the\n"
2225+
"environment variable PGDATA.\n"),
22372226
progname);
22382227
exit(1);
22392228
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp