gawk-diffs
[Top][All Lists]
Advanced

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

[SCM] gawk branch, stable/pretty-printer, created. gawk-4.1.0-5539-gea47


From: Arnold Robbins
Subject: [SCM] gawk branch, stable/pretty-printer, created. gawk-4.1.0-5539-gea471067
Date: Wed, 25 Sep 2024 01:38:23 -0400 (EDT)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".

The branch, stable/pretty-printer has been created
        at  ea471067dfa8536dd413eda63e74597dc4ad5348 (commit)

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=ea471067dfa8536dd413eda63e74597dc4ad5348

commit ea471067dfa8536dd413eda63e74597dc4ad5348
Author: Arnold D. Robbins <arnold@skeeve.com>
Date:   Wed Sep 25 08:37:47 2024 +0300

    Clean up spurious newlines in pretty printer output.

diff --git a/ChangeLog b/ChangeLog
index f606530d..828b367d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2024-09-25         Arnold D. Robbins     <arnold@skeeve.com>
+
+       Clean up spurious newlines in pretty printer output.
+       Thanks to John Devin <john.m.devin@gmail.com> for the
+       motivation.
+
+       * awk.h (close_prof_file): New function.
+       * main.c (main): All close_prof_file.
+       * profile.c (close_prof_file): New function.
+       (at_start): New variable.
+       (pprint, print_lib_list, print_include_list, print_comment,
+       pp_func, pp_namespace): Use it.
+
 2024-09-19         Arnold D. Robbins     <arnold@skeeve.com>
 
        * array.c (do_delete): Handle case where subscript is Node_elem_new.
diff --git a/awk.h b/awk.h
index 9997534d..683a90c2 100644
--- a/awk.h
+++ b/awk.h
@@ -1745,6 +1745,7 @@ extern void (*lintfunc)(const char *mesg, ...);
 /* profile.c */
 extern void init_profiling_signals(void);
 extern void set_prof_file(const char *filename);
+extern void close_prof_file(void);
 extern void dump_prog(INSTRUCTION *code);
 extern char *pp_number(NODE *n);
 extern char *pp_string(const char *in_str, size_t len, int delim);
diff --git a/main.c b/main.c
index 4ef0208d..9c6e66ef 100644
--- a/main.c
+++ b/main.c
@@ -546,6 +546,7 @@ main(int argc, char **argv)
                set_current_namespace(awk_namespace);
                dump_prog(code_block);
                dump_funcs();
+               close_prof_file();
        }
 
        if (do_dump_vars)
diff --git a/profile.c b/profile.c
index 256c641d..962b8cdc 100644
--- a/profile.c
+++ b/profile.c
@@ -67,6 +67,8 @@ static long indent_level = 0;
 static const char tabs[] = 
"\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
 static const size_t tabs_len = sizeof(tabs) - 1;
 
+static bool at_start = true;
+
 #define check_indent_level() \
        if (indent_level + 1 > tabs_len) \
                /* We're allowed to be snarky, occasionally. */ \
@@ -114,6 +116,17 @@ set_prof_file(const char *file)
        }
 }
 
+/* close_prof_file --- close the output file for profiling or pretty-printing 
*/
+
+void
+close_prof_file(void)
+{
+       if (prof_fp != NULL
+           && fileno(prof_fp) != fileno(stdout)
+           && fileno(prof_fp) != fileno(stderr))
+               (void) fclose(prof_fp);
+}
+
 /* init_profiling_signals --- set up signal handling for gawk --profile */
 
 void
@@ -269,7 +282,11 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, int flags)
                                        if (! rule_count[rule]++)
                                                fprintf(prof_fp, _("\t# %s 
rule(s)\n\n"), ruletab[rule]);
                                        indent(0);
-                               }
+                               } else if (! at_start)
+                                       putc('\n', prof_fp);
+                               else
+                                       at_start = false;
+
                                fprintf(prof_fp, "%s {", ruletab[rule]);
                                end_line(pc);
                                skip_comment = true;
@@ -277,6 +294,10 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, int flags)
                                if (do_profile && ! rule_count[rule]++)
                                        fprintf(prof_fp, _("\t# Rule(s)\n\n"));
                                ip1 = pc->nexti;
+                               if (! at_start)
+                                       putc('\n', prof_fp);
+                               else
+                                       at_start = false;
                                indent(ip1->exec_count);
                                if (ip1 != (pc + 1)->firsti) {          /* 
non-empty pattern */
                                        pprint(ip1->nexti, (pc + 1)->firsti, 
NO_PPRINT_FLAGS);
@@ -308,7 +329,7 @@ pprint(INSTRUCTION *startp, INSTRUCTION *endp, int flags)
                        indent_out();
                        if (do_profile)
                                indent(0);
-                       fprintf(prof_fp, "}\n\n");
+                       fprintf(prof_fp, "}\n");
                        pc = (pc + 1)->lasti;
                        break;
 
@@ -1338,7 +1359,7 @@ print_lib_list(FILE *prof_fp)
                }
        }
        if (found)      /* we found some */
-               fprintf(prof_fp, "\n");
+               at_start = false;
 }
 
 /* print_include_list --- print a list of all files included */
@@ -1369,7 +1390,7 @@ print_include_list(FILE *prof_fp)
                }
        }
        if (found)      /* we found some */
-               fprintf(prof_fp, "\n");
+               at_start = false;
 }
 
 /* print_comment --- print comment text with proper indentation */
@@ -1381,6 +1402,13 @@ print_comment(INSTRUCTION* pc, long in)
        size_t count;
        bool after_newline = false;
 
+       if (pc->memory->comment_type == BLOCK_COMMENT) {
+               if (! at_start && indent_level == 0)
+                       putc('\n', prof_fp);
+               else
+                       at_start = false;
+       }
+
        count = pc->memory->stlen;
        text = pc->memory->stptr;
 
@@ -2031,6 +2059,7 @@ pp_func(INSTRUCTION *pc, void *data ATTRIBUTE_UNUSED)
        if (do_profile)
                indent(0);
        fprintf(prof_fp, "}\n");
+       at_start = false;
        return 0;
 }
 
@@ -2071,8 +2100,8 @@ 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 (! at_start)
+               fprintf(prof_fp, "\n");
 
        if (do_profile)
                indent(SPACEOVER);
@@ -2082,9 +2111,11 @@ pp_namespace(const char *name, INSTRUCTION *comment)
        if (comment != NULL) {
                putc('\t', prof_fp);
                print_comment(comment, 0);
-               putc('\n', prof_fp);
+               // no newline here, print_comment puts one out
        } else
-               fprintf(prof_fp, "\n\n");
+               fprintf(prof_fp, "\n");
+
+       at_start = false;
 }
 
 /* pp_namespace_list --- print the list, back to front, using recursion */

-----------------------------------------------------------------------


hooks/post-receive
-- 
gawk



reply via email to

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