Bug 59990 - substr does not work
Summary: substr does not work
Keywords:
Status: CLOSED WORKSFORME
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gawk
Version: 7.2
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Florian La Roche
QA Contact: Brock Organ
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-02-18 13:06 UTC by Andreas Luik
Modified: 2007-04-18 16:40 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2002-02-18 16:31:27 UTC
Embargoed:


Attachments (Terms of Use)

Description Andreas Luik 2002-02-18 13:06:48 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.76 [en] (X11; U; SunOS 5.6 sun4u)

Description of problem:
The attached awk script does not return the correct output, but mostly
return nothing, which seems to be a failure of the substr() function,
which returns the empty string.

test.awk:
BEGIN {
        upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        lower = "abcdefghijklmnopqrstuvwxyz";
        value = "0123456789";
        Z = index(upper, "Z") + 1;
        V = index(value, "9") + 1;
}
{
        str = ""
        for (i=1; i <= length($1); i++)
        {
                c = substr($1, i, 1);
                if      (c == "-") a = "-"
                else if (c == ".") a = "."
                else if (c ~ /[0-9]/) a = substr(value, V-index(value,c), 1)
                else if (c ~ /[A-Z]/) a = substr(upper, Z-index(upper,c), 1)
                else  a = substr(lower, Z-index(lower,c), 1);
                str = str a;
        }
        print str;
}


Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1.Save abovementioned test.awk to a file
2.run
    $ echo foo-bar | awk -f test.awk
3.Observe, that the output is "-z", correct output would be
"ull-yzi".

	

Actual Results:  $ echo foo-bar | gawk-3.1.0 -f test.awk
-z


Expected Results:  on a RedHat 6.2 platform:

$ echo foo-bar | gawk -f test.awk
ull-yzi


Additional info:

1. the problem also exists with a gawk compiled from gawk-3.1.0 sources on
RedHat 7.2.
2. the problem does not exist with a gawk compiled from gawk-3.1.0
sources on RedHat 7.1.
3. the problem does not exist with the gawk-3.0.6 binary from
RedHat 7.1.

Comment 1 Florian La Roche 2002-02-18 16:31:22 UTC
This seems to work fine for me on a 7.2 system with the current errata rpms
from ftp.redhat.com applied. Does it make a difference if the glibc update
is applied? What is set in /etc/sysconfig/i18n?

cu,

Florian La Roche




Note You need to log in before you can comment on or make changes to this bug.