Skip to content

Commit 8da88a6

Browse files
committed
Sorry, that I send this letter/patch again, but previous sending is
still without answer. I want continue with to_char(), but I need any answer for this patch. Please. Thank! (and sorry of my impatient :-) Karel
1 parent 27fdbca commit 8da88a6

File tree

3 files changed

+176
-2
lines changed

3 files changed

+176
-2
lines changed

src/backend/utils/adt/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Makefile for utils/adt
55
#
66
# IDENTIFICATION
7-
# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.30 1999/12/28 13:40:48 wieck Exp $
7+
# $Header: /cvsroot/pgsql/src/backend/utils/adt/Makefile,v 1.31 2000/01/07 17:22:47 momjian Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -35,7 +35,7 @@ OBJS = acl.o arrayfuncs.o arrayutils.o bool.o cash.o char.o chunk.o \
3535
regexp.o regproc.o ruleutils.o selfuncs.o sets.o \
3636
tid.o timestamp.o varchar.o varlena.o version.o \
3737
network.o mac.o inet_net_ntop.o inet_net_pton.o \
38-
ri_triggers.o pg_lzcompress.o
38+
ri_triggers.o pg_lzcompress.o pg_locale.o
3939

4040
all: SUBSYS.o
4141

src/backend/utils/adt/pg_locale.c

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
2+
/*------
3+
* pg_locale.c
4+
*
5+
* The PostgreSQL locale utils.
6+
*
7+
* 2000 Karel Zak - Zakkr
8+
*
9+
*------
10+
*/
11+
12+
#include <stdio.h>
13+
14+
#include "postgres.h"
15+
16+
#ifdef USE_LOCALE
17+
18+
#include <locale.h>
19+
#include "utils/pg_locale.h"
20+
21+
/* #define DEBUG_LOCALE_UTILS */
22+
23+
24+
/*------
25+
* Return in PG_LocaleCategories current locale setting
26+
*------
27+
*/
28+
PG_LocaleCategories *
29+
PGLC_current( PG_LocaleCategories *lc )
30+
{
31+
lc->lang = getenv("LANG");
32+
33+
lc->lc_ctype = setlocale(LC_CTYPE, NULL);
34+
lc->lc_numeric = setlocale(LC_NUMERIC, NULL);
35+
lc->lc_time = setlocale(LC_TIME, NULL);
36+
lc->lc_collate = setlocale(LC_COLLATE, NULL);
37+
lc->lc_monetary = setlocale(LC_MONETARY, NULL);
38+
lc->lc_messages = setlocale(LC_MESSAGES, NULL);
39+
40+
return lc;
41+
}
42+
43+
44+
#ifdef DEBUG_LOCALE_UTILS
45+
46+
/*------
47+
* Print a PG_LocaleCategories struct as DEBUG
48+
*------
49+
*/
50+
PG_LocaleCategories *
51+
PGLC_debug_lc( PG_LocaleCategories *lc )
52+
{
53+
elog(DEBUG, "CURRENT LOCALE ENVIRONMENT:\n\nLANG: \t%s\nLC_CTYPE:\t%s\nLC_NUMERIC:\t%s\nLC_TIME:\t%s\nLC_COLLATE:\t%s\nLC_MONETARY:\t%s\nLC_MESSAGES:\t%s\n",
54+
lc->lang,
55+
lc->lc_ctype,
56+
lc->lc_numeric,
57+
lc->lc_time,
58+
lc->lc_collate,
59+
lc->lc_monetary,
60+
lc->lc_messages
61+
);
62+
63+
return lc;
64+
}
65+
66+
#endif
67+
68+
/*------
69+
* Set locales via a PG_LocaleCategories struct
70+
*------
71+
*/
72+
PG_LocaleCategories *
73+
PGLC_setlocale( PG_LocaleCategories *lc )
74+
{
75+
if (!setlocale(LC_CTYPE, lc->lc_ctype ))
76+
elog(NOTICE, "pg_setlocale(): 'LC_CTYPE=%s' cannot be honored.", lc->lc_ctype);
77+
78+
if (!setlocale(LC_NUMERIC, lc->lc_numeric ))
79+
elog(NOTICE, "pg_setlocale(): 'LC_NUMERIC=%s' cannot be honored.", lc->lc_numeric);
80+
81+
if (!setlocale(LC_TIME, lc->lc_time ))
82+
elog(NOTICE, "pg_setlocale(): 'LC_TIME=%s' cannot be honored.", lc->lc_time);
83+
84+
if (!setlocale(LC_COLLATE, lc->lc_collate ))
85+
elog(NOTICE, "pg_setlocale(): 'LC_COLLATE=%s' cannot be honored.", lc->lc_collate);
86+
87+
if (!setlocale(LC_MONETARY, lc->lc_monetary ))
88+
elog(NOTICE, "pg_setlocale(): 'LC_MONETARY=%s' cannot be honored.", lc->lc_monetary);
89+
90+
if (!setlocale(LC_MESSAGES, lc->lc_messages ))
91+
elog(NOTICE, "pg_setlocale(): 'LC_MESSAGE=%s' cannot be honored.", lc->lc_messages);
92+
93+
return lc;
94+
}
95+
96+
/*------
97+
* Return the POSIX lconv struct (contains number/money formatting information)
98+
* with locale information for *all* categories.
99+
* => Returned lconv is *independent* on current locale catogories setting - in
100+
* contrast to standard localeconv().
101+
*
102+
* ! libc prepare memory space for lconv itself and all returned strings in
103+
* lconv are *static strings*.
104+
*------
105+
*/
106+
struct lconv *
107+
PGLC_localeconv()
108+
{
109+
PG_LocaleCategories lc;
110+
struct lconv *lconv;
111+
112+
/* Save current locale setting to lc */
113+
PGLC_current(&lc);
114+
115+
/* Set all locale category for current lang */
116+
setlocale(LC_ALL, "");
117+
118+
/* Get numeric formatting information */
119+
lconv = localeconv();
120+
121+
/* Set previous original locale */
122+
PGLC_setlocale(&lc);
123+
124+
return lconv;
125+
}
126+
127+
128+
#endif /* USE_LOCALE */

src/include/utils/pg_locale.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
/*------
3+
* pg_locale.h
4+
*
5+
* The PostgreSQL locale utils
6+
*
7+
* 2000 Karel Zak - Zakkr
8+
*
9+
*------
10+
*/
11+
12+
#ifndef _PG_LOCALE_
13+
#define _PG_LOCALE_
14+
15+
#ifdef USE_LOCALE
16+
17+
/*------
18+
* POSIX locale categories and environment variable LANG
19+
*------
20+
*/
21+
typedef struct PG_LocaleCategories {
22+
char *lang,
23+
*lc_ctype,
24+
*lc_numeric,
25+
*lc_time,
26+
*lc_collate,
27+
*lc_monetary,
28+
*lc_messages;
29+
} PG_LocaleCategories;
30+
31+
32+
extern PG_LocaleCategories *PGLC_current( PG_LocaleCategories *lc );
33+
extern PG_LocaleCategories *PGLC_setlocale( PG_LocaleCategories *lc );
34+
35+
/*------
36+
* Return the POSIX lconv struct (contains number/money formatting information)
37+
* with locale information for *all* categories. Returned lconv is *independent*
38+
* on current locale catogories setting - in contrast to standard localeconv().
39+
*------
40+
*/
41+
extern struct lconv *PGLC_localeconv();
42+
43+
44+
#endif /* USE_LOCALE */
45+
46+
#endif /* _PG_LOCALE_ */

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