]> granicus.if.org Git - postgresql/commitdiff
Move psql's print.c and mbprint.c into src/fe_utils.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 24 Mar 2016 22:27:28 +0000 (18:27 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 24 Mar 2016 22:27:28 +0000 (18:27 -0400)
Just turning the crank ...

21 files changed:
src/bin/psql/Makefile
src/bin/psql/command.c
src/bin/psql/command.h
src/bin/psql/common.c
src/bin/psql/common.h
src/bin/psql/describe.c
src/bin/psql/mbprint.h [deleted file]
src/bin/psql/nls.mk
src/bin/psql/settings.h
src/bin/psql/startup.c
src/bin/scripts/.gitignore
src/bin/scripts/Makefile
src/bin/scripts/createlang.c
src/bin/scripts/droplang.c
src/bin/scripts/nls.mk
src/fe_utils/Makefile
src/fe_utils/mbprint.c [moved from src/bin/psql/mbprint.c with 93% similarity]
src/fe_utils/print.c [moved from src/bin/psql/print.c with 98% similarity]
src/include/fe_utils/mbprint.h [new file with mode: 0644]
src/include/fe_utils/print.h [moved from src/bin/psql/print.h with 93% similarity]
src/tools/msvc/Mkvcbuild.pm

index 251d638990096828e81fbf9fd21899ac516a0434..4e68e3ebdca486611af20e239392801b68fcbc5a 100644 (file)
@@ -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)
 
index e5ec8af11c56120ed1e9c69d6c4c630ed220ab32..50dc43bf61a45a7265368d330149d981443441cf 100644 (file)
@@ -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"
index e2b6ea8ed031f6b27e8afa0e21bfe52b900a7817..4f0140fd5639355941a16187eefccfc203848590 100644 (file)
@@ -8,7 +8,7 @@
 #ifndef COMMAND_H
 #define COMMAND_H
 
-#include "print.h"
+#include "fe_utils/print.h"
 #include "psqlscan.h"
 
 
index 2b67a439da76481baade0273cf9ecb749854f62d..892058e9ac833645e583734ab6567a8ffb0bf055 100644 (file)
@@ -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);
index ba4c5699b3d65ef1f149e3e49354d3ac91b7ab73..bdcb58f2f38430ec44174d3da9c2f2bbb9cd051c 100644 (file)
@@ -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);
index b824d4e54929e3ce2024803eadbc0eb8326f7979..7b2f4e64ef199620f147da5fec8a440d9909c2e0 100644 (file)
@@ -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"
 
diff --git a/src/bin/psql/mbprint.h b/src/bin/psql/mbprint.h
deleted file mode 100644 (file)
index 01064d3..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-/* 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 */
index 3746eeaeab27dcb5c9d7cb78b1abae538c526899..b9a7992a4fa9cda603d26207a4270b459c08302a 100644 (file)
@@ -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
index 20a6470e9d32bd3c2cdd3c15bf0205a67a639bce..159a7a5579a942cdb7bebd20826dc3222a9a0e3b 100644 (file)
@@ -10,7 +10,7 @@
 
 
 #include "variables.h"
-#include "print.h"
+#include "fe_utils/print.h"
 
 #define DEFAULT_FIELD_SEP "|"
 #define DEFAULT_RECORD_SEP "\n"
index 4bb3fdc595af2f5cfd41ff8d762caccd897fa6a0..07e94d064a39a8e5c2608cd07f739b8f532efd0d 100644 (file)
@@ -26,7 +26,7 @@
 #include "help.h"
 #include "input.h"
 #include "mainloop.h"
-#include "print.h"
+#include "fe_utils/print.h"
 #include "settings.h"
 
 
index 784f25b93e7760ca901490214ada978e7290f0c6..40998d9670d07dac6cda50060faeead0e2ad5c27 100644 (file)
@@ -9,7 +9,4 @@
 /vacuumdb
 /pg_isready
 
-/mbprint.c
-/print.c
-
 /tmp_check/
index 5e47e13a78a98fcf56d589420b947d391bdab7f9..4e342ef88875a662213c8b98b0a59f396585151e 100644 (file)
@@ -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:
index ad298c97f5adfa7b1c2c2f08d430b0f2d1d2578e..f4eb0797f0019724c5f4178819356634d06d021a 100644 (file)
@@ -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);
 
index 9bbbd9a20a769a13eaef095862537f2eb7a71954..8b23fe13792ca57a141f35c646110595d51904c1 100644 (file)
@@ -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))
 
index 36299d8267a1168b975bee52fcb0eb4e5f3e9e2b..45c1a7be1b9bbd872aa77f94ca1e70a886d66a58 100644 (file)
@@ -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
index f6a52dfdb411750581cca8c5e82fd607723e7f35..3223f1f26c723d1bb676ce7332881516087d6507 100644 (file)
@@ -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
 
similarity index 93%
rename from src/bin/psql/mbprint.c
rename to src/fe_utils/mbprint.c
index 0776545ad042c25c0e65fc6d0b5e5f10b6793d76..97ba692724922e79d8cba850e4e859b6dda6cdc3 100644 (file)
@@ -1,20 +1,21 @@
-/*
- * 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)
 {
similarity index 98%
rename from src/bin/psql/print.c
rename to src/fe_utils/print.c
index f25a66eb36f72c6014e9b5355b5612b15b1a7aab..30efd3fdc62b66ed91663ad613943a3d4976c27e 100644 (file)
@@ -1,13 +1,24 @@
-/*
- * 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;
@@ -139,7 +141,7 @@ typedef struct unicodeStyleFormat
        bool            wrap_right_border;
 } unicodeStyleFormat;
 
-const unicodeStyleFormat unicode_style = {
+static const unicodeStyleFormat unicode_style = {
        {
                {
                        /* ─ */
diff --git a/src/include/fe_utils/mbprint.h b/src/include/fe_utils/mbprint.h
new file mode 100644 (file)
index 0000000..e37eb5c
--- /dev/null
@@ -0,0 +1,29 @@
+/*-------------------------------------------------------------------------
+ *
+ * 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 */
similarity index 93%
rename from src/bin/psql/print.h
rename to src/include/fe_utils/print.h
index 9033c4bce382345e6ecf1240c7ea877bb09fd0b2..ff902370f32e8512f0407e0800710ce75b6cba2c 100644 (file)
@@ -1,9 +1,14 @@
-/*
- * 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 */
@@ -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 */
index d05b92a988a1d60592b3f114a0ab893483055914..1cd8452f49ece27f9983b4597ce0d25a51109fe1 100644 (file)
@@ -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');