1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-05 07:21:24 +03:00

Enable locale, so case conversion (identifier processing) and number

formatting (\timing) works correctly.  Change "Total time" to "Time"
since there is nothing that "total" refers to.  Remove non-multibyte
code.
This commit is contained in:
Peter Eisentraut
2002-08-27 20:16:49 +00:00
parent 7af5ea736f
commit 7292131c66
8 changed files with 18 additions and 140 deletions

View File

@ -1,5 +1,5 @@
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.73 2002/08/23 01:27:44 tgl Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.74 2002/08/27 20:16:48 petere Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
@ -1591,7 +1591,7 @@ lo_import 152801
<term><literal>\timing</literal></term> <term><literal>\timing</literal></term>
<listitem> <listitem>
<para> <para>
Toggles a display of how long each query takes, in milliseconds. Toggles a display of how long each SQL statement takes, in milliseconds.
</para> </para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.42 2002/08/10 19:35:00 tgl Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.43 2002/08/27 20:16:48 petere Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
@ -466,7 +466,7 @@ SendQuery(const char *query)
/* Possible microtiming output */ /* Possible microtiming output */
if (pset.timing && success) if (pset.timing && success)
printf(gettext("Total time: %.2f msec\n"), printf(gettext("Time: %.2f ms\n"),
((after.tv_sec-before.tv_sec)*1000000 + after.tv_usec - before.tv_usec) / 1000.0); ((after.tv_sec-before.tv_sec)*1000000 + after.tv_usec - before.tv_usec) / 1000.0);
return success; return success;

View File

@ -3,7 +3,7 @@
* *
* Copyright 2000-2002 by PostgreSQL Global Development Group * Copyright 2000-2002 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.65 2002/08/27 18:28:28 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.66 2002/08/27 20:16:48 petere Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include "describe.h" #include "describe.h"
@ -305,11 +305,9 @@ listAllDbs(bool verbose)
"SELECT d.datname as \"%s\",\n" "SELECT d.datname as \"%s\",\n"
" u.usename as \"%s\"", " u.usename as \"%s\"",
_("Name"), _("Owner")); _("Name"), _("Owner"));
#ifdef MULTIBYTE
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
",\n pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\"", ",\n pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\"",
_("Encoding")); _("Encoding"));
#endif
if (verbose) if (verbose)
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
",\n pg_catalog.obj_description(d.oid, 'pg_database') as \"%s\"", ",\n pg_catalog.obj_description(d.oid, 'pg_database') as \"%s\"",

View File

@ -3,14 +3,12 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.3 2001/10/28 06:25:58 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.4 2002/08/27 20:16:48 petere Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include "mbprint.h" #include "mbprint.h"
#ifdef MULTIBYTE
#include "mb/pg_wchar.h" #include "mb/pg_wchar.h"
#include "settings.h" #include "settings.h"
@ -195,7 +193,7 @@ utf2ucs(const unsigned char *c)
/* mb_utf_wcwidth : calculate column length for the utf8 string pwcs /* mb_utf_wcwidth : calculate column length for the utf8 string pwcs
*/ */
static int static int
mb_utf_wcswidth(unsigned char *pwcs, int len) mb_utf_wcswidth(unsigned char *pwcs, size_t len)
{ {
int w, int w,
l = 0; l = 0;
@ -312,7 +310,7 @@ mb_utf_validate(unsigned char *pwcs)
*/ */
int int
pg_wcswidth(unsigned char *pwcs, int len) pg_wcswidth(unsigned char *pwcs, size_t len)
{ {
if (pset.encoding == PG_UTF8) if (pset.encoding == PG_UTF8)
return mb_utf_wcswidth(pwcs, len); return mb_utf_wcswidth(pwcs, len);
@ -340,14 +338,3 @@ mbvalidate(unsigned char *pwcs)
return pwcs; return pwcs;
} }
} }
#else /* !MULTIBYTE */
/* in single-byte environment, all cells take 1 column */
int
pg_wcswidth(unsigned char *pwcs, int len)
{
return len;
}
#endif

View File

