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

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

gawk option processing


From: Stepan Kasal
Subject: gawk option processing
Date: Mon, 20 May 2002 15:27:24 +0200
User-agent: Mutt/1.2.5.1i

Hallo,
        I've created a patch relative to gawk-3.1.1. Its main purpose
is change of option processing.

Currently, all the options are processed in one big while(switch())
loop.  Since the options may contain information how should the engine
be set up (--posix) for example, as well as variable assignments (-v
and also -F options), it's difficult to get all in one loop:
        1) you have to do some preliminary initialization,
        2) you process the option loop (including pre-assignments),
        3) if the setup is not default, you have to redo certain parts
           of the initialisation (reset the regex engine, reinterpret
           RS and FS, at least).

I thought the code could be much cleaner if we just remember the
assignments and process them later.
(In fact the current code contains something similar--the -f options
(source files) are remmbered for later compilation.)
So the program looks much better (at least to me :-), you have
        1) process options (deferring not only -f's but also -v and -F)
        2) do the initialisation (things like --posix are already known)
        3) do all the pre-assignments

Patch is attached.  (It's hand crafted so that it applies to plain
gawk-3.1.1 as well as gawk-3.1.1 with my previous patches.  The flaw is that
it reports "fuzz 2" to hunks #4 and #5 of main.c in both versions.)

To support the patch I've even thouht out an artificial bug report:
Since the following two commands are equvalent:
        $ awk --re-interval -F':{2}' 'BEGIN{$0="a::b";print $2}'
        b
        $ awk -F':{2}' --re-interval 'BEGIN{$0="a::b";print $2}'
        b
the following two should also be:
        $ awk --traditional -F\t 'BEGIN{$0="atc\tha";print $2}'
        ha
        $ awk -F\t --traditional 'BEGIN{$0="atc\tha";print $2}'
        c       ha
But, as you see, they are not.

The patch also contains the following changes:

arg_assign has again a third parameter, initing.
It's used to generate more comprehensive error/warning messages (and to exit
eventually, so the caller need not to check it).

arg_assign returns int (Bool), not pointer, since the poiter is never used.
(This change remove a "bad coding style" error from io.c--Aharon, you told
me to read the section about coding style, and you break your own rules! ;-)

pre_assign is no longer needed, since the code in profile.c seems to be fixed.

typo: "profling"

Looking forward to any comments to the patch,
        Stepan Kasal

Attachment: gawk-3.1.1-options_vF.patch
Description: Text document


reply via email to

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