bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gawk locale setting


From: Aharon Robbins
Subject: Re: gawk locale setting
Date: Mon, 28 Apr 2003 15:41:56 +0300

Greetings all. Re this:

> Date: Wed, 23 Apr 2003 15:57:15 +0200
> From: Stepan Kasal <address@hidden>
> To: robert <address@hidden>
> Cc: address@hidden
> Subject: Re: gawk locale setting
>
> Hello,
>
> On Wed, Apr 09, 2003 at 08:58:29PM +0200, robert wrote:
> > I am using Mandrake Linux 9.1 and gawk 3.1.1. I wondering if even i have 
> > LC_NUMERIC set to "de" the output of the decimal_point is "." The locale 
>
> unfortunately not.  Current gawk (version 3.1.2) doesn't use LC_NUMERIC.
> (To be exact, the gawk C source code enforces LC_NUMERIC=C.)
>
> So the print/printf commands within awk source are not affected by
> the value of LC_NUMERIC.
>
> It is planned that gawk programs could make use of LC_NUMERIC value,
> either taken from environment or specified explicitely, but in both
> cases the program would have to switch this on, it won't be on by default
> because of backwadr compatibility.
>
> The plan is that
>       PROCINFO["LC_NUMERIC"] = "de"
> would choose ``de'' explicitely and
>       PROCINFO["LC_NUMERIC"] = ""
> would import the value from current environment.
>
> But no final decisin has been made yet.
> Any comments are welcome.
>
> Have a nice day,
>       Stepan Kasal

Actually, since my long-ago email with Stepan, I've decided that
gawk is just going to follow POSIX.  Here is a patch based on
my current code base.

Arnold

--- ../gawk-3.1.2/main.c        2003-03-19 14:11:18.000000000 +0200
+++ main.c      2003-04-12 22:51:17.000000000 +0300
@@ -232,8 +232,10 @@
 #endif
 #if defined(LC_NUMERIC)
        /*
-        * Force the issue here. On some systems, gawk ends up
-        * printing output with commas for the decimal point.
+        * Force the issue here.  According to POSIX 2001, decimal
+        * point is used for parsing source code and for command-line
+        * assignments and the locale value for processing input,
+        * number to string conversion, and printing output.
         */
        setlocale(LC_NUMERIC, "C");
 #endif
@@ -548,6 +550,11 @@
 
        init_profiling_signals();
 
+#if defined(LC_NUMERIC)
+       /* See comment above. */
+       setlocale(LC_NUMERIC, "");
+#endif
+
        /* Whew. Finally, run the program. */
        if (begin_block != NULL) {
                in_begin_rule = TRUE;
@@ -973,6 +980,11 @@
                 */
                it = make_str_node(cp, strlen(cp), SCAN);
                it->flags |= (MAYBE_NUM|SCALAR);
+#ifdef LC_NUMERIC
+               setlocale(LC_NUMERIC, "C");
+               (void) force_number(it);
+               setlocale(LC_NUMERIC, "");
+#endif /* LC_NUMERIC */
                var = variable(arg, FALSE, Node_var);
                lhs = get_lhs(var, &after_assign, FALSE);
                unref(*lhs);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]