Skip to content

Commit d65bea2

Browse files
committed
Move psql's print.c and mbprint.c into src/fe_utils.
Just turning the crank ...
1 parent a376960 commit d65bea2

File tree

21 files changed

+108
-94
lines changed

21 files changed

+108
-94
lines changed

src/bin/psql/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ override CPPFLAGS := -I. -I$(srcdir) -I$(libpq_srcdir) $(CPPFLAGS)
2222
LDFLAGS += -L$(top_builddir)/src/fe_utils -lpgfeutils
2323

2424
OBJS= command.o common.o help.o input.o stringutils.o mainloop.o copy.o \
25-
startup.o prompt.o variables.o large_obj.o print.o describe.o \
26-
tab-complete.o mbprint.o \
25+
startup.o prompt.o variables.o large_obj.o describe.o \
26+
tab-complete.o \
2727
sql_help.o psqlscan.o psqlscanslash.o \
2828
$(WIN32RES)
2929

src/bin/psql/command.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#include "input.h"
4545
#include "large_obj.h"
4646
#include "mainloop.h"
47-
#include "print.h"
47+
#include "fe_utils/print.h"
4848
#include "psqlscanslash.h"
4949
#include "settings.h"
5050
#include "variables.h"

src/bin/psql/command.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef COMMAND_H
99
#define COMMAND_H
1010

11-
#include "print.h"
11+
#include "fe_utils/print.h"
1212
#include "psqlscan.h"
1313

1414

src/bin/psql/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include "settings.h"
2424
#include "command.h"
2525
#include "copy.h"
26-
#include "mbprint.h"
26+
#include "fe_utils/mbprint.h"
2727

2828

2929
static bool ExecQueryUsingCursor(const char *query, double *elapsed_msec);

src/bin/psql/common.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <setjmp.h>
1212

1313
#include "libpq-fe.h"
14-
#include "print.h"
14+
#include "fe_utils/print.h"
1515

1616
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
1717

@@ -28,10 +28,6 @@ extern volatile bool sigint_interrupt_enabled;
2828

2929
extern sigjmp_buf sigint_interrupt_jmp;
3030

31-
extern volatile bool cancel_pressed;
32-
33-
/* Note: cancel_pressed is defined in print.c, see that file for reasons */
34-
3531
extern void setup_cancel_handler(void);
3632

3733
extern void SetCancelConn(void);

src/bin/psql/describe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
#include "common.h"
2121
#include "describe.h"
22-
#include "mbprint.h"
23-
#include "print.h"
22+
#include "fe_utils/mbprint.h"
23+
#include "fe_utils/print.h"
2424
#include "settings.h"
2525
#include "variables.h"
2626

src/bin/psql/mbprint.h

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/bin/psql/nls.mk

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
CATALOG_NAME = psql
33
AVAIL_LANGUAGES = cs de es fr it ja pl pt_BR ru zh_CN zh_TW
44
GETTEXT_FILES = command.c common.c copy.c help.c input.c large_obj.c \
5-
mainloop.c print.c psqlscan.c psqlscanslash.c startup.c \
5+
mainloop.c psqlscan.c psqlscanslash.c startup.c \
66
describe.c sql_help.h sql_help.c \
77
tab-complete.c variables.c \
8+
../../fe_utils/print.c \
89
../../common/exec.c ../../common/fe_memutils.c ../../common/username.c \
910
../../common/wait_error.c
1011
GETTEXT_TRIGGERS = N_ psql_error simple_prompt

src/bin/psql/settings.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
#include "variables.h"
13-
#include "print.h"
13+
#include "fe_utils/print.h"
1414

1515
#define DEFAULT_FIELD_SEP "|"
1616
#define DEFAULT_RECORD_SEP "\n"

src/bin/psql/startup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "help.h"
2727
#include "input.h"
2828
#include "mainloop.h"
29-
#include "print.h"
29+
#include "fe_utils/print.h"
3030
#include "settings.h"
3131

3232

src/bin/scripts/.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,4 @@
99
/vacuumdb
1010
/pg_isready
1111

12-
/mbprint.c
13-
/print.c
14-
1512
/tmp_check/

src/bin/scripts/Makefile

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ include $(top_builddir)/src/Makefile.global
1818

1919
PROGRAMS = createdb createlang createuser dropdb droplang dropuser clusterdb vacuumdb reindexdb pg_isready
2020

21-
override CPPFLAGS := -I$(top_srcdir)/src/bin/psql -I$(libpq_srcdir) $(CPPFLAGS)
21+
override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
2222
LDFLAGS += -L$(top_builddir)/src/fe_utils -lpgfeutils
2323

2424
all: $(PROGRAMS)
@@ -27,19 +27,16 @@ all: $(PROGRAMS)
2727
$(CC) $(CFLAGS) $^ $(libpq_pgport) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
2828

2929
createdb: createdb.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
30-
createlang: createlang.o common.o print.o mbprint.o | submake-libpq submake-libpgport
30+
createlang: createlang.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
3131
createuser: createuser.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
3232
dropdb: dropdb.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
33-
droplang: droplang.o common.o print.o mbprint.o | submake-libpq submake-libpgport
33+
droplang: droplang.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
3434
dropuser: dropuser.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
3535
clusterdb: clusterdb.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
3636
vacuumdb: vacuumdb.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
3737
reindexdb: reindexdb.o common.o | submake-libpq submake-libpgport submake-libpgfeutils
3838
pg_isready: pg_isready.o common.o | submake-libpq submake-libpgport
3939

40-
print.c mbprint.c : % : $(top_srcdir)/src/bin/psql/%
41-
rm -f $@ && $(LN_S) $< .
42-
4340
install: all installdirs
4441
$(INSTALL_PROGRAM) createdb$(X) '$(DESTDIR)$(bindir)'/createdb$(X)
4542
$(INSTALL_PROGRAM) dropdb$(X) '$(DESTDIR)$(bindir)'/dropdb$(X)
@@ -60,8 +57,7 @@ uninstall:
6057

6158
clean distclean maintainer-clean:
6259
rm -f $(addsuffix $(X), $(PROGRAMS)) $(addsuffix .o, $(PROGRAMS))
63-
rm -f common.o print.o mbprint.o $(WIN32RES)
64-
rm -f print.c mbprint.c
60+
rm -f common.o $(WIN32RES)
6561
rm -rf tmp_check
6662

6763
check:

src/bin/scripts/createlang.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "postgres_fe.h"
1313

1414
#include "common.h"
15-
#include "print.h"
15+
#include "fe_utils/print.h"
1616

1717
static void help(const char *progname);
1818

src/bin/scripts/droplang.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "postgres_fe.h"
1313

1414
#include "common.h"
15-
#include "print.h"
15+
#include "fe_utils/print.h"
1616

1717
#define atooid(x) ((Oid) strtoul((x), NULL, 10))
1818

src/bin/scripts/nls.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ GETTEXT_FILES = createdb.c createlang.c createuser.c \
66
clusterdb.c vacuumdb.c reindexdb.c \
77
pg_isready.c \
88
common.c \
9+
../../fe_utils/print.c \
910
../../common/fe_memutils.c ../../common/username.c
1011
GETTEXT_TRIGGERS = simple_prompt yesno_prompt

src/fe_utils/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ include $(top_builddir)/src/Makefile.global
1717

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

20-
OBJS = simple_list.o string_utils.o
20+
OBJS = mbprint.o print.o simple_list.o string_utils.o
2121

2222
all: libpgfeutils.a
2323

src/bin/psql/mbprint.c renamed to src/fe_utils/mbprint.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
/*
2-
* psql - the PostgreSQL interactive terminal
1+
/*-------------------------------------------------------------------------
2+
*
3+
* Multibyte character printing support for frontend code
4+
*
35
*
4-
* Copyright (c) 2000-2016, PostgreSQL Global Development Group
6+
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1994, Regents of the University of California
58
*
6-
* src/bin/psql/mbprint.c
9+
* src/fe_utils/mbprint.c
710
*
8-
* XXX this file does not really belong in psql/. Perhaps move to libpq?
9-
* It also seems that the mbvalidate function is redundant with existing
10-
* functionality.
11+
*-------------------------------------------------------------------------
1112
*/
12-
1313
#include "postgres_fe.h"
14-
#include "mbprint.h"
15-
#ifndef PGSCRIPTS
16-
#include "settings.h"
17-
#endif
14+
15+
#include "fe_utils/mbprint.h"
16+
17+
#include "libpq-fe.h"
18+
1819

1920
/*
2021
* 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,
381382
(lines + 1)->ptr = NULL; /* terminate line array */
382383
}
383384

385+
386+
/*
387+
* Encoding validation: delete any unvalidatable characters from the string
388+
*
389+
* This seems redundant with existing functionality elsewhere?
390+
*/
384391
unsigned char *
385392
mbvalidate(unsigned char *pwcs, int encoding)
386393
{

src/bin/psql/print.c renamed to src/fe_utils/print.c

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
/*
2-
* psql - the PostgreSQL interactive terminal
1+
/*-------------------------------------------------------------------------
2+
*
3+
* Query-result printing support for frontend code
4+
*
5+
* This file used to be part of psql, but now it's separated out to allow
6+
* other frontend programs to use it. Because the printing code needs
7+
* access to the cancel_pressed flag as well as SIGPIPE trapping and
8+
* pager open/close functions, all that stuff came with it.
9+
*
10+
*
11+
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
12+
* Portions Copyright (c) 1994, Regents of the University of California
313
*
4-
* Copyright (c) 2000-2016, PostgreSQL Global Development Group
14+
* src/fe_utils/print.c
515
*
6-
* src/bin/psql/print.c
16+
*-------------------------------------------------------------------------
717
*/
818
#include "postgres_fe.h"
919

1020
#include <limits.h>
21+
#include <locale.h>
1122
#include <math.h>
1223
#include <signal.h>
1324
#include <unistd.h>
@@ -20,32 +31,23 @@
2031
#include <termios.h>
2132
#endif
2233

23-
#include <locale.h>
34+
#include "fe_utils/print.h"
2435

2536
#include "catalog/pg_type.h"
37+
#include "fe_utils/mbprint.h"
2638

27-
#include "common.h"
28-
#include "mbprint.h"
29-
#include "print.h"
3039

3140
/*
32-
* We define the cancel_pressed flag in this file, rather than common.c where
33-
* it naturally belongs, because this file is also used by non-psql programs
34-
* (see the bin/scripts/ directory). In those programs cancel_pressed will
35-
* never become set and will have no effect.
41+
* If the calling program doesn't have any mechanism for setting
42+
* cancel_pressed, it will have no effect.
3643
*
3744
* Note: print.c's general strategy for when to check cancel_pressed is to do
3845
* so at completion of each row of output.
3946
*/
4047
volatile bool cancel_pressed = false;
4148

42-
/*
43-
* Likewise, the sigpipe_trap and pager open/close functions are here rather
44-
* than in common.c so that this file can be used by non-psql programs.
45-
*/
4649
static bool always_ignore_sigpipe = false;
4750

48-
4951
/* info for locale-aware numeric formatting; set up by setDecimalLocale() */
5052
static char *decimal_point;
5153
static int groupdigits;
@@ -139,7 +141,7 @@ typedef struct unicodeStyleFormat
139141
bool wrap_right_border;
140142
} unicodeStyleFormat;
141143

142-
const unicodeStyleFormat unicode_style = {
144+
static const unicodeStyleFormat unicode_style = {
143145
{
144146
{
145147
/* ─ */

src/include/fe_utils/mbprint.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* Multibyte character printing support for frontend code
4+
*
5+
*
6+
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1994, Regents of the University of California
8+
*
9+
* src/include/fe_utils/mbprint.h
10+
*
11+
*-------------------------------------------------------------------------
12+
*/
13+
#ifndef MBPRINT_H
14+
#define MBPRINT_H
15+
16+
struct lineptr
17+
{
18+
unsigned char *ptr;
19+
int width;
20+
};
21+
22+
extern unsigned char *mbvalidate(unsigned char *pwcs, int encoding);
23+
extern int pg_wcswidth(const char *pwcs, size_t len, int encoding);
24+
extern void pg_wcsformat(const unsigned char *pwcs, size_t len, int encoding,
25+
struct lineptr * lines, int count);
26+
extern void pg_wcssize(const unsigned char *pwcs, size_t len, int encoding,
27+
int *width, int *height, int *format_size);
28+
29+
#endif /* MBPRINT_H */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy