Commit d65bea26 authored by Tom Lane's avatar Tom Lane

Move psql's print.c and mbprint.c into src/fe_utils.

Just turning the crank ...
parent a376960c
......@@ -22,8 +22,8 @@ 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 \
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)
......
......@@ -44,7 +44,7 @@
#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"
......
......@@ -8,7 +8,7 @@
#ifndef COMMAND_H
#define COMMAND_H
#include "print.h"
#include "fe_utils/print.h"
#include "psqlscan.h"
......
......@@ -23,7 +23,7 @@
#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);
......
......@@ -11,7 +11,7 @@
#include <setjmp.h>
#include "libpq-fe.h"
#include "print.h"
#include "fe_utils/print.h"
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
......@@ -28,10 +28,6 @@ extern volatile bool sigint_interrupt_enabled;
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);
......
......@@ -19,8 +19,8 @@
#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"
......
......@@ -2,9 +2,10 @@
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
......
......@@ -10,7 +10,7 @@
#include "variables.h"
#include "print.h"
#include "fe_utils/print.h"
#define DEFAULT_FIELD_SEP "|"
#define DEFAULT_RECORD_SEP "\n"
......
......@@ -26,7 +26,7 @@
#include "help.h"
#include "input.h"
#include "mainloop.h"
#include "print.h"
#include "fe_utils/print.h"
#include "settings.h"
......
......@@ -9,7 +9,4 @@
/vacuumdb
/pg_isready
/mbprint.c
/print.c
/tmp_check/
......@@ -18,7 +18,7 @@ include $(top_builddir)/src/Makefile.global
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)
......@@ -27,19 +27,16 @@ 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)
......@@ -60,8 +57,7 @@ uninstall:
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:
......
......@@ -12,7 +12,7 @@
#include "postgres_fe.h"
#include "common.h"
#include "print.h"
#include "fe_utils/print.h"
static void help(const char *progname);
......
......@@ -12,7 +12,7 @@
#include "postgres_fe.h"
#include "common.h"
#include "print.h"
#include "fe_utils/print.h"
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
......
......@@ -6,5 +6,6 @@ GETTEXT_FILES = createdb.c createlang.c createuser.c \
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
......@@ -17,7 +17,7 @@ include $(top_builddir)/src/Makefile.global
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
......@@ -381,6 +382,12 @@ pg_wcsformat(const unsigned char *pwcs, size_t len, int encoding,
(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>
......@@ -20,32 +31,23 @@
#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;
......@@ -139,7 +141,7 @@ typedef struct unicodeStyleFormat
bool wrap_right_border;
} unicodeStyleFormat;
const unicodeStyleFormat unicode_style = {
static const unicodeStyleFormat unicode_style = {
{
{
/* ─ */
......
/* src/bin/psql/mbprint.h */
/*-------------------------------------------------------------------------
*
* 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;
......@@ -11,7 +21,8 @@ struct lineptr
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_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);
......
/*
* 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
......@@ -11,6 +16,13 @@
#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 */
......@@ -161,6 +173,8 @@ typedef struct printQueryOpt
} 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... */
......@@ -196,10 +210,4 @@ extern void setDecimalLocale(void);
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 */
......@@ -120,7 +120,7 @@ sub mkvcbuild
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');
......@@ -622,17 +622,12 @@ sub mkvcbuild
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');
......
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