From patchwork Fri Jan 3 21:56:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Edward E X-Patchwork-Id: 1431 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 0C5DF160B0FFD for ; Sun, 5 Jan 2020 12:48:47 +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.9.2] [127.0.0.10, 127.0.0.4] [127.0.0.14] Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Sun, 5 Jan 2020 12:48:46 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 31CE217D8E89C8; Sun, 5 Jan 2020 12:48:40 +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 D7C8017D8E89C0; Sun, 5 Jan 2020 12:48:39 +0000 (UTC) Authentication-Results: orion.archlinux.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Q5l1iQ45 Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id C526A2BE61; Sun, 5 Jan 2020 12:48:39 +0000 (UTC) Authentication-Results: luna.archlinux.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Q5l1iQ45 Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 80C792B398 for ; Fri, 3 Jan 2020 21:58:17 +0000 (UTC) Received: from mail-yw1-xc42.google.com (mail-yw1-xc42.google.com [IPv6:2607:f8b0:4864:20::c42]) by luna.archlinux.org (Postfix) with ESMTPS for ; Fri, 3 Jan 2020 21:58:17 +0000 (UTC) Received: by mail-yw1-xc42.google.com with SMTP id x138so19110945ywd.9 for ; Fri, 03 Jan 2020 13:58:17 -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=A+6dj30BlEIMA0ISEuVSN044zdGnUEIOKyzfDCvmto8=; b=Q5l1iQ45d7/CatcWSFTNL2y+4RySjkmFekuHyn3oSHoEyssvxzVRWPOziy5hOlCoGD a98qrmcmHUL5SLI/S1EYC8aCDzGNCXavvebxYgUZWY4TF1LsZquLd4Yf5O0Y/Pv1nm4/ ElSeSHHjy6K7yK9yJmSaAI/Luu8vnOMx/b0tCzEBrNFZZ0EqUk2sJ0Ma4v7nh/QssZI/ 4MnIZPDgKV8B8tDmglbaatOhwf/mggch+RO4KsEsq8DT5qTenmd5/jzFV+k+lf5iFe5G GUx7tIeia9g5gSR0Q96rgB5sLBRzacbK6vNLLzOyX9imxgwTpzwFmeF9sYLSmflwCfj6 QjRw== 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=A+6dj30BlEIMA0ISEuVSN044zdGnUEIOKyzfDCvmto8=; b=fVdQ9LffWOEEO1XvPqmSX4zbnycGrp94wIHusP2KlqKTA9IUlqNlnJQ+Jsqv8pka9Z zXImNVvNvvyznpg6z1l90T6RWyB2Ls3PiX7Kvwz04r5RKAQh//IHQUGOYOYY0cO+hn4E qA/AqBXWXsCtQQGEbUpBzBgA68iiS9TtYFE+cTqJzX5B/0tum2wa+dE4cub13E5DyIgh uh1SJgJuHJFRX+LN+GHBRWZDXkvVNnpfdclS/MIXQKezsVj8iwbfHDbLzcJZH1je5oM2 nl5B/Ni3mSImv/Z6FaecUwcL5f0MwXvcYuuIXzQe16AFs5EgLcgZgY4QS5mJYdgFGmma cWzA== X-Gm-Message-State: APjAAAWfZOp/BlSTCNSgVhqtjgP8oO9Q+AGUMGtr+1ilO7ourUjSjW+z K1vDCchYhUC0mf2ipTqEFFZNcsW/ X-Google-Smtp-Source: APXvYqz3Id6ToitykUHeBEz0K17d82h0qwJhgBgnqFYZnUE21ahIBgOTYtUz25Ba3G+y5vUtotTNHA== X-Received: by 2002:a81:1ad5:: with SMTP id a204mr66569380ywa.486.1578088695097; Fri, 03 Jan 2020 13:58:15 -0800 (PST) Received: from localhost.localdomain ([172.58.142.160]) by smtp.gmail.com with ESMTPSA id d137sm22404319ywd.86.2020.01.03.13.58.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jan 2020 13:58:14 -0800 (PST) From: Edward E To: pacman-contrib@lists.archlinux.org Subject: [PATCH 1/2] pactree: Add --debug Date: Fri, 3 Jan 2020 15:56:59 -0600 Message-Id: <20200103215701.2814-1-develinthedetail@gmail.com> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 X-Mailman-Approved-At: Sun, 05 Jan 2020 12:48:38 +0000 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 --- doc/pactree.8.txt | 3 +++ src/pactree.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) 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..8b77f05 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 *info; 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;36m", /* bold cyan */ "\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,38 @@ 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) +{ + const char *log_color = ""; + const char *log_title = ""; + + switch(level) { + case ALPM_LOG_ERROR: + log_color = color->error; + log_title = "error: "; + break; + case ALPM_LOG_WARNING: + log_color = color->error; + log_title = "warning: "; + break; + case ALPM_LOG_DEBUG: + log_color = color->info; + log_title = "debug: "; + break; + case ALPM_LOG_FUNCTION: + log_color = color->info; + log_title = "function: "; + break; + } + + fprintf(stderr, "%s%s%s", log_color, log_title, color->off); + vfprintf(stderr, fmt, args); +} + /* Trim whitespace and newlines from a string */ static size_t strtrim(char *str) @@ -222,6 +258,7 @@ 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" + " --debug display debug messages\n" " --config set an alternate configuration file\n"); } @@ -249,6 +286,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} }; @@ -269,6 +307,9 @@ static int parse_options(int argc, char *argv[]) case OP_CONFIG: configfile = optarg; break; + case OP_DEBUG: + debug = 1; + break; case 'b': dbpath = optarg; break; @@ -500,6 +541,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);