Commit ee24d2b5 authored by Peter Eisentraut's avatar Peter Eisentraut

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: default avatarAleksandr Parfenov <a.parfenov@postgrespro.ru>
parent 8e673801
...@@ -145,7 +145,7 @@ static char *xlog_dir = NULL; ...@@ -145,7 +145,7 @@ static char *xlog_dir = NULL;
/* internal vars */ /* internal vars */
static const char *progname; static const char *progname;
static char *encodingid = "0"; static int encodingid;
static char *bki_file; static char *bki_file;
static char *desc_file; static char *desc_file;
static char *shdesc_file; static char *shdesc_file;
...@@ -236,7 +236,7 @@ static void writefile(char *path, char **lines); ...@@ -236,7 +236,7 @@ static void writefile(char *path, char **lines);
static FILE *popen_check(const char *command, const char *mode); static FILE *popen_check(const char *command, const char *mode);
static void exit_nicely(void); static void exit_nicely(void);
static char *get_id(void); static char *get_id(void);
static char *get_encoding_id(char *encoding_name); static int get_encoding_id(char *encoding_name);
static void set_input(char **dest, char *filename); static void set_input(char **dest, char *filename);
static void check_input(char *path); static void check_input(char *path);
static void write_version_file(char *extrapath); static void write_version_file(char *extrapath);
...@@ -636,7 +636,7 @@ encodingid_to_string(int enc) ...@@ -636,7 +636,7 @@ encodingid_to_string(int enc)
/* /*
* get the encoding id for a given encoding name * get the encoding id for a given encoding name
*/ */
static char * static int
get_encoding_id(char *encoding_name) get_encoding_id(char *encoding_name)
{ {
int enc; int enc;
...@@ -644,7 +644,7 @@ get_encoding_id(char *encoding_name) ...@@ -644,7 +644,7 @@ get_encoding_id(char *encoding_name)
if (encoding_name && *encoding_name) if (encoding_name && *encoding_name)
{ {
if ((enc = pg_valid_server_encoding(encoding_name)) >= 0) if ((enc = pg_valid_server_encoding(encoding_name)) >= 0)
return encodingid_to_string(enc); return enc;
} }
fprintf(stderr, _("%s: \"%s\" is not a valid server encoding name\n"), fprintf(stderr, _("%s: \"%s\" is not a valid server encoding name\n"),
progname, encoding_name ? encoding_name : "(null)"); progname, encoding_name ? encoding_name : "(null)");
...@@ -1328,7 +1328,7 @@ bootstrap_template1(void) ...@@ -1328,7 +1328,7 @@ bootstrap_template1(void)
bki_lines = replace_token(bki_lines, "POSTGRES", escape_quotes(username)); bki_lines = replace_token(bki_lines, "POSTGRES", escape_quotes(username));
bki_lines = replace_token(bki_lines, "ENCODING", encodingid); bki_lines = replace_token(bki_lines, "ENCODING", encodingid_to_string(encodingid));
bki_lines = replace_token(bki_lines, "LC_COLLATE", escape_quotes(lc_collate)); bki_lines = replace_token(bki_lines, "LC_COLLATE", escape_quotes(lc_collate));
...@@ -2454,8 +2454,6 @@ setup_bin_paths(const char *argv0) ...@@ -2454,8 +2454,6 @@ setup_bin_paths(const char *argv0)
void void
setup_locale_encoding(void) setup_locale_encoding(void)
{ {
int user_enc;
setlocales(); setlocales();
if (strcmp(lc_ctype, lc_collate) == 0 && if (strcmp(lc_ctype, lc_collate) == 0 &&
...@@ -2505,12 +2503,11 @@ setup_locale_encoding(void) ...@@ -2505,12 +2503,11 @@ setup_locale_encoding(void)
* UTF-8. * UTF-8.
*/ */
#ifdef WIN32 #ifdef WIN32
encodingid = PG_UTF8;
printf(_("Encoding \"%s\" implied by locale is not allowed as a server-side encoding.\n" printf(_("Encoding \"%s\" implied by locale is not allowed as a server-side encoding.\n"
"The default database encoding will be set to \"%s\" instead.\n"), "The default database encoding will be set to \"%s\" instead.\n"),
pg_encoding_to_char(ctype_enc), pg_encoding_to_char(ctype_enc),
pg_encoding_to_char(PG_UTF8)); pg_encoding_to_char(encodingid));
ctype_enc = PG_UTF8;
encodingid = encodingid_to_string(ctype_enc);
#else #else
fprintf(stderr, fprintf(stderr,
_("%s: locale \"%s\" requires unsupported encoding \"%s\"\n"), _("%s: locale \"%s\" requires unsupported encoding \"%s\"\n"),
...@@ -2524,17 +2521,16 @@ setup_locale_encoding(void) ...@@ -2524,17 +2521,16 @@ setup_locale_encoding(void)
} }
else else
{ {
encodingid = encodingid_to_string(ctype_enc); encodingid = ctype_enc;
printf(_("The default database encoding has accordingly been set to \"%s\".\n"), printf(_("The default database encoding has accordingly been set to \"%s\".\n"),
pg_encoding_to_char(ctype_enc)); pg_encoding_to_char(encodingid));
} }
} }
else else
encodingid = get_encoding_id(encoding); encodingid = get_encoding_id(encoding);
user_enc = atoi(encodingid); if (!check_locale_encoding(lc_ctype, encodingid) ||
if (!check_locale_encoding(lc_ctype, user_enc) || !check_locale_encoding(lc_collate, encodingid))
!check_locale_encoding(lc_collate, user_enc))
exit(1); /* check_locale_encoding printed the error */ exit(1); /* check_locale_encoding printed the error */
} }
......
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