Commit 588d963b authored by Tom Lane's avatar Tom Lane

Create src/fe_utils/, and move stuff into there from pg_dump's dumputils.

Per discussion, we want to create a static library and put the stuff into
it that until now has been shared across src/bin/ directories by ad-hoc
methods like symlinking a source file.  This commit creates the library and
populates it with a couple of files that contain the widely-useful portions
of pg_dump's dumputils.c file.  dumputils.c survives, because it has some
stuff that didn't seem appropriate for fe_utils, but it's significantly
smaller and is no longer referenced from any other directory.

Follow-on patches will move more stuff into fe_utils.

The Mkvcbuild.pm hacking here is just a best guess; we'll see how the
buildfarm likes it.
parent a596db33
...@@ -22,6 +22,7 @@ SUBDIRS = \ ...@@ -22,6 +22,7 @@ SUBDIRS = \
include \ include \
interfaces \ interfaces \
backend/replication/libpqwalreceiver \ backend/replication/libpqwalreceiver \
fe_utils \
bin \ bin \
pl \ pl \
makefiles \ makefiles \
......
...@@ -501,7 +501,12 @@ submake-libpgport: ...@@ -501,7 +501,12 @@ submake-libpgport:
$(MAKE) -C $(top_builddir)/src/port all $(MAKE) -C $(top_builddir)/src/port all
$(MAKE) -C $(top_builddir)/src/common all $(MAKE) -C $(top_builddir)/src/common all
.PHONY: submake-libpq submake-libpgport submake-libpgfeutils:
$(MAKE) -C $(top_builddir)/src/port all
$(MAKE) -C $(top_builddir)/src/common all
$(MAKE) -C $(top_builddir)/src/fe_utils all
.PHONY: submake-libpq submake-libpgport submake-libpgfeutils
########################################################################## ##########################################################################
......
...@@ -17,6 +17,7 @@ top_builddir = ../../.. ...@@ -17,6 +17,7 @@ top_builddir = ../../..
include $(top_builddir)/src/Makefile.global include $(top_builddir)/src/Makefile.global
override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS) override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
LDFLAGS += -L$(top_builddir)/src/fe_utils -lpgfeutils
OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \ OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \
pg_backup_null.o pg_backup_tar.o pg_backup_directory.o \ pg_backup_null.o pg_backup_tar.o pg_backup_directory.o \
...@@ -24,13 +25,13 @@ OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \ ...@@ -24,13 +25,13 @@ OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \
all: pg_dump pg_restore pg_dumpall all: pg_dump pg_restore pg_dumpall
pg_dump: pg_dump.o common.o pg_dump_sort.o $(OBJS) | submake-libpq submake-libpgport pg_dump: pg_dump.o common.o pg_dump_sort.o $(OBJS) | submake-libpq submake-libpgport submake-libpgfeutils
$(CC) $(CFLAGS) pg_dump.o common.o pg_dump_sort.o $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X) $(CC) $(CFLAGS) pg_dump.o common.o pg_dump_sort.o $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
pg_restore: pg_restore.o $(OBJS) | submake-libpq submake-libpgport pg_restore: pg_restore.o $(OBJS) | submake-libpq submake-libpgport submake-libpgfeutils
$(CC) $(CFLAGS) pg_restore.o $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X) $(CC) $(CFLAGS) pg_restore.o $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
pg_dumpall: pg_dumpall.o dumputils.o | submake-libpq submake-libpgport pg_dumpall: pg_dumpall.o dumputils.o | submake-libpq submake-libpgport submake-libpgfeutils
$(CC) $(CFLAGS) pg_dumpall.o dumputils.o $(WIN32RES) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X) $(CC) $(CFLAGS) pg_dumpall.o dumputils.o $(WIN32RES) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
install: all installdirs install: all installdirs
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <ctype.h> #include <ctype.h>
#include "catalog/pg_class.h" #include "catalog/pg_class.h"
#include "fe_utils/string_utils.h"
/* /*
...@@ -992,37 +993,3 @@ strInArray(const char *pattern, char **arr, int arr_size) ...@@ -992,37 +993,3 @@ strInArray(const char *pattern, char **arr, int arr_size)
} }
return -1; return -1;
} }
/*
* Support for simple list operations
*/
void
simple_oid_list_append(SimpleOidList *list, Oid val)
{
SimpleOidListCell *cell;
cell = (SimpleOidListCell *) pg_malloc(sizeof(SimpleOidListCell));
cell->next = NULL;
cell->val = val;
if (list->tail)
list->tail->next = cell;
else
list->head = cell;
list->tail = cell;
}
bool
simple_oid_list_member(SimpleOidList *list, Oid val)
{
SimpleOidListCell *cell;
for (cell = list->head; cell; cell = cell->next)
{
if (cell->val == val)
return true;
}
return false;
}
This diff is collapsed.
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* Utility routines for SQL dumping * Utility routines for SQL dumping
*
* Basically this is stuff that is useful in both pg_dump and pg_dumpall. * Basically this is stuff that is useful in both pg_dump and pg_dumpall.
* Lately it's also being used by psql and bin/scripts/ ...
* *
* *
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
...@@ -18,39 +18,6 @@ ...@@ -18,39 +18,6 @@
#include "libpq-fe.h" #include "libpq-fe.h"
#include "pqexpbuffer.h" #include "pqexpbuffer.h"
/*
* Data structures for simple lists of OIDs and strings. The support for
* these is very primitive compared to the backend's List facilities, but
* it's all we need in pg_dump.
*/
typedef struct SimpleOidListCell
{
struct SimpleOidListCell *next;
Oid val;
} SimpleOidListCell;
typedef struct SimpleOidList
{
SimpleOidListCell *head;
SimpleOidListCell *tail;
} SimpleOidList;
typedef struct SimpleStringListCell
{
struct SimpleStringListCell *next;
bool touched; /* true, when this string was searched and
* touched */
char val[FLEXIBLE_ARRAY_MEMBER]; /* null-terminated string here */
} SimpleStringListCell;
typedef struct SimpleStringList
{
SimpleStringListCell *head;
SimpleStringListCell *tail;
} SimpleStringList;
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
/* /*
* Preferred strftime(3) format specifier for printing timestamps in pg_dump * Preferred strftime(3) format specifier for printing timestamps in pg_dump
* and friends. * and friends.
...@@ -68,22 +35,7 @@ typedef struct SimpleStringList ...@@ -68,22 +35,7 @@ typedef struct SimpleStringList
#define PGDUMP_STRFTIME_FMT "%Y-%m-%d %H:%M:%S" #define PGDUMP_STRFTIME_FMT "%Y-%m-%d %H:%M:%S"
#endif #endif
extern int quote_all_identifiers;
extern PQExpBuffer (*getLocalPQExpBuffer) (void);
extern const char *fmtId(const char *identifier);
extern const char *fmtQualifiedId(int remoteVersion,
const char *schema, const char *id);
extern void appendStringLiteral(PQExpBuffer buf, const char *str,
int encoding, bool std_strings);
extern void appendStringLiteralConn(PQExpBuffer buf, const char *str,
PGconn *conn);
extern void appendStringLiteralDQ(PQExpBuffer buf, const char *str,
const char *dqprefix);
extern void appendByteaLiteral(PQExpBuffer buf,
const unsigned char *str, size_t length,
bool std_strings);
extern bool parsePGArray(const char *atext, char ***itemarray, int *nitems);
extern bool buildACLCommands(const char *name, const char *subname, extern bool buildACLCommands(const char *name, const char *subname,
const char *type, const char *acls, const char *owner, const char *type, const char *acls, const char *owner,
const char *prefix, int remoteVersion, const char *prefix, int remoteVersion,
...@@ -92,20 +44,9 @@ extern bool buildDefaultACLCommands(const char *type, const char *nspname, ...@@ -92,20 +44,9 @@ extern bool buildDefaultACLCommands(const char *type, const char *nspname,
const char *acls, const char *owner, const char *acls, const char *owner,
int remoteVersion, int remoteVersion,
PQExpBuffer sql); PQExpBuffer sql);
extern bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf,
const char *pattern,
bool have_where, bool force_escape,
const char *schemavar, const char *namevar,
const char *altnamevar, const char *visibilityrule);
extern void buildShSecLabelQuery(PGconn *conn, const char *catalog_name, extern void buildShSecLabelQuery(PGconn *conn, const char *catalog_name,
uint32 objectId, PQExpBuffer sql); uint32 objectId, PQExpBuffer sql);
extern void emitShSecLabels(PGconn *conn, PGresult *res, extern void emitShSecLabels(PGconn *conn, PGresult *res,
PQExpBuffer buffer, const char *target, const char *objname); PQExpBuffer buffer, const char *target, const char *objname);
extern void set_dump_section(const char *arg, int *dumpSections);
extern void simple_string_list_append(SimpleStringList *list, const char *val);
extern bool simple_string_list_member(SimpleStringList *list, const char *val);
extern const char *simple_string_list_not_touched(SimpleStringList *list);
#endif /* DUMPUTILS_H */ #endif /* DUMPUTILS_H */
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "parallel.h" #include "parallel.h"
#include "pg_backup_utils.h" #include "pg_backup_utils.h"
#include "fe_utils/string_utils.h"
#ifndef WIN32 #ifndef WIN32
#include <sys/types.h> #include <sys/types.h>
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#ifndef PG_BACKUP_H #ifndef PG_BACKUP_H
#define PG_BACKUP_H #define PG_BACKUP_H
#include "dumputils.h" #include "fe_utils/simple_list.h"
#include "libpq-fe.h" #include "libpq-fe.h"
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include "pg_backup_archiver.h" #include "pg_backup_archiver.h"
#include "pg_backup_db.h" #include "pg_backup_db.h"
#include "pg_backup_utils.h" #include "pg_backup_utils.h"
#include "dumputils.h"
#include "fe_utils/string_utils.h"
#include <ctype.h> #include <ctype.h>
#include <fcntl.h> #include <fcntl.h>
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "pg_backup_archiver.h" #include "pg_backup_archiver.h"
#include "pg_backup_utils.h" #include "pg_backup_utils.h"
#include "fe_utils/string_utils.h"
#include "libpq/libpq-fs.h" #include "libpq/libpq-fs.h"
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "pg_backup_tar.h" #include "pg_backup_tar.h"
#include "pg_backup_utils.h" #include "pg_backup_utils.h"
#include "pgtar.h" #include "pgtar.h"
#include "fe_utils/string_utils.h"
#include <sys/stat.h> #include <sys/stat.h>
#include <ctype.h> #include <ctype.h>
......
...@@ -61,6 +61,7 @@ ...@@ -61,6 +61,7 @@
#include "pg_backup_db.h" #include "pg_backup_db.h"
#include "pg_backup_utils.h" #include "pg_backup_utils.h"
#include "pg_dump.h" #include "pg_dump.h"
#include "fe_utils/string_utils.h"
typedef struct typedef struct
......
...@@ -536,9 +536,6 @@ extern ExtensionInfo *findExtensionByOid(Oid oid); ...@@ -536,9 +536,6 @@ extern ExtensionInfo *findExtensionByOid(Oid oid);
extern void setExtensionMembership(ExtensionMemberId *extmems, int nextmems); extern void setExtensionMembership(ExtensionMemberId *extmems, int nextmems);
extern ExtensionInfo *findOwningExtension(CatalogId catalogId); extern ExtensionInfo *findOwningExtension(CatalogId catalogId);
extern void simple_oid_list_append(SimpleOidList *list, Oid val);
extern bool simple_oid_list_member(SimpleOidList *list, Oid val);
extern void parseOidArray(const char *str, Oid *array, int arraysize); extern void parseOidArray(const char *str, Oid *array, int arraysize);
extern void sortDumpableObjects(DumpableObject **objs, int numObjs, extern void sortDumpableObjects(DumpableObject **objs, int numObjs,
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "dumputils.h" #include "dumputils.h"
#include "pg_backup.h" #include "pg_backup.h"
#include "fe_utils/string_utils.h"
/* version string we expect back from pg_dump */ /* version string we expect back from pg_dump */
#define PGDUMP_VERSIONSTR "pg_dump (PostgreSQL) " PG_VERSION "\n" #define PGDUMP_VERSIONSTR "pg_dump (PostgreSQL) " PG_VERSION "\n"
......
...@@ -2,6 +2,5 @@ ...@@ -2,6 +2,5 @@
/psqlscanslash.c /psqlscanslash.c
/sql_help.h /sql_help.h
/sql_help.c /sql_help.c
/dumputils.c
/psql /psql
...@@ -18,25 +18,23 @@ include $(top_builddir)/src/Makefile.global ...@@ -18,25 +18,23 @@ include $(top_builddir)/src/Makefile.global
REFDOCDIR= $(top_srcdir)/doc/src/sgml/ref REFDOCDIR= $(top_srcdir)/doc/src/sgml/ref
override CPPFLAGS := -I. -I$(srcdir) -I$(libpq_srcdir) -I$(top_srcdir)/src/bin/pg_dump $(CPPFLAGS) override CPPFLAGS := -I. -I$(srcdir) -I$(libpq_srcdir) $(CPPFLAGS)
LDFLAGS += -L$(top_builddir)/src/fe_utils -lpgfeutils
OBJS= command.o common.o help.o input.o stringutils.o mainloop.o copy.o \ 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 \ startup.o prompt.o variables.o large_obj.o print.o describe.o \
tab-complete.o mbprint.o dumputils.o \ tab-complete.o mbprint.o \
sql_help.o psqlscan.o psqlscanslash.o \ sql_help.o psqlscan.o psqlscanslash.o \
$(WIN32RES) $(WIN32RES)
all: psql all: psql
psql: $(OBJS) | submake-libpq submake-libpgport psql: $(OBJS) | submake-libpq submake-libpgport submake-libpgfeutils
$(CC) $(CFLAGS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X) $(CC) $(CFLAGS) $(OBJS) $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
help.o: sql_help.h help.o: sql_help.h
dumputils.c: % : $(top_srcdir)/src/bin/pg_dump/%
rm -f $@ && $(LN_S) $< .
sql_help.c: sql_help.h ; sql_help.c: sql_help.h ;
sql_help.h: create_help.pl $(wildcard $(REFDOCDIR)/*.sgml) sql_help.h: create_help.pl $(wildcard $(REFDOCDIR)/*.sgml)
$(PERL) $< $(REFDOCDIR) $* $(PERL) $< $(REFDOCDIR) $*
...@@ -67,7 +65,7 @@ uninstall: ...@@ -67,7 +65,7 @@ uninstall:
rm -f '$(DESTDIR)$(bindir)/psql$(X)' '$(DESTDIR)$(datadir)/psqlrc.sample' rm -f '$(DESTDIR)$(bindir)/psql$(X)' '$(DESTDIR)$(datadir)/psqlrc.sample'
clean distclean: clean distclean:
rm -f psql$(X) $(OBJS) dumputils.c lex.backup rm -f psql$(X) $(OBJS) lex.backup
# files removed here are supposed to be in the distribution tarball, # files removed here are supposed to be in the distribution tarball,
# so do not clean them in the clean/distclean rules # so do not clean them in the clean/distclean rules
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include "libpq-fe.h" #include "libpq-fe.h"
#include "pqexpbuffer.h" #include "pqexpbuffer.h"
#include "dumputils.h" #include "fe_utils/string_utils.h"
#include "common.h" #include "common.h"
#include "copy.h" #include "copy.h"
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "libpq-fe.h" #include "libpq-fe.h"
#include "pqexpbuffer.h" #include "pqexpbuffer.h"
#include "dumputils.h"
#include "settings.h" #include "settings.h"
#include "common.h" #include "common.h"
......
...@@ -15,10 +15,10 @@ ...@@ -15,10 +15,10 @@
#include <ctype.h> #include <ctype.h>
#include "catalog/pg_default_acl.h" #include "catalog/pg_default_acl.h"
#include "fe_utils/string_utils.h"
#include "common.h" #include "common.h"
#include "describe.h" #include "describe.h"
#include "dumputils.h"
#include "mbprint.h" #include "mbprint.h"
#include "print.h" #include "print.h"
#include "settings.h" #include "settings.h"
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
/vacuumdb /vacuumdb
/pg_isready /pg_isready
/dumputils.c
/mbprint.c /mbprint.c
/print.c /print.c
......
...@@ -18,27 +18,25 @@ include $(top_builddir)/src/Makefile.global ...@@ -18,27 +18,25 @@ include $(top_builddir)/src/Makefile.global
PROGRAMS = createdb createlang createuser dropdb droplang dropuser clusterdb vacuumdb reindexdb pg_isready PROGRAMS = createdb createlang createuser dropdb droplang dropuser clusterdb vacuumdb reindexdb pg_isready
override CPPFLAGS := -I$(top_srcdir)/src/bin/pg_dump -I$(top_srcdir)/src/bin/psql -I$(libpq_srcdir) $(CPPFLAGS) override CPPFLAGS := -I$(top_srcdir)/src/bin/psql -I$(libpq_srcdir) $(CPPFLAGS)
LDFLAGS += -L$(top_builddir)/src/fe_utils -lpgfeutils
all: $(PROGRAMS) all: $(PROGRAMS)
%: %.o $(WIN32RES) %: %.o $(WIN32RES)
$(CC) $(CFLAGS) $^ $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X) $(CC) $(CFLAGS) $^ $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
createdb: createdb.o common.o dumputils.o | submake-libpq submake-libpgport createdb: createdb.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
createlang: createlang.o common.o print.o mbprint.o | submake-libpq submake-libpgport createlang: createlang.o common.o print.o mbprint.o | submake-libpq submake-libpgport
createuser: createuser.o common.o dumputils.o | submake-libpq submake-libpgport createuser: createuser.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
dropdb: dropdb.o common.o dumputils.o | submake-libpq submake-libpgport dropdb: dropdb.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
droplang: droplang.o common.o print.o mbprint.o | submake-libpq submake-libpgport droplang: droplang.o common.o print.o mbprint.o | submake-libpq submake-libpgport
dropuser: dropuser.o common.o dumputils.o | submake-libpq submake-libpgport dropuser: dropuser.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
clusterdb: clusterdb.o common.o dumputils.o | submake-libpq submake-libpgport clusterdb: clusterdb.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
vacuumdb: vacuumdb.o common.o dumputils.o | submake-libpq submake-libpgport vacuumdb: vacuumdb.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
reindexdb: reindexdb.o common.o dumputils.o | submake-libpq submake-libpgport reindexdb: reindexdb.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
pg_isready: pg_isready.o common.o | submake-libpq submake-libpgport pg_isready: pg_isready.o common.o | submake-libpq submake-libpgport
dumputils.c: % : $(top_srcdir)/src/bin/pg_dump/%
rm -f $@ && $(LN_S) $< .
print.c mbprint.c : % : $(top_srcdir)/src/bin/psql/% print.c mbprint.c : % : $(top_srcdir)/src/bin/psql/%
rm -f $@ && $(LN_S) $< . rm -f $@ && $(LN_S) $< .
...@@ -62,8 +60,8 @@ uninstall: ...@@ -62,8 +60,8 @@ uninstall:
clean distclean maintainer-clean: clean distclean maintainer-clean:
rm -f $(addsuffix $(X), $(PROGRAMS)) $(addsuffix .o, $(PROGRAMS)) rm -f $(addsuffix $(X), $(PROGRAMS)) $(addsuffix .o, $(PROGRAMS))
rm -f common.o dumputils.o print.o mbprint.o $(WIN32RES) rm -f common.o print.o mbprint.o $(WIN32RES)
rm -f dumputils.c print.c mbprint.c rm -f print.c mbprint.c
rm -rf tmp_check rm -rf tmp_check
check: check:
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "postgres_fe.h" #include "postgres_fe.h"
#include "common.h" #include "common.h"
#include "dumputils.h" #include "fe_utils/simple_list.h"
static void cluster_one_database(const char *dbname, bool verbose, const char *table, static void cluster_one_database(const char *dbname, bool verbose, const char *table,
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "postgres_fe.h" #include "postgres_fe.h"
#include "common.h" #include "common.h"
#include "dumputils.h" #include "fe_utils/string_utils.h"
static void help(const char *progname); static void help(const char *progname);
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
#include "postgres_fe.h" #include "postgres_fe.h"
#include "common.h" #include "common.h"
#include "dumputils.h" #include "fe_utils/simple_list.h"
#include "fe_utils/string_utils.h"
static void help(const char *progname); static void help(const char *progname);
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "postgres_fe.h" #include "postgres_fe.h"
#include "common.h" #include "common.h"
#include "dumputils.h" #include "fe_utils/string_utils.h"
static void help(const char *progname); static void help(const char *progname);
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "postgres_fe.h" #include "postgres_fe.h"
#include "common.h" #include "common.h"
#include "dumputils.h" #include "fe_utils/string_utils.h"
static void help(const char *progname); static void help(const char *progname);
......
...@@ -11,7 +11,8 @@ ...@@ -11,7 +11,8 @@
#include "postgres_fe.h" #include "postgres_fe.h"
#include "common.h" #include "common.h"
#include "dumputils.h" #include "fe_utils/simple_list.h"
#include "fe_utils/string_utils.h"
static void reindex_one_database(const char *name, const char *dbname, static void reindex_one_database(const char *name, const char *dbname,
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
#include "postgres_fe.h" #include "postgres_fe.h"
#include "common.h" #include "common.h"
#include "dumputils.h" #include "fe_utils/simple_list.h"
#include "fe_utils/string_utils.h"
#define ERRCODE_UNDEFINED_TABLE "42P01" #define ERRCODE_UNDEFINED_TABLE "42P01"
......
#-------------------------------------------------------------------------
#
# Makefile
# Makefile for src/fe_utils
#
# This makefile generates a static library, libpgfeutils.a,
# for use by client applications
#
# IDENTIFICATION
# src/fe_utils/Makefile
#
#-------------------------------------------------------------------------
subdir = src/fe_utils
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
override CPPFLAGS := -DFRONTEND -I$(libpq_srcdir) $(CPPFLAGS)
OBJS = simple_list.o string_utils.o
all: libpgfeutils.a
libpgfeutils.a: $(OBJS)
rm -f $@
$(AR) $(AROPT) $@ $^
# libpgfeutils could be useful to contrib, so install it
install: all installdirs
$(INSTALL_STLIB) libpgfeutils.a '$(DESTDIR)$(libdir)/libpgfeutils.a'
installdirs:
$(MKDIR_P) '$(DESTDIR)$(libdir)'
uninstall:
rm -f '$(DESTDIR)$(libdir)/libpgfeutils.a'
clean distclean maintainer-clean:
rm -f libpgfeutils.a $(OBJS)
/*-------------------------------------------------------------------------
*
* Simple list facilities for frontend code
*
* Data structures for simple lists of OIDs and strings. The support for
* these is very primitive compared to the backend's List facilities, but
* it's all we need in, eg, pg_dump.
*
*
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/fe_utils/simple_list.c
*
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include "fe_utils/simple_list.h"
/*
* Append an OID to the list.
*/
void
simple_oid_list_append(SimpleOidList *list, Oid val)
{
SimpleOidListCell *cell;
cell = (SimpleOidListCell *) pg_malloc(sizeof(SimpleOidListCell));
cell->next = NULL;
cell->val = val;
if (list->tail)
list->tail->next = cell;
else
list->head = cell;
list->tail = cell;
}
/*
* Is OID present in the list?
*/
bool
simple_oid_list_member(SimpleOidList *list, Oid val)
{
SimpleOidListCell *cell;
for (cell = list->head; cell; cell = cell->next)
{
if (cell->val == val)
return true;
}
return false;
}
/*
* Append a string to the list.
*
* The given string is copied, so it need not survive past the call.
*/
void
simple_string_list_append(SimpleStringList *list, const char *val)
{
SimpleStringListCell *cell;
cell = (SimpleStringListCell *)
pg_malloc(offsetof(SimpleStringListCell, val) +strlen(val) + 1);
cell->next = NULL;
cell->touched = false;
strcpy(cell->val, val);
if (list->tail)
list->tail->next = cell;
else
list->head = cell;
list->tail = cell;
}
/*
* Is string present in the list?
*
* If found, the "touched" field of the first match is set true.
*/
bool
simple_string_list_member(SimpleStringList *list, const char *val)
{
SimpleStringListCell *cell;
for (cell = list->head; cell; cell = cell->next)
{
if (strcmp(cell->val, val) == 0)
{
cell->touched = true;
return true;
}
}
return false;
}
/*
* Find first not-touched list entry, if there is one.
*/
const char *
simple_string_list_not_touched(SimpleStringList *list)
{
SimpleStringListCell *cell;
for (cell = list->head; cell; cell = cell->next)
{
if (!cell->touched)
return cell->val;
}
return NULL;
}
This diff is collapsed.
...@@ -16,8 +16,9 @@ include $(top_builddir)/src/Makefile.global ...@@ -16,8 +16,9 @@ include $(top_builddir)/src/Makefile.global
all: pg_config.h pg_config_ext.h pg_config_os.h all: pg_config.h pg_config_ext.h pg_config_os.h
# Subdirectories containing headers for server-side dev # Subdirectories containing installable headers
SUBDIRS = access bootstrap catalog commands common datatype executor foreign \ SUBDIRS = access bootstrap catalog commands common datatype \
executor fe_utils foreign \
lib libpq mb nodes optimizer parser postmaster regex replication \ lib libpq mb nodes optimizer parser postmaster regex replication \
rewrite storage tcop snowball snowball/libstemmer tsearch \ rewrite storage tcop snowball snowball/libstemmer tsearch \
tsearch/dicts utils port port/atomics port/win32 port/win32_msvc \ tsearch/dicts utils port port/atomics port/win32 port/win32_msvc \
......
/*-------------------------------------------------------------------------
*
* Simple list facilities for frontend code
*
* Data structures for simple lists of OIDs and strings. The support for
* these is very primitive compared to the backend's List facilities, but
* it's all we need in, eg, pg_dump.
*
*
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/fe_utils/simple_list.h
*
*-------------------------------------------------------------------------
*/
#ifndef SIMPLE_LIST_H
#define SIMPLE_LIST_H
typedef struct SimpleOidListCell
{
struct SimpleOidListCell *next;
Oid val;
} SimpleOidListCell;
typedef struct SimpleOidList
{
SimpleOidListCell *head;
SimpleOidListCell *tail;
} SimpleOidList;
typedef struct SimpleStringListCell
{
struct SimpleStringListCell *next;
bool touched; /* true, when this string was searched and
* touched */
char val[FLEXIBLE_ARRAY_MEMBER]; /* null-terminated string here */
} SimpleStringListCell;
typedef struct SimpleStringList
{
SimpleStringListCell *head;
SimpleStringListCell *tail;
} SimpleStringList;
extern void simple_oid_list_append(SimpleOidList *list, Oid val);
extern bool simple_oid_list_member(SimpleOidList *list, Oid val);
extern void simple_string_list_append(SimpleStringList *list, const char *val);
extern bool simple_string_list_member(SimpleStringList *list, const char *val);
extern const char *simple_string_list_not_touched(SimpleStringList *list);
#endif /* SIMPLE_LIST_H */
/*-------------------------------------------------------------------------
*
* String-processing utility routines for frontend code
*
* Assorted utility functions that are useful in constructing SQL queries
* and interpreting backend output.
*
*
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/fe_utils/string_utils.h
*
*-------------------------------------------------------------------------
*/
#ifndef STRING_UTILS_H
#define STRING_UTILS_H
#include "libpq-fe.h"
#include "pqexpbuffer.h"
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
/* Global variables controlling behavior of fmtId() and fmtQualifiedId() */
extern int quote_all_identifiers;
extern PQExpBuffer (*getLocalPQExpBuffer) (void);
/* Functions */
extern const char *fmtId(const char *identifier);
extern const char *fmtQualifiedId(int remoteVersion,
const char *schema, const char *id);
extern void appendStringLiteral(PQExpBuffer buf, const char *str,
int encoding, bool std_strings);
extern void appendStringLiteralConn(PQExpBuffer buf, const char *str,
PGconn *conn);
extern void appendStringLiteralDQ(PQExpBuffer buf, const char *str,
const char *dqprefix);
extern void appendByteaLiteral(PQExpBuffer buf,
const unsigned char *str, size_t length,
bool std_strings);
extern bool parsePGArray(const char *atext, char ***itemarray, int *nitems);
extern bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf,
const char *pattern,
bool have_where, bool force_escape,
const char *schemavar, const char *namevar,
const char *altnamevar, const char *visibilityrule);
#endif /* STRING_UTILS_H */
...@@ -25,6 +25,7 @@ our (@ISA, @EXPORT_OK); ...@@ -25,6 +25,7 @@ our (@ISA, @EXPORT_OK);
my $solution; my $solution;
my $libpgport; my $libpgport;
my $libpgcommon; my $libpgcommon;
my $libpgfeutils;
my $postgres; my $postgres;
my $libpq; my $libpq;
...@@ -62,7 +63,7 @@ my $frontend_extralibs = { ...@@ -62,7 +63,7 @@ my $frontend_extralibs = {
'psql' => ['ws2_32.lib'] }; 'psql' => ['ws2_32.lib'] };
my $frontend_extraincludes = { my $frontend_extraincludes = {
'initdb' => ['src/timezone'], 'initdb' => ['src/timezone'],
'psql' => [ 'src/bin/pg_dump', 'src/backend' ], 'psql' => [ 'src/backend' ],
'pgbench' => [ 'src/bin/psql' ] }; 'pgbench' => [ 'src/bin/psql' ] };
my $frontend_extrasource = { my $frontend_extrasource = {
'psql' => ['src/bin/psql/psqlscan.l', 'src/bin/psql/psqlscanslash.l'], 'psql' => ['src/bin/psql/psqlscan.l', 'src/bin/psql/psqlscanslash.l'],
...@@ -118,6 +119,9 @@ sub mkvcbuild ...@@ -118,6 +119,9 @@ sub mkvcbuild
our @pgcommonbkndfiles = @pgcommonallfiles; our @pgcommonbkndfiles = @pgcommonallfiles;
our @pgfeutilsfiles = qw(
simple_list.c string_utils.c);
$libpgport = $solution->AddProject('libpgport', 'lib', 'misc'); $libpgport = $solution->AddProject('libpgport', 'lib', 'misc');
$libpgport->AddDefine('FRONTEND'); $libpgport->AddDefine('FRONTEND');
$libpgport->AddFiles('src/port', @pgportfiles); $libpgport->AddFiles('src/port', @pgportfiles);
...@@ -126,6 +130,10 @@ sub mkvcbuild ...@@ -126,6 +130,10 @@ sub mkvcbuild
$libpgcommon->AddDefine('FRONTEND'); $libpgcommon->AddDefine('FRONTEND');
$libpgcommon->AddFiles('src/common', @pgcommonfrontendfiles); $libpgcommon->AddFiles('src/common', @pgcommonfrontendfiles);
$libpgfeutils = $solution->AddProject('libpgfeutils', 'lib', 'misc');
$libpgfeutils->AddDefine('FRONTEND');
$libpgfeutils->AddFiles('src/fe_utils', @pgfeutilsfiles);
$postgres = $solution->AddProject('postgres', 'exe', '', 'src/backend'); $postgres = $solution->AddProject('postgres', 'exe', '', 'src/backend');
$postgres->AddIncludeDir('src/backend'); $postgres->AddIncludeDir('src/backend');
$postgres->AddDir('src/backend/port/win32'); $postgres->AddDir('src/backend/port/win32');
...@@ -613,11 +621,7 @@ sub mkvcbuild ...@@ -613,11 +621,7 @@ sub mkvcbuild
foreach my $f (@files) foreach my $f (@files)
{ {
$f =~ s/\.o$/\.c/; $f =~ s/\.o$/\.c/;
if ($f eq 'dumputils.c') if ($f =~ /print\.c$/)
{
$proj->AddFile('src/bin/pg_dump/dumputils.c');
}
elsif ($f =~ /print\.c$/)
{ # Also catches mbprint.c { # Also catches mbprint.c
$proj->AddFile('src/bin/psql/' . $f); $proj->AddFile('src/bin/psql/' . $f);
} }
...@@ -627,9 +631,9 @@ sub mkvcbuild ...@@ -627,9 +631,9 @@ sub mkvcbuild
} }
} }
$proj->AddIncludeDir('src/interfaces/libpq'); $proj->AddIncludeDir('src/interfaces/libpq');
$proj->AddIncludeDir('src/bin/pg_dump');
$proj->AddIncludeDir('src/bin/psql'); $proj->AddIncludeDir('src/bin/psql');
$proj->AddReference($libpq, $libpgcommon, $libpgport); $proj->AddReference($libpq, $libpgfeutils, $libpgcommon,
$libpgport);
$proj->AddDirResourceFile('src/bin/scripts'); $proj->AddDirResourceFile('src/bin/scripts');
$proj->AddLibrary('ws2_32.lib'); $proj->AddLibrary('ws2_32.lib');
} }
...@@ -680,7 +684,7 @@ sub AddSimpleFrontend ...@@ -680,7 +684,7 @@ sub AddSimpleFrontend
my $p = $solution->AddProject($n, 'exe', 'bin'); my $p = $solution->AddProject($n, 'exe', 'bin');
$p->AddDir('src/bin/' . $n); $p->AddDir('src/bin/' . $n);
$p->AddReference($libpgcommon, $libpgport); $p->AddReference($libpgfeutils, $libpgcommon, $libpgport);
if ($uselibpq) if ($uselibpq)
{ {
$p->AddIncludeDir('src/interfaces/libpq'); $p->AddIncludeDir('src/interfaces/libpq');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment