1 |
commit: 35d7272b07fbbdc21c13b963e042aaf62481430a |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu May 2 15:46:37 2019 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu May 2 15:46:37 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=35d7272b |
7 |
|
8 |
libq/cache: implement escape processing in cache_read_file_ebuild |
9 |
|
10 |
- replace escapes (\\ -> \, \" -> ") |
11 |
- replace line-continuation escape+nl by space |
12 |
|
13 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
14 |
|
15 |
TODO.md | 6 ++---- |
16 |
libq/cache.c | 36 +++++++++++++++++++++++++----------- |
17 |
2 files changed, 27 insertions(+), 15 deletions(-) |
18 |
|
19 |
diff --git a/TODO.md b/TODO.md |
20 |
index 3a3c26a..9d44710 100644 |
21 |
--- a/TODO.md |
22 |
+++ b/TODO.md |
23 |
@@ -11,14 +11,14 @@ |
24 |
- multiline reads don't yet work for quse/qsearch |
25 |
|
26 |
- standardize/unify/clean up misc handling of colors |
27 |
+ define rules: |
28 |
+ BOLD CATEGORY/ BLUE PKG GREEN ::REPO NORM [ MAGENTA USE NORM ] |
29 |
|
30 |
- remove odd rmspace for each string in libq/set.c (allows a lot less |
31 |
malloc/frees) |
32 |
|
33 |
- make set.c to array (xarray) instead of C-array (list) |
34 |
|
35 |
-- equiv of `equery m` (metadata) |
36 |
- |
37 |
- env vars only get expanded once, so this fails:<br> |
38 |
`ACCEPT_LICENSE="foo"`<br> |
39 |
`ACCEPT_LICENSE="${ACCEPT_LICENSE} bar"`<br> |
40 |
@@ -30,8 +30,6 @@ |
41 |
|
42 |
- vdb repo/slot think about when it is freed (see cache\_pkg\_close) |
43 |
|
44 |
-- cache:cache\_read\_file\_ebuild deal with \\\\n sequences |
45 |
- |
46 |
- qcache -> rename to qkeyword |
47 |
|
48 |
- quse -K -> move to qkeyword |
49 |
|
50 |
diff --git a/libq/cache.c b/libq/cache.c |
51 |
index ee3a47c..9993002 100644 |
52 |
--- a/libq/cache.c |
53 |
+++ b/libq/cache.c |
54 |
@@ -370,8 +370,9 @@ cache_read_file_ebuild(cache_pkg_ctx *pkg_ctx) |
55 |
size_t len; |
56 |
char *p; |
57 |
char *q; |
58 |
- char *r; |
59 |
+ char *w; |
60 |
char **key; |
61 |
+ bool esc; |
62 |
bool findnl; |
63 |
|
64 |
if ((f = fdopen(pkg_ctx->fd, "r")) == NULL) |
65 |
@@ -422,22 +423,35 @@ cache_read_file_ebuild(cache_pkg_ctx *pkg_ctx) |
66 |
if (*q == '"' || *q == '\'') { |
67 |
/* find matching quote */ |
68 |
p++; |
69 |
+ w = p; |
70 |
+ esc = false; |
71 |
do { |
72 |
- while (*p != '\0' && *p != *q) |
73 |
- p++; |
74 |
- if (*p == *q) { |
75 |
- for (r = p - 1; r > q; r--) |
76 |
- if (*r != '\\') |
77 |
- break; |
78 |
- if (r != q && (p - 1 - r) % 2 == 1) { |
79 |
- /* escaped, move along */ |
80 |
- p++; |
81 |
- continue; |
82 |
+ while (*p != '\0' && *p != *q) { |
83 |
+ if (*p == '\\') { |
84 |
+ esc = !esc; |
85 |
+ if (esc) { |
86 |
+ p++; |
87 |
+ continue; |
88 |
+ } |
89 |
+ } else { |
90 |
+ /* implement line continuation (\ before newline) */ |
91 |
+ if (esc && (*p == '\n' || *p == '\r')) |
92 |
+ *p = ' '; |
93 |
+ esc = false; |
94 |
} |
95 |
+ |
96 |
+ *w++ = *p++; |
97 |
+ } |
98 |
+ if (*p == *q && esc) { |
99 |
+ /* escaped, move along */ |
100 |
+ esc = false; |
101 |
+ *w++ = *p++; |
102 |
+ continue; |
103 |
} |
104 |
break; |
105 |
} while (1); |
106 |
q++; |
107 |
+ *w = '\0'; |
108 |
} else { |
109 |
/* find first whitespace */ |
110 |
while (!isspace((int)*p)) |