Just turning the crank ...
LDFLAGS += -L$(top_builddir)/src/fe_utils -lpgfeutils
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 \
+ startup.o prompt.o variables.o large_obj.o describe.o \
+ tab-complete.o \
sql_help.o psqlscan.o psqlscanslash.o \
$(WIN32RES)
#include "input.h"
#include "large_obj.h"
#include "mainloop.h"
-#include "print.h"
+#include "fe_utils/print.h"
#include "psqlscanslash.h"
#include "settings.h"
#include "variables.h"
#ifndef COMMAND_H
#define COMMAND_H
-#include "print.h"
+#include "fe_utils/print.h"
#include "psqlscan.h"
#include "settings.h"
#include "command.h"
#include "copy.h"
-#include "mbprint.h"
+#include "fe_utils/mbprint.h"
static bool ExecQueryUsingCursor(const char *query, double *elapsed_msec);
#include <setjmp.h>
#include "libpq-fe.h"
-#include "print.h"
+#include "fe_utils/print.h"
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
extern sigjmp_buf sigint_interrupt_jmp;
-extern volatile bool cancel_pressed;
-
-/* Note: cancel_pressed is defined in print.c, see that file for reasons */
-
extern void setup_cancel_handler(void);
extern void SetCancelConn(void);
#include "common.h"
#include "describe.h"
-#include "mbprint.h"
-#include "print.h"
+#include "fe_utils/mbprint.h"
+#include "fe_utils/print.h"
#include "settings.h"
#include "variables.h"
+++ /dev/null
-/* src/bin/psql/mbprint.h */
-#ifndef MBPRINT_H
-#define MBPRINT_H
-
-
-struct lineptr
-{
- unsigned char *ptr;
- int width;
-};
-
-extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding);
-extern int pg_wcswidth(const char *pwcs, size_t len, int encoding);
-extern void pg_wcsformat(const unsigned char *pwcs, size_t len, int encoding, struct lineptr * lines, int count);
-extern void pg_wcssize(const unsigned char *pwcs, size_t len, int encoding,
- int *width, int *height, int *format_size);
-
-#endif /* MBPRINT_H */
CATALOG_NAME = psql
AVAIL_LANGUAGES = cs de es fr it ja pl pt_BR ru zh_CN zh_TW
GETTEXT_FILES = command.c common.c copy.c help.c input.c large_obj.c \
- mainloop.c print.c psqlscan.c psqlscanslash.c startup.c \
+ mainloop.c psqlscan.c psqlscanslash.c startup.c \
describe.c sql_help.h sql_help.c \
tab-complete.c variables.c \
+ ../../fe_utils/print.c \
../../common/exec.c ../../common/fe_memutils.c ../../common/username.c \
../../common/wait_error.c
GETTEXT_TRIGGERS = N_ psql_error simple_prompt
#include "variables.h"
-#include "print.h"
+#include "fe_utils/print.h"
#define DEFAULT_FIELD_SEP "|"
#define DEFAULT_RECORD_SEP "\n"
#include "help.h"
#include "input.h"
#include "mainloop.h"
-#include "print.h"
+#include "fe_utils/print.h"
#include "settings.h"
/vacuumdb
/pg_isready
-/mbprint.c
-/print.c
-
/tmp_check/
PROGRAMS = createdb createlang createuser dropdb droplang dropuser clusterdb vacuumdb reindexdb pg_isready
-override CPPFLAGS := -I$(top_srcdir)/src/bin/psql -I$(libpq_srcdir) $(CPPFLAGS)
+override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
LDFLAGS += -L$(top_builddir)/src/fe_utils -lpgfeutils
all: $(PROGRAMS)
$(CC) $(CFLAGS) $^ $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
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 | submake-libpq submake-libpgport submake-libpgfeutils
createuser: createuser.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
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 | submake-libpq submake-libpgport submake-libpgfeutils
dropuser: dropuser.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
clusterdb: clusterdb.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
vacuumdb: vacuumdb.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
reindexdb: reindexdb.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
pg_isready: pg_isready.o common.o | submake-libpq submake-libpgport
-print.c mbprint.c : % : $(top_srcdir)/src/bin/psql/%
- rm -f $@ && $(LN_S) $< .
-
install: all installdirs
$(INSTALL_PROGRAM) createdb$(X) '$(DESTDIR)$(bindir)'/createdb$(X)
$(INSTALL_PROGRAM) dropdb$(X) '$(DESTDIR)$(bindir)'/dropdb$(X)
clean distclean maintainer-clean:
rm -f $(addsuffix $(X), $(PROGRAMS)) $(addsuffix .o, $(PROGRAMS))
- rm -f common.o print.o mbprint.o $(WIN32RES)
- rm -f print.c mbprint.c
+ rm -f common.o $(WIN32RES)
rm -rf tmp_check
check:
#include "postgres_fe.h"
#include "common.h"
-#include "print.h"
+#include "fe_utils/print.h"
static void help(const char *progname);
#include "postgres_fe.h"
#include "common.h"
-#include "print.h"
+#include "fe_utils/print.h"
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
clusterdb.c vacuumdb.c reindexdb.c \
pg_isready.c \
common.c \
+ ../../fe_utils/print.c \
../../common/fe_memutils.c ../../common/username.c
GETTEXT_TRIGGERS = simple_prompt yesno_prompt
override CPPFLAGS := -DFRONTEND -I$(libpq_srcdir) $(CPPFLAGS)
-OBJS = simple_list.o string_utils.o
+OBJS = mbprint.o print.o simple_list.o string_utils.o
all: libpgfeutils.a
-/*
- * psql - the PostgreSQL interactive terminal
+/*-------------------------------------------------------------------------
+ *
+ * Multibyte character printing support for frontend code
+ *
*
- * Copyright (c) 2000-2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
*
- * src/bin/psql/mbprint.c
+ * src/fe_utils/mbprint.c
*
- * XXX this file does not really belong in psql/. Perhaps move to libpq?
- * It also seems that the mbvalidate function is redundant with existing
- * functionality.
+ *-------------------------------------------------------------------------
*/
-
#include "postgres_fe.h"
-#include "mbprint.h"
-#ifndef PGSCRIPTS
-#include "settings.h"
-#endif
+
+#include "fe_utils/mbprint.h"
+
+#include "libpq-fe.h"
+
/*
* To avoid version-skew problems, this file must not use declarations
(lines + 1)->ptr = NULL; /* terminate line array */
}
+
+/*
+ * Encoding validation: delete any unvalidatable characters from the string
+ *
+ * This seems redundant with existing functionality elsewhere?
+ */
unsigned char *
mbvalidate(unsigned char *pwcs, int encoding)
{
-/*
- * psql - the PostgreSQL interactive terminal
+/*-------------------------------------------------------------------------
+ *
+ * Query-result printing support for frontend code
+ *
+ * This file used to be part of psql, but now it's separated out to allow
+ * other frontend programs to use it. Because the printing code needs
+ * access to the cancel_pressed flag as well as SIGPIPE trapping and
+ * pager open/close functions, all that stuff came with it.
+ *
+ *
+ * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
*
- * Copyright (c) 2000-2016, PostgreSQL Global Development Group
+ * src/fe_utils/print.c
*
- * src/bin/psql/print.c
+ *-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include <limits.h>
+#include <locale.h>
#include <math.h>
#include <signal.h>
#include <unistd.h>
#include <termios.h>
#endif
-#include <locale.h>
+#include "fe_utils/print.h"
#include "catalog/pg_type.h"
+#include "fe_utils/mbprint.h"
-#include "common.h"
-#include "mbprint.h"
-#include "print.h"
/*
- * We define the cancel_pressed flag in this file, rather than common.c where
- * it naturally belongs, because this file is also used by non-psql programs
- * (see the bin/scripts/ directory). In those programs cancel_pressed will
- * never become set and will have no effect.
+ * If the calling program doesn't have any mechanism for setting
+ * cancel_pressed, it will have no effect.
*
* Note: print.c's general strategy for when to check cancel_pressed is to do
* so at completion of each row of output.
*/
volatile bool cancel_pressed = false;
-/*
- * Likewise, the sigpipe_trap and pager open/close functions are here rather
- * than in common.c so that this file can be used by non-psql programs.
- */
static bool always_ignore_sigpipe = false;
-
/* info for locale-aware numeric formatting; set up by setDecimalLocale() */
static char *decimal_point;
static int groupdigits;
bool wrap_right_border;
} unicodeStyleFormat;
-const unicodeStyleFormat unicode_style = {
+static const unicodeStyleFormat unicode_style = {
{
{
/* ─ */
--- /dev/null
+/*-------------------------------------------------------------------------
+ *
+ * Multibyte character printing support for frontend code
+ *
+ *
+ * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/fe_utils/mbprint.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef MBPRINT_H
+#define MBPRINT_H
+
+struct lineptr
+{
+ unsigned char *ptr;
+ int width;
+};
+
+extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding);
+extern int pg_wcswidth(const char *pwcs, size_t len, int encoding);
+extern void pg_wcsformat(const unsigned char *pwcs, size_t len, int encoding,
+ struct lineptr * lines, int count);
+extern void pg_wcssize(const unsigned char *pwcs, size_t len, int encoding,
+ int *width, int *height, int *format_size);
+
+#endif /* MBPRINT_H */
-/*
- * psql - the PostgreSQL interactive terminal
+/*-------------------------------------------------------------------------
+ *
+ * Query-result printing support for frontend code
+ *
*
- * Copyright (c) 2000-2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
*
- * src/bin/psql/print.h
+ * src/include/fe_utils/print.h
+ *
+ *-------------------------------------------------------------------------
*/
#ifndef PRINT_H
#define PRINT_H
#include "libpq-fe.h"
+/* This is not a particularly great place for this ... */
+#ifndef __CYGWIN__
+#define DEFAULT_PAGER "more"
+#else
+#define DEFAULT_PAGER "less"
+#endif
+
enum printFormat
{
PRINT_NOTHING = 0, /* to make sure someone initializes this */
} printQueryOpt;
+extern volatile bool cancel_pressed;
+
extern const printTextFormat pg_asciiformat;
extern const printTextFormat pg_asciiformat_old;
extern printTextFormat pg_utf8format; /* ideally would be const, but... */
extern const printTextFormat *get_line_style(const printTableOpt *opt);
extern void refresh_utf8format(const printTableOpt *opt);
-#ifndef __CYGWIN__
-#define DEFAULT_PAGER "more"
-#else
-#define DEFAULT_PAGER "less"
-#endif
-
#endif /* PRINT_H */
our @pgcommonbkndfiles = @pgcommonallfiles;
our @pgfeutilsfiles = qw(
- simple_list.c string_utils.c);
+ mbprint.c print.c simple_list.c string_utils.c);
$libpgport = $solution->AddProject('libpgport', 'lib', 'misc');
$libpgport->AddDefine('FRONTEND');
foreach my $f (@files)
{
$f =~ s/\.o$/\.c/;
- if ($f =~ /print\.c$/)
- { # Also catches mbprint.c
- $proj->AddFile('src/bin/psql/' . $f);
- }
- elsif ($f =~ /\.c$/)
+ if ($f =~ /\.c$/)
{
$proj->AddFile('src/bin/scripts/' . $f);
}
}
$proj->AddIncludeDir('src/interfaces/libpq');
- $proj->AddIncludeDir('src/bin/psql');
$proj->AddReference($libpq, $libpgfeutils, $libpgcommon,
$libpgport);
$proj->AddDirResourceFile('src/bin/scripts');