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
7015111a
Commit
7015111a
authored
Jul 06, 2002
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move simple_prompt() into its own file to be shared with psql and pg_dump.
parent
d66f172f
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
258 additions
and
230 deletions
+258
-230
src/bin/pg_dump/Makefile
src/bin/pg_dump/Makefile
+3
-3
src/bin/pg_dump/pg_backup_db.c
src/bin/pg_dump/pg_backup_db.c
+1
-109
src/bin/pg_dump/pg_dump.h
src/bin/pg_dump/pg_dump.h
+4
-1
src/bin/pg_dump/sprompt.c
src/bin/pg_dump/sprompt.c
+121
-0
src/bin/psql/Makefile
src/bin/psql/Makefile
+2
-2
src/bin/psql/common.c
src/bin/psql/common.c
+2
-114
src/bin/psql/common.h
src/bin/psql/common.h
+4
-1
src/bin/psql/sprompt.c
src/bin/psql/sprompt.c
+121
-0
No files found.
src/bin/pg_dump/Makefile
View file @
7015111a
...
...
@@ -5,7 +5,7 @@
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
#
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.3
3 2002/06/20 20:29:41
momjian Exp $
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.3
4 2002/07/06 20:12:30
momjian Exp $
#
#-------------------------------------------------------------------------
...
...
@@ -13,8 +13,8 @@ subdir = src/bin/pg_dump
top_builddir
=
../../..
include
$(top_builddir)/src/Makefile.global
OBJS
=
pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o
pg_backup_files.o
\
pg_backup_null.o pg_backup_tar
.o
OBJS
=
pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o
\
pg_backup_files.o pg_backup_null.o pg_backup_tar.o sprompt
.o
ifdef
STRDUP
OBJS
+=
$(top_builddir)
/src/utils/strdup.o
...
...
src/bin/pg_dump/pg_backup_db.c
View file @
7015111a
...
...
@@ -5,7 +5,7 @@
* Implements the basic DB functions used by the archiver.
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.3
4 2002/07/04 15:35:07
momjian Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.3
5 2002/07/06 20:12:30
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -37,114 +37,6 @@ static char *_sendSQLLine(ArchiveHandle *AH, char *qry, char *eos);
static
char
*
_sendCopyLine
(
ArchiveHandle
*
AH
,
char
*
qry
,
char
*
eos
);
/*
* simple_prompt --- borrowed from psql
*
* Generalized function especially intended for reading in usernames and
* password interactively. Reads from /dev/tty or stdin/stderr.
*
* prompt: The prompt to print
* maxlen: How many characters to accept
* echo: Set to false if you want to hide what is entered (for passwords)
*
* Returns a malloc()'ed string with the input (w/o trailing newline).
*/
static
bool
prompt_state
=
false
;
char
*
simple_prompt
(
const
char
*
prompt
,
int
maxlen
,
bool
echo
)
{
int
length
;
char
*
destination
;
FILE
*
termin
,
*
termout
;
#ifdef HAVE_TERMIOS_H
struct
termios
t_orig
,
t
;
#endif
destination
=
(
char
*
)
malloc
(
maxlen
+
2
);
if
(
!
destination
)
return
NULL
;
prompt_state
=
true
;
/* disable SIGINT */
/*
* Do not try to collapse these into one "w+" mode file. Doesn't work
* on some platforms (eg, HPUX 10.20).
*/
termin
=
fopen
(
"/dev/tty"
,
"r"
);
termout
=
fopen
(
"/dev/tty"
,
"w"
);
if
(
!
termin
||
!
termout
)
{
if
(
termin
)
fclose
(
termin
);
if
(
termout
)
fclose
(
termout
);
termin
=
stdin
;
termout
=
stderr
;
}
#ifdef HAVE_TERMIOS_H
if
(
!
echo
)
{
tcgetattr
(
fileno
(
termin
),
&
t
);
t_orig
=
t
;
t
.
c_lflag
&=
~
ECHO
;
tcsetattr
(
fileno
(
termin
),
TCSAFLUSH
,
&
t
);
}
#endif
if
(
prompt
)
{
fputs
(
gettext
(
prompt
),
termout
);
fflush
(
termout
);
}
if
(
fgets
(
destination
,
maxlen
,
termin
)
==
NULL
)
destination
[
0
]
=
'\0'
;
length
=
strlen
(
destination
);
if
(
length
>
0
&&
destination
[
length
-
1
]
!=
'\n'
)
{
/* eat rest of the line */
char
buf
[
128
];
int
buflen
;
do
{
if
(
fgets
(
buf
,
sizeof
(
buf
),
termin
)
==
NULL
)
break
;
buflen
=
strlen
(
buf
);
}
while
(
buflen
>
0
&&
buf
[
buflen
-
1
]
!=
'\n'
);
}
if
(
length
>
0
&&
destination
[
length
-
1
]
==
'\n'
)
/* remove trailing newline */
destination
[
length
-
1
]
=
'\0'
;
#ifdef HAVE_TERMIOS_H
if
(
!
echo
)
{
tcsetattr
(
fileno
(
termin
),
TCSAFLUSH
,
&
t_orig
);
fputs
(
"
\n
"
,
termout
);
fflush
(
termout
);
}
#endif
if
(
termin
!=
stdin
)
{
fclose
(
termin
);
fclose
(
termout
);
}
prompt_state
=
false
;
/* SIGINT okay again */
return
destination
;
}
static
int
_parse_version
(
ArchiveHandle
*
AH
,
const
char
*
versionString
)
{
...
...
src/bin/pg_dump/pg_dump.h
View file @
7015111a
...
...
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_dump.h,v 1.
89 2002/07/02 05:49:52
momjian Exp $
* $Id: pg_dump.h,v 1.
90 2002/07/06 20:12:30
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -209,4 +209,7 @@ extern void dumpTables(Archive *fout, TableInfo tblinfo[], int numTables,
const
bool
schemaOnly
,
const
bool
dataOnly
);
extern
void
dumpIndexes
(
Archive
*
fout
,
TableInfo
*
tbinfo
,
int
numTables
);
/* sprompt.h */
extern
char
*
simple_prompt
(
const
char
*
prompt
,
int
maxlen
,
bool
echo
);
#endif
/* PG_DUMP_H */
src/bin/pg_dump/sprompt.c
0 → 100644
View file @
7015111a
/*
* psql - the PostgreSQL interactive terminal
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/sprompt.c,v 1.1 2002/07/06 20:12:30 momjian Exp $
*/
/*
* simple_prompt
*
* Generalized function especially intended for reading in usernames and
* password interactively. Reads from /dev/tty or stdin/stderr.
*
* prompt: The prompt to print
* maxlen: How many characters to accept
* echo: Set to false if you want to hide what is entered (for passwords)
*
* Returns a malloc()'ed string with the input (w/o trailing newline).
*/
#include "postgres_fe.h"
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
bool
prompt_state
=
false
;
extern
char
*
simple_prompt
(
const
char
*
prompt
,
int
maxlen
,
bool
echo
);
char
*
simple_prompt
(
const
char
*
prompt
,
int
maxlen
,
bool
echo
)
{
int
length
;
char
*
destination
;
FILE
*
termin
,
*
termout
;
#ifdef HAVE_TERMIOS_H
struct
termios
t_orig
,
t
;
#endif
destination
=
(
char
*
)
malloc
(
maxlen
+
2
);
if
(
!
destination
)
return
NULL
;
prompt_state
=
true
;
/* disable SIGINT */
/*
* Do not try to collapse these into one "w+" mode file. Doesn't work
* on some platforms (eg, HPUX 10.20).
*/
termin
=
fopen
(
"/dev/tty"
,
"r"
);
termout
=
fopen
(
"/dev/tty"
,
"w"
);
if
(
!
termin
||
!
termout
)
{
if
(
termin
)
fclose
(
termin
);
if
(
termout
)
fclose
(
termout
);
termin
=
stdin
;
termout
=
stderr
;
}
#ifdef HAVE_TERMIOS_H
if
(
!
echo
)
{
tcgetattr
(
fileno
(
termin
),
&
t
);
t_orig
=
t
;
t
.
c_lflag
&=
~
ECHO
;
tcsetattr
(
fileno
(
termin
),
TCSAFLUSH
,
&
t
);
}
#endif
if
(
prompt
)
{
fputs
(
gettext
(
prompt
),
termout
);
fflush
(
termout
);
}
if
(
fgets
(
destination
,
maxlen
,
termin
)
==
NULL
)
destination
[
0
]
=
'\0'
;
length
=
strlen
(
destination
);
if
(
length
>
0
&&
destination
[
length
-
1
]
!=
'\n'
)
{
/* eat rest of the line */
char
buf
[
128
];
int
buflen
;
do
{
if
(
fgets
(
buf
,
sizeof
(
buf
),
termin
)
==
NULL
)
break
;
buflen
=
strlen
(
buf
);
}
while
(
buflen
>
0
&&
buf
[
buflen
-
1
]
!=
'\n'
);
}
if
(
length
>
0
&&
destination
[
length
-
1
]
==
'\n'
)
/* remove trailing newline */
destination
[
length
-
1
]
=
'\0'
;
#ifdef HAVE_TERMIOS_H
if
(
!
echo
)
{
tcsetattr
(
fileno
(
termin
),
TCSAFLUSH
,
&
t_orig
);
fputs
(
"
\n
"
,
termout
);
fflush
(
termout
);
}
#endif
if
(
termin
!=
stdin
)
{
fclose
(
termin
);
fclose
(
termout
);
}
prompt_state
=
false
;
/* SIGINT okay again */
return
destination
;
}
src/bin/psql/Makefile
View file @
7015111a
...
...
@@ -5,7 +5,7 @@
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
#
# $Header: /cvsroot/pgsql/src/bin/psql/Makefile,v 1.3
2 2002/06/20 20:29:42
momjian Exp $
# $Header: /cvsroot/pgsql/src/bin/psql/Makefile,v 1.3
3 2002/07/06 20:12:30
momjian Exp $
#
#-------------------------------------------------------------------------
...
...
@@ -19,7 +19,7 @@ override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
OBJS
=
command.o common.o help.o input.o stringutils.o mainloop.o
\
copy.o startup.o prompt.o variables.o large_obj.o print.o describe.o
\
tab-complete.o mbprint.o
sprompt.o
tab-complete.o mbprint.o
all
:
submake psql
...
...
src/bin/psql/common.c
View file @
7015111a
...
...
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.4
0 2002/03/06 06:10:31
momjian Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.4
1 2002/07/06 20:12:30
momjian Exp $
*/
#include "postgres_fe.h"
...
...
@@ -12,9 +12,6 @@
#include <errno.h>
#include <stdarg.h>
#include <sys/time.h>
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
#ifndef HAVE_STRDUP
#include <strdup.h>
#endif
...
...
@@ -37,6 +34,7 @@
#include "print.h"
#include "mainloop.h"
extern
bool
prompt_state
;
/*
* "Safe" wrapper around strdup()
...
...
@@ -158,115 +156,6 @@ NoticeProcessor(void *arg, const char *message)
/*
* simple_prompt
*
* Generalized function especially intended for reading in usernames and
* password interactively. Reads from /dev/tty or stdin/stderr.
*
* prompt: The prompt to print
* maxlen: How many characters to accept
* echo: Set to false if you want to hide what is entered (for passwords)
*
* Returns a malloc()'ed string with the input (w/o trailing newline).
*/
static
bool
prompt_state
=
false
;
char
*
simple_prompt
(
const
char
*
prompt
,
int
maxlen
,
bool
echo
)
{
int
length
;
char
*
destination
;
FILE
*
termin
,
*
termout
;
#ifdef HAVE_TERMIOS_H
struct
termios
t_orig
,
t
;
#endif
destination
=
(
char
*
)
malloc
(
maxlen
+
2
);
if
(
!
destination
)
return
NULL
;
prompt_state
=
true
;
/* disable SIGINT */
/*
* Do not try to collapse these into one "w+" mode file. Doesn't work
* on some platforms (eg, HPUX 10.20).
*/
termin
=
fopen
(
"/dev/tty"
,
"r"
);
termout
=
fopen
(
"/dev/tty"
,
"w"
);
if
(
!
termin
||
!
termout
)
{
if
(
termin
)
fclose
(
termin
);
if
(
termout
)
fclose
(
termout
);
termin
=
stdin
;
termout
=
stderr
;
}
#ifdef HAVE_TERMIOS_H
if
(
!
echo
)
{
tcgetattr
(
fileno
(
termin
),
&
t
);
t_orig
=
t
;
t
.
c_lflag
&=
~
ECHO
;
tcsetattr
(
fileno
(
termin
),
TCSAFLUSH
,
&
t
);
}
#endif
if
(
prompt
)
{
fputs
(
gettext
(
prompt
),
termout
);
fflush
(
termout
);
}
if
(
fgets
(
destination
,
maxlen
,
termin
)
==
NULL
)
destination
[
0
]
=
'\0'
;
length
=
strlen
(
destination
);
if
(
length
>
0
&&
destination
[
length
-
1
]
!=
'\n'
)
{
/* eat rest of the line */
char
buf
[
128
];
int
buflen
;
do
{
if
(
fgets
(
buf
,
sizeof
(
buf
),
termin
)
==
NULL
)
break
;
buflen
=
strlen
(
buf
);
}
while
(
buflen
>
0
&&
buf
[
buflen
-
1
]
!=
'\n'
);
}
if
(
length
>
0
&&
destination
[
length
-
1
]
==
'\n'
)
/* remove trailing newline */
destination
[
length
-
1
]
=
'\0'
;
#ifdef HAVE_TERMIOS_H
if
(
!
echo
)
{
tcsetattr
(
fileno
(
termin
),
TCSAFLUSH
,
&
t_orig
);
fputs
(
"
\n
"
,
termout
);
fflush
(
termout
);
}
#endif
if
(
termin
!=
stdin
)
{
fclose
(
termin
);
fclose
(
termout
);
}
prompt_state
=
false
;
/* SIGINT okay again */
return
destination
;
}
/*
* Code to support query cancellation
*
...
...
@@ -276,7 +165,6 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
* so. We use write() to print to stdout because it's better to use simple
* facilities in a signal handler.
*/
PGconn
*
cancelConn
;
volatile
bool
cancel_pressed
;
...
...
src/bin/psql/common.h
View file @
7015111a
...
...
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.1
7 2001/11/05 17:46:31
momjian Exp $
* $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.1
8 2002/07/06 20:12:30
momjian Exp $
*/
#ifndef COMMON_H
#define COMMON_H
...
...
@@ -37,4 +37,7 @@ extern PGresult *PSQLexec(const char *query);
extern
bool
SendQuery
(
const
char
*
query
);
/* sprompt.h */
extern
char
*
simple_prompt
(
const
char
*
prompt
,
int
maxlen
,
bool
echo
);
#endif
/* COMMON_H */
src/bin/psql/sprompt.c
0 → 100644
View file @
7015111a
/*
* psql - the PostgreSQL interactive terminal
*
* Copyright 2000 by PostgreSQL Global Development Group
*
* $Header: /cvsroot/pgsql/src/bin/psql/Attic/sprompt.c,v 1.1 2002/07/06 20:12:30 momjian Exp $
*/
/*
* simple_prompt
*
* Generalized function especially intended for reading in usernames and
* password interactively. Reads from /dev/tty or stdin/stderr.
*
* prompt: The prompt to print
* maxlen: How many characters to accept
* echo: Set to false if you want to hide what is entered (for passwords)
*
* Returns a malloc()'ed string with the input (w/o trailing newline).
*/
#include "postgres_fe.h"
#ifdef HAVE_TERMIOS_H
#include <termios.h>
#endif
bool
prompt_state
=
false
;
extern
char
*
simple_prompt
(
const
char
*
prompt
,
int
maxlen
,
bool
echo
);
char
*
simple_prompt
(
const
char
*
prompt
,
int
maxlen
,
bool
echo
)
{
int
length
;
char
*
destination
;
FILE
*
termin
,
*
termout
;
#ifdef HAVE_TERMIOS_H
struct
termios
t_orig
,
t
;
#endif
destination
=
(
char
*
)
malloc
(
maxlen
+
2
);
if
(
!
destination
)
return
NULL
;
prompt_state
=
true
;
/* disable SIGINT */
/*
* Do not try to collapse these into one "w+" mode file. Doesn't work
* on some platforms (eg, HPUX 10.20).
*/
termin
=
fopen
(
"/dev/tty"
,
"r"
);
termout
=
fopen
(
"/dev/tty"
,
"w"
);
if
(
!
termin
||
!
termout
)
{
if
(
termin
)
fclose
(
termin
);
if
(
termout
)
fclose
(
termout
);
termin
=
stdin
;
termout
=
stderr
;
}
#ifdef HAVE_TERMIOS_H
if
(
!
echo
)
{
tcgetattr
(
fileno
(
termin
),
&
t
);
t_orig
=
t
;
t
.
c_lflag
&=
~
ECHO
;
tcsetattr
(
fileno
(
termin
),
TCSAFLUSH
,
&
t
);
}
#endif
if
(
prompt
)
{
fputs
(
gettext
(
prompt
),
termout
);
fflush
(
termout
);
}
if
(
fgets
(
destination
,
maxlen
,
termin
)
==
NULL
)
destination
[
0
]
=
'\0'
;
length
=
strlen
(
destination
);
if
(
length
>
0
&&
destination
[
length
-
1
]
!=
'\n'
)
{
/* eat rest of the line */
char
buf
[
128
];
int
buflen
;
do
{
if
(
fgets
(
buf
,
sizeof
(
buf
),
termin
)
==
NULL
)
break
;
buflen
=
strlen
(
buf
);
}
while
(
buflen
>
0
&&
buf
[
buflen
-
1
]
!=
'\n'
);
}
if
(
length
>
0
&&
destination
[
length
-
1
]
==
'\n'
)
/* remove trailing newline */
destination
[
length
-
1
]
=
'\0'
;
#ifdef HAVE_TERMIOS_H
if
(
!
echo
)
{
tcsetattr
(
fileno
(
termin
),
TCSAFLUSH
,
&
t_orig
);
fputs
(
"
\n
"
,
termout
);
fflush
(
termout
);
}
#endif
if
(
termin
!=
stdin
)
{
fclose
(
termin
);
fclose
(
termout
);
}
prompt_state
=
false
;
/* SIGINT okay again */
return
destination
;
}
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