From 5b1311acfbd6b84dbb84975240914214c51fcb48 Mon Sep 17 00:00:00 2001
From: "Marc G. Fournier" <scrappy@hub.org>
Date: Wed, 2 Apr 1997 18:13:47 +0000
Subject: [PATCH] From: Oleg Bartunov <oleg@sai.msu.su> Subject: [HACKERS]
 locale patches !

Hi there,

here are little patches to get Postgres 6.1 works with locale stuff.
This is a patch against 970402.tar.gz, there are no problem to apply them
by hand to 6.0 release. Collate stuff tested about 1-2 months in real
working database but I'm sure there must be no problem. US hackers
could vote against locale implementation ( locale for sure will affect to
speed of postgres ), so I introduce variable USE_LOCALE which
controls locale stuff. Non-US users now could use ~* operator
for searching and <order by> for strings with nation alphabet.
Please, don't forget, as I did first time, to set environment variable
LC_CTYPE and LC_COLLATE because backend get locale information from them.
I start postmaster from a little script, assuming that shell is Bash shell
it looks like:

#!/bin/sh

export LC_CTYPE=koi8-r
export LC_COLLATE=koi8-r
postmaster -B 1024 -S -D/usr/local/pgsql/data/ -o '-Fe'
---
 src/Makefile.global.in              | 12 +++++++++++-
 src/backend/bootstrap/Makefile      |  9 +--------
 src/backend/main/main.c             |  9 ++++++++-
 src/backend/optimizer/geqo/Makefile |  4 ++--
 src/backend/parser/Makefile         |  9 +--------
 src/backend/postmaster/Makefile     | 13 +------------
 src/backend/tcop/Makefile           |  9 +--------
 src/backend/utils/adt/varlena.c     | 10 +++++++++-
 src/interfaces/libpgtcl/Makefile    |  7 +------
 9 files changed, 35 insertions(+), 47 deletions(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index bb21d7d38c3..56f284d75c9 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -7,7 +7,7 @@
 #
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.14 1997/03/26 06:53:57 scrappy Exp $
+#    $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.15 1997/04/02 18:10:32 scrappy Exp $
 #
 # NOTES
 #    Essentially all Postgres make files include this file and use the 
@@ -146,6 +146,11 @@ ENFORCE_ALIGNMENT= true
 # Comment out PROFILE to generate a profile version of the binaries
 #PROFILE= -p -non_shared
 
+# Define USE_LOCALE to get Postgres work (sort, search)
+# with national alphabet. Remember to define environment variables
+# $LC_COLLATE and $LC_CTYPE before starting postmaster !
+USE_LOCALE = 1
+
 # If you plan to use Kerberos for authentication...
 #
 # Comment out KRBVERS if you do not use Kerberos.
@@ -716,6 +721,11 @@ ifndef CASSERT
    CFLAGS+= -DNO_ASSERT_CHECKING
 endif
 
+ifdef USE_LOCALE
+ CFLAGS+= -DUSE_LOCALE
+endif
+
+
 ifdef PROFILE
    CFLAGS+= $(PROFILE)
    LDFLAGS+= $(PROFILE)
diff --git a/src/backend/bootstrap/Makefile b/src/backend/bootstrap/Makefile
index 6702bce1b61..0c3567e7e20 100644
--- a/src/backend/bootstrap/Makefile
+++ b/src/backend/bootstrap/Makefile
@@ -4,7 +4,7 @@
 #    Makefile for the bootstrap module
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/backend/bootstrap/Makefile,v 1.4 1996/11/14 07:33:20 bryanh Exp $
+#    $Header: /cvsroot/pgsql/src/backend/bootstrap/Makefile,v 1.5 1997/04/02 18:10:46 scrappy Exp $
 #
 #
 # We must build bootparse.c and bootscanner.c with yacc and lex and sed,
@@ -27,13 +27,6 @@ INCLUDE_OPT= -I.. \
 
 CFLAGS+= $(INCLUDE_OPT) 
 
-ifeq ($(CC), gcc)
-# Until we figure out how to get rid of the warnings in this directory,
-# we must turn off any -Werror that is in CFLAGS now.  These options only
-# exist for the gcc compiler.
-CFLAGS+= -Wno-error
-endif
-
 BOOTYACCS= bootstrap_tokens.h bootparse.c
 
 OBJS= bootparse.o bootscanner.o bootstrap.o 
diff --git a/src/backend/main/main.c b/src/backend/main/main.c
index aa8d9836d55..2fa7a46242c 100644
--- a/src/backend/main/main.c
+++ b/src/backend/main/main.c
@@ -7,13 +7,16 @@
  *
  *
  * IDENTIFICATION
- *    $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.3 1996/11/14 20:49:09 scrappy Exp $
+ *    $Header: /cvsroot/pgsql/src/backend/main/main.c,v 1.4 1997/04/02 18:11:08 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#ifdef USE_LOCALE  
+  #include <locale.h>
+#endif
 #include "postgres.h"
 #include "miscadmin.h"
 #include "bootstrap/bootstrap.h"	/* for BootstrapMain() */
@@ -31,6 +34,10 @@ int
 main(int argc, char *argv[])
 {
     int len;
+#ifdef USE_LOCALE
+    setlocale(LC_CTYPE,""); /* take locale information from an environment */
+    setlocale(LC_COLLATE,"");
+#endif
 #if defined(NOFIXADE) || defined(NOPRINTADE)
     /*
      * Must be first so that the bootstrap code calls it, too.
diff --git a/src/backend/optimizer/geqo/Makefile b/src/backend/optimizer/geqo/Makefile
index fac006c6db3..217c6bcb8a0 100644
--- a/src/backend/optimizer/geqo/Makefile
+++ b/src/backend/optimizer/geqo/Makefile
@@ -5,7 +5,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $Id: Makefile,v 1.3 1997/03/14 16:02:40 scrappy Exp $
+# $Id: Makefile,v 1.4 1997/04/02 18:11:49 scrappy Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -16,7 +16,7 @@ INCLUDE_OPT = -I../.. \
               -I../../port/$(PORTNAME) \
               -I../../../include
 
-CFLAGS+=$(INCLUDE_OPT) -Wno-error
+CFLAGS+=$(INCLUDE_OPT) 
 
 OBJS =	geqo_copy.o geqo_eval.o geqo_main.o geqo_misc.o \
 	geqo_params.o geqo_paths.o geqo_pool.o geqo_recombination.o \
diff --git a/src/backend/parser/Makefile b/src/backend/parser/Makefile
index 2c9d6616c7a..cee2f1eebeb 100644
--- a/src/backend/parser/Makefile
+++ b/src/backend/parser/Makefile
@@ -4,7 +4,7 @@
 #    Makefile for parser
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/backend/parser/Makefile,v 1.4 1996/11/14 07:33:30 bryanh Exp $
+#    $Header: /cvsroot/pgsql/src/backend/parser/Makefile,v 1.5 1997/04/02 18:12:14 scrappy Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -17,13 +17,6 @@ INCLUDE_OPT= -I.. \
 
 CFLAGS+= $(INCLUDE_OPT)
 
-ifeq ($(CC), gcc)
-# Until we figure out how to get rid of the warnings in this directory,
-# we must turn off any -Werror that is in CFLAGS now.  These options only
-# exist for the gcc compiler.
-CFLAGS+= -Wno-error
-endif
-
 OBJS= analyze.o catalog_utils.o dbcommands.o gram.o \
       keywords.o parser.o parse_query.o scan.o scansup.o sysfunc.o
 
diff --git a/src/backend/postmaster/Makefile b/src/backend/postmaster/Makefile
index 7a771db8eb0..115a403d3a4 100644
--- a/src/backend/postmaster/Makefile
+++ b/src/backend/postmaster/Makefile
@@ -4,7 +4,7 @@
 #    Makefile for postmaster
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/backend/postmaster/Makefile,v 1.4 1996/12/28 02:12:04 momjian Exp $
+#    $Header: /cvsroot/pgsql/src/backend/postmaster/Makefile,v 1.5 1997/04/02 18:12:39 scrappy Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -17,17 +17,6 @@ INCLUDE_OPT = -I.. \
 
 CFLAGS+=$(INCLUDE_OPT)
 
-ifeq ($(PORTNAME), sparc_solaris)
-
-ifeq ($(CC), gcc)
-# Until we figure out how to get rid of the warnings in this directory,
-# we must turn off any -Werror that is in CFLAGS now.  These options only
-# exist for the gcc compiler.
-CFLAGS+= -Wno-error
-endif
-
-endif
-
 OBJS = postmaster.o
 
 all: SUBSYS.o
diff --git a/src/backend/tcop/Makefile b/src/backend/tcop/Makefile
index a40e3e717e5..e0790234e10 100644
--- a/src/backend/tcop/Makefile
+++ b/src/backend/tcop/Makefile
@@ -4,7 +4,7 @@
 #    Makefile for tcop
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/backend/tcop/Makefile,v 1.9 1997/03/25 02:35:22 scrappy Exp $
+#    $Header: /cvsroot/pgsql/src/backend/tcop/Makefile,v 1.10 1997/04/02 18:13:01 scrappy Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -17,13 +17,6 @@ INCLUDE_OPT= -I.. \
 
 CFLAGS+= $(INCLUDE_OPT)
 
-ifeq ($(CC), gcc)
-# Until we figure out how to get rid of the warnings in this directory,
-# we must turn off any -Werror that is in CFLAGS now.  These options only
-# exist for the gcc compiler.
-CFLAGS+= -Wno-error
-endif
-
 OBJS= aclchk.o dest.o fastpath.o postgres.o pquery.o utility.o variable.o
 
 all: SUBSYS.o
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 88eec7a6830..f4ab1a6f585 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *    $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.11 1997/03/14 23:21:12 scrappy Exp $
+ *    $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.12 1997/04/02 18:13:24 scrappy Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -311,7 +311,11 @@ text_lt(struct varlena *arg1, struct varlena *arg2)
 	    len--;
 	}
     if (len)
+#ifdef USE_LOCALE
+        return (bool) (strcoll(a2p,a1p));
+#else
 	return (bool) (*a1p < *a2p);
+#endif
     else
 	return (bool) (arg1->vl_len < arg2->vl_len);
 }
@@ -342,7 +346,11 @@ text_le(struct varlena *arg1, struct varlena *arg2)
 	    len--;
 	}
     if (len)
+#ifdef USE_LOCALE
+        return (bool) (strcoll(a2p,a1p));
+#else
 	return (bool) (*a1p < *a2p);
+#endif
     else
 	return ((bool) VARSIZE(arg1) <= VARSIZE(arg2));
 }
diff --git a/src/interfaces/libpgtcl/Makefile b/src/interfaces/libpgtcl/Makefile
index 6780b71c694..059072c9ffb 100644
--- a/src/interfaces/libpgtcl/Makefile
+++ b/src/interfaces/libpgtcl/Makefile
@@ -7,7 +7,7 @@
 #
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/Makefile,v 1.11 1997/03/25 09:19:41 scrappy Exp $
+#    $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/Makefile,v 1.12 1997/04/02 18:13:47 scrappy Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -25,11 +25,6 @@ ifdef KRBVERS
 CFLAGS+= $(KRBFLAGS)
 endif
 
-ifeq ($(CC), gcc)
-  CFLAGS+= -Wno-error
-endif
-
-
 shlib             := 
 install-shlib-dep :=
 
-- 
GitLab