[tz] winnow patches

Alan Barrett apb at cequrux.com
Sat Sep 7 14:57:01 UTC 2013


On Sun, 01 Sep 2013, Zefram wrote:
> OK, patches.  You can pull the changes from my git repo, 
> <git://git.fysh.org/zefram/tz.git> branch zefram/winnow.  It's 
> based on Eggert's current master branch.  Unfortunately the 
> first patch, which adds the population data, is a bit big for 
> the mailing list:

While trying to test this code, I encountered two problems in the
awk programs.

1. The standard awk split() function does not accept regular 
expressions delimited by slashes.  For example, you should use the 
standard

         split(region_data, rd, "\\n")

instead of the non-standard

         split(region_data, rd, /\n/)

2. In standard awk, the command line option "-v variable=value" 
requires the "value" part to be expressed in the same notation 
as is used for double-quoted strings in awk source code.  By my 
reading of the POSIX specification for awk 
<http://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html>, 
this implies that raw newlines are not allowed there, although 
newlines encoded as \n are allowed.  You can deal with this using 
environment variables, like this:

                 winnow_result=$(
                         d="$region_data" \
                         $AWK '
                         BEGIN {
                                 d = ENVIRON["d"]
                                 gsub(/\t[^\t\n]*/, "", d)
                                 print d
                                 exit
                         }
                 ' </dev/null | [...]

Alternatively, you could pass positional arguments instead of options,
like this:

                 winnow_result=$(
                         $AWK '
                         BEGIN {
                                 d = ARGV[1]
                                 gsub(/\t[^\t\n]*/, "", d)
                                 print d
                                 exit
                         }
                 ' \
                 "$region_data" \
                 </dev/null | [...]

--apb (Alan Barrett)



More information about the tz mailing list