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

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

[gawk] docu-bug: translate.awk not correct


From: Steffen Schuler
Subject: [gawk] docu-bug: translate.awk not correct
Date: Mon, 2 Feb 2009 22:17:26 +0100
User-agent: Mutt/1.5.13 (2006-08-11)

Greetings.

In gawk.texi of gawk-devel and the versions before and in your book
"Effective awk-Programming" the following bug was found:

$ echo ab | gawk -f translate ab ba
aa

Correct would be output: "ba".

Bug fix:

-----------------8<-------------------------------------
-     function stranslate(from, to, target,     lf, lt, t_ar, i, c)
+     function stranslate(from, to, target,     lf, lt, t_ar, i, c, out)
     {
         lf = length(from)
         lt = length(to)
         for (i = 1; i <= lt; i++)
             t_ar[substr(from, i, 1)] = substr(to, i, 1)
         if (lt < lf)
             for (; i <= lf; i++)
                 t_ar[substr(from, i, 1)] = substr(to, lt, 1)
-         for (i = 1; i <= lf; i++) {
-             c = substr(from, i, 1)
-             if (index(target, c) > 0)
-                 gsub(c, t_ar[c], target)
-         }
-         return target
+         for (i = 1; i <= length(target); i++) {
+             c = substr(target, i, 1)
+             if (c in t_ar)
+                 c = t_ar[c]
+             out = out c
+         }
+         return out
     }
-----------------8<-------------------------------------

Regards,

Steffen

-- 
Steffen Schuler (goedel) <address@hidden>
Key ID: 0x42C5D853 / Key-server: pgp.mit.edu

Attachment: signature.asc
Description: Digital signature


reply via email to

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