bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Possible gawk Bug--Handling of --source Option


From: Neil R. Ormos
Subject: Re: [bug-gawk] Possible gawk Bug--Handling of --source Option
Date: Thu, 4 May 2017 20:36:13 -0500 (CDT)

I'm forwarding the message below, originally
written by Arnold Robbins, to the list, at his
request.  It reports changes he made to address
an issue I reported under this Subject:.

I'm sorry for the delay; I didn't notice
the request to forward until late.

Thanks to Mr. Robbins for this fix and his
continued work on gawk.

Best regards,

--Neil Ormos

---------- Forwarded message ----------
Date: Sun, 23 Apr 2017 22:20:40 +0300
From: Arnold Robbins <address@hidden>
To: address@hidden
Subject: Re: [bug-gawk] Possible gawk Bug--Handling of --source Option

Hi.

Thanks for this report.  The diff at the end of the message fixes the
problem and improves the documentation. I will commit this change to
the master branch shortly.

Thanks,

Arnold

> Date: Thu, 13 Apr 2017 14:58:02 -0500 (CDT)
> From: "Neil R. Ormos" <address@hidden>
> To: Bug Gawk Mailing List <address@hidden>
> Subject: [bug-gawk] Possible gawk Bug--Handling of --source Option
>
> I have a question about a behavior of gawk 4.1.1 which differs from that
> in 3.1.7.  I'm not sure if it's a bug.
>
> The possible bug relates how gawk handles program text provided on the
> command line in an argument to a --source= option.
>
> Older gawk (e.g. 3.1.7) appears to allow the statements of a single
> action to be distributed among several --source= arguments that appear
> on the command line invoking gawk.
>
> The gawk in Debian Stable (e.g. 4.1.1) appears to require that any
> action opened in a --source= argument be closed in the same argument,
> so that an action cannot span multple --source= arguments.
>
> As far as I can tell, the the GNU Awk User's Guide does not directly
> specify either the new or the old behavior.  However, the manual's
> section directed to the igawk shell-wrapper script [*], that provides
> a mechanism for including files but otherwise appears to be intended
> to simulate invoking gawk the ordinary way, characterizes the wrapper
> script's handling of a --source argument as, "The source text is appended
> to program".
>
> [*] http://www.gnu.org/software/gawk/manual/gawk.html#Igawk-Program
>
> ############################################################
> ### OLD ###
>
> > lsb_release -d
> Description:    Debian GNU/Linux 6.0.10 (squeeze)
>
> > gawk --version
> GNU Awk 3.1.7
> [...]
>
> > gawk --source='BEGIN{a=5};' --source='BEGIN{print a}'
> 5
>
> > gawk --source='BEGIN{a=5; ' --source='print a}'
> 5
>
> ############################################################
> ### NEW ###
>
> > lsb_release -d
> Description:  Debian GNU/Linux 8.7 (jessie)
>
> > gawk --version
> GNU Awk 4.1.1, API: 1.1 (GNU MPFR 3.1.2-p3, GNU MP 6.0.0)
> [...]
>
> > gawk --source='BEGIN{a=5};' --source='BEGIN{print a}'
> 5
>
> > gawk --source='BEGIN{a=5; ' --source='print a}'
> gawk: cmd. line:1: BEGIN{a=5;
> gawk: cmd. line:1:            ^ unexpected newline or end of string
>
> ############################################################
>
> This seems like a bug to me, but I don't know if the completeness of a 
> --source argument is specified more definitively somewhere other than in the 
> User's Guide.
>
> Thanks for your help.
>
> Best regards,
>
> --Neil Ormos

--------------------------------------------------------------
diff --git a/ChangeLog b/ChangeLog
index 101a89f..c91c833 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2017-04-23         Arnold D. Robbins     <address@hidden>
+
+       * awkgram.y (nextc): Adjust so that 3.1.x behavior is restored
+       whereby --source arguments are concatenated. Thanks to
+       "Neil R. Ormos" <address@hidden> for the report.
+
 2017-04-21         Arnold D. Robbins     <address@hidden>

        * awk.h (NODE): Put the `val' subportion back the way it
diff --git a/awkgram.y b/awkgram.y
index 46970ee..6e4d6c3 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -3099,8 +3099,21 @@ nextc(bool check_for_bad)
 {
        if (gawk_mb_cur_max > 1) {
 again:
+#ifdef NO_CONTINUE_SOURCE_STRINGS
                if (lexeof)
                        return END_FILE;
+#else
+               if (lexeof) {
+                       if (sourcefile->next == srcfiles)
+                               return END_FILE;
+                       else {
+                               next_sourcefile();
+                               if (get_src_buf())
+                                       goto again;
+                               return END_SRC;
+                       }
+               }
+#endif
                if (lexptr == NULL || lexptr >= lexend) {
                        if (get_src_buf())
                                goto again;
@@ -3152,8 +3165,17 @@ again:
                return (int) (unsigned char) *lexptr++;
        } else {
                do {
+#ifdef NO_CONTINUE_SOURCE_STRINGS
                        if (lexeof)
                                return END_FILE;
+#else
+                       if (lexeof) {
+                               if (sourcefile->next == srcfiles)
+                                       return END_FILE;
+                               else
+                                       next_sourcefile();
+                       }
+#endif
                        if (lexptr && lexptr < lexend) {
                                if (check_for_bad || *lexptr == '\0')
                                        check_bad_char(*lexptr);
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 24ff43a..ad5aca4 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,7 @@
+2017-04-23         Arnold D. Robbins     <address@hidden>
+
+       * gawktexi.in: Improve documentation of --source option.
+
 2017-04-20         Arnold D. Robbins     <address@hidden>

        * gawktexi.in: Document --disable-mpfr configure option.
diff --git a/doc/gawktexi.in b/doc/gawktexi.in
index bbf7f5d..d570793 100644
--- a/doc/gawktexi.in
+++ b/doc/gawktexi.in
@@ -3872,6 +3872,24 @@ This is particularly useful
 when you have library functions that you want to use from your command-line
 programs (@pxref{AWKPATH Variable}).

+Note that @command{gawk} treats each string as if it ended with
+a newline character (even if it doesn't). This makes building
+the total program easier.
+
address@hidden CAUTION
+At the moment, there is no requirement that each @var{program-text}
+be a full syntactic unit. I.e., the following currently works:
+
address@hidden
+$ @kbd{gawk -e 'BEGIN @{ a = 5 ;' -e 'print a @}'}
address@hidden 5
address@hidden example
+
address@hidden
+However, this could change in the future, so it's not a
+good idea to rely upon this feature.
address@hidden quotation
+
 @item @option{-E} @var{file}
 @itemx @option{--exec} @var{file}
 @cindex @option{-E} option



reply via email to

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