Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7015111

Browse files
committed
Move simple_prompt() into its own file to be shared with psql and pg_dump.
1 parentd66f172 commit7015111

File tree

8 files changed

+258
-230
lines changed

8 files changed

+258
-230
lines changed

‎src/bin/pg_dump/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
66
# Portions Copyright (c) 1994, Regents of the University of California
77
#
8-
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.33 2002/06/20 20:29:41 momjian Exp $
8+
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.34 2002/07/06 20:12:30 momjian Exp $
99
#
1010
#-------------------------------------------------------------------------
1111

1212
subdir = src/bin/pg_dump
1313
top_builddir = ../../..
1414
include$(top_builddir)/src/Makefile.global
1515

16-
OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.opg_backup_files.o\
17-
pg_backup_null.o pg_backup_tar.o
16+
OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o\
17+
pg_backup_files.o pg_backup_null.o pg_backup_tar.o sprompt.o
1818

1919
ifdefSTRDUP
2020
OBJS+=$(top_builddir)/src/utils/strdup.o

‎src/bin/pg_dump/pg_backup_db.c

Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*Implements the basic DB functions used by the archiver.
66
*
77
* IDENTIFICATION
8-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.34 2002/07/04 15:35:07 momjian Exp $
8+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.35 2002/07/06 20:12:30 momjian Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -37,114 +37,6 @@ static char *_sendSQLLine(ArchiveHandle *AH, char *qry, char *eos);
3737
staticchar*_sendCopyLine(ArchiveHandle*AH,char*qry,char*eos);
3838

3939

