public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Fabian Groffen" <grobian@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage-utils:master commit in: /, libq/
Date: Thu,  2 May 2019 15:48:49 +0000 (UTC)	[thread overview]
Message-ID: <1556811997.35d7272b07fbbdc21c13b963e042aaf62481430a.grobian@gentoo> (raw)

commit:     35d7272b07fbbdc21c13b963e042aaf62481430a
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu May  2 15:46:37 2019 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu May  2 15:46:37 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=35d7272b

libq/cache: implement escape processing in cache_read_file_ebuild

- replace escapes (\\ -> \, \" -> ")
- replace line-continuation escape+nl by space

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 TODO.md      |  6 ++----
 libq/cache.c | 36 +++++++++++++++++++++++++-----------
 2 files changed, 27 insertions(+), 15 deletions(-)

diff --git a/TODO.md b/TODO.md
index 3a3c26a..9d44710 100644
--- a/TODO.md
+++ b/TODO.md
@@ -11,14 +11,14 @@
 - multiline reads don't yet work for quse/qsearch
 
 - standardize/unify/clean up misc handling of colors
+  define rules:
+    BOLD CATEGORY/ BLUE PKG GREEN ::REPO NORM [ MAGENTA USE NORM ]
 
 - remove odd rmspace for each string in libq/set.c (allows a lot less
   malloc/frees)
 
 - make set.c to array (xarray) instead of C-array (list)
 
-- equiv of `equery m` (metadata)
-
 - env vars only get expanded once, so this fails:<br>
   `ACCEPT_LICENSE="foo"`<br>
   `ACCEPT_LICENSE="${ACCEPT_LICENSE} bar"`<br>
@@ -30,8 +30,6 @@
 
 - vdb repo/slot think about when it is freed (see cache\_pkg\_close)
 
-- cache:cache\_read\_file\_ebuild deal with \\\\n sequences
-
 - qcache -> rename to qkeyword
 
 - quse -K -> move to qkeyword

diff --git a/libq/cache.c b/libq/cache.c
index ee3a47c..9993002 100644
--- a/libq/cache.c
+++ b/libq/cache.c
@@ -370,8 +370,9 @@ cache_read_file_ebuild(cache_pkg_ctx *pkg_ctx)
 	size_t len;
 	char *p;
 	char *q;
-	char *r;
+	char *w;
 	char **key;
+	bool esc;
 	bool findnl;
 
 	if ((f = fdopen(pkg_ctx->fd, "r")) == NULL)
@@ -422,22 +423,35 @@ cache_read_file_ebuild(cache_pkg_ctx *pkg_ctx)
 			if (*q == '"' || *q == '\'') {
 				/* find matching quote */
 				p++;
+				w = p;
+				esc = false;
 				do {
-					while (*p != '\0' && *p != *q)
-						p++;
-					if (*p == *q) {
-						for (r = p - 1; r > q; r--)
-							if (*r != '\\')
-								break;
-						if (r != q && (p - 1 - r) % 2 == 1) {
-							/* escaped, move along */
-							p++;
-							continue;
+					while (*p != '\0' && *p != *q) {
+						if (*p == '\\') {
+							esc = !esc;
+							if (esc) {
+								p++;
+								continue;
+							}
+						} else {
+							/* implement line continuation (\ before newline) */
+							if (esc && (*p == '\n' || *p == '\r'))
+								*p = ' ';
+							esc = false;
 						}
+
+						*w++ = *p++;
+					}
+					if (*p == *q && esc) {
+						/* escaped, move along */
+						esc = false;
+						*w++ = *p++;
+						continue;
 					}
 					break;
 				} while (1);
 				q++;
+				*w = '\0';
 			} else {
 				/* find first whitespace */
 				while (!isspace((int)*p))


             reply	other threads:[~2019-05-02 15:48 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-02 15:48 Fabian Groffen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-01-02  7:57 [gentoo-commits] proj/portage-utils:master commit in: /, libq/ Fabian Groffen
2020-05-16 18:27 Fabian Groffen
2020-01-05 16:08 Fabian Groffen
2020-01-04 19:48 Fabian Groffen
2020-01-01 17:54 Fabian Groffen
2019-11-15 13:52 Fabian Groffen
2019-07-14 13:09 Fabian Groffen
2019-05-07  6:19 Fabian Groffen
2019-05-06 17:33 Fabian Groffen
2018-05-18 16:58 Fabian Groffen
2016-12-29  2:25 Mike Frysinger
2016-12-29  2:25 Mike Frysinger
2016-02-14  1:26 Mike Frysinger
2016-02-14  1:26 Mike Frysinger
2015-11-28  2:44 Mike Frysinger
2015-11-28  2:44 Mike Frysinger
2015-02-24  1:26 Mike Frysinger
2014-03-21  5:32 Mike Frysinger
2014-03-10  8:45 Mike Frysinger
2014-03-10  6:00 Mike Frysinger
2014-03-08  5:51 Mike Frysinger
2014-03-08  5:51 Mike Frysinger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1556811997.35d7272b07fbbdc21c13b963e042aaf62481430a.grobian@gentoo \
    --to=grobian@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox