Re: [mu SETUP] Can't change to static / bitwise ops in 'awk'

From: Alfie Costa (agcosta@gis.net)
Date: Sat Apr 13 2002 - 08:37:46 CEST


On 12 Apr 2002, at 15:37, Michele Andreoli <mulinux@sunsite.dk> wrote:

> I solved the problem, enhancing a little the "expr" command: now it
> is able to to logical bitwise operation such
>
> # expr 4 & 255
> # expr ~ 4
>
> etc (must quote \&, \~).
> After that, I changed the ip_network and the ip_broadcast AWK script,
> calling the external program expr (ugly, but awk do not seems to support
> this kind of C language operation).

Thinking "that can't be right", I looked in the mawk manual. But no, it IS
right, there are no bitwise operators in awk, maybe because there's no declared
number types.

So I got to thinking, "how hard can it be?" Thus:

        http://www.gis.net/~agcosta/mu_files/awktest.gz (410 bytes)

(Answer: harder than it looked.)

Note that the kludges or functions, (bit_and(), bit_or(), bit_xor(), and
bit_not()), don't understand two's complement negative numbers. Maybe there's
too many variables, and somebody here on the list knows how to simplify the
code.

Redundant, given the new 'expr' changes, but if you
still would like some bitwise functions in 'awk'...

---------------------------------------------------------------------
To unsubscribe, e-mail: mulinux-unsubscribe@sunsite.dk
For additional commands, e-mail: mulinux-help@sunsite.dk



This archive was generated by hypermail 2.1.6 : Sat Feb 08 2003 - 15:27:21 CET