2010-10-12 14:46:12 -04:00
|
|
|
/*
|
|
|
|
* pactree.c - a simple dependency tree viewer
|
|
|
|
*
|
2011-01-05 23:45:15 -05:00
|
|
|
* Copyright (c) 2010-2011 Pacman Development Team <pacman-dev@archlinux.org>
|
2010-10-12 14:46:12 -04:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2011-09-18 16:19:32 -04:00
|
|
|
#include <ctype.h>
|
2010-10-12 14:46:12 -04:00
|
|
|
#include <getopt.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <alpm.h>
|
|
|
|
#include <alpm_list.h>
|
|
|
|
|
2011-06-21 13:47:50 -04:00
|
|
|
#define LINE_MAX 512
|
|
|
|
|
2010-10-12 14:46:12 -04:00
|
|
|
/* output */
|
2011-05-04 16:49:47 -04:00
|
|
|
struct graph_style {
|
|
|
|
const char *provides;
|
|
|
|
const char *tip1;
|
|
|
|
const char *tip2;
|
|
|
|
int indent;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct graph_style graph_default = {
|
|
|
|
" provides",
|
|
|
|
"|--",
|
|
|
|
"+--",
|
|
|
|
3
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct graph_style graph_linear = {
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
/* color choices */
|
|
|
|
struct color_choices {
|
|
|
|
const char *branch1;
|
|
|
|
const char *branch2;
|
|
|
|
const char *leaf1;
|
|
|
|
const char *leaf2;
|
|
|
|
const char *off;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct color_choices use_color = {
|
|
|
|
"\033[0;33m", /* yellow */
|
|
|
|
"\033[0;37m", /* white */
|
|
|
|
"\033[1;32m", /* bold green */
|
|
|
|
"\033[0;32m", /* green */
|
|
|
|
"\033[0m"
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct color_choices no_color = {
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
""
|
|
|
|
};
|
2010-10-12 14:46:12 -04:00
|
|
|
|
2011-10-10 08:38:59 -04:00
|
|
|
/* long operations */
|
|
|
|
enum {
|
|
|
|
OP_CONFIG = 1000
|
|
|
|
};
|
|
|
|
|
2010-10-12 14:46:12 -04:00
|
|
|
/* globals */
|
2011-06-28 00:04:00 -04:00
|
|
|
alpm_handle_t *handle = NULL;
|
2010-10-12 14:46:12 -04:00
|
|
|
alpm_list_t *walked = NULL;
|
2010-10-13 09:50:13 -04:00
|
|
|
alpm_list_t *provisions = NULL;
|
2010-10-12 14:46:12 -04:00
|
|
|
|
|
|
|
/* options */
|
2011-05-04 16:49:47 -04:00
|
|
|
struct color_choices *color = &no_color;
|
|
|
|
struct graph_style *style = &graph_default;
|
2010-10-12 14:46:12 -04:00
|
|
|
int graphviz = 0;
|
|
|
|
int max_depth = -1;
|
|
|
|
int reverse = 0;
|
|
|
|
int unique = 0;
|
2011-06-21 13:47:50 -04:00
|
|
|
int searchsyncs = 0;
|
2011-05-04 16:49:47 -04:00
|
|
|
const char *dbpath = DBPATH;
|
2011-10-10 08:38:59 -04:00
|
|
|
const char *configfile = CONFFILE;
|
2010-10-12 14:46:12 -04:00
|
|
|
|
2011-09-18 16:22:38 -04:00
|
|
|
#ifndef HAVE_STRNDUP
|
|
|
|
/* A quick and dirty implementation derived from glibc */
|
|
|
|
static size_t strnlen(const char *s, size_t max)
|
|
|
|
{
|
|
|
|
register const char *p;
|
|
|
|
for(p = s; *p && max--; ++p);
|
|
|
|
return (p - s);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *strndup(const char *s, size_t n)
|
|
|
|
{
|
|
|
|
size_t len = strnlen(s, n);
|
|
|
|
char *new = (char *) malloc(len + 1);
|
|
|
|
|
|
|
|
if(new == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
new[len] = '\0';
|
|
|
|
return (char *)memcpy(new, s, len);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-06-21 13:47:50 -04:00
|
|
|
static char *strtrim(char *str)
|
|
|
|
{
|
|
|
|
char *pch = str;
|
|
|
|
|
|
|
|
if(str == NULL || *str == '\0') {
|
|
|
|
/* string is empty, so we're done. */
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(isspace((unsigned char)*pch)) {
|
|
|
|
pch++;
|
|
|
|
}
|
|
|
|
if(pch != str) {
|
2011-08-25 18:14:19 -04:00
|
|
|
size_t len = strlen(pch);
|
|
|
|
if(len) {
|
|
|
|
memmove(str, pch, len + 1);
|
|
|
|
} else {
|
|
|
|
*str = '\0';
|
|
|
|
}
|
2011-06-21 13:47:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check if there wasn't anything but whitespace in the string. */
|
|
|
|
if(*str == '\0') {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
pch = (str + (strlen(str) - 1));
|
|
|
|
while(isspace((unsigned char)*pch)) {
|
|
|
|
pch--;
|
|
|
|
}
|
|
|
|
*++pch = '\0';
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2011-06-27 11:10:08 -04:00
|
|
|
static int register_syncs(void) {
|
2011-06-21 13:47:50 -04:00
|
|
|
FILE *fp;
|
|
|
|
char *ptr, *section = NULL;
|
|
|
|
char line[LINE_MAX];
|
2011-06-27 17:29:49 -04:00
|
|
|
const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL;
|
2011-06-21 13:47:50 -04:00
|
|
|
|
2011-10-10 08:38:59 -04:00
|
|
|
fp = fopen(configfile, "r");
|
2011-06-21 13:47:50 -04:00
|
|
|
if(!fp) {
|
2011-10-10 09:22:52 -04:00
|
|
|
fprintf(stderr, "error: config file %s could not be read\n", configfile);
|
2011-06-21 13:47:50 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(fgets(line, LINE_MAX, fp)) {
|
|
|
|
strtrim(line);
|
|
|
|
|
|
|
|
if(line[0] == '#' || !strlen(line)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((ptr = strchr(line, '#'))) {
|
|
|
|
*ptr = '\0';
|
|
|
|
strtrim(line);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(line[0] == '[' && line[strlen(line) - 1] == ']') {
|
|
|
|
free(section);
|
|
|
|
section = strndup(&line[1], strlen(line) - 2);
|
|
|
|
|
|
|
|
if(section && strcmp(section, "options") != 0) {
|
2011-06-27 17:29:49 -04:00
|
|
|
alpm_db_register_sync(handle, section, level);
|
2011-06-21 13:47:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(section);
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-12 14:46:12 -04:00
|
|
|
static int parse_options(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int opt, option_index = 0;
|
|
|
|
char *endptr = NULL;
|
|
|
|
|
2011-08-08 14:37:30 -04:00
|
|
|
static const struct option opts[] = {
|
2010-10-12 14:46:12 -04:00
|
|
|
{"dbpath", required_argument, 0, 'b'},
|
|
|
|
{"color", no_argument, 0, 'c'},
|
|
|
|
{"depth", required_argument, 0, 'd'},
|
|
|
|
{"graph", no_argument, 0, 'g'},
|
|
|
|
{"help", no_argument, 0, 'h'},
|
|
|
|
{"linear", no_argument, 0, 'l'},
|
|
|
|
{"reverse", no_argument, 0, 'r'},
|
2011-06-21 13:47:50 -04:00
|
|
|
{"sync", no_argument, 0, 'S'},
|
2010-10-12 14:46:12 -04:00
|
|
|
{"unique", no_argument, 0, 'u'},
|
2011-10-10 08:38:59 -04:00
|
|
|
|
|
|
|
{"config", required_argument, 0, OP_CONFIG},
|
2010-10-12 14:46:12 -04:00
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2011-06-21 13:47:50 -04:00
|
|
|
while((opt = getopt_long(argc, argv, "b:cd:ghlrsu", opts, &option_index))) {
|
2010-10-12 14:46:12 -04:00
|
|
|
if(opt < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(opt) {
|
2011-10-10 08:38:59 -04:00
|
|
|
case OP_CONFIG:
|
|
|
|
configfile = optarg;
|
|
|
|
break;
|
2010-10-12 14:46:12 -04:00
|
|
|
case 'b':
|
2011-05-04 16:49:47 -04:00
|
|
|
dbpath = optarg;
|
2010-10-12 14:46:12 -04:00
|
|
|
break;
|
|
|
|
case 'c':
|
2011-05-04 16:49:47 -04:00
|
|
|
color = &use_color;
|
2010-10-12 14:46:12 -04:00
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
/* validate depth */
|
2011-01-07 22:06:06 -05:00
|
|
|
max_depth = (int)strtol(optarg, &endptr, 10);
|
2010-10-12 14:46:12 -04:00
|
|
|
if(*endptr != '\0') {
|
|
|
|
fprintf(stderr, "error: invalid depth -- %s\n", optarg);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
graphviz = 1;
|
|
|
|
break;
|
|
|
|
case 'l':
|
2011-05-04 16:49:47 -04:00
|
|
|
style = &graph_linear;
|
2010-10-12 14:46:12 -04:00
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
reverse = 1;
|
|
|
|
break;
|
2011-06-21 13:47:50 -04:00
|
|
|
case 's':
|
|
|
|
searchsyncs = 1;
|
|
|
|
break;
|
2010-10-12 14:46:12 -04:00
|
|
|
case 'u':
|
2011-05-04 16:49:47 -04:00
|
|
|
unique = 1;
|
|
|
|
style = &graph_linear;
|
2010-10-12 14:46:12 -04:00
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
case '?':
|
|
|
|
default:
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2010-10-12 14:46:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!argv[optind]) {
|
2011-03-20 20:45:57 -04:00
|
|
|
return 1;
|
2010-10-12 14:46:12 -04:00
|
|
|
}
|
|
|
|
|
2011-03-20 20:45:57 -04:00
|
|
|
return 0;
|
2010-10-12 14:46:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void usage(void)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "pactree v" PACKAGE_VERSION "\n"
|
|
|
|
"Usage: pactree [options] PACKAGE\n\n"
|
|
|
|
" -b, --dbpath <path> set an alternate database location\n"
|
|
|
|
" -c, --color colorize output\n"
|
|
|
|
" -d, --depth <#> limit the depth of recursion\n"
|
|
|
|
" -g, --graph generate output for graphviz's dot\n"
|
2011-10-10 08:38:59 -04:00
|
|
|
" -h, --help display this help message\n"
|
2010-10-12 14:46:12 -04:00
|
|
|
" -l, --linear enable linear output\n"
|
|
|
|
" -r, --reverse show reverse dependencies\n"
|
2011-06-21 13:47:50 -04:00
|
|
|
" -s, --sync search sync DBs instead of local\n"
|
2011-10-10 08:38:59 -04:00
|
|
|
" -u, --unique show dependencies with no duplicates (implies -l)\n"
|
|
|
|
" --config <path> set an alternate configuration file\n");
|
2010-10-12 14:46:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cleanup(void)
|
|
|
|
{
|
|
|
|
alpm_list_free(walked);
|
2010-10-13 09:50:13 -04:00
|
|
|
alpm_list_free(provisions);
|
2011-06-03 16:46:06 -04:00
|
|
|
alpm_release(handle);
|
2010-10-12 14:46:12 -04:00
|
|
|
}
|
|
|
|
|
2010-10-13 09:50:13 -04:00
|
|
|
/* pkg provides provision */
|
|
|
|
static void print_text(const char *pkg, const char *provision, int depth)
|
2010-10-12 14:46:12 -04:00
|
|
|
{
|
2011-05-04 16:49:47 -04:00
|
|
|
int indent_sz = (depth + 1) * style->indent;
|
2010-10-12 14:46:12 -04:00
|
|
|
|
2010-10-13 11:11:14 -04:00
|
|
|
if(!pkg && !provision) {
|
|
|
|
/* not much we can do */
|
2010-10-12 14:46:12 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-13 11:11:14 -04:00
|
|
|
if(!pkg && provision) {
|
|
|
|
/* we failed to resolve provision */
|
2011-05-04 16:49:47 -04:00
|
|
|
printf("%s%*s%s%s%s [unresolvable]%s\n", color->branch1, indent_sz,
|
|
|
|
style->tip1, color->leaf1, provision, color->branch1, color->off);
|
2010-10-13 11:11:14 -04:00
|
|
|
} else if(provision && strcmp(pkg, provision) != 0) {
|
|
|
|
/* pkg provides provision */
|
2011-05-04 16:49:47 -04:00
|
|
|
printf("%s%*s%s%s%s%s %s%s%s\n", color->branch2, indent_sz, style->tip2,
|
|
|
|
color->leaf1, pkg, color->leaf2, style->provides, color->leaf1, provision,
|
|
|
|
color->off);
|
2010-10-12 14:46:12 -04:00
|
|
|
} else {
|
2010-10-13 11:11:14 -04:00
|
|
|
/* pkg is a normal package */
|
2011-05-04 16:49:47 -04:00
|
|
|
printf("%s%*s%s%s%s\n", color->branch1, indent_sz, style->tip1, color->leaf1,
|
|
|
|
pkg, color->off);
|
2010-10-12 14:46:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-13 09:50:13 -04:00
|
|
|
static void print_graph(const char *parentname, const char *pkgname, const char *depname)
|
2010-10-12 14:46:12 -04:00
|
|
|
{
|
2010-10-13 09:50:13 -04:00
|
|
|
if(depname) {
|
|
|
|
printf("\"%s\" -> \"%s\" [color=chocolate4];\n", parentname, depname);
|
|
|
|
if(pkgname && strcmp(depname, pkgname) != 0 && !alpm_list_find_str(provisions, depname)) {
|
|
|
|
printf("\"%s\" -> \"%s\" [arrowhead=none, color=grey];\n", depname, pkgname);
|
|
|
|
provisions = alpm_list_add(provisions, (char *)depname);
|
|
|
|
}
|
|
|
|
} else if(pkgname) {
|
|
|
|
printf("\"%s\" -> \"%s\" [color=chocolate4];\n", parentname, pkgname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* parent depends on dep which is satisfied by pkg */
|
|
|
|
static void print(const char *parentname, const char *pkgname, const char *depname, int depth)
|
|
|
|
{
|
|
|
|
if(graphviz) {
|
|
|
|
print_graph(parentname, pkgname, depname);
|
|
|
|
} else {
|
|
|
|
print_text(pkgname, depname, depth);
|
2010-10-12 14:46:12 -04:00
|
|
|
}
|
2010-10-13 09:50:13 -04:00
|
|
|
}
|
2010-10-12 14:46:12 -04:00
|
|
|
|
2010-10-13 09:50:13 -04:00
|
|
|
static void print_start(const char *pkgname, const char *provname)
|
|
|
|
{
|
|
|
|
if(graphviz) {
|
|
|
|
printf("digraph G { START [color=red, style=filled];\n"
|
|
|
|
"node [style=filled, color=green];\n"
|
|
|
|
" \"START\" -> \"%s\";\n", pkgname);
|
2010-10-12 14:46:12 -04:00
|
|
|
} else {
|
2010-10-13 09:50:13 -04:00
|
|
|
print_text(pkgname, provname, 0);
|
2010-10-12 14:46:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-13 09:50:13 -04:00
|
|
|
static void print_end(void)
|
|
|
|
{
|
|
|
|
if(graphviz) {
|
|
|
|
/* close graph output */
|
|
|
|
printf("}\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-28 09:26:39 -04:00
|
|
|
static alpm_pkg_t *get_pkg_from_dbs(alpm_list_t *dbs, const char *needle) {
|
2011-06-21 13:42:17 -04:00
|
|
|
alpm_list_t *i;
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *ret;
|
2011-06-21 13:42:17 -04:00
|
|
|
|
|
|
|
for(i = dbs; i; i = alpm_list_next(i)) {
|
|
|
|
ret = alpm_db_get_pkg(alpm_list_getdata(i), needle);
|
|
|
|
if(ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-10-13 09:50:13 -04:00
|
|
|
|
2010-10-12 14:46:12 -04:00
|
|
|
/**
|
|
|
|
* walk dependencies in reverse, showing packages which require the target
|
|
|
|
*/
|
2011-06-28 09:26:39 -04:00
|
|
|
static void walk_reverse_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, int depth)
|
2010-10-12 14:46:12 -04:00
|
|
|
{
|
|
|
|
alpm_list_t *required_by, *i;
|
|
|
|
|
2011-06-21 13:42:17 -04:00
|
|
|
if(!pkg || ((max_depth >= 0) && (depth == max_depth + 1))) {
|
2010-10-12 14:46:12 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-25 11:57:20 -04:00
|
|
|
walked = alpm_list_add(walked, (void *)alpm_pkg_get_name(pkg));
|
2010-10-12 14:46:12 -04:00
|
|
|
required_by = alpm_pkg_compute_requiredby(pkg);
|
|
|
|
|
|
|
|
for(i = required_by; i; i = alpm_list_next(i)) {
|
|
|
|
const char *pkgname = alpm_list_getdata(i);
|
|
|
|
|
2010-10-13 09:50:13 -04:00
|
|
|
if(alpm_list_find_str(walked, pkgname)) {
|
|
|
|
/* if we've already seen this package, don't print in "unique" output
|
|
|
|
* and don't recurse */
|
|
|
|
if(!unique) {
|
|
|
|
print(alpm_pkg_get_name(pkg), pkgname, NULL, depth);
|
|
|
|
}
|
2010-10-12 14:46:12 -04:00
|
|
|
} else {
|
2010-10-13 09:50:13 -04:00
|
|
|
print(alpm_pkg_get_name(pkg), pkgname, NULL, depth);
|
2011-06-21 13:42:17 -04:00
|
|
|
walk_reverse_deps(dblist, get_pkg_from_dbs(dblist, pkgname), depth + 1);
|
2010-10-12 14:46:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FREELIST(required_by);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* walk dependencies, showing dependencies of the target
|
|
|
|
*/
|
2011-06-28 09:26:39 -04:00
|
|
|
static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, int depth)
|
2010-10-12 14:46:12 -04:00
|
|
|
{
|
|
|
|
alpm_list_t *i;
|
|
|
|
|
|
|
|
if((max_depth >= 0) && (depth == max_depth + 1)) {
|
2010-10-13 09:50:13 -04:00
|
|
|
return;
|
2010-10-12 14:46:12 -04:00
|
|
|
}
|
|
|
|
|
2011-03-25 11:57:20 -04:00
|
|
|
walked = alpm_list_add(walked, (void *)alpm_pkg_get_name(pkg));
|
2010-10-12 14:46:12 -04:00
|
|
|
|
|
|
|
for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) {
|
2011-06-28 00:29:55 -04:00
|
|
|
alpm_depend_t *depend = alpm_list_getdata(i);
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *provider = alpm_find_dbs_satisfier(handle, dblist, depend->name);
|
2010-10-12 14:46:12 -04:00
|
|
|
|
2010-10-13 09:50:13 -04:00
|
|
|
if(provider) {
|
|
|
|
const char *provname = alpm_pkg_get_name(provider);
|
2010-10-12 14:46:12 -04:00
|
|
|
|
2010-10-13 09:50:13 -04:00
|
|
|
if(alpm_list_find_str(walked, provname)) {
|
|
|
|
/* if we've already seen this package, don't print in "unique" output
|
|
|
|
* and don't recurse */
|
|
|
|
if(!unique) {
|
2011-06-16 12:42:10 -04:00
|
|
|
print(alpm_pkg_get_name(pkg), provname, depend->name, depth);
|
2010-10-13 09:50:13 -04:00
|
|
|
}
|
|
|
|
} else {
|
2011-06-16 12:42:10 -04:00
|
|
|
print(alpm_pkg_get_name(pkg), provname, depend->name, depth);
|
2011-06-21 13:42:17 -04:00
|
|
|
walk_deps(dblist, provider, depth + 1);
|
2010-10-12 14:46:12 -04:00
|
|
|
}
|
2010-10-13 09:50:13 -04:00
|
|
|
} else {
|
|
|
|
/* unresolvable package */
|
2011-06-16 12:42:10 -04:00
|
|
|
print(alpm_pkg_get_name(pkg), NULL, depend->name, depth);
|
2010-10-12 14:46:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2011-06-21 13:47:50 -04:00
|
|
|
int freelist = 0, ret = 0;
|
2011-06-28 00:50:48 -04:00
|
|
|
enum _alpm_errno_t err;
|
2010-10-12 14:46:12 -04:00
|
|
|
const char *target_name;
|
2011-06-28 09:26:39 -04:00
|
|
|
alpm_pkg_t *pkg;
|
2011-06-21 13:42:17 -04:00
|
|
|
alpm_list_t *dblist = NULL;
|
2010-10-12 14:46:12 -04:00
|
|
|
|
2011-06-07 17:06:16 -04:00
|
|
|
if(parse_options(argc, argv) != 0) {
|
2010-10-12 14:46:12 -04:00
|
|
|
usage();
|
2011-06-07 17:06:16 -04:00
|
|
|
ret = 1;
|
2010-10-12 14:46:12 -04:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2011-06-07 17:06:16 -04:00
|
|
|
handle = alpm_initialize(ROOTDIR, dbpath, &err);
|
|
|
|
if(!handle) {
|
|
|
|
fprintf(stderr, "error: cannot initialize alpm: %s\n",
|
|
|
|
alpm_strerror(err));
|
|
|
|
ret = 1;
|
2010-10-12 14:46:12 -04:00
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2011-06-21 13:47:50 -04:00
|
|
|
if(searchsyncs) {
|
2011-06-27 11:10:08 -04:00
|
|
|
if(register_syncs() != 0) {
|
2011-06-21 13:47:50 -04:00
|
|
|
ret = 1;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
dblist = alpm_option_get_syncdbs(handle);
|
|
|
|
} else {
|
|
|
|
dblist = alpm_list_add(dblist, alpm_option_get_localdb(handle));
|
|
|
|
freelist = 1;
|
|
|
|
}
|
2011-06-07 17:06:16 -04:00
|
|
|
|
2010-10-12 14:46:12 -04:00
|
|
|
/* we only care about the first non option arg for walking */
|
|
|
|
target_name = argv[optind];
|
|
|
|
|
2011-06-21 13:42:17 -04:00
|
|
|
pkg = alpm_find_dbs_satisfier(handle, dblist, target_name);
|
2010-10-13 09:50:13 -04:00
|
|
|
if(!pkg) {
|
2010-10-12 14:46:12 -04:00
|
|
|
fprintf(stderr, "error: package '%s' not found\n", target_name);
|
|
|
|
ret = 1;
|
|
|
|
goto finish;
|
|
|
|
}
|
|
|
|
|
2010-10-13 09:50:13 -04:00
|
|
|
print_start(alpm_pkg_get_name(pkg), target_name);
|
2010-10-12 14:46:12 -04:00
|
|
|
|
|
|
|
if(reverse) {
|
2011-06-21 13:42:17 -04:00
|
|
|
walk_reverse_deps(dblist, pkg, 1);
|
2010-10-12 14:46:12 -04:00
|
|
|
} else {
|
2011-06-21 13:42:17 -04:00
|
|
|
walk_deps(dblist, pkg, 1);
|
2010-10-12 14:46:12 -04:00
|
|
|
}
|
|
|
|
|
2010-10-13 09:50:13 -04:00
|
|
|
print_end();
|
2010-10-12 14:46:12 -04:00
|
|
|
|
2011-06-21 13:47:50 -04:00
|
|
|
if(freelist) {
|
|
|
|
alpm_list_free(dblist);
|
|
|
|
}
|
2011-06-21 13:42:17 -04:00
|
|
|
|
2010-10-12 14:46:12 -04:00
|
|
|
finish:
|
|
|
|
cleanup();
|
2011-03-20 20:45:57 -04:00
|
|
|
return ret;
|
2010-10-12 14:46:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim: set ts=2 sw=2 noet: */
|