[PATCH] awk: GNU extension -e
Denys Vlasenko
vda.linux at googlemail.com
Tue Nov 12 13:21:36 UTC 2013
On Tue, Nov 5, 2013 at 12:55 PM, Sven-Göran Bergh
<svengbergh-busybox at yahoo.com> wrote:
> Example: awk -f mylib.awk '{print myfunction($1);}' ...
+ g_progname = "cmd. line";
+#if ENABLE_FEATURE_AWK_GNU_EXTENSIONS
+ while (list_e) { /* -e */
+ parse_program(llist_pop(&list_e));
+ }
+ if (AWK_PROG_DEFINED) /* -e or -f */
+ argc++;
+ if (*argv && access(*argv, F_OK)) /* not a file -> parse it */
+ parse_program(*argv++);
+ else if (!AWK_PROG_DEFINED) /* no program defined */
+ bb_show_usage();
+#else
+ if (AWK_PROG_DEFINED) {
argc++;
} else { // no -f: take program from 1st parameter
if (!argc)
bb_show_usage();
- g_progname = "cmd. line";
parse_program(*argv++);
}
- if (opt & 0x8) // -W
+#endif
The above looks too complex. Can it be just:
g_progname = "cmd. line";
#if ENABLE_FEATURE_AWK_GNU_EXTENSIONS
while (list_e) { /* -e */
parse_program(llist_pop(&list_e));
}
#endif
if (!(opt & (OPT_f | OPT_e))) {
if (!*argv)
bb_show_usage();
parse_program(*argv++);
argc++;
}
>+//config: * simultaneous use of -f and an Awk program on the command line.
>+//config: This enables the use of awk library files.
>+//config: Ex: awk -f mylib.awk '{print myfunction($1);}' ...
This does not seem to work with GNU Awk 4.0.1:
$ awk -f EMPTYFILE 'BEGIN {print "hello";}'
$ awk -f EMPTYFILE -e 'BEGIN {print "hello";}'
hello
$
In the first case, it seems that 'BEGIN {print "hello";}'
is taken as a _filename_, not _awk program_.
More information about the busybox
mailing list