@ -1,17 +1,13 @@
/* $Id: mbprint.h,v 1.4 2001/11/05 17:46:31 momjian Exp $ */ /* $Id: mbprint.h,v 1.5 2002/08/27 20:16:48 petere Exp $ */
#ifndef MBPRINT_H #ifndef MBPRINT_H
#define MBPRINT_H #define MBPRINT_H
#ifdef MULTIBYTE
#include "mb/pg_wchar.h" #include "mb/pg_wchar.h"
pg_wchar utf2ucs(const unsigned char *c); pg_wchar utf2ucs(const unsigned char *c);
unsigned char *mbvalidate(unsigned char *pwcs); unsigned char *mbvalidate(unsigned char *pwcs);
#endif /* MULTIBYTE */
int pg_wcswidth(unsigned char *pwcs, int len); int pg_wcswidth(unsigned char *pwcs, size_t len);
#endif /* MBPRINT_H */ #endif /* MBPRINT_H */

View File

@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.28 2002/07/18 04:46:24 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.29 2002/08/27 20:16:48 petere Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include "print.h" #include "print.h"
@ -209,13 +209,9 @@ print_aligned_text(const char *title, const char *const * headers,
FILE *fout) FILE *fout)
{ {
unsigned int col_count = 0; unsigned int col_count = 0;
#ifdef MULTIBYTE
unsigned int cell_count = 0; unsigned int cell_count = 0;
unsigned int *head_w, unsigned int *head_w,
*cell_w; *cell_w;
#endif
unsigned int i, unsigned int i,
tmp; tmp;
unsigned int *widths, unsigned int *widths,
@ -233,7 +229,6 @@ print_aligned_text(const char *title, const char *const * headers,
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#ifdef MULTIBYTE
head_w = calloc(col_count, sizeof(*head_w)); head_w = calloc(col_count, sizeof(*head_w));
if (!head_w) if (!head_w)
{ {
@ -256,7 +251,6 @@ print_aligned_text(const char *title, const char *const * headers,
} }
else else
cell_w = 0; cell_w = 0;
#endif
/* calc column widths */ /* calc column widths */
@ -264,18 +258,14 @@ print_aligned_text(const char *title, const char *const * headers,
{ {
if ((tmp = pg_wcswidth((unsigned char *) headers[i], strlen(headers[i]))) > widths[i]) if ((tmp = pg_wcswidth((unsigned char *) headers[i], strlen(headers[i]))) > widths[i])
widths[i] = tmp; widths[i] = tmp;
#ifdef MULTIBYTE
head_w[i] = tmp; head_w[i] = tmp;
#endif
} }
for (i = 0, ptr = cells; *ptr; ptr++, i++) for (i = 0, ptr = cells; *ptr; ptr++, i++)
{ {
if ((tmp = pg_wcswidth((unsigned char *) *ptr, strlen(*ptr))) > widths[i % col_count]) if ((tmp = pg_wcswidth((unsigned char *) *ptr, strlen(*ptr))) > widths[i % col_count])
widths[i % col_count] = tmp; widths[i % col_count] = tmp;
#ifdef MULTIBYTE
cell_w[i] = tmp; cell_w[i] = tmp;
#endif
} }
if (opt_border == 0) if (opt_border == 0)
total_w = col_count - 1; total_w = col_count - 1;
@ -313,11 +303,7 @@ print_aligned_text(const char *title, const char *const * headers,
{ {
int nbspace; int nbspace;
#ifdef MULTIBYTE
nbspace = widths[i] - head_w[i]; nbspace = widths[i] - head_w[i];
#else
nbspace = widths[i] - strlen(headers[i]);
#endif
/* centered */ /* centered */
fprintf(fout, "%-*s%s%-*s", fprintf(fout, "%-*s%s%-*s",
@ -356,26 +342,16 @@ print_aligned_text(const char *title, const char *const * headers,
/* content */ /* content */
if (opt_align[(i) % col_count] == 'r') if (opt_align[(i) % col_count] == 'r')
{ {
#ifdef MULTIBYTE
fprintf(fout, "%*s%s", fprintf(fout, "%*s%s",
widths[i % col_count] - cell_w[i], "", cells[i]); widths[i % col_count] - cell_w[i], "", cells[i]);
#else
fprintf(fout, "%*s", widths[i % col_count], cells[i]);
#endif
} }
else else
{ {
if ((i + 1) % col_count == 0 && opt_border != 2) if ((i + 1) % col_count == 0 && opt_border != 2)
fputs(cells[i], fout); fputs(cells[i], fout);
else else
{
#ifdef MULTIBYTE
fprintf(fout, "%-s%*s", cells[i], fprintf(fout, "%-s%*s", cells[i],
widths[i % col_count] - cell_w[i], ""); widths[i % col_count] - cell_w[i], "");
#else
fprintf(fout, "%-*s", widths[i % col_count], cells[i]);
#endif
}
} }
/* divider */ /* divider */
@ -406,10 +382,8 @@ print_aligned_text(const char *title, const char *const * headers,
fputc('\n', fout); fputc('\n', fout);
/* clean up */ /* clean up */
#ifdef MULTIBYTE
free(cell_w); free(cell_w);
free(head_w); free(head_w);
#endif
free(widths); free(widths);
} }
@ -429,12 +403,9 @@ print_aligned_vertical(const char *title, const char *const * headers,
hwidth = 0, hwidth = 0,
dwidth = 0; dwidth = 0;
char *divider; char *divider;
#ifdef MULTIBYTE
unsigned int cell_count = 0; unsigned int cell_count = 0;
unsigned int *cell_w, unsigned int *cell_w,
*head_w; *head_w;
#endif
if (cells[0] == NULL) if (cells[0] == NULL)
{ {
@ -442,8 +413,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
return; return;
} }
#ifdef MULTIBYTE /* count headers and find longest one */
/* pre-count headers */
for (ptr = headers; *ptr; ptr++) for (ptr = headers; *ptr; ptr++)
col_count++; col_count++;
head_w = calloc(col_count, sizeof(*head_w)); head_w = calloc(col_count, sizeof(*head_w));
@ -480,22 +450,6 @@ print_aligned_vertical(const char *title, const char *const * headers,
dwidth = tmp; dwidth = tmp;
cell_w[i] = tmp; cell_w[i] = tmp;
} }
#else
/* count columns and find longest header */
for (ptr = headers; *ptr; ptr++)
{
col_count++;
if ((tmp = strlen(*ptr)) > hwidth)
hwidth = tmp; /* don't wanna call strlen twice */
}
/* find longest data cell */
for (ptr = cells; *ptr; ptr++)
{
if ((tmp = strlen(*ptr)) > dwidth)
dwidth = tmp;
}
#endif
/* print title */ /* print title */
if (!opt_barebones && title) if (!opt_barebones && title)
@ -569,12 +523,8 @@ print_aligned_vertical(const char *title, const char *const * headers,
if (opt_border == 2) if (opt_border == 2)
fputs("| ", fout); fputs("| ", fout);
#if MULTIBYTE
fprintf(fout, "%-s%*s", headers[i % col_count], fprintf(fout, "%-s%*s", headers[i % col_count],
hwidth - head_w[i % col_count], ""); hwidth - head_w[i % col_count], "");
#else
fprintf(fout, "%-*s", hwidth, headers[i % col_count]);
#endif
if (opt_border > 0) if (opt_border > 0)
fputs(" | ", fout); fputs(" | ", fout);
@ -584,13 +534,7 @@ print_aligned_vertical(const char *title, const char *const * headers,
if (opt_border < 2) if (opt_border < 2)
fprintf(fout, "%s\n", *ptr); fprintf(fout, "%s\n", *ptr);
else else
{
#ifdef MULTIBYTE
fprintf(fout, "%-s%*s |\n", *ptr, dwidth - cell_w[i], ""); fprintf(fout, "%-s%*s |\n", *ptr, dwidth - cell_w[i], "");
#else
fprintf(fout, "%-*s |\n", dwidth, *ptr);
#endif
}
} }
if (opt_border == 2) if (opt_border == 2)
@ -610,10 +554,8 @@ print_aligned_vertical(const char *title, const char *const * headers,
fputc('\n', fout); fputc('\n', fout);
free(divider); free(divider);
#ifdef MULTIBYTE
free(cell_w); free(cell_w);
free(head_w); free(head_w);
#endif
} }
@ -1167,13 +1109,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
} }
for (i = 0; i < nfields; i++) for (i = 0; i < nfields; i++)
{
#ifdef MULTIBYTE
headers[i] = mbvalidate(PQfname(result, i)); headers[i] = mbvalidate(PQfname(result, i));
#else
headers[i] = PQfname(result, i);
#endif
}
/* set cells */ /* set cells */
@ -1189,13 +1125,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
if (PQgetisnull(result, i / nfields, i % nfields)) if (PQgetisnull(result, i / nfields, i % nfields))
cells[i] = opt->nullPrint ? opt->nullPrint : ""; cells[i] = opt->nullPrint ? opt->nullPrint : "";
else else
{
#ifdef MULTIBYTE
cells[i] = mbvalidate(PQgetvalue(result, i / nfields, i % nfields)); cells[i] = mbvalidate(PQgetvalue(result, i / nfields, i % nfields));
#else
cells[i] = PQgetvalue(result, i / nfields, i % nfields);
#endif
}
} }
/* set footers */ /* set footers */

View File

@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.62 2002/08/10 19:35:01 tgl Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.63 2002/08/27 20:16:48 petere Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
@ -11,7 +11,7 @@
#ifndef WIN32 #ifndef WIN32
#include <unistd.h> #include <unistd.h>
#else /* WIN32 */ #else /* WIN32 */
#include <io.h> #include <io.h>
#include <windows.h> #include <windows.h>
#include <win32.h> #include <win32.h>
@ -21,9 +21,7 @@
#include <getopt.h> #include <getopt.h>
#endif #endif
#ifdef ENABLE_NLS
#include <locale.h> #include <locale.h>
#endif
#include "libpq-fe.h" #include "libpq-fe.h"
@ -37,12 +35,7 @@
#include "settings.h" #include "settings.h"
#include "variables.h" #include "variables.h"
#ifdef MULTIBYTE
#include "mb/pg_wchar.h" #include "mb/pg_wchar.h"
#else
/* XXX Grand unified hard-coded badness; this should go into libpq */
#define pg_encoding_to_char(x) "SQL_ASCII"
#endif
/* /*
* Global psql options * Global psql options
@ -105,8 +98,8 @@ main(int argc, char *argv[])
char *password = NULL; char *password = NULL;
bool need_pass; bool need_pass;
#ifdef ENABLE_NLS
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
#ifdef ENABLE_NLS
bindtextdomain("psql", LOCALEDIR); bindtextdomain("psql", LOCALEDIR);
textdomain("psql"); textdomain("psql");
#endif #endif
@ -638,26 +631,8 @@ showVersion(void)
{ {
puts("psql (PostgreSQL) " PG_VERSION); puts("psql (PostgreSQL) " PG_VERSION);
#if defined(USE_READLINE) || defined(MULTIBYTE) #if defined(USE_READLINE)
fputs(gettext("contains support for: "), stdout); puts(gettext("contains support for readline"));
#ifdef USE_READLINE
fputs(gettext("readline"), stdout);
#define _Feature
#endif
#ifdef MULTIBYTE
#ifdef _Feature
fputs(", ", stdout);
#else
#define _Feature
#endif
fputs(gettext("multibyte"), stdout);
#endif
#undef _Feature
puts("");
#endif #endif
puts(gettext("Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group\n" puts(gettext("Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group\n"

View File

@ -3,7 +3,7 @@
* *
* Copyright 2000 by PostgreSQL Global Development Group * Copyright 2000 by PostgreSQL Global Development Group
* *
* $Header: /cvsroot/pgsql/src/bin/psql/stringutils.c,v 1.29 2002/07/02 05:49:18 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/psql/stringutils.c,v 1.30 2002/08/27 20:16:49 petere Exp $
*/ */
#include "postgres_fe.h" #include "postgres_fe.h"
#include "stringutils.h" #include "stringutils.h"
@ -52,10 +52,6 @@ strtokx(const char *s,
char *start; char *start;
char *cp = NULL; char *cp = NULL;
#ifndef MULTIBYTE
(void) encoding; /* not used */
#endif
if (s) if (s)
{ {
free(storage); free(storage);
@ -95,11 +91,7 @@ strtokx(const char *s,
for (p = start; for (p = start;
*p && (*p != *cp || *(p - 1) == escape); *p && (*p != *cp || *(p - 1) == escape);
#ifdef MULTIBYTE
p += PQmblen(p, encoding) p += PQmblen(p, encoding)
#else
p++
#endif
); );
/* not yet end of string? */ /* not yet end of string? */