40-
/*
41-
* simple_prompt --- borrowed from psql
42-
*
43-
* Generalized function especially intended for reading in usernames and
44-
* password interactively. Reads from /dev/tty or stdin/stderr.
45-
*
46-
* prompt:The prompt to print
47-
* maxlen:How many characters to accept
48-
* echo:Set to false if you want to hide what is entered (for passwords)
49-
*
50-
* Returns a malloc()'ed string with the input (w/o trailing newline).
51-
*/
52-
staticboolprompt_state= false;
53-
54-
char*
55-
simple_prompt(constchar*prompt,intmaxlen,boolecho)
56-
{
57-
intlength;
58-
char*destination;
59-
FILE*termin,
60-
*termout;
61-
62-
#ifdefHAVE_TERMIOS_H
63-
structtermiost_orig,
64-
t;
65-
#endif
66-
67-
destination= (char*)malloc(maxlen+2);
68-
if (!destination)
69-
returnNULL;
70-
71-
prompt_state= true;/* disable SIGINT */
72-
73-
/*
74-
* Do not try to collapse these into one "w+" mode file. Doesn't work
75-
* on some platforms (eg, HPUX 10.20).
76-
*/
77-
termin=fopen("/dev/tty","r");
78-
termout=fopen("/dev/tty","w");
79-
if (!termin|| !termout)
80-
{
81-
if (termin)
82-
fclose(termin);
83-
if (termout)
84-
fclose(termout);
85-
termin=stdin;
86-
termout=stderr;
87-
}
88-
89-
#ifdefHAVE_TERMIOS_H
90-
if (!echo)
91-
{
92-
tcgetattr(fileno(termin),&t);
93-
t_orig=t;
94-
t.c_lflag &= ~ECHO;
95-
tcsetattr(fileno(termin),TCSAFLUSH,&t);
96-
}
97-
#endif
98-
99-
if (prompt)
100-
{
101-
fputs(gettext(prompt),termout);
102-
fflush(termout);
103-
}
104-
105-
if (fgets(destination,maxlen,termin)==NULL)
106-
destination[0]='\0';
107-
108-
length=strlen(destination);
109-
if (length>0&&destination[length-1]!='\n')
110-
{
111-
/* eat rest of the line */
112-
charbuf[128];
113-
intbuflen;
114-
115-
do
116-
{
117-
if (fgets(buf,sizeof(buf),termin)==NULL)
118-
break;
119-
buflen=strlen(buf);
120-
}while (buflen>0&&buf[buflen-1]!='\n');
121-
}
122-
123-
if (length>0&&destination[length-1]=='\n')
124-
/* remove trailing newline */
125-
destination[length-1]='\0';
126-
127-
#ifdefHAVE_TERMIOS_H
128-
if (!echo)
129-
{
130-
tcsetattr(fileno(termin),TCSAFLUSH,&t_orig);
131-
fputs("\n",termout);
132-
fflush(termout);
133-
}
134-
#endif
135-
136-
if (termin!=stdin)
137-
{
138-
fclose(termin);
139-
fclose(termout);
140-
}
141-
142-
prompt_state= false;/* SIGINT okay again */
143-
144-
returndestination;
145-
}
146-
147-
14840
staticint
14941
_parse_version(ArchiveHandle*AH,constchar*versionString)
15042
{

‎src/bin/pg_dump/pg_dump.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: pg_dump.h,v 1.89 2002/07/02 05:49:52 momjian Exp $
9+
* $Id: pg_dump.h,v 1.90 2002/07/06 20:12:30 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -209,4 +209,7 @@ extern void dumpTables(Archive *fout, TableInfo tblinfo[], int numTables,
209209
constboolschemaOnly,constbooldataOnly);
210210
externvoiddumpIndexes(Archive*fout,TableInfo*tbinfo,intnumTables);
211211

212+
/* sprompt.h */
213+
externchar*simple_prompt(constchar*prompt,intmaxlen,boolecho);
214+
212215
#endif/* PG_DUMP_H */

‎src/bin/pg_dump/sprompt.c

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
/*
2+
* psql - the PostgreSQL interactive terminal
3+
*
4+
* Copyright 2000 by PostgreSQL Global Development Group
5+
*
6+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/sprompt.c,v 1.1 2002/07/06 20:12:30 momjian Exp $
7+
*/
8+
9+
/*
10+
* simple_prompt
11+
*
12+
* Generalized function especially intended for reading in usernames and
13+
* password interactively. Reads from /dev/tty or stdin/stderr.
14+
*
15+
* prompt:The prompt to print
16+
* maxlen:How many characters to accept
17+
* echo:Set to false if you want to hide what is entered (for passwords)
18+
*
19+
* Returns a malloc()'ed string with the input (w/o trailing newline).
20+
*/
21+
#include"postgres_fe.h"
22+
23+
#ifdefHAVE_TERMIOS_H
24+
#include<termios.h>
25+
#endif
26+
27+
boolprompt_state= false;
28+
externchar*simple_prompt(constchar*prompt,intmaxlen,boolecho);
29+
30+
char*
31+
simple_prompt(constchar*prompt,intmaxlen,boolecho)
32+
{
33+
intlength;
34+
char*destination;
35+
FILE*termin,
36+
*termout;
37+
38+
#ifdefHAVE_TERMIOS_H
39+
structtermiost_orig,
40+
t;
41+
#endif
42+
43+
destination= (char*)malloc(maxlen+2);
44+
if (!destination)
45+
returnNULL;
46+
47+
prompt_state= true;/* disable SIGINT */
48+
49+
/*
50+
* Do not try to collapse these into one "w+" mode file. Doesn't work
51+
* on some platforms (eg, HPUX 10.20).
52+
*/
53+
termin=fopen("/dev/tty","r");
54+
termout=fopen("/dev/tty","w");
55+
if (!termin|| !termout)
56+
{
57+
if (termin)
58+
fclose(termin);
59+
if (termout)
60+
fclose(termout);
61+
termin=stdin;
62+
termout=stderr;
63+
}
64+
65+
#ifdefHAVE_TERMIOS_H
66+
if (!echo)
67+
{
68+
tcgetattr(fileno(termin),&t);
69+
t_orig=t;
70+
t.c_lflag &= ~ECHO;
71+
tcsetattr(fileno(termin),TCSAFLUSH,&t);
72+
}
73+
#endif
74+
75+
if (prompt)
76+
{
77+
fputs(gettext(prompt),termout);
78+
fflush(termout);
79+
}
80+
81+
if (fgets(destination,maxlen,termin)==NULL)
82+
destination[0]='\0';
83+
84+
length=strlen(destination);
85+
if (length>0&&destination[length-1]!='\n')
86+
{
87+
/* eat rest of the line */
88+
charbuf[128];
89+
intbuflen;
90+
91+
do
92+
{
93+
if (fgets(buf,sizeof(buf),termin)==NULL)
94+
break;
95+
buflen=strlen(buf);
96+
}while (buflen>0&&buf[buflen-1]!='\n');
97+
}
98+
99+
if (length>0&&destination[length-1]=='\n')
100+
/* remove trailing newline */
101+
destination[length-1]='\0';
102+
103+
#ifdefHAVE_TERMIOS_H
104+
if (!echo)
105+
{
106+
tcsetattr(fileno(termin),TCSAFLUSH,&t_orig);
107+
fputs("\n",termout);
108+
fflush(termout);
109+
}
110+
#endif
111+
112+
if (termin!=stdin)
113+
{
114+
fclose(termin);
115+
fclose(termout);
116+
}
117+
118+
prompt_state= false;/* SIGINT okay again */
119+
120+
returndestination;
121+
}

‎src/bin/psql/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
66
# Portions Copyright (c) 1994, Regents of the University of California
77
#
8-
# $Header: /cvsroot/pgsql/src/bin/psql/Makefile,v 1.32 2002/06/20 20:29:42 momjian Exp $
8+
# $Header: /cvsroot/pgsql/src/bin/psql/Makefile,v 1.33 2002/07/06 20:12:30 momjian Exp $
99
#
1010
#-------------------------------------------------------------------------
1111

@@ -19,7 +19,7 @@ override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
1919

2020
OBJS=command.o common.o help.o input.o stringutils.o mainloop.o\
2121
copy.o startup.o prompt.o variables.o large_obj.o print.o describe.o\
22-
tab-complete.o mbprint.o
22+
sprompt.otab-complete.o mbprint.o
2323

2424
all: submake psql
2525

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp