Обсуждение: Moved simple_prompt()/sprompt.c

Поиск
Список
Период
Сортировка

Moved simple_prompt()/sprompt.c

От
Bruce Momjian
Дата:
I have moved simple_prompt()/sprompt.c into /port.  It was used by psql,
pg_dump, and scripts, and had already gotten out of sync with a recent
Win32 password patch.

If a file is needed by three non-backend directories, /port seems to be
the proper place for it.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
Index: src/Makefile.global.in
===================================================================
RCS file: /cvsroot/pgsql-server/src/Makefile.global.in,v
retrieving revision 1.165
diff -c -c -r1.165 Makefile.global.in
*** src/Makefile.global.in    8 Aug 2003 02:48:24 -0000    1.165
--- src/Makefile.global.in    8 Aug 2003 04:38:40 -0000
***************
*** 341,347 ****
  #
  # substitute implementations of the C library

! LIBOBJS = @LIBOBJS@ path.o thread.o

  ifneq (,$(LIBOBJS))
  LIBS += -lpgport
--- 341,347 ----
  #
  # substitute implementations of the C library

! LIBOBJS = @LIBOBJS@ path.o sprompt.o thread.o

  ifneq (,$(LIBOBJS))
  LIBS += -lpgport
Index: src/bin/pg_dump/Makefile
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/pg_dump/Makefile,v
retrieving revision 1.39
diff -c -c -r1.39 Makefile
*** src/bin/pg_dump/Makefile    12 Dec 2002 21:02:00 -0000    1.39
--- src/bin/pg_dump/Makefile    8 Aug 2003 04:38:41 -0000
***************
*** 13,21 ****
  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 \
!       sprompt.o dumputils.o

  EXTRA_OBJS = $(top_builddir)/src/backend/parser/keywords.o

--- 13,21 ----
  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 \
!     dumputils.o

  EXTRA_OBJS = $(top_builddir)/src/backend/parser/keywords.o

***************
*** 31,37 ****
      $(CC) $(CFLAGS) pg_restore.o $(OBJS) $(EXTRA_OBJS) $(libpq) $(LDFLAGS) $(LIBS) -o $@

  pg_dumpall: pg_dumpall.o $(libpq_builddir)/libpq.a
!     $(CC) $(CFLAGS) pg_dumpall.o dumputils.o sprompt.o $(EXTRA_OBJS) $(libpq) $(LDFLAGS) $(LIBS) -o $@

  .PHONY: submake-backend
  submake-backend:
--- 31,37 ----
      $(CC) $(CFLAGS) pg_restore.o $(OBJS) $(EXTRA_OBJS) $(libpq) $(LDFLAGS) $(LIBS) -o $@

  pg_dumpall: pg_dumpall.o $(libpq_builddir)/libpq.a
!     $(CC) $(CFLAGS) pg_dumpall.o dumputils.o $(EXTRA_OBJS) $(libpq) $(LDFLAGS) $(LIBS) -o $@

  .PHONY: submake-backend
  submake-backend:
Index: src/bin/pg_dump/dumputils.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/pg_dump/dumputils.h,v
retrieving revision 1.7
diff -c -c -r1.7 dumputils.h
*** src/bin/pg_dump/dumputils.h    4 Aug 2003 02:40:09 -0000    1.7
--- src/bin/pg_dump/dumputils.h    8 Aug 2003 04:38:41 -0000
***************
*** 18,25 ****
  #include "pqexpbuffer.h"


- extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
-
  extern const char *fmtId(const char *identifier);
  extern void appendStringLiteral(PQExpBuffer buf, const char *str,
                      bool escapeAll);
--- 18,23 ----
Index: src/bin/pg_dump/pg_dump.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/pg_dump/pg_dump.h,v
retrieving revision 1.103
diff -c -c -r1.103 pg_dump.h
*** src/bin/pg_dump/pg_dump.h    4 Aug 2003 02:40:09 -0000    1.103
--- src/bin/pg_dump/pg_dump.h    8 Aug 2003 04:38:41 -0000
***************
*** 235,241 ****
             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 */
--- 235,238 ----
Index: src/bin/psql/Makefile
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/Makefile,v
retrieving revision 1.36
diff -c -c -r1.36 Makefile
*** src/bin/psql/Makefile    6 Jun 2003 22:17:42 -0000    1.36
--- src/bin/psql/Makefile    8 Aug 2003 04:38:42 -0000
***************
*** 17,25 ****

  override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS) -DFRONTEND

! 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 \
!     sprompt.o tab-complete.o mbprint.o

  all: submake-libpq submake-libpgport psql

--- 17,25 ----

  override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS) -DFRONTEND

! 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

  all: submake-libpq submake-libpgport psql

Index: src/bin/psql/bcc32.mak
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/bcc32.mak,v
retrieving revision 1.2
diff -c -c -r1.2 bcc32.mak
*** src/bin/psql/bcc32.mak    12 Jun 2003 08:15:28 -0000    1.2
--- src/bin/psql/bcc32.mak    8 Aug 2003 04:38:42 -0000
***************
*** 65,71 ****
      -@erase "$(INTDIR)\copy.obj"
      -@erase "$(INTDIR)\startup.obj"
      -@erase "$(INTDIR)\prompt.obj"
-     -@erase "$(INTDIR)\sprompt.obj"
      -@erase "$(INTDIR)\variables.obj"
      -@erase "$(INTDIR)\large_obj.obj"
      -@erase "$(INTDIR)\print.obj"
--- 65,70 ----
***************
*** 119,125 ****
      copy.obj \
      startup.obj \
      prompt.obj \
-     sprompt.obj \
      variables.obj \
      large_obj.obj \
      print.obj \
--- 118,123 ----
Index: src/bin/psql/common.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/common.h,v
retrieving revision 1.27
diff -c -c -r1.27 common.h
*** src/bin/psql/common.h    4 Aug 2003 23:59:39 -0000    1.27
--- src/bin/psql/common.h    8 Aug 2003 04:38:42 -0000
***************
*** 24,31 ****

  extern void NoticeProcessor(void *arg, const char *message);

- extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
-
  extern volatile bool cancel_pressed;

  extern void ResetCancelConn(void);
--- 24,29 ----
***************
*** 39,47 ****
  extern bool SendQuery(const char *query);

  extern bool is_superuser(void);
-
- /* sprompt.h */
- extern char *simple_prompt(const char *prompt, int maxlen, bool echo);

  /* Parse a numeric character code from the string pointed at by *buf, e.g.
   * one written as 0x0c (hexadecimal) or 015 (octal); advance *buf to the last
--- 37,42 ----
Index: src/bin/psql/win32.mak
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/psql/win32.mak,v
retrieving revision 1.13
diff -c -c -r1.13 win32.mak
*** src/bin/psql/win32.mak    12 Jun 2003 08:15:28 -0000    1.13
--- src/bin/psql/win32.mak    8 Aug 2003 04:38:42 -0000
***************
*** 28,34 ****
      -@erase "$(INTDIR)\copy.obj"
      -@erase "$(INTDIR)\startup.obj"
      -@erase "$(INTDIR)\prompt.obj"
-     -@erase "$(INTDIR)\sprompt.obj"
      -@erase "$(INTDIR)\variables.obj"
      -@erase "$(INTDIR)\large_obj.obj"
      -@erase "$(INTDIR)\print.obj"
--- 28,33 ----
***************
*** 66,72 ****
      "$(INTDIR)\copy.obj" \
      "$(INTDIR)\startup.obj" \
      "$(INTDIR)\prompt.obj" \
-     "$(INTDIR)\sprompt.obj" \
      "$(INTDIR)\variables.obj" \
      "$(INTDIR)\large_obj.obj" \
      "$(INTDIR)\print.obj" \
--- 65,70 ----
Index: src/bin/scripts/Makefile
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/scripts/Makefile,v
retrieving revision 1.21
diff -c -c -r1.21 Makefile
*** src/bin/scripts/Makefile    18 Jun 2003 12:19:11 -0000    1.21
--- src/bin/scripts/Makefile    8 Aug 2003 04:38:42 -0000
***************
*** 17,38 ****

  override CPPFLAGS := -I$(top_srcdir)/src/bin/pg_dump -I$(top_srcdir)/src/bin/psql -I$(libpq_srcdir) $(CPPFLAGS)

-
  all: submake-libpq submake-backend $(PROGRAMS)

  %: %.o
      $(CC) $(CFLAGS) $^ $(libpq) $(LDFLAGS) $(LIBS) -o $@

! createdb: createdb.o common.o dumputils.o sprompt.o $(top_builddir)/src/backend/parser/keywords.o
! createlang: createlang.o common.o sprompt.o print.o mbprint.o
! createuser: createuser.o common.o dumputils.o sprompt.o $(top_builddir)/src/backend/parser/keywords.o
! dropdb: dropdb.o common.o dumputils.o sprompt.o $(top_builddir)/src/backend/parser/keywords.o
! droplang: droplang.o common.o sprompt.o print.o mbprint.o
! dropuser: dropuser.o common.o dumputils.o sprompt.o $(top_builddir)/src/backend/parser/keywords.o
! clusterdb: clusterdb.o common.o dumputils.o sprompt.o $(top_builddir)/src/backend/parser/keywords.o
! vacuumdb: vacuumdb.o common.o sprompt.o

! dumputils.c sprompt.c : % : $(top_srcdir)/src/bin/pg_dump/%
      rm -f $@ && $(LN_S) $< .

  print.c mbprint.c : % : $(top_srcdir)/src/bin/psql/%
--- 17,37 ----

  override CPPFLAGS := -I$(top_srcdir)/src/bin/pg_dump -I$(top_srcdir)/src/bin/psql -I$(libpq_srcdir) $(CPPFLAGS)

  all: submake-libpq submake-backend $(PROGRAMS)

  %: %.o
      $(CC) $(CFLAGS) $^ $(libpq) $(LDFLAGS) $(LIBS) -o $@

! createdb: createdb.o common.o dumputils.o $(top_builddir)/src/backend/parser/keywords.o
! createlang: createlang.o common.o print.o mbprint.o
! createuser: createuser.o common.o dumputils.o $(top_builddir)/src/backend/parser/keywords.o
! dropdb: dropdb.o common.o dumputils.o $(top_builddir)/src/backend/parser/keywords.o
! droplang: droplang.o common.o print.o mbprint.o
! dropuser: dropuser.o common.o dumputils.o $(top_builddir)/src/backend/parser/keywords.o
! clusterdb: clusterdb.o common.o dumputils.o $(top_builddir)/src/backend/parser/keywords.o
! vacuumdb: vacuumdb.o common.o

! dumputils.c: % : $(top_srcdir)/src/bin/pg_dump/%
      rm -f $@ && $(LN_S) $< .

  print.c mbprint.c : % : $(top_srcdir)/src/bin/psql/%
***************
*** 61,64 ****


  clean distclean maintainer-clean:
!     rm -f $(addsuffix $(X), $(PROGRAMS)) $(addsuffix .o, $(PROGRAMS)) common.o dumputils.o sprompt.o print.o
mbprint.odumputils.c sprompt.c print.c mbprint.c 
--- 60,63 ----


  clean distclean maintainer-clean:
!     rm -f $(addsuffix $(X), $(PROGRAMS)) $(addsuffix .o, $(PROGRAMS)) common.o dumputils.o print.o mbprint.o
dumputils.cprint.c mbprint.c 
Index: src/bin/scripts/common.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/bin/scripts/common.h,v
retrieving revision 1.5
diff -c -c -r1.5 common.h
*** src/bin/scripts/common.h    7 Aug 2003 21:11:58 -0000    1.5
--- src/bin/scripts/common.h    8 Aug 2003 04:38:42 -0000
***************
*** 17,24 ****

  void        handle_help_version_opts(int argc, char *argv[], const char *fixed_progname, help_handler hlp);

- extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
-
  PGconn *connectDatabase(const char *dbname, const char *pghost, const char *pgport,
          const char *pguser, bool require_password, const char *progname);

--- 17,22 ----
Index: src/include/port.h
===================================================================
RCS file: /cvsroot/pgsql-server/src/include/port.h,v
retrieving revision 1.10
diff -c -c -r1.10 port.h
*** src/include/port.h    4 Aug 2003 02:40:10 -0000    1.10
--- src/include/port.h    8 Aug 2003 04:38:42 -0000
***************
*** 18,31 ****
  #endif

  /* Portable path handling for Unix/Win32 */
! bool        is_absolute_path(const char *filename);
! char       *first_path_separator(const char *filename);
! char       *last_path_separator(const char *filename);
! char       *get_progname(char *argv0);

  #if defined(bsdi) || defined(netbsd)
! int            fseeko(FILE *stream, off_t offset, int whence);
! off_t        ftello(FILE *stream);
  #endif

  #ifdef WIN32
--- 18,33 ----
  #endif

  /* Portable path handling for Unix/Win32 */
! extern bool        is_absolute_path(const char *filename);
! extern char       *first_path_separator(const char *filename);
! extern char       *last_path_separator(const char *filename);
! extern char       *get_progname(char *argv0);
!
! extern char *simple_prompt(const char *prompt, int maxlen, bool echo);

  #if defined(bsdi) || defined(netbsd)
! extern int            fseeko(FILE *stream, off_t offset, int whence);
! extern off_t        ftello(FILE *stream);
  #endif

  #ifdef WIN32
***************
*** 33,40 ****
   * Win32 doesn't have reliable rename/unlink during concurrent access
   */
  #ifndef FRONTEND
! int            pgrename(const char *from, const char *to);
! int            pgunlink(const char *path);

  #define rename(from, to)    pgrename(from, to)
  #define unlink(path)        pgunlink(path)
--- 35,42 ----
   * Win32 doesn't have reliable rename/unlink during concurrent access
   */
  #ifndef FRONTEND
! extern int            pgrename(const char *from, const char *to);
! extern int            pgunlink(const char *path);

  #define rename(from, to)    pgrename(from, to)
  #define unlink(path)        pgunlink(path)
Index: src/interfaces/libpq/Makefile
===================================================================
RCS file: /cvsroot/pgsql-server/src/interfaces/libpq/Makefile,v
retrieving revision 1.89
diff -c -c -r1.89 Makefile
*** src/interfaces/libpq/Makefile    8 Aug 2003 03:22:24 -0000    1.89
--- src/interfaces/libpq/Makefile    8 Aug 2003 04:38:43 -0000
***************
*** 23,29 ****
  OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \
        fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o \
        dllist.o md5.o ip.o wchar.o encnames.o \
!       $(filter crypt.o getaddrinfo.o inet_aton.o snprintf.o strerror.o path.o thread.o, $(LIBOBJS))


  # Add libraries that libpq depends (or might depend) on into the
--- 23,29 ----
  OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \
        fe-protocol2.o fe-protocol3.o pqexpbuffer.o pqsignal.o fe-secure.o \
        dllist.o md5.o ip.o wchar.o encnames.o \
!       $(filter crypt.o getaddrinfo.o inet_aton.o snprintf.o sprompt.o strerror.o path.o thread.o, $(LIBOBJS))


  # Add libraries that libpq depends (or might depend) on into the
***************
*** 46,52 ****
  # For port modules, this only happens if configure decides the module
  # is needed (see filter hack in OBJS, above).

! crypt.c getaddrinfo.c inet_aton.c snprintf.c strerror.c path.c thread.c: % : $(top_srcdir)/src/port/%
      rm -f $@ && $(LN_S) $< .

  md5.c ip.c: % : $(backend_src)/libpq/%
--- 46,52 ----
  # For port modules, this only happens if configure decides the module
  # is needed (see filter hack in OBJS, above).

! crypt.c getaddrinfo.c inet_aton.c snprintf.c sprompt.c strerror.c path.c thread.c: % : $(top_srcdir)/src/port/%
      rm -f $@ && $(LN_S) $< .

  md5.c ip.c: % : $(backend_src)/libpq/%

Re: Moved simple_prompt()/sprompt.c

От
Peter Eisentraut
Дата:
Bruce Momjian writes:

> If a file is needed by three non-backend directories, /port seems to be
> the proper place for it.

src/port is intended for replacement implementations of standard library
functions.  If we make it an "everything that is used in more than one
place" directory, we should be very clear about that strategy.  Else,
src/utils might be a better place.

-- 
Peter Eisentraut   peter_e@gmx.net


Re: Moved simple_prompt()/sprompt.c

От
Tom Lane
Дата:
Peter Eisentraut <peter_e@gmx.net> writes:
> Bruce Momjian writes:
>> If a file is needed by three non-backend directories, /port seems to be
>> the proper place for it.

> src/port is intended for replacement implementations of standard library
> functions.

I concur, src/port is *not* the right place.  src/port is for stuff that
is platform-dependent.
        regards, tom lane


Re: Moved simple_prompt()/sprompt.c

От
Bruce Momjian
Дата:
Tom Lane wrote:
> Peter Eisentraut <peter_e@gmx.net> writes:
> > Bruce Momjian writes:
> >> If a file is needed by three non-backend directories, /port seems to be
> >> the proper place for it.
> 
> > src/port is intended for replacement implementations of standard library
> > functions.
> 
> I concur, src/port is *not* the right place.  src/port is for stuff that
> is platform-dependent.

Yes, thread.c, path.c, and sprompt.c should be in utils, but how do I do
that?  Utils seems to be a place things are pulled from, rather than a
library that goes with every link.

Is it worth creating another library that acts just like /port but is
called utils, or should we just rename the directory to portutils?

I am looking to move fmtId() over to port too so psql can use it.  It is
already used by pg_dump, and /scripts.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073
 


Re: Moved simple_prompt()/sprompt.c

От
Tom Lane
Дата:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> Yes, thread.c, path.c, and sprompt.c should be in utils, but how do I do
> that?  Utils seems to be a place things are pulled from, rather than a
> library that goes with every link.

> Is it worth creating another library that acts just like /port but is
> called utils, or should we just rename the directory to portutils?

path.c is arguably okay material for /port, since it is dealing with
platform-to-platform variations.

sprompt.c is only going to be used by stuff under src/bin.  I wonder if
we should create a src/bin/utils directory.

Not sure about thread.c --- perhaps we could just dump it into libpq.
(libpq requires it anyway, no?  So why not export it from there and let
the apps atop libpq use the same instance.)

> I am looking to move fmtId() over to port too so psql can use it.  It is
> already used by pg_dump, and /scripts.

That's definitely not port/ material.  A src/bin/utils/ directory would
make sense for it though.
        regards, tom lane


Re: Moved simple_prompt()/sprompt.c

От
Bruce Momjian
Дата:
Tom Lane wrote:
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > Yes, thread.c, path.c, and sprompt.c should be in utils, but how do I do
> > that?  Utils seems to be a place things are pulled from, rather than a
> > library that goes with every link.
> 
> > Is it worth creating another library that acts just like /port but is
> > called utils, or should we just rename the directory to portutils?
> 
> path.c is arguably okay material for /port, since it is dealing with
> platform-to-platform variations.
> 
> sprompt.c is only going to be used by stuff under src/bin.  I wonder if
> we should create a src/bin/utils directory.

I found it used by two contrib modules.  I just removed the old
duplicate code because they are already linking with pgport.  For this
reason, src/bin/utils is looking worse, so perhaps we should be looking
at /utils and creating a libpgutils library like pgport for 7.5.

> Not sure about thread.c --- perhaps we could just dump it into libpq.
> (libpq requires it anyway, no?  So why not export it from there and let
> the apps atop libpq use the same instance.)

Yes, libpq would probably be best until we find someone else who needs
it.

> > I am looking to move fmtId() over to port too so psql can use it.  It is
> > already used by pg_dump, and /scripts.
> 
> That's definitely not port/ material.  A src/bin/utils/ directory would
> make sense for it though.

I am thinking of just leaving fmtId() in /pg_dump and symlinking from
there as /scripts does.  It is pretty specific.  fmtId() actually links
in /src/backend/parser/keywords.o, so it is a really wild function.  If
we put fmtId() in a library, we would need to put keywords.o in there
too, and that is just too weird, and a dependency mess.

--  Bruce Momjian                        |  http://candle.pha.pa.us pgman@candle.pha.pa.us               |  (610)
359-1001+  If your life is a hard drive,     |  13 Roberts Road +  Christ can be your backup.        |  Newtown Square,
Pennsylvania19073