From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 2464B138334 for ; Thu, 2 May 2019 15:48:54 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1C43DE07EA; Thu, 2 May 2019 15:48:53 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id DF6D8E07EA for ; Thu, 2 May 2019 15:48:52 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 5466E342F7A for ; Thu, 2 May 2019 15:48:51 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 2651957F for ; Thu, 2 May 2019 15:48:49 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" Message-ID: <1556811997.35d7272b07fbbdc21c13b963e042aaf62481430a.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: /, libq/ X-VCS-Repository: proj/portage-utils X-VCS-Files: TODO.md libq/cache.c X-VCS-Directories: / libq/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 35d7272b07fbbdc21c13b963e042aaf62481430a X-VCS-Branch: master Date: Thu, 2 May 2019 15:48:49 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 136df09e-33d4-425a-b3a9-ebcf4f1ed799 X-Archives-Hash: a8674c4afc354b3775aa40f339b33348 commit: 35d7272b07fbbdc21c13b963e042aaf62481430a Author: Fabian Groffen gentoo org> AuthorDate: Thu May 2 15:46:37 2019 +0000 Commit: Fabian Groffen gentoo 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 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:
`ACCEPT_LICENSE="foo"`
`ACCEPT_LICENSE="${ACCEPT_LICENSE} bar"`
@@ -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))