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

Commitee24d2b

Browse files
committed
Clean up excessive code
The encoding ID was converted between string and number too many times,probably a remnant from the shell script days.Reviewed-by: Aleksandr Parfenov <a.parfenov@postgrespro.ru>
1 parent8e67380 commitee24d2b

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

‎src/bin/initdb/initdb.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ static char *xlog_dir = NULL;
145145

146146
/* internal vars */
147147
staticconstchar*progname;
148-
staticchar*encodingid="0";
148+
staticintencodingid;
149149
staticchar*bki_file;
150150
staticchar*desc_file;
151151
staticchar*shdesc_file;
@@ -236,7 +236,7 @@ static void writefile(char *path, char **lines);
236236
staticFILE*popen_check(constchar*command,constchar*mode);
237237
staticvoidexit_nicely(void);
238238
staticchar*get_id(void);
239-
staticchar*get_encoding_id(char*encoding_name);
239+
staticintget_encoding_id(char*encoding_name);
240240
staticvoidset_input(char**dest,char*filename);
241241
staticvoidcheck_input(char*path);
242242
staticvoidwrite_version_file(char*extrapath);
@@ -636,15 +636,15 @@ encodingid_to_string(int enc)
636636
/*
637637
* get the encoding id for a given encoding name
638638
*/
639-
staticchar*
639+
staticint
640640
get_encoding_id(char*encoding_name)
641641
{
642642
intenc;
643643

644644
if (encoding_name&&*encoding_name)
645645
{
646646
if ((enc=pg_valid_server_encoding(encoding_name)) >=0)
647-
returnencodingid_to_string(enc);
647+
returnenc;
648648
}
649649
fprintf(stderr,_("%s: \"%s\" is not a valid server encoding name\n"),
650650
progname,encoding_name ?encoding_name :"(null)");
@@ -1328,7 +1328,7 @@ bootstrap_template1(void)
13281328

13291329
bki_lines=replace_token(bki_lines,"POSTGRES",escape_quotes(username));
13301330

1331-
bki_lines=replace_token(bki_lines,"ENCODING",encodingid);
1331+
bki_lines=replace_token(bki_lines,"ENCODING",encodingid_to_string(encodingid));
13321332

13331333
bki_lines=replace_token(bki_lines,"LC_COLLATE",escape_quotes(lc_collate));
13341334

@@ -2454,8 +2454,6 @@ setup_bin_paths(const char *argv0)
24542454
void
24552455
setup_locale_encoding(void)
24562456
{
2457-
intuser_enc;
2458-
24592457
setlocales();
24602458

24612459
if (strcmp(lc_ctype,lc_collate)==0&&
@@ -2505,12 +2503,11 @@ setup_locale_encoding(void)
25052503
* UTF-8.
25062504
*/
25072505
#ifdefWIN32
2506+
encodingid=PG_UTF8;
25082507
printf(_("Encoding \"%s\" implied by locale is not allowed as a server-side encoding.\n"
25092508
"The default database encoding will be set to \"%s\" instead.\n"),
25102509
pg_encoding_to_char(ctype_enc),
2511-
pg_encoding_to_char(PG_UTF8));
2512-
ctype_enc=PG_UTF8;
2513-
encodingid=encodingid_to_string(ctype_enc);
2510+
pg_encoding_to_char(encodingid));
25142511
#else
25152512
fprintf(stderr,
25162513
_("%s: locale \"%s\" requires unsupported encoding \"%s\"\n"),
@@ -2524,17 +2521,16 @@ setup_locale_encoding(void)
25242521
}
25252522
else
25262523
{
2527-
encodingid=encodingid_to_string(ctype_enc);
2524+
encodingid=ctype_enc;
25282525
printf(_("The default database encoding has accordingly been set to \"%s\".\n"),
2529-
pg_encoding_to_char(ctype_enc));
2526+
pg_encoding_to_char(encodingid));
25302527
}
25312528
}
25322529
else
25332530
encodingid=get_encoding_id(encoding);
25342531

2535-
user_enc=atoi(encodingid);
2536-
if (!check_locale_encoding(lc_ctype,user_enc)||
2537-
!check_locale_encoding(lc_collate,user_enc))
2532+
if (!check_locale_encoding(lc_ctype,encodingid)||
2533+
!check_locale_encoding(lc_collate,encodingid))
25382534
exit(1);/* check_locale_encoding printed the error */
25392535

25402536
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp