bug-gawk
[Top][All Lists]
Advanced

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

Re: Gawk --pretty-print and @namespace bug(?)


From: arnold
Subject: Re: Gawk --pretty-print and @namespace bug(?)
Date: Thu, 13 Aug 2020 12:50:30 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Hi.

J Naman <gawker@703n.com> wrote:

> --pretty-print output a @namespace directive *appended to a comment line,
> thus commented out.*
> FYI: Running on *Windows* GNU Awk 5.1.0, API: 3.0 (GNU MPFR 3.1.5, GNU MP
> 6.1.2).
> Source & awkprof attached.

Bug fixed.  Thanks for the report.

> BTW, I never knew/realized/saw in docs that *--prettyprint lists functions
> in alphabetical order*,* when you include the namespace*
> *as part of the name of the function.* My functions were reordered compared
> to source, which I worried might be a bug. Found out it isn't.
>
> A very minor, low priority, *suggestion* for some future update to *The
> User’s Guide for GNU Awk*
> *Add a sentence such as* "--prettyprint lists functions in alphabetical
> order, when you include the namespace
> as part of the name of the function." to the @namespace and/or -prettyprint
> sections
> Thanks! John Naman, gawker@703n.com

I have revised the code to print functions in the awk namespace first,
alphabetically, and then to print them alphabetical by namespace and
alphabetical within each namespace.

I have also updated the doc.

Diff is below. The repo is updated, which includes updates to the
test suite; test suite diffs are not included below.

Thanks!

Arnold
-----------------------------------------
diff --git a/ChangeLog b/ChangeLog
index 9f5b2f4c..2ab03d3f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-08-12         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * profile.c (pp_namespace): Always print a newline before the
+       @namespace, in case it comes after a comment. Thanks to J Naman
+       for the report.
+       * symbol.c (comp_symbol): Adjust comparison so that names in the
+       awk namespace come out first. Makes the order of functions in
+       pretty-printed output more sane. Thanks also to J Naman for
+       getting me to explore this issue.
+
 2020-07-29         Arnold D. Robbins     <arnold@skeeve.com>
 
        * custom.h (FLEXIBLE_ARRAY_MEMBER): Define to 1 for dfa.h.
diff --git a/NEWS b/NEWS
index c879e110..53963c38 100644
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,10 @@ Changes from 5.1.0 to 5.1.1
 7. The test suite has been improved, making it easier to run the entire
    suite with -M. Use `GAWK_TEST_ARGS=-M make check' to do so.
 
+8. Profiling and pretty-printing output has been modified slightly so
+   that functions are presented in a reasonable order with respect
+   to the namespaces that contain them.
+
 Changes from 5.0.1 to 5.1.0
 ---------------------------
 
diff --git a/doc/ChangeLog b/doc/ChangeLog
index a2ce4805..02c5b02d 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,7 @@
+2020-08-12         Arnold D. Robbins     <arnold@skeeve.com>
+
+       * gawktexi.in (Profiling): Add explanation of function order.
+
 2020-07-28         Arnold D. Robbins     <arnold@skeeve.com>
 
        * gawktexi.in: Change a FIXME into a real cross reference. Thanks
diff --git a/doc/gawktexi.in b/doc/gawktexi.in
index 9057e91d..b147b634 100644
--- a/doc/gawktexi.in
+++ b/doc/gawktexi.in
@@ -54,7 +54,7 @@
 @c applies to and all the info about who's publishing this edition
 
 @c These apply across the board.
-@set UPDATE-MONTH July, 2020
+@set UPDATE-MONTH August, 2020
 @set VERSION 5.1
 @set PATCHLEVEL 0
 
@@ -28738,6 +28738,12 @@ front of the @code{BEGIN} and @code{END} rules,
 the @code{BEGINFILE} and @code{ENDFILE} rules,
 the pattern--action rules, and the functions.
 
+@item
+Functions are listed alphabetically. All functions in the @code{awk}
+namespace are listed first, in alphabetical order.  Then come the
+functions in namespaces.  The namespaces are listed in alphabetical order,
+and the functions within each namespace are listed alphabetically.
+
 @end itemize
 
 The profiled version of your program may not look exactly like what you
diff --git a/profile.c b/profile.c
index f959c228..44e171fc 100644
--- a/profile.c
+++ b/profile.c
@@ -2059,6 +2059,9 @@ pp_namespace(const char *name, INSTRUCTION *comment)
        // info saved in Op_namespace instructions.
        current_namespace = name;
 
+       // force newline, could be after a comment
+       fprintf(prof_fp, "\n");
+
        if (do_profile)
                indent(SPACEOVER);
 
diff --git a/symbol.c b/symbol.c
index 29052366..844d8ee8 100644
--- a/symbol.c
+++ b/symbol.c
@@ -366,7 +366,18 @@ comp_symbol(const void *v1, const void *v2)
        n1 = *npp1;
        n2 = *npp2;
 
-       return strcmp(n1->vname, n2->vname);
+       // names in awk namespace come out first
+       bool n1_is_in_ns = (strchr(n1->vname, ':') != NULL);
+       bool n2_is_in_ns = (strchr(n2->vname, ':') != NULL);
+
+       if (n1_is_in_ns && n2_is_in_ns)
+               return strcmp(n1->vname, n2->vname);
+       else if (n1_is_in_ns && ! n2_is_in_ns)
+               return 1;
+       else if (! n1_is_in_ns && n2_is_in_ns)
+               return -1;
+       else
+               return strcmp(n1->vname, n2->vname);
 }
 
 



reply via email to

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