aboutsummaryrefslogtreecommitdiffstats
path: root/awkgram.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2016-03-27 06:22:32 +0300
committerArnold D. Robbins <arnold@skeeve.com>2016-03-27 06:22:32 +0300
commit3a154919fe4c0e820f989e2bb347d6f8b87a7a79 (patch)
treea00771ee28a8a50be5226028e369a74f960fdabb /awkgram.c
parent75310c929a0f7a2f957ec866a8caa093283a386f (diff)
downloadegawk-3a154919fe4c0e820f989e2bb347d6f8b87a7a79.tar.gz
egawk-3a154919fe4c0e820f989e2bb347d6f8b87a7a79.tar.bz2
egawk-3a154919fe4c0e820f989e2bb347d6f8b87a7a79.zip
Pretty printer: remove CRs and trailing newlines from comments.
Diffstat (limited to 'awkgram.c')
-rw-r--r--awkgram.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/awkgram.c b/awkgram.c
index a11498fe..bd531efb 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -5602,10 +5602,14 @@ get_comment(int flag)
tok = tokstart;
tokadd('#');
sl = sourceline;
+ char *p1;
+ char *p2;
while (true) {
while ((c = nextc(false)) != '\n' && c != END_FILE) {
- tokadd(c);
+ /* ignore \r characters */
+ if (c != '\r')
+ tokadd(c);
}
if (flag == EOL_COMMENT) {
/* comment at end of line. */
@@ -5638,6 +5642,15 @@ get_comment(int flag)
if (comment != NULL)
prior_comment = comment;
+ /* remove any trailing blank lines (consecutive \n) from comment */
+ p1 = tok - 1;
+ p2 = tok - 2;
+ while (*p1 == '\n' && *p2 == '\n') {
+ p1--;
+ p2--;
+ tok--;
+ }
+
comment = bcalloc(Op_comment, 1, sl);
comment->source_file = source;
comment->memory = make_str_node(tokstart, tok - tokstart, 0);