Skip to content

Commit 0b10d35

Browse files
committed
Avoid dependency on backend's multibyte module as possible.
Now frontend/libpq has its own version of pg_encoding_to_char and pg_char_to_encoding.
1 parent e5b6b0e commit 0b10d35

File tree

2 files changed

+71
-6
lines changed

2 files changed

+71
-6
lines changed

src/interfaces/libpq/Makefile

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $Header: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v 1.46 2000/10/25 16:13:52 petere Exp $
7+
# $Header: /cvsroot/pgsql/src/interfaces/libpq/Makefile,v 1.47 2000/10/30 10:31:45 ishii Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -23,7 +23,7 @@ OBJS= fe-auth.o fe-connect.o fe-exec.o fe-misc.o fe-print.o fe-lobj.o \
2323
pqexpbuffer.o dllist.o pqsignal.o $(SNPRINTF) $(INET_ATON)
2424

2525
ifdef MULTIBYTE
26-
OBJS+= common.o wchar.o conv.o big5.o mbutils.o
26+
OBJS+= common.o wchar.o
2727
endif
2828

2929
# Add libraries that libpq depends (or might depend) on into the
@@ -57,9 +57,7 @@ inet_aton.c: $(backend_src)/port/inet_aton.c
5757
rm -f $@ && $(LN_S) $< .
5858

5959
ifdef MULTIBYTE
60-
maps = iso8859.map UTF_to_EUC_JP.map EUC_JP_to_UTF.map sjis.map
61-
conv.c: $(maps)
62-
common.c wchar.c conv.c big5.c mbutils.c $(maps) : % : $(backend_src)/utils/mb/%
60+
common.c wchar.c : % : $(backend_src)/utils/mb/%
6361
rm -f $@ && $(LN_S) $< .
6462
endif
6563

src/interfaces/libpq/fe-connect.c

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.142 2000/10/23 14:50:44 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.143 2000/10/30 10:31:46 ishii Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2694,3 +2694,70 @@ defaultNoticeProcessor(void *arg, const char *message)
26942694
/* Note: we expect the supplied string to end with a newline already. */
26952695
fprintf(stderr, "%s", message);
26962696
}
2697+
2698+
#ifdef MULTIBYTE
2699+
/*
2700+
* convert an encoding string to encoding symbol value.
2701+
* case is ignored.
2702+
* if there's no valid encoding, returns -1
2703+
*/
2704+
2705+
typedef struct {
2706+
int encoding; /* encoding symbol value */
2707+
char *name; /* encoding string */
2708+
} PQ_encoding_conv_tbl;
2709+
2710+
static PQ_encoding_conv_tbl pq_conv_tbl[] = {
2711+
{SQL_ASCII, "SQL_ASCII"},
2712+
{EUC_JP, "EUC_JP"},
2713+
{EUC_CN, "EUC_CN"},
2714+
{EUC_KR, "EUC_KR"},
2715+
{UNICODE, "UNICODE"},
2716+
{MULE_INTERNAL, "MULE_INTERNAL"},
2717+
{LATIN1, "LATIN1"},
2718+
{LATIN2, "LATIN2"},
2719+
{LATIN3, "LATIN3"},
2720+
{LATIN4, "LATIN4"},
2721+
{LATIN5, "LATIN5"},
2722+
{KOI8, "KOI8"},
2723+
{WIN, "WIN"},
2724+
{ALT, "ALT"},
2725+
{SJIS, "SJIS"},
2726+
{BIG5, "BIG5"},
2727+
{WIN1250, "WIN1250"},
2728+
{-1, ""}
2729+
};
2730+
2731+
int
2732+
pg_char_to_encoding(const char *s)
2733+
{
2734+
PQ_encoding_conv_tbl *p = pq_conv_tbl;
2735+
2736+
if (!s)
2737+
return (-1);
2738+
2739+
for (; p->encoding >= 0; p++)
2740+
{
2741+
if (!strcasecmp(s, p->name))
2742+
break;
2743+
}
2744+
return (p->encoding);
2745+
}
2746+
2747+
/*
2748+
* convert encoding symbol to encoding char.
2749+
* if there's no valid encoding symbol, returns ""
2750+
*/
2751+
const char *
2752+
pg_encoding_to_char(int encoding)
2753+
{
2754+
PQ_encoding_conv_tbl *p = pq_conv_tbl;
2755+
2756+
for (; p->encoding >= 0; p++)
2757+
{
2758+
if (p->encoding == encoding)
2759+
return (p->name);
2760+
}
2761+
return ("");
2762+
}
2763+
#endif

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