aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--doc/ChangeLog4
-rw-r--r--doc/gawk.texi19
-rw-r--r--doc/gawktexi.in19
-rw-r--r--main.c28
5 files changed, 76 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 18372620..8e2e51a0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2015-05-15 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * main.c (load_procinfo_argv): New function to save argv array values
+ in PROCINFO["argv"][0..argc-1].
+ (load_procinfo): Call load_procinfo_argv.
+
2015-05-05 Arnold D. Robbins <arnold@skeeve.com>
* awkgram.y (yylex): Yet Another Fix for parsing bracket
diff --git a/doc/ChangeLog b/doc/ChangeLog
index 6a19e9d3..edb19d48 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,7 @@
+2015-05-15 Andrew J. Schorr <aschorr@telemetry-investments.com>
+
+ * gawktexi.in (Undocumented): Describe the new PROCINFO["argv"] array.
+
2015-05-14 Arnold D. Robbins <arnold@skeeve.com>
* gawktexi.in (Bugs): Add that email should be in plain
diff --git a/doc/gawk.texi b/doc/gawk.texi
index b684341b..b1ff4944 100644
--- a/doc/gawk.texi
+++ b/doc/gawk.texi
@@ -4907,6 +4907,25 @@ function names added by @command{gawk} after the code was written.
Standard @command{awk} built-in functions, such as @code{sin()} or
@code{substr()} are @emph{not} shadowed in this way.
+The @code{PROCINFO["argv"]} array contains all of the command-line arguments
+(after glob expansion and redirection processing on platforms where that must
+be done manually by the program) with subscripts ranging from 0 through
+@code{argc} @minus{} 1. For example, @code{PROCINFO["argv"][0]} will contain
+the name by which @command{gawk} was invoked. Here is an example of how this
+feature may be used:
+
+@example
+awk '
+BEGIN @{
+ for (i = 0; i < length(PROCINFO["argv"]); i++)
+ print i, PROCINFO["argv"][i]
+@}'
+@end example
+
+Please note that this differs from the standard @code{ARGV} array which does
+not include command-line arguments that have already been processed by
+@command{gawk} (@pxref{ARGC and ARGV}).
+
@end ignore
@node Invoking Summary
diff --git a/doc/gawktexi.in b/doc/gawktexi.in
index da7eeef1..2610a74b 100644
--- a/doc/gawktexi.in
+++ b/doc/gawktexi.in
@@ -4818,6 +4818,25 @@ function names added by @command{gawk} after the code was written.
Standard @command{awk} built-in functions, such as @code{sin()} or
@code{substr()} are @emph{not} shadowed in this way.
+The @code{PROCINFO["argv"]} array contains all of the command-line arguments
+(after glob expansion and redirection processing on platforms where that must
+be done manually by the program) with subscripts ranging from 0 through
+@code{argc} @minus{} 1. For example, @code{PROCINFO["argv"][0]} will contain
+the name by which @command{gawk} was invoked. Here is an example of how this
+feature may be used:
+
+@example
+awk '
+BEGIN @{
+ for (i = 0; i < length(PROCINFO["argv"]); i++)
+ print i, PROCINFO["argv"][i]
+@}'
+@end example
+
+Please note that this differs from the standard @code{ARGV} array which does
+not include command-line arguments that have already been processed by
+@command{gawk} (@pxref{ARGC and ARGV}).
+
@end ignore
@node Invoking Summary
diff --git a/main.c b/main.c
index ef4f8550..b17ab309 100644
--- a/main.c
+++ b/main.c
@@ -892,6 +892,33 @@ load_environ()
return ENVIRON_node;
}
+static void
+load_procinfo_argv()
+{
+ NODE *tmp;
+ NODE **aptr;
+ NODE *argv_array;
+ int i;
+
+ tmp = make_string("argv", 4);
+ aptr = assoc_lookup(PROCINFO_node, tmp);
+ unref(tmp);
+ unref(*aptr);
+ getnode(argv_array);
+ memset(argv_array, '\0', sizeof(NODE)); /* valgrind wants this */
+ null_array(argv_array);
+ *aptr = argv_array;
+ argv_array->parent_array = PROCINFO_node;
+ argv_array->vname = estrdup("argv", 4);
+ for (i = 0; d_argv[i] != NULL; i++) {
+ tmp = make_number(i);
+ aptr = assoc_lookup(argv_array, tmp);
+ unref(tmp);
+ unref(*aptr);
+ *aptr = make_string(d_argv[i], strlen(d_argv[i]));
+ }
+}
+
/* load_procinfo --- populate the PROCINFO array */
static NODE *
@@ -991,6 +1018,7 @@ load_procinfo()
groupset = NULL;
}
#endif
+ load_procinfo_argv();
return PROCINFO_node;
}