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.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 2FAC7158090 for ; Thu, 26 May 2022 14:36:39 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 51047E0821; Thu, 26 May 2022 14:36:38 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 36AF0E0821 for ; Thu, 26 May 2022 14:36:38 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 28534341625 for ; Thu, 26 May 2022 14:36:37 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A1EC548C for ; Thu, 26 May 2022 14:36:35 +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: <1653557231.8ca9d1625448544f72aa0d45a1cbbdfa8dcfb22e.grobian@gentoo> Subject: [gentoo-commits] proj/portage-utils:master commit in: libq/ X-VCS-Repository: proj/portage-utils X-VCS-Files: libq/dep.c libq/dep.h X-VCS-Directories: libq/ X-VCS-Committer: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: 8ca9d1625448544f72aa0d45a1cbbdfa8dcfb22e X-VCS-Branch: master Date: Thu, 26 May 2022 14:36:35 +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: 46a411fb-6b6f-408d-bfa2-b3a193ebe446 X-Archives-Hash: 181cf5699ef11ce96b39ecf591a59e15 commit: 8ca9d1625448544f72aa0d45a1cbbdfa8dcfb22e Author: Fabian Groffen gentoo org> AuthorDate: Thu May 26 09:27:11 2022 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Thu May 26 09:27:11 2022 +0000 URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=8ca9d162 libq/dep: add dep_resolve_tree function allow resolving a dep-specification to atoms found in a tree, e.g. see what would get selected Signed-off-by: Fabian Groffen gentoo.org> libq/dep.c | 77 +++++++++++++++++++++++++++++++++++++++----------------------- libq/dep.h | 12 ++++++---- 2 files changed, 56 insertions(+), 33 deletions(-) diff --git a/libq/dep.c b/libq/dep.c index 99629e7..4138a1c 100644 --- a/libq/dep.c +++ b/libq/dep.c @@ -1,5 +1,5 @@ /* - * Copyright 2005-2019 Gentoo Foundation + * Copyright 2005-2022 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2010 Ned Ludd - @@ -20,6 +20,7 @@ #include "atom.h" #include "dep.h" #include "set.h" +#include "tree.h" #include "xarray.h" #include "xasprintf.h" @@ -62,8 +63,6 @@ static void _dep_burn_node(dep_node *node) { assert(node); - if (node->info_on_heap) - free(node->info); if (node->atom) atom_implode(node->atom); free(node); @@ -237,7 +236,6 @@ dep_print_tree( { size_t s; int indent = 4; /* Gentoo 4-wide indent standard */ - depend_atom *d = NULL; bool singlechild = false; bool nonewline = false; @@ -260,33 +258,31 @@ dep_print_tree( if (root->type == DEP_OR) fprintf(fp, "|| ("); if (root->info) { - if (hlatoms != NULL && array_cnt(hlatoms) > 0 && - root->type == DEP_NORM) - { - size_t i; - depend_atom *m; - char *oslot; - - d = root->atom; - d->pfx_op = d->sfx_op = ATOM_OP_NONE; - - array_for_each(hlatoms, i, m) { - oslot = d->SLOT; - if (m->SLOT == NULL) - d->SLOT = NULL; - - if (atom_compare(m, d) == EQUAL) { - m = NULL; - break; + if (root->type == DEP_NORM) { + bool dohl = false; + + if (hlatoms != NULL && array_cnt(hlatoms) > 0) + { + size_t i; + depend_atom *m; + + array_for_each(hlatoms, i, m) { + /* make m query, such that any specifics (SLOT, + * pfx/sfx) from the depstring are ignored while + * highlighting */ + if (atom_compare(root->atom, m) == EQUAL) { + dohl = true; + break; + } } - d->SLOT = oslot; } - if (m == NULL) { /* match found */ - fprintf(fp, "%s%s%s", hlcolor, root->info, NORM); - } else { - fprintf(fp, "%s", root->info); - } + fprintf(fp, "%s%s%s", + dohl ? hlcolor : "", + atom_to_string(root->atom), + dohl ? NORM : ""); + if (root->atom_resolved && verbose > 0) + fprintf(fp, " # %s", root->info); } else { fprintf(fp, "%s", root->info); } @@ -355,6 +351,31 @@ dep_prune_use(dep_node *root, set *use) dep_prune_use(root->children, use); } +void +dep_resolve_tree(dep_node *root, tree_ctx *t) +{ + if (root->type != DEP_NULL) { + if (root->type == DEP_NORM && root->atom) { + depend_atom *d = root->atom; + tree_match_ctx *r = tree_match_atom(t, d, + TREE_MATCH_DEFAULT | + TREE_MATCH_LATEST); + if (r != NULL) { + atom_implode(d); + root->atom = atom_clone(r->atom); + root->atom_resolved = 1; + tree_match_close(r); + } + } + + if (root->children) + dep_resolve_tree(root->children, t); + } + + if (root->neighbor) + dep_resolve_tree(root->neighbor, t); +} + void dep_flatten_tree(const dep_node *root, array_t *out) { diff --git a/libq/dep.h b/libq/dep.h index 1055d29..68d5c75 100644 --- a/libq/dep.h +++ b/libq/dep.h @@ -1,5 +1,5 @@ /* - * Copyright 2005-2019 Gentoo Foundation + * Copyright 2005-2022 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 */ @@ -9,6 +9,7 @@ #include "atom.h" #include "colors.h" #include "set.h" +#include "tree.h" #include "xarray.h" typedef enum { @@ -28,10 +29,10 @@ static const char * const _dep_names[] = { }; struct _dep_node { - dep_type type; - char *info; - char info_on_heap; - depend_atom *atom; + dep_type type; + char *info; + char atom_resolved:1; + depend_atom *atom; struct _dep_node *parent; struct _dep_node *neighbor; struct _dep_node *children; @@ -47,6 +48,7 @@ typedef struct _dep_node dep_node; dep_node *dep_grow_tree(const char *depend); void dep_print_tree(FILE *fp, const dep_node *root, size_t space, array_t *m, const char *c, int verbose); +void dep_resolve_tree(dep_node *root, tree_ctx *t); void dep_burn_tree(dep_node *root); void dep_prune_use(dep_node *root, set *use); void dep_flatten_tree(const dep_node *root, array_t *out);