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
641b658c
Commit
641b658c
authored
Oct 23, 2002
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Page \h output and centralize psql paging code in PageOutput().
parent
30963fc2
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
86 additions
and
99 deletions
+86
-99
src/bin/psql/command.c
src/bin/psql/command.c
+3
-2
src/bin/psql/common.c
src/bin/psql/common.c
+44
-1
src/bin/psql/common.h
src/bin/psql/common.h
+3
-1
src/bin/psql/help.c
src/bin/psql/help.c
+23
-49
src/bin/psql/help.h
src/bin/psql/help.h
+2
-2
src/bin/psql/print.c
src/bin/psql/print.c
+11
-44
No files found.
src/bin/psql/command.c
View file @
641b658c
...
...
@@ -3,7 +3,7 @@
*
* Copyright 2000-2002 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.8
3 2002/10/15 02:24:15 tgl
Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.8
4 2002/10/23 19:23:56 momjian
Exp $
*/
#include "postgres_fe.h"
#include "command.h"
...
...
@@ -493,7 +493,8 @@ exec_command(const char *cmd,
/* help */
else
if
(
strcmp
(
cmd
,
"h"
)
==
0
||
strcmp
(
cmd
,
"help"
)
==
0
)
{
helpSQL
(
options_string
?
&
options_string
[
strspn
(
options_string
,
"
\t\n\r
"
)]
:
NULL
);
helpSQL
(
options_string
?
&
options_string
[
strspn
(
options_string
,
"
\t\n\r
"
)]
:
NULL
,
pset
.
popt
.
topt
.
pager
);
/* set pointer to end of line */
if
(
string
)
string
+=
strlen
(
string
);
...
...
src/bin/psql/common.c
View file @
641b658c
...
...
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.4
8 2002/10/15 16:44:21 tgl
Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.4
9 2002/10/23 19:23:56 momjian
Exp $
*/
#include "postgres_fe.h"
...
...
@@ -515,3 +515,46 @@ SendQuery(const char *query)
return
success
;
}
/*
* PageOutput
*
* Tests if pager is needed and returns appropriate FILE pointer.
*/
FILE
*
PageOutput
(
int
lines
,
bool
pager
)
{
/* check whether we need / can / are supposed to use pager */
if
(
pager
#ifndef WIN32
&&
isatty
(
fileno
(
stdin
))
&&
isatty
(
fileno
(
stdout
))
#endif
)
{
const
char
*
pagerprog
;
#ifdef TIOCGWINSZ
int
result
;
struct
winsize
screen_size
;
result
=
ioctl
(
fileno
(
stdout
),
TIOCGWINSZ
,
&
screen_size
);
if
(
result
==
-
1
||
lines
>
screen_size
.
ws_row
)
{
#endif
pagerprog
=
getenv
(
"PAGER"
);
if
(
!
pagerprog
)
pagerprog
=
DEFAULT_PAGER
;
#ifndef WIN32
pqsignal
(
SIGPIPE
,
SIG_IGN
);
#endif
return
popen
(
pagerprog
,
"w"
);
#ifdef TIOCGWINSZ
}
#endif
}
return
stdout
;
}
src/bin/psql/common.h
View file @
641b658c
...
...
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.
19 2002/10/15 02:24:16 tgl
Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.
20 2002/10/23 19:23:56 momjian
Exp $
*/
#ifndef COMMON_H
#define COMMON_H
...
...
@@ -37,6 +37,8 @@ extern PGresult *PSQLexec(const char *query, bool ignore_command_ok);
extern
bool
SendQuery
(
const
char
*
query
);
extern
FILE
*
PageOutput
(
int
lines
,
bool
pager
);
/* sprompt.h */
extern
char
*
simple_prompt
(
const
char
*
prompt
,
int
maxlen
,
bool
echo
);
...
...
src/bin/psql/help.c
View file @
641b658c
...
...
@@ -3,9 +3,10 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.5
8 2002/10/18 22:05:36 petere
Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.5
9 2002/10/23 19:23:56 momjian
Exp $
*/
#include "postgres_fe.h"
#include "common.h"
#include "print.h"
#include "help.h"
...
...
@@ -161,48 +162,11 @@ struct winsize
void
slashUsage
(
bool
pager
)
{
FILE
*
output
,
*
pagerfd
=
NULL
;
/* check whether we need / can / are supposed to use pager */
if
(
pager
#ifndef WIN32
&&
isatty
(
fileno
(
stdin
))
&&
isatty
(
fileno
(
stdout
))
#endif
)
{
const
char
*
pagerprog
;
FILE
*
output
;
#ifdef TIOCGWINSZ
int
result
;
struct
winsize
screen_size
;
output
=
PageOutput
(
50
,
pager
);
result
=
ioctl
(
fileno
(
stdout
),
TIOCGWINSZ
,
&
screen_size
);
if
(
result
==
-
1
||
50
>
screen_size
.
ws_row
)
{
#endif
pagerprog
=
getenv
(
"PAGER"
);
if
(
!
pagerprog
)
pagerprog
=
DEFAULT_PAGER
;
pagerfd
=
popen
(
pagerprog
,
"w"
);
#ifdef TIOCGWINSZ
}
#endif
}
if
(
pagerfd
)
{
output
=
pagerfd
;
#ifndef WIN32
pqsignal
(
SIGPIPE
,
SIG_IGN
);
#endif
}
else
output
=
stdout
;
/* if you add/remove a line here, change the row test above */
/* if you add/remove a line here, change the row count above */
/*
* if this " is the start of the string then it ought to end there to
...
...
@@ -262,9 +226,9 @@ slashUsage(bool pager)
fprintf
(
output
,
_
(
"
\\
z [PATTERN] list table access privileges (same as
\\
dp)
\n
"
));
fprintf
(
output
,
_
(
"
\\
! [COMMAND] execute command in shell or start interactive shell
\n
"
));
if
(
pagerfd
)
if
(
output
!=
stdout
)
{
pclose
(
pagerfd
);
pclose
(
output
);
#ifndef WIN32
pqsignal
(
SIGPIPE
,
SIG_DFL
);
#endif
...
...
@@ -278,7 +242,7 @@ slashUsage(bool pager)
*
*/
void
helpSQL
(
const
char
*
topic
)
helpSQL
(
const
char
*
topic
,
bool
pager
)
{
#define VALUE_OR_NULL(a) ((a) ? (a) : "")
...
...
@@ -286,21 +250,31 @@ helpSQL(const char *topic)
{
int
i
;
int
items_per_column
=
(
QL_HELP_COUNT
+
2
)
/
3
;
FILE
*
output
;
output
=
PageOutput
(
items_per_column
,
pager
);
puts
(
_
(
"Available help:"
)
);
fputs
(
_
(
"Available help:
\n
"
),
output
);
for
(
i
=
0
;
i
<
items_per_column
;
i
++
)
{
printf
(
" %-26s%-26s"
,
fprintf
(
output
,
" %-26s%-26s"
,
VALUE_OR_NULL
(
QL_HELP
[
i
].
cmd
),
VALUE_OR_NULL
(
QL_HELP
[
i
+
items_per_column
].
cmd
));
if
(
i
+
2
*
items_per_column
<
QL_HELP_COUNT
)
printf
(
"%-26s"
,
fprintf
(
output
,
"%-26s"
,
VALUE_OR_NULL
(
QL_HELP
[
i
+
2
*
items_per_column
].
cmd
));
fputc
(
'\n'
,
stdout
);
fputc
(
'\n'
,
output
);
}
/* Only close if we used the pager */
if
(
output
!=
stdout
)
{
pclose
(
output
);
#ifndef WIN32
pqsignal
(
SIGPIPE
,
SIG_DFL
);
#endif
}
}
else
{
int
i
;
...
...
src/bin/psql/help.h
View file @
641b658c
...
...
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/help.h,v 1.
9 2002/07/15 01:56:25
momjian Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/help.h,v 1.
10 2002/10/23 19:23:57
momjian Exp $
*/
#ifndef HELP_H
#define HELP_H
...
...
@@ -12,7 +12,7 @@ void usage(void);
void
slashUsage
(
bool
pager
);
void
helpSQL
(
const
char
*
topic
);
void
helpSQL
(
const
char
*
topic
,
bool
pager
);
void
print_copyright
(
void
);
...
...
src/bin/psql/print.c
View file @
641b658c
...
...
@@ -3,9 +3,10 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.3
2 2002/10/03 17:09:42
momjian Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.3
3 2002/10/23 19:23:57
momjian Exp $
*/
#include "postgres_fe.h"
#include "common.h"
#include "print.h"
#include <math.h>
...
...
@@ -970,9 +971,7 @@ printTable(const char *title,
{
const
char
*
default_footer
[]
=
{
NULL
};
unsigned
short
int
border
=
opt
->
border
;
FILE
*
pagerfd
=
NULL
,
*
output
;
FILE
*
output
;
if
(
opt
->
format
==
PRINT_NOTHING
)
return
;
...
...
@@ -983,25 +982,12 @@ printTable(const char *title,
if
(
opt
->
format
!=
PRINT_HTML
&&
border
>
2
)
border
=
2
;
/* check whether we need / can / are supposed to use pager */
if
(
fout
==
stdout
&&
opt
->
pager
#ifndef WIN32
&&
isatty
(
fileno
(
stdin
))
&&
isatty
(
fileno
(
stdout
))
#endif
)
if
(
fout
==
stdout
)
{
const
char
*
pagerprog
;
#ifdef TIOCGWINSZ
unsigned
int
col_count
=
0
,
row_count
=
0
,
lines
;
int
col_count
=
0
,
row_count
=
0
,
lines
;
const
char
*
const
*
ptr
;
int
result
;
struct
winsize
screen_size
;
/* rough estimate of columns and rows */
if
(
headers
)
...
...
@@ -1020,31 +1006,11 @@ printTable(const char *title,
if
(
footers
&&
!
opt
->
tuples_only
)
for
(
ptr
=
footers
;
*
ptr
;
ptr
++
)
lines
++
;
result
=
ioctl
(
fileno
(
stdout
),
TIOCGWINSZ
,
&
screen_size
);
if
(
result
==
-
1
||
lines
>
screen_size
.
ws_row
)
{
#endif
pagerprog
=
getenv
(
"PAGER"
);
if
(
!
pagerprog
)
pagerprog
=
DEFAULT_PAGER
;
pagerfd
=
popen
(
pagerprog
,
"w"
);
#ifdef TIOCGWINSZ
}
#endif
}
if
(
pagerfd
)
{
output
=
pagerfd
;
#ifndef WIN32
pqsignal
(
SIGPIPE
,
SIG_IGN
);
#endif
output
=
PageOutput
(
lines
,
opt
->
pager
);
}
else
output
=
fout
;
/* print the stuff */
switch
(
opt
->
format
)
...
...
@@ -1077,9 +1043,10 @@ printTable(const char *title,
fprintf
(
stderr
,
"+ Oops, you shouldn't see this!
\n
"
);
}
if
(
pagerfd
)
/* Only close if we used the pager */
if
(
fout
==
stdout
&&
output
!=
stdout
)
{
pclose
(
pagerfd
);
pclose
(
output
);
#ifndef WIN32
pqsignal
(
SIGPIPE
,
SIG_DFL
);
#endif
...
...
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