diff options
author | Bogdan Purcareata <bogdan.purcareata@freescale.com> | 2013-05-16 12:09:44 +0300 |
---|---|---|
committer | Bruce Ashfield <bruce.ashfield@windriver.com> | 2013-05-17 09:47:32 -0700 |
commit | ea1d9e46ad4392ad7e6d82fce95aa8500d48cbf9 (patch) | |
tree | 46fabe93930c0a46af4cb3eab20c5ca7590ca86d /recipes-core | |
parent | 1cbe97b642b44df5e60fb422164bd9773401db02 (diff) | |
download | meta-virtualization-ea1d9e46ad4392ad7e6d82fce95aa8500d48cbf9.tar.gz |
busybox awk: make -F STR interpret escape sequences
Patch implements functionality mentioned in the title and has
been applied to busybox 1.21.0. This patch is included into the
meta-virtualization layer since it provides awk functionality to
the lxc-clone command in the lxc containers package.
Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Signed-off-by: Bruce Ashfield <bruce.ashfield@windriver.com>
Diffstat (limited to 'recipes-core')
-rw-r--r-- | recipes-core/busybox/busybox_1.20.2.bbappend | 4 | ||||
-rw-r--r-- | recipes-core/busybox/busybox_1.20.2/busybox-awk-make--F-STR-interpret-escape.patch | 90 |
2 files changed, 93 insertions, 1 deletions
diff --git a/recipes-core/busybox/busybox_1.20.2.bbappend b/recipes-core/busybox/busybox_1.20.2.bbappend index 43b35241..b04339af 100644 --- a/recipes-core/busybox/busybox_1.20.2.bbappend +++ b/recipes-core/busybox/busybox_1.20.2.bbappend | |||
@@ -1 +1,3 @@ | |||
1 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}-${PV}/${MACHINE}:${THISDIR}/${PN}/${MACHINE}:${THISDIR}/${PN}-${PV}:${THISDIR}/${PN}:" | 1 | FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}_${PV}:${THISDIR}/${PN}-${PV}/${MACHINE}:${THISDIR}/${PN}/${MACHINE}:${THISDIR}/${PN}-${PV}:${THISDIR}/${PN}:" |
2 | |||
3 | SRC_URI += "file://busybox-awk-make--F-STR-interpret-escape.patch" | ||
diff --git a/recipes-core/busybox/busybox_1.20.2/busybox-awk-make--F-STR-interpret-escape.patch b/recipes-core/busybox/busybox_1.20.2/busybox-awk-make--F-STR-interpret-escape.patch new file mode 100644 index 00000000..e6a9d7ad --- /dev/null +++ b/recipes-core/busybox/busybox_1.20.2/busybox-awk-make--F-STR-interpret-escape.patch | |||
@@ -0,0 +1,90 @@ | |||
1 | From ea664dde87d8e52df7d4003d988352a66562a945 Mon Sep 17 00:00:00 2001 | ||
2 | From: Denys Vlasenko <vda.linux@googlemail.com> | ||
3 | Date: Fri, 22 Jun 2012 16:41:01 +0000 | ||
4 | Subject: awk: make -F STR interpret escape sequences. Closes 5126 | ||
5 | |||
6 | Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com> | ||
7 | --- | ||
8 | diff --git a/editors/awk.c b/editors/awk.c | ||
9 | index 71abca2..d69720d 100644 | ||
10 | --- a/editors/awk.c | ||
11 | +++ b/editors/awk.c | ||
12 | @@ -696,6 +696,10 @@ static char nextchar(char **s) | ||
13 | pps = *s; | ||
14 | if (c == '\\') | ||
15 | c = bb_process_escape_sequence((const char**)s); | ||
16 | + /* Example awk statement: | ||
17 | + * s = "abc\"def" | ||
18 | + * we must treat \" as " | ||
19 | + */ | ||
20 | if (c == '\\' && *s == pps) { /* unrecognized \z? */ | ||
21 | c = *(*s); /* yes, fetch z */ | ||
22 | if (c) | ||
23 | @@ -704,6 +708,15 @@ static char nextchar(char **s) | ||
24 | return c; | ||
25 | } | ||
26 | |||
27 | +/* TODO: merge with strcpy_and_process_escape_sequences()? | ||
28 | + */ | ||
29 | +static void unescape_string_in_place(char *s1) | ||
30 | +{ | ||
31 | + char *s = s1; | ||
32 | + while ((*s1 = nextchar(&s)) != '\0') | ||
33 | + s1++; | ||
34 | +} | ||
35 | + | ||
36 | static ALWAYS_INLINE int isalnum_(int c) | ||
37 | { | ||
38 | return (isalnum(c) || c == '_'); | ||
39 | @@ -2992,7 +3005,7 @@ static int awk_exit(int r) | ||
40 | * otherwise return 0 */ | ||
41 | static int is_assignment(const char *expr) | ||
42 | { | ||
43 | - char *exprc, *val, *s, *s1; | ||
44 | + char *exprc, *val; | ||
45 | |||
46 | if (!isalnum_(*expr) || (val = strchr(expr, '=')) == NULL) { | ||
47 | return FALSE; | ||
48 | @@ -3002,10 +3015,7 @@ static int is_assignment(const char *expr) | ||
49 | val = exprc + (val - expr); | ||
50 | *val++ = '\0'; | ||
51 | |||
52 | - s = s1 = val; | ||
53 | - while ((*s1 = nextchar(&s)) != '\0') | ||
54 | - s1++; | ||
55 | - | ||
56 | + unescape_string_in_place(val); | ||
57 | setvar_u(newvar(exprc), val); | ||
58 | free(exprc); | ||
59 | return TRUE; | ||
60 | @@ -3118,8 +3128,10 @@ int awk_main(int argc, char **argv) | ||
61 | opt = getopt32(argv, "F:v:f:W:", &opt_F, &list_v, &list_f, NULL); | ||
62 | argv += optind; | ||
63 | argc -= optind; | ||
64 | - if (opt & 0x1) | ||
65 | - setvar_s(intvar[FS], opt_F); // -F | ||
66 | + if (opt & 0x1) { /* -F */ | ||
67 | + unescape_string_in_place(opt_F); | ||
68 | + setvar_s(intvar[FS], opt_F); | ||
69 | + } | ||
70 | while (list_v) { /* -v */ | ||
71 | if (!is_assignment(llist_pop(&list_v))) | ||
72 | bb_show_usage(); | ||
73 | diff --git a/testsuite/awk.tests b/testsuite/awk.tests | ||
74 | index e671907..d4c390d 100755 | ||
75 | --- a/testsuite/awk.tests | ||
76 | +++ b/testsuite/awk.tests | ||
77 | @@ -43,6 +43,11 @@ testing "awk long field sep" "awk -F-- '{ print NF, length(\$NF), \$NF }'" \ | ||
78 | "" \ | ||
79 | "a--\na--b--\na--b--c--\na--b--c--d--" | ||
80 | |||
81 | +testing "awk -F handles escapes" "awk -F'\\x21' '{print \$1}'" \ | ||
82 | + "a\n" \ | ||
83 | + "" \ | ||
84 | + "a!b\n" | ||
85 | + | ||
86 | # '@(samp|code|file)\{' is an invalid extended regex (unmatched '{'), | ||
87 | # but gawk 3.1.5 does not bail out on it. | ||
88 | testing "awk gsub falls back to non-extended-regex" \ | ||
89 | -- | ||
90 | cgit v0.9.1 | ||