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

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

Re: printf expert system idea; gawk printf peculiarity


From: Aharon Robbins
Subject: Re: printf expert system idea; gawk printf peculiarity
Date: Sun, 28 Oct 2001 16:56:48 +0200

Greetings.  Re this:

> From: address@hidden (Dan Jacobson)
> Subject: printf expert system idea; gawk printf peculiarity
> Date: 28 Oct 2001 04:51:59 +0800
>
> Given that gawk is rightly picky here:
>
> BEGIN{printf "%s%s%s", a,a}
> awk: a.awk:1: fatal: not enough arguments to satisfy format string
>       `%s%s%s'
>           ^ ran out for this one
>
> then how could it just let smile and let this past:
>
> BEGIN{printf "%s%s%s", a,a,a,a}

In the grand tradition of the C version of printf(3s), which allows you
to silently supply extra arguments to printf, gawk also doesn't complain.
As it's not a "gee, I can't continue" sort of error, gawk by default
lets it go.

There is actually a lint check for this, but the code that enables
it didn't get revised when I changed how printf works for 3.1 See the
patch below.

> Oh and by the way, why does it say "ran out for this one" when it
> really ran out for the last one.

It would seem to be an off-by-one error.  Patch also included
below.

Arnold
---------------------------------------------------------------
*** ../gawk-3.1.0/builtin.c     Tue Feb 27 12:14:24 2001
--- builtin.c   Sun Oct 28 16:54:45 2001
***************
*** 945,958 ****
                if (toofew)
                        fatal("%s\n\t`%s'\n\t%*s%s",
                              _("not enough arguments to satisfy format 
string"),
!                             fmt_string, s1 - fmt_string - 2, "",
                              _("^ ran out for this one"));
        }
        if (do_lint) {
                if (need_format)
                        lintwarn(
                        _("[s]printf: format specifier does not have control 
letter"));
!               if (carg != NULL)
                        lintwarn(
                        _("too many arguments supplied for format string"));
        }
--- 956,969 ----
                if (toofew)
                        fatal("%s\n\t`%s'\n\t%*s%s",
                              _("not enough arguments to satisfy format 
string"),
!                             fmt_string, s1 - fmt_string - 1, "",
                              _("^ ran out for this one"));
        }
        if (do_lint) {
                if (need_format)
                        lintwarn(
                        _("[s]printf: format specifier does not have control 
letter"));
!               if (cur_arg < num_args)
                        lintwarn(
                        _("too many arguments supplied for format string"));
        }



reply via email to

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