aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--doc/ChangeLog4
-rw-r--r--doc/gawk.texi13
-rw-r--r--doc/gawktexi.in13
-rw-r--r--msg.c9
5 files changed, 42 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 8c92378b..47e5cdd3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2019-04-18 Arnold D. Robbins <arnold@skeeve.com>
+
+ * msg.c (msg): Add an undocumented feature. "Use the Source, Luke."
+
2019-04-12 Arnold D. Robbins <arnold@skeeve.com>
* configure.ac: Update version to 5.0.0.
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 6f4467d9..f3964012 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,7 @@
+2019-04-18 Arnold D. Robbins <arnold@skeeve.com>
+
+ * gawktexi.in (Undocumented): Note an undocumented feature.
+
2019-04-14 Arnold D. Robbins <arnold@skeeve.com>
* gawktexi.in (Case-sensitivity): Document that single-byte
diff --git a/doc/gawk.texi b/doc/gawk.texi
index e5371c61..02481a7c 100644
--- a/doc/gawk.texi
+++ b/doc/gawk.texi
@@ -5035,6 +5035,19 @@ returns a textual version of the flags for scalar variables, and the
array back-end implementation type for arrays. This interface is subject
to change and may not be stable.
+When not in POSIX or compatibility mode, if you set @code{LINENO} to a
+numeric value using the @option{-v} option, @command{gawk} adds that value
+to the real line number for use in error messages. This is intended for
+use within Bash shell scripts, such that the error message will reflect
+the line number in the shell script, instead of in the @command{awk}
+program. To demonstrate:
+
+@exmaple
+$ @kbd{gawk -v LINENO=10 'BEGIN @{ print("hi" @}'}
+@error{} gawk: cmd. line:11: BEGIN @{ print("hi" @}
+@error{} gawk: cmd. line:11: ^ syntax error
+@end example
+
@end ignore
@node Invoking Summary
diff --git a/doc/gawktexi.in b/doc/gawktexi.in
index 14e20b7a..0408d61c 100644
--- a/doc/gawktexi.in
+++ b/doc/gawktexi.in
@@ -4945,6 +4945,19 @@ returns a textual version of the flags for scalar variables, and the
array back-end implementation type for arrays. This interface is subject
to change and may not be stable.
+When not in POSIX or compatibility mode, if you set @code{LINENO} to a
+numeric value using the @option{-v} option, @command{gawk} adds that value
+to the real line number for use in error messages. This is intended for
+use within Bash shell scripts, such that the error message will reflect
+the line number in the shell script, instead of in the @command{awk}
+program. To demonstrate:
+
+@exmaple
+$ @kbd{gawk -v LINENO=10 'BEGIN @{ print("hi" @}'}
+@error{} gawk: cmd. line:11: BEGIN @{ print("hi" @}
+@error{} gawk: cmd. line:11: ^ syntax error
+@end example
+
@end ignore
@node Invoking Summary
diff --git a/msg.c b/msg.c
index 12cc2aac..ca988ad3 100644
--- a/msg.c
+++ b/msg.c
@@ -46,10 +46,17 @@ err(bool isfatal, const char *s, const char *emsg, va_list argp)
static bool first = true;
static bool add_src_info = false;
+ static long lineno_val = 0; // Easter Egg
if (first) {
first = false;
add_src_info = (getenv("GAWK_MSG_SRC") != NULL);
+ if (! do_traditional) {
+ NODE *n = lookup("LINENO");
+
+ if (n != NULL && n->type == Node_var)
+ lineno_val = get_number_d(n->var_value);
+ }
}
(void) fflush(output_fp);
@@ -67,7 +74,7 @@ err(bool isfatal, const char *s, const char *emsg, va_list argp)
else
(void) fprintf(stderr, _("cmd. line:"));
- (void) fprintf(stderr, "%d: ", sourceline);
+ (void) fprintf(stderr, "%d: ", sourceline + lineno_val);
}
#ifdef HAVE_MPFR