Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
73a7c322
Commit
73a7c322
authored
Jul 10, 2005
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add psql \pset numericsep to allow output numbers like 100,000.0 or
100.000,0. Eugen Nedelcu
parent
be3aa30d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
308 additions
and
87 deletions
+308
-87
doc/src/sgml/ref/psql-ref.sgml
doc/src/sgml/ref/psql-ref.sgml
+13
-1
src/bin/psql/command.c
src/bin/psql/command.c
+12
-2
src/bin/psql/help.c
src/bin/psql/help.c
+2
-2
src/bin/psql/print.c
src/bin/psql/print.c
+279
-81
src/bin/psql/print.h
src/bin/psql/print.h
+2
-1
No files found.
doc/src/sgml/ref/psql-ref.sgml
View file @
73a7c322
<!--
<!--
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.14
5 2005/06/14 02:57:38
momjian Exp $
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.14
6 2005/07/10 03:46:12
momjian Exp $
PostgreSQL documentation
PostgreSQL documentation
-->
-->
...
@@ -1492,6 +1492,18 @@ lo_import 152801
...
@@ -1492,6 +1492,18 @@ lo_import 152801
</listitem>
</listitem>
</varlistentry>
</varlistentry>
<varlistentry>
<term><literal>numericsep</literal></term>
<listitem>
<para>
Specifies the character separator between groups of three digits
to the left of the decimal marker. The default is <literal>''</>
(none). Setting this to a period also changes the decimal marker
to a comma.
</para>
</listitem>
</varlistentry>
<varlistentry>
<varlistentry>
<term><literal>recordsep</literal></term>
<term><literal>recordsep</literal></term>
<listitem>
<listitem>
...
...
src/bin/psql/command.c
View file @
73a7c322
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
*
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
*
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.14
6 2005/06/13 06:36:22 neilc
Exp $
* $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.14
7 2005/07/10 03:46:13 momjian
Exp $
*/
*/
#include "postgres_fe.h"
#include "postgres_fe.h"
#include "command.h"
#include "command.h"
...
@@ -838,7 +838,6 @@ exec_command(const char *cmd,
...
@@ -838,7 +838,6 @@ exec_command(const char *cmd,
else
if
(
strcmp
(
cmd
,
"x"
)
==
0
)
else
if
(
strcmp
(
cmd
,
"x"
)
==
0
)
success
=
do_pset
(
"expanded"
,
NULL
,
&
pset
.
popt
,
quiet
);
success
=
do_pset
(
"expanded"
,
NULL
,
&
pset
.
popt
,
quiet
);
/* \z -- list table rights (equivalent to \dp) */
/* \z -- list table rights (equivalent to \dp) */
else
if
(
strcmp
(
cmd
,
"z"
)
==
0
)
else
if
(
strcmp
(
cmd
,
"z"
)
==
0
)
{
{
...
@@ -1421,6 +1420,17 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
...
@@ -1421,6 +1420,17 @@ do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
:
_
(
"Expanded display is off.
\n
"
));
:
_
(
"Expanded display is off.
\n
"
));
}
}
else
if
(
strcmp
(
param
,
"numericsep"
)
==
0
)
{
if
(
value
)
{
free
(
popt
->
topt
.
numericSep
);
popt
->
topt
.
numericSep
=
pg_strdup
(
value
);
}
if
(
!
quiet
)
printf
(
_
(
"Numeric separator is
\"
%s
\"
.
\n
"
),
popt
->
topt
.
numericSep
);
}
/* null display */
/* null display */
else
if
(
strcmp
(
param
,
"null"
)
==
0
)
else
if
(
strcmp
(
param
,
"null"
)
==
0
)
{
{
...
...
src/bin/psql/help.c
View file @
73a7c322
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
*
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
*
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.10
3 2005/07/06 03:14:48
momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/help.c,v 1.10
4 2005/07/10 03:46:13
momjian Exp $
*/
*/
#include "postgres_fe.h"
#include "postgres_fe.h"
#include "common.h"
#include "common.h"
...
@@ -239,7 +239,7 @@ slashUsage(unsigned short int pager)
...
@@ -239,7 +239,7 @@ slashUsage(unsigned short int pager)
fprintf
(
output
,
_
(
"
\\
pset NAME [VALUE]
\n
"
fprintf
(
output
,
_
(
"
\\
pset NAME [VALUE]
\n
"
" set table output option
\n
"
" set table output option
\n
"
" (NAME := {format|border|expanded|fieldsep|footer|null|
\n
"
" (NAME := {format|border|expanded|fieldsep|footer|null|
\n
"
" recordsep|tuples_only|title|tableattr|pager})
\n
"
));
"
numericsep|
recordsep|tuples_only|title|tableattr|pager})
\n
"
));
fprintf
(
output
,
_
(
"
\\
t show only rows (currently %s)
\n
"
),
fprintf
(
output
,
_
(
"
\\
t show only rows (currently %s)
\n
"
),
ON
(
pset
.
popt
.
topt
.
tuples_only
));
ON
(
pset
.
popt
.
topt
.
tuples_only
));
fprintf
(
output
,
_
(
"
\\
T [STRING] set HTML <table> tag attributes, or unset if none
\n
"
));
fprintf
(
output
,
_
(
"
\\
T [STRING] set HTML <table> tag attributes, or unset if none
\n
"
));
...
...
src/bin/psql/print.c
View file @
73a7c322
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
*
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
*
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.6
0 2005/06/14 22:15:57
momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.6
1 2005/07/10 03:46:13
momjian Exp $
*/
*/
#include "postgres_fe.h"
#include "postgres_fe.h"
#include "common.h"
#include "common.h"
...
@@ -29,20 +29,107 @@
...
@@ -29,20 +29,107 @@
#include "mbprint.h"
#include "mbprint.h"
static
int
num_numericseps
(
const
char
*
my_str
)
{
int
old_len
,
dec_len
,
int_len
;
if
(
my_str
[
0
]
==
'-'
)
my_str
++
;
old_len
=
strlen
(
my_str
);
dec_len
=
strchr
(
my_str
,
'.'
)
?
strlen
(
strchr
(
my_str
,
'.'
))
:
0
;
int_len
=
old_len
-
dec_len
;
if
(
int_len
%
3
!=
0
)
return
int_len
/
3
;
else
return
int_len
/
3
-
1
;
/* no leading separator */
}
static
int
len_with_numericsep
(
const
char
*
my_str
)
{
return
strlen
(
my_str
)
+
num_numericseps
(
my_str
);
}
static
void
format_numericsep
(
char
*
my_str
,
char
*
numericsep
)
{
int
i
,
j
,
digits_before_sep
,
old_len
,
new_len
,
dec_len
,
int_len
;
char
*
dec_point
;
char
*
new_str
;
char
*
dec_value
;
if
(
strcmp
(
numericsep
,
"."
)
!=
0
)
dec_point
=
"."
;
else
dec_point
=
","
;
if
(
my_str
[
0
]
==
'-'
)
my_str
++
;
old_len
=
strlen
(
my_str
);
dec_len
=
strchr
(
my_str
,
'.'
)
?
strlen
(
strchr
(
my_str
,
'.'
))
:
0
;
int_len
=
old_len
-
dec_len
;
digits_before_sep
=
int_len
%
3
;
new_len
=
int_len
+
int_len
/
3
+
dec_len
;
if
(
digits_before_sep
==
0
)
new_len
--
;
/* no leading separator */
new_str
=
malloc
(
new_len
);
if
(
!
new_str
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
for
(
i
=
0
,
j
=
0
;
;
i
++
,
j
++
)
{
/* hit decimal point */
if
(
my_str
[
i
]
==
'.'
)
{
new_str
[
j
]
=
*
dec_point
;
new_str
[
j
+
1
]
=
'\0'
;
dec_value
=
strchr
(
my_str
,
'.'
);
strcat
(
new_str
,
++
dec_value
);
break
;
}
/* end of string */
if
(
my_str
[
i
]
==
'\0'
)
{
new_str
[
j
]
=
'\0'
;
break
;
}
/* add separator? */
if
(
i
!=
0
&&
(
i
-
(
digits_before_sep
?
digits_before_sep
:
3
))
%
3
==
0
)
new_str
[
j
++
]
=
*
numericsep
;
new_str
[
j
]
=
my_str
[
i
];
}
strcpy
(
my_str
,
new_str
);
free
(
new_str
);
}
/*************************/
/*************************/
/* Unaligned text */
/* Unaligned text */
/*************************/
/*************************/
static
void
static
void
print_unaligned_text
(
const
char
*
title
,
const
char
*
const
*
headers
,
print_unaligned_text
(
const
char
*
title
,
const
char
*
const
*
headers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
opt_fieldsep
,
const
char
*
opt_recordsep
,
bool
opt_barebones
,
const
char
*
opt_align
,
const
char
*
opt_fieldsep
,
FILE
*
fout
)
const
char
*
opt_recordsep
,
bool
opt_barebones
,
char
*
opt_numericsep
,
FILE
*
fout
)
{
{
unsigned
int
col_count
=
0
;
unsigned
int
col_count
=
0
;
unsigned
int
i
;
unsigned
int
i
;
const
char
*
const
*
ptr
;
const
char
*
const
*
ptr
;
bool
need_recordsep
=
false
;
bool
need_recordsep
=
false
;
if
(
!
opt_fieldsep
)
if
(
!
opt_fieldsep
)
...
@@ -77,7 +164,24 @@ print_unaligned_text(const char *title, const char *const * headers,
...
@@ -77,7 +164,24 @@ print_unaligned_text(const char *title, const char *const * headers,
fputs
(
opt_recordsep
,
fout
);
fputs
(
opt_recordsep
,
fout
);
need_recordsep
=
false
;
need_recordsep
=
false
;
}
}
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
>
0
&&
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
{
char
*
my_cell
=
malloc
(
len_with_numericsep
(
*
ptr
));
if
(
!
my_cell
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
strcpy
(
my_cell
,
*
ptr
);
format_numericsep
(
my_cell
,
opt_numericsep
);
fputs
(
my_cell
,
fout
);
free
(
my_cell
);
}
else
fputs
(
*
ptr
,
fout
);
fputs
(
*
ptr
,
fout
);
if
((
i
+
1
)
%
col_count
)
if
((
i
+
1
)
%
col_count
)
fputs
(
opt_fieldsep
,
fout
);
fputs
(
opt_fieldsep
,
fout
);
else
else
...
@@ -107,14 +211,15 @@ print_unaligned_text(const char *title, const char *const * headers,
...
@@ -107,14 +211,15 @@ print_unaligned_text(const char *title, const char *const * headers,
static
void
static
void
print_unaligned_vertical
(
const
char
*
title
,
const
char
*
const
*
headers
,
print_unaligned_vertical
(
const
char
*
title
,
const
char
*
const
*
headers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
const
*
cells
,
const
char
*
opt_fieldsep
,
const
char
*
opt_recordsep
,
bool
opt_barebones
,
const
char
*
const
*
footers
,
const
char
*
opt_align
,
FILE
*
fout
)
const
char
*
opt_fieldsep
,
const
char
*
opt_recordsep
,
bool
opt_barebones
,
char
*
opt_numericsep
,
FILE
*
fout
)
{
{
unsigned
int
col_count
=
0
;
unsigned
int
col_count
=
0
;
unsigned
int
i
;
unsigned
int
i
;
const
char
*
const
*
ptr
;
const
char
*
const
*
ptr
;
if
(
!
opt_fieldsep
)
if
(
!
opt_fieldsep
)
opt_fieldsep
=
""
;
opt_fieldsep
=
""
;
...
@@ -141,6 +246,22 @@ print_unaligned_vertical(const char *title, const char *const * headers,
...
@@ -141,6 +246,22 @@ print_unaligned_vertical(const char *title, const char *const * headers,
fputs
(
headers
[
i
%
col_count
],
fout
);
fputs
(
headers
[
i
%
col_count
],
fout
);
fputs
(
opt_fieldsep
,
fout
);
fputs
(
opt_fieldsep
,
fout
);
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
!=
0
&&
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
{
char
*
my_cell
=
malloc
(
len_with_numericsep
(
*
ptr
));
if
(
!
my_cell
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
strcpy
(
my_cell
,
*
ptr
);
format_numericsep
(
my_cell
,
opt_numericsep
);
fputs
(
my_cell
,
fout
);
free
(
my_cell
);
}
else
fputs
(
*
ptr
,
fout
);
fputs
(
*
ptr
,
fout
);
}
}
...
@@ -202,9 +323,9 @@ _print_horizontal_line(const unsigned int col_count, const unsigned int *widths,
...
@@ -202,9 +323,9 @@ _print_horizontal_line(const unsigned int col_count, const unsigned int *widths,
static
void
static
void
print_aligned_text
(
const
char
*
title
,
const
char
*
const
*
headers
,
print_aligned_text
(
const
char
*
title
,
const
char
*
const
*
headers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
opt_align
,
bool
opt_barebones
,
const
char
*
opt_align
,
bool
opt_barebones
,
char
*
opt_numericsep
,
unsigned
short
int
opt_border
,
int
encoding
,
unsigned
short
int
opt_border
,
int
encoding
,
FILE
*
fout
)
FILE
*
fout
)
{
{
...
@@ -216,7 +337,7 @@ print_aligned_text(const char *title, const char *const * headers,
...
@@ -216,7 +337,7 @@ print_aligned_text(const char *title, const char *const * headers,
tmp
;
tmp
;
unsigned
int
*
widths
,
unsigned
int
*
widths
,
total_w
;
total_w
;
const
char
*
const
*
ptr
;
const
char
*
const
*
ptr
;
/* count columns */
/* count columns */
for
(
ptr
=
headers
;
*
ptr
;
ptr
++
)
for
(
ptr
=
headers
;
*
ptr
;
ptr
++
)
...
@@ -271,7 +392,15 @@ print_aligned_text(const char *title, const char *const * headers,
...
@@ -271,7 +392,15 @@ print_aligned_text(const char *title, const char *const * headers,
for
(
i
=
0
,
ptr
=
cells
;
*
ptr
;
ptr
++
,
i
++
)
for
(
i
=
0
,
ptr
=
cells
;
*
ptr
;
ptr
++
,
i
++
)
{
{
tmp
=
pg_wcswidth
((
unsigned
char
*
)
*
ptr
,
strlen
(
*
ptr
),
encoding
);
int
numericseps
;
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
!=
0
&&
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
numericseps
=
num_numericseps
(
*
ptr
);
else
numericseps
=
0
;
tmp
=
pg_wcswidth
((
unsigned
char
*
)
*
ptr
,
strlen
(
*
ptr
),
encoding
)
+
numericseps
;
if
(
tmp
>
widths
[
i
%
col_count
])
if
(
tmp
>
widths
[
i
%
col_count
])
widths
[
i
%
col_count
]
=
tmp
;
widths
[
i
%
col_count
]
=
tmp
;
cell_w
[
i
]
=
tmp
;
cell_w
[
i
]
=
tmp
;
...
@@ -351,8 +480,22 @@ print_aligned_text(const char *title, const char *const * headers,
...
@@ -351,8 +480,22 @@ 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'
)
{
{
fprintf
(
fout
,
"%*s%s"
,
if
(
strlen
(
*
ptr
)
>
0
&&
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
widths
[
i
%
col_count
]
-
cell_w
[
i
],
""
,
cells
[
i
]);
{
char
*
my_cell
=
malloc
(
cell_w
[
i
]);
if
(
!
my_cell
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
strcpy
(
my_cell
,
*
ptr
);
format_numericsep
(
my_cell
,
opt_numericsep
);
fprintf
(
fout
,
"%*s%s"
,
widths
[
i
%
col_count
]
-
cell_w
[
i
],
""
,
my_cell
);
free
(
my_cell
);
}
else
fprintf
(
fout
,
"%*s%s"
,
widths
[
i
%
col_count
]
-
cell_w
[
i
],
""
,
*
ptr
);
}
}
else
else
{
{
...
@@ -406,14 +549,15 @@ print_aligned_text(const char *title, const char *const * headers,
...
@@ -406,14 +549,15 @@ print_aligned_text(const char *title, const char *const * headers,
static
void
static
void
print_aligned_vertical
(
const
char
*
title
,
const
char
*
const
*
headers
,
print_aligned_vertical
(
const
char
*
title
,
const
char
*
const
*
headers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
bool
opt_barebones
,
unsigned
short
int
opt_border
,
const
char
*
opt_align
,
bool
opt_barebones
,
char
*
opt_numericsep
,
unsigned
short
int
opt_border
,
int
encoding
,
FILE
*
fout
)
int
encoding
,
FILE
*
fout
)
{
{
unsigned
int
col_count
=
0
;
unsigned
int
col_count
=
0
;
unsigned
int
record
=
1
;
unsigned
int
record
=
1
;
const
char
*
const
*
ptr
;
const
char
*
const
*
ptr
;
unsigned
int
i
,
unsigned
int
i
,
tmp
=
0
,
tmp
=
0
,
hwidth
=
0
,
hwidth
=
0
,
...
@@ -471,7 +615,15 @@ print_aligned_vertical(const char *title, const char *const * headers,
...
@@ -471,7 +615,15 @@ print_aligned_vertical(const char *title, const char *const * headers,
/* find longest data cell */
/* find longest data cell */
for
(
i
=
0
,
ptr
=
cells
;
*
ptr
;
ptr
++
,
i
++
)
for
(
i
=
0
,
ptr
=
cells
;
*
ptr
;
ptr
++
,
i
++
)
{
{
tmp
=
pg_wcswidth
((
unsigned
char
*
)
*
ptr
,
strlen
(
*
ptr
),
encoding
);
int
numericseps
;
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
!=
0
&&
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
numericseps
=
num_numericseps
(
*
ptr
);
else
numericseps
=
0
;
tmp
=
pg_wcswidth
((
unsigned
char
*
)
*
ptr
,
strlen
(
*
ptr
),
encoding
)
+
numericseps
;
if
(
tmp
>
dwidth
)
if
(
tmp
>
dwidth
)
dwidth
=
tmp
;
dwidth
=
tmp
;
cell_w
[
i
]
=
tmp
;
cell_w
[
i
]
=
tmp
;
...
@@ -556,10 +708,24 @@ print_aligned_vertical(const char *title, const char *const * headers,
...
@@ -556,10 +708,24 @@ print_aligned_vertical(const char *title, const char *const * headers,
else
else
fputs
(
" "
,
fout
);
fputs
(
" "
,
fout
);
{
char
*
my_cell
=
malloc
(
cell_w
[
i
]);
if
(
!
my_cell
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
strcpy
(
my_cell
,
*
ptr
);
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
!=
0
&&
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
format_numericsep
(
my_cell
,
opt_numericsep
);
if
(
opt_border
<
2
)
if
(
opt_border
<
2
)
fprintf
(
fout
,
"%s
\n
"
,
*
ptr
);
puts
(
my_cell
);
else
else
fprintf
(
fout
,
"%-s%*s |
\n
"
,
*
ptr
,
dwidth
-
cell_w
[
i
],
""
);
fprintf
(
fout
,
"%-s%*s |
\n
"
,
my_cell
,
dwidth
-
cell_w
[
i
],
""
);
free
(
my_cell
);
}
}
}
if
(
opt_border
==
2
)
if
(
opt_border
==
2
)
...
@@ -637,15 +803,15 @@ html_escaped_print(const char *in, FILE *fout)
...
@@ -637,15 +803,15 @@ html_escaped_print(const char *in, FILE *fout)
static
void
static
void
print_html_text
(
const
char
*
title
,
const
char
*
const
*
headers
,
print_html_text
(
const
char
*
title
,
const
char
*
const
*
headers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
opt_align
,
bool
opt_barebones
,
unsigned
short
int
opt_border
,
const
char
*
opt_align
,
bool
opt_barebones
,
c
onst
char
*
opt_table_att
r
,
c
har
*
opt_numericsep
,
unsigned
short
int
opt_borde
r
,
FILE
*
fout
)
const
char
*
opt_table_attr
,
FILE
*
fout
)
{
{
unsigned
int
col_count
=
0
;
unsigned
int
col_count
=
0
;
unsigned
int
i
;
unsigned
int
i
;
const
char
*
const
*
ptr
;
const
char
*
const
*
ptr
;
fprintf
(
fout
,
"<table border=
\"
%d
\"
"
,
opt_border
);
fprintf
(
fout
,
"<table border=
\"
%d
\"
"
,
opt_border
);
if
(
opt_table_attr
)
if
(
opt_table_attr
)
...
@@ -683,11 +849,27 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
...
@@ -683,11 +849,27 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
fputs
(
" <tr valign=
\"
top
\"
>
\n
"
,
fout
);
fputs
(
" <tr valign=
\"
top
\"
>
\n
"
,
fout
);
fprintf
(
fout
,
" <td align=
\"
%s
\"
>"
,
opt_align
[(
i
)
%
col_count
]
==
'r'
?
"right"
:
"left"
);
fprintf
(
fout
,
" <td align=
\"
%s
\"
>"
,
opt_align
[(
i
)
%
col_count
]
==
'r'
?
"right"
:
"left"
);
if
((
*
ptr
)[
strspn
(
*
ptr
,
"
\t
"
)]
==
'\0'
)
/* is string only
/* is string only whitespace? */
* whitespace? */
if
((
*
ptr
)[
strspn
(
*
ptr
,
"
\t
"
)]
==
'\0'
)
fputs
(
" "
,
fout
);
fputs
(
" "
,
fout
);
else
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
!=
0
&&
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
{
char
*
my_cell
=
malloc
(
len_with_numericsep
(
*
ptr
));
if
(
!
my_cell
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
strcpy
(
my_cell
,
*
ptr
);
format_numericsep
(
my_cell
,
opt_numericsep
);
html_escaped_print
(
my_cell
,
fout
);
free
(
my_cell
);
}
else
else
html_escaped_print
(
*
ptr
,
fout
);
html_escaped_print
(
*
ptr
,
fout
);
fputs
(
"</td>
\n
"
,
fout
);
fputs
(
"</td>
\n
"
,
fout
);
if
((
i
+
1
)
%
col_count
==
0
)
if
((
i
+
1
)
%
col_count
==
0
)
...
@@ -714,16 +896,16 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
...
@@ -714,16 +896,16 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
static
void
static
void
print_html_vertical
(
const
char
*
title
,
const
char
*
const
*
headers
,
print_html_vertical
(
const
char
*
title
,
const
char
*
const
*
headers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
opt_align
,
bool
opt_barebones
,
unsigned
short
int
opt_border
,
const
char
*
opt_align
,
bool
opt_barebones
,
const
char
*
opt_table_att
r
,
char
*
opt_numericsep
,
unsigned
short
int
opt_borde
r
,
FILE
*
fout
)
const
char
*
opt_table_attr
,
FILE
*
fout
)
{
{
unsigned
int
col_count
=
0
;
unsigned
int
col_count
=
0
;
unsigned
int
i
;
unsigned
int
i
;
unsigned
int
record
=
1
;
unsigned
int
record
=
1
;
const
char
*
const
*
ptr
;
const
char
*
const
*
ptr
;
fprintf
(
fout
,
"<table border=
\"
%d
\"
"
,
opt_border
);
fprintf
(
fout
,
"<table border=
\"
%d
\"
"
,
opt_border
);
if
(
opt_table_attr
)
if
(
opt_table_attr
)
...
@@ -758,11 +940,27 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
...
@@ -758,11 +940,27 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
fputs
(
"</th>
\n
"
,
fout
);
fputs
(
"</th>
\n
"
,
fout
);
fprintf
(
fout
,
" <td align=
\"
%s
\"
>"
,
opt_align
[
i
%
col_count
]
==
'r'
?
"right"
:
"left"
);
fprintf
(
fout
,
" <td align=
\"
%s
\"
>"
,
opt_align
[
i
%
col_count
]
==
'r'
?
"right"
:
"left"
);
if
((
*
ptr
)[
strspn
(
*
ptr
,
"
\t
"
)]
==
'\0'
)
/* is string only
/* is string only whitespace? */
* whitespace? */
if
((
*
ptr
)[
strspn
(
*
ptr
,
"
\t
"
)]
==
'\0'
)
fputs
(
" "
,
fout
);
fputs
(
" "
,
fout
);
else
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
!=
0
&&
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
{
char
*
my_cell
=
malloc
(
len_with_numericsep
(
*
ptr
));
if
(
!
my_cell
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
strcpy
(
my_cell
,
*
ptr
);
format_numericsep
(
my_cell
,
opt_numericsep
);
html_escaped_print
(
my_cell
,
fout
);
free
(
my_cell
);
}
else
else
html_escaped_print
(
*
ptr
,
fout
);
html_escaped_print
(
*
ptr
,
fout
);
fputs
(
"</td>
\n
</tr>
\n
"
,
fout
);
fputs
(
"</td>
\n
</tr>
\n
"
,
fout
);
}
}
...
@@ -829,14 +1027,14 @@ latex_escaped_print(const char *in, FILE *fout)
...
@@ -829,14 +1027,14 @@ latex_escaped_print(const char *in, FILE *fout)
static
void
static
void
print_latex_text
(
const
char
*
title
,
const
char
*
const
*
headers
,
print_latex_text
(
const
char
*
title
,
const
char
*
const
*
headers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
opt_align
,
bool
opt_barebones
,
unsigned
short
int
opt_border
,
const
char
*
opt_align
,
bool
opt_barebones
,
FILE
*
fout
)
unsigned
short
int
opt_border
,
FILE
*
fout
)
{
{
unsigned
int
col_count
=
0
;
unsigned
int
col_count
=
0
;
unsigned
int
i
;
unsigned
int
i
;
const
char
*
const
*
ptr
;
const
char
*
const
*
ptr
;
/* print title */
/* print title */
...
@@ -921,14 +1119,14 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
...
@@ -921,14 +1119,14 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
static
void
static
void
print_latex_vertical
(
const
char
*
title
,
const
char
*
const
*
headers
,
print_latex_vertical
(
const
char
*
title
,
const
char
*
const
*
headers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
opt_align
,
bool
opt_barebones
,
unsigned
short
int
opt_border
,
const
char
*
opt_align
,
bool
opt_barebones
,
FILE
*
fout
)
unsigned
short
int
opt_border
,
FILE
*
fout
)
{
{
unsigned
int
col_count
=
0
;
unsigned
int
col_count
=
0
;
unsigned
int
i
;
unsigned
int
i
;
const
char
*
const
*
ptr
;
const
char
*
const
*
ptr
;
unsigned
int
record
=
1
;
unsigned
int
record
=
1
;
(
void
)
opt_align
;
/* currently unused parameter */
(
void
)
opt_align
;
/* currently unused parameter */
...
@@ -1027,14 +1225,14 @@ troff_ms_escaped_print(const char *in, FILE *fout)
...
@@ -1027,14 +1225,14 @@ troff_ms_escaped_print(const char *in, FILE *fout)
static
void
static
void
print_troff_ms_text
(
const
char
*
title
,
const
char
*
const
*
headers
,
print_troff_ms_text
(
const
char
*
title
,
const
char
*
const
*
headers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
opt_align
,
bool
opt_barebones
,
unsigned
short
int
opt_border
,
const
char
*
opt_align
,
bool
opt_barebones
,
FILE
*
fout
)
unsigned
short
int
opt_border
,
FILE
*
fout
)
{
{
unsigned
int
col_count
=
0
;
unsigned
int
col_count
=
0
;
unsigned
int
i
;
unsigned
int
i
;
const
char
*
const
*
ptr
;
const
char
*
const
*
ptr
;
/* print title */
/* print title */
...
@@ -1111,14 +1309,14 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
...
@@ -1111,14 +1309,14 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
static
void
static
void
print_troff_ms_vertical
(
const
char
*
title
,
const
char
*
const
*
headers
,
print_troff_ms_vertical
(
const
char
*
title
,
const
char
*
const
*
headers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
opt_align
,
bool
opt_barebones
,
unsigned
short
int
opt_border
,
const
char
*
opt_align
,
bool
opt_barebones
,
FILE
*
fout
)
unsigned
short
int
opt_border
,
FILE
*
fout
)
{
{
unsigned
int
col_count
=
0
;
unsigned
int
col_count
=
0
;
unsigned
int
i
;
unsigned
int
i
;
const
char
*
const
*
ptr
;
const
char
*
const
*
ptr
;
unsigned
int
record
=
1
;
unsigned
int
record
=
1
;
unsigned
short
current_format
=
0
;
/* 0=none, 1=header, 2=body */
unsigned
short
current_format
=
0
;
/* 0=none, 1=header, 2=body */
...
@@ -1263,9 +1461,9 @@ PageOutput(int lines, unsigned short int pager)
...
@@ -1263,9 +1461,9 @@ PageOutput(int lines, unsigned short int pager)
void
void
printTable
(
const
char
*
title
,
printTable
(
const
char
*
title
,
const
char
*
const
*
headers
,
const
char
*
const
*
headers
,
const
char
*
const
*
cells
,
const
char
*
const
*
cells
,
const
char
*
const
*
footers
,
const
char
*
const
*
footers
,
const
char
*
align
,
const
char
*
align
,
const
printTableOpt
*
opt
,
FILE
*
fout
,
FILE
*
flog
)
const
printTableOpt
*
opt
,
FILE
*
fout
,
FILE
*
flog
)
{
{
...
@@ -1298,7 +1496,7 @@ printTable(const char *title,
...
@@ -1298,7 +1496,7 @@ printTable(const char *title,
int
col_count
=
0
,
int
col_count
=
0
,
row_count
=
0
,
row_count
=
0
,
lines
;
lines
;
const
char
*
const
*
ptr
;
const
char
*
const
*
ptr
;
/* rough estimate of columns and rows */
/* rough estimate of columns and rows */
if
(
headers
)
if
(
headers
)
...
@@ -1325,38 +1523,38 @@ printTable(const char *title,
...
@@ -1325,38 +1523,38 @@ printTable(const char *title,
/* print the stuff */
/* print the stuff */
if
(
flog
)
if
(
flog
)
print_aligned_text
(
title
,
headers
,
cells
,
footers
,
align
,
opt
->
tuples_only
,
border
,
opt
->
encoding
,
flog
);
print_aligned_text
(
title
,
headers
,
cells
,
footers
,
align
,
opt
->
tuples_only
,
opt
->
numericSep
,
border
,
opt
->
encoding
,
flog
);
switch
(
opt
->
format
)
switch
(
opt
->
format
)
{
{
case
PRINT_UNALIGNED
:
case
PRINT_UNALIGNED
:
if
(
use_expanded
)
if
(
use_expanded
)
print_unaligned_vertical
(
title
,
headers
,
cells
,
footers
,
print_unaligned_vertical
(
title
,
headers
,
cells
,
footers
,
align
,
opt
->
fieldSep
,
opt
->
recordSep
,
opt
->
fieldSep
,
opt
->
recordSep
,
opt
->
tuples_only
,
output
);
opt
->
tuples_only
,
o
pt
->
numericSep
,
o
utput
);
else
else
print_unaligned_text
(
title
,
headers
,
cells
,
footers
,
print_unaligned_text
(
title
,
headers
,
cells
,
footers
,
align
,
opt
->
fieldSep
,
opt
->
recordSep
,
opt
->
fieldSep
,
opt
->
recordSep
,
opt
->
tuples_only
,
output
);
opt
->
tuples_only
,
o
pt
->
numericSep
,
o
utput
);
break
;
break
;
case
PRINT_ALIGNED
:
case
PRINT_ALIGNED
:
if
(
use_expanded
)
if
(
use_expanded
)
print_aligned_vertical
(
title
,
headers
,
cells
,
footers
,
print_aligned_vertical
(
title
,
headers
,
cells
,
footers
,
align
,
opt
->
tuples_only
,
border
,
opt
->
tuples_only
,
opt
->
numericSep
,
border
,
opt
->
encoding
,
output
);
opt
->
encoding
,
output
);
else
else
print_aligned_text
(
title
,
headers
,
cells
,
footers
,
print_aligned_text
(
title
,
headers
,
cells
,
footers
,
align
,
align
,
opt
->
tuples_only
,
opt
->
tuples_only
,
opt
->
numericSep
,
border
,
opt
->
encoding
,
output
);
border
,
opt
->
encoding
,
output
);
break
;
break
;
case
PRINT_HTML
:
case
PRINT_HTML
:
if
(
use_expanded
)
if
(
use_expanded
)
print_html_vertical
(
title
,
headers
,
cells
,
footers
,
print_html_vertical
(
title
,
headers
,
cells
,
footers
,
align
,
align
,
opt
->
tuples_only
,
opt
->
tuples_only
,
opt
->
numericSep
,
border
,
opt
->
tableAttr
,
output
);
border
,
opt
->
tableAttr
,
output
);
else
else
print_html_text
(
title
,
headers
,
cells
,
footers
,
print_html_text
(
title
,
headers
,
cells
,
footers
,
align
,
opt
->
tuples_only
,
border
,
align
,
opt
->
tuples_only
,
opt
->
numericSep
,
border
,
opt
->
tableAttr
,
output
);
opt
->
tableAttr
,
output
);
break
;
break
;
case
PRINT_LATEX
:
case
PRINT_LATEX
:
...
...
src/bin/psql/print.h
View file @
73a7c322
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
*
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
*
* $PostgreSQL: pgsql/src/bin/psql/print.h,v 1.2
5 2005/06/14 02:57:41
momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/print.h,v 1.2
6 2005/07/10 03:46:13
momjian Exp $
*/
*/
#ifndef PRINT_H
#ifndef PRINT_H
#define PRINT_H
#define PRINT_H
...
@@ -40,6 +40,7 @@ typedef struct _printTableOpt
...
@@ -40,6 +40,7 @@ typedef struct _printTableOpt
char
*
fieldSep
;
/* field separator for unaligned text mode */
char
*
fieldSep
;
/* field separator for unaligned text mode */
char
*
recordSep
;
/* record separator for unaligned text
char
*
recordSep
;
/* record separator for unaligned text
* mode */
* mode */
char
*
numericSep
;
/* numeric units separator */
char
*
tableAttr
;
/* attributes for HTML <table ...> */
char
*
tableAttr
;
/* attributes for HTML <table ...> */
int
encoding
;
/* character encoding */
int
encoding
;
/* character encoding */
bool
normal_query
;
/* are we presenting the results of a
bool
normal_query
;
/* are we presenting the results of a
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment