From patchwork Tue Jan 7 01:16:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward E X-Patchwork-Id: 1433 X-Patchwork-Delegate: johannes@kyriasis.com Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id 5006D16128E13 for ; Tue, 7 Jan 2020 01:17:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.3 (2019-12-06) on apollo.archlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=DKIM_SIGNED=0.1, DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,FREEMAIL_FROM=0.5, MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3,SPF_HELO_NONE=0.001, T_DMARC_POLICY_NONE=0.01,T_DMARC_SIMPLE_DKIM=0.01 autolearn=ham autolearn_force=no version=3.4.3 X-Spam-BL-Results: [127.0.0.10] [127.0.9.2] [127.0.0.14] Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Tue, 7 Jan 2020 01:17:01 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 2E92517E9EE2AF; Tue, 7 Jan 2020 01:16:58 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [5.9.250.164]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: luna) by orion.archlinux.org (Postfix) with ESMTPSA id E798B17E9EE2AB; Tue, 7 Jan 2020 01:16:57 +0000 (UTC) Authentication-Results: orion.archlinux.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jTYfZtjQ Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id D28DF2BE67; Tue, 7 Jan 2020 01:16:57 +0000 (UTC) Authentication-Results: luna.archlinux.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jTYfZtjQ Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 9DF542BE60 for ; Tue, 7 Jan 2020 01:16:53 +0000 (UTC) Received: from mail-yw1-xc33.google.com (mail-yw1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) by luna.archlinux.org (Postfix) with ESMTPS for ; Tue, 7 Jan 2020 01:16:53 +0000 (UTC) Received: by mail-yw1-xc33.google.com with SMTP id d7so22728280ywl.12 for ; Mon, 06 Jan 2020 17:16:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=EEAVAftgcC3u7vCY2Vjc6C9iEcclo0a1NTY1udbIc/8=; b=jTYfZtjQTqlilH06MP8NgQ7pSgge0hk+J8R+spOwBqOjkV/W30fKOERr1FGCMFbEZG kkqGHlcgRVNpEzxYSzLUmfEJAlobowQ70d3dWhVpmjBmT+xgS9Th7ZPhJQ0joLzd6VHw FI69gfxpxcf355OhM0LJ32CqeumOIoCKGJqdlV8/TLA/cFYlXkTMST6vVPlU5KsgrlIf PXl9I7+39qLH7bNozb8DXifhW4TeE+cXxFyZBWI/e2J85q2VznB13we8a3XJxgZdz4mm RFm5nfTLSUsM78w/L4tcr6xbqnOhECsqSs9MBdN+DsbuWsr69ZCqkpETO9cRiKEeBhI4 Li0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=EEAVAftgcC3u7vCY2Vjc6C9iEcclo0a1NTY1udbIc/8=; b=gz7qpULveZFCrw0vXhGr3CsHRbCV73bwkW1xBrklNj/FVwdQZbk3jFWKg3eygwqk74 R4AT0zn1s1CTgJxAwwpymbrKbM/F7IzrFYFksvek/vGjTpKsQ54IslfFBdO7WstwV6c0 KsBFyZ2P9075X5MbqL6LL0XgtBJgyQ71YoE3IujbFKcjlDoftzwMVXbYDUgpzuI82bQ3 /UDPhWjOmrVjex5eThc3AFPxeoQ6hR7JQbGR3Np594J8VYFcE+2oTl1ijlzrv/gNwfi9 V02xWnuveXBirAL5KtKsx5nu+nJncIW8ZiAYQwm23vmMsrI+Qa02EP1VbEhXgFGuvX8h Myqw== X-Gm-Message-State: APjAAAWNBn4p7bKBHF0xeGhdna7Il/6wSjzTo8WcfpM4dguPZZNR9RrZ BvOIJGBEY0PVpj3m8I2Dkrs6stCk X-Google-Smtp-Source: APXvYqyOHx7HyLtZoN0qtpVFk27xNe9lDXkfeMISgYyMpk2aYAvmwQIahiQpa/GbKJiCNLqIQSOM6w== X-Received: by 2002:a81:6e04:: with SMTP id j4mr8690994ywc.232.1578359811877; Mon, 06 Jan 2020 17:16:51 -0800 (PST) Received: from localhost.localdomain ([172.58.139.245]) by smtp.gmail.com with ESMTPSA id l74sm29103336ywc.45.2020.01.06.17.16.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jan 2020 17:16:51 -0800 (PST) From: Edward E To: pacman-contrib@lists.archlinux.org Subject: [PATCH v2 1/2] pactree: Add --debug Date: Mon, 6 Jan 2020 19:16:42 -0600 Message-Id: <20200107011643.19462-1-develinthedetail@gmail.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 X-BeenThere: pacman-contrib@lists.archlinux.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for pacman-contrib development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Edward E Errors-To: pacman-contrib-bounces@lists.archlinux.org Sender: "pacman-contrib" Signed-off-by: Edward E --- Regarding colors, now cb_log() simply follows pacman's lead. Also changed from v1: re-ordered longopts in usage(), as well as OP_* getopt switch cases. I don't know how important alphabetized options are, hope it makes sense to do this now while I'm at it? doc/pactree.8.txt | 3 +++ src/pactree.c | 49 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/doc/pactree.8.txt b/doc/pactree.8.txt index b177788..57a91cb 100644 --- a/doc/pactree.8.txt +++ b/doc/pactree.8.txt @@ -61,6 +61,9 @@ Options *\--config *:: Specify an alternate pacman configuration file. +*\--debug*:: + Print log messages produced by libalpm. + See Also -------- diff --git a/src/pactree.c b/src/pactree.c index a862f9e..feac956 100644 --- a/src/pactree.c +++ b/src/pactree.c @@ -78,6 +78,8 @@ struct color_choices { const char *branch2; const char *leaf1; const char *leaf2; + const char *error; + const char *warning; const char *off; }; @@ -86,6 +88,8 @@ static struct color_choices use_color = { "\033[0;37m", /* white */ "\033[1;32m", /* bold green */ "\033[0;32m", /* green */ + "\033[1;31m", /* bold red */ + "\033[1;33m", /* bold yellow */ "\033[0m" }; @@ -94,12 +98,15 @@ static struct color_choices no_color = { "", "", "", + "", + "", "" }; /* long operations */ enum { - OP_CONFIG = 1000 + OP_CONFIG = 1000, + OP_DEBUG }; /* globals */ @@ -115,9 +122,32 @@ static int max_depth = -1; static int reverse = 0; static int unique = 0; static int searchsyncs = 0; +static int debug = 0; static const char *dbpath = DBPATH; static const char *configfile = CONFFILE; +void cb_log(alpm_loglevel_t level, const char *fmt, va_list args) +{ + switch(level) { + case ALPM_LOG_ERROR: + fprintf(stderr, "%s%s%s", color->error, "error: ", + color->off); + break; + case ALPM_LOG_WARNING: + fprintf(stderr, "%s%s%s", color->warning, "warning: ", + color->off); + break; + case ALPM_LOG_DEBUG: + fprintf(stderr, "debug: "); + break; + case ALPM_LOG_FUNCTION: + fprintf(stderr, "function: "); + break; + } + + vfprintf(stderr, fmt, args); +} + /* Trim whitespace and newlines from a string */ static size_t strtrim(char *str) @@ -222,7 +252,8 @@ static void usage(void) " -s, --sync search sync databases instead of local\n" " -u, --unique show dependencies with no duplicates (implies -l)\n" " -v, --version display the version\n" - " --config set an alternate configuration file\n"); + " --config set an alternate configuration file\n" + " --debug display debug messages\n"); } static void version(void) @@ -249,6 +280,7 @@ static int parse_options(int argc, char *argv[]) {"version", no_argument, 0, 'v'}, {"config", required_argument, 0, OP_CONFIG}, + {"debug", no_argument, 0, OP_DEBUG}, {0, 0, 0, 0} }; @@ -263,12 +295,15 @@ static int parse_options(int argc, char *argv[]) } switch(opt) { - case 'a': - style = &graph_default; - break; case OP_CONFIG: configfile = optarg; break; + case OP_DEBUG: + debug = 1; + break; + case 'a': + style = &graph_default; + break; case 'b': dbpath = optarg; break; @@ -500,6 +535,10 @@ int main(int argc, char *argv[]) cleanup(1); } + if(debug) { + alpm_option_set_logcb(handle, cb_log); + } + if(searchsyncs) { if(register_syncs() != 0) { cleanup(1);