summaryrefslogtreecommitdiff
path: root/src/pacman/query.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pacman/query.c')
-rw-r--r--src/pacman/query.c69
1 files changed, 42 insertions, 27 deletions
diff --git a/src/pacman/query.c b/src/pacman/query.c
index e999a328..74d3ff21 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -1,7 +1,7 @@
/*
* query.c
*
- * Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org>
+ * Copyright (c) 2002-2008 by Judd Vinet <jvinet@zeroflux.org>
*
* 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
@@ -62,28 +62,28 @@ static int query_fileowner(alpm_list_t *targets)
/* This code is here for safety only */
if(targets == NULL) {
- fprintf(stderr, _("error: no file was specified for --owns\n"));
+ pm_fprintf(stderr, PM_LOG_ERROR, _("no file was specified for --owns\n"));
return(1);
}
for(t = targets; t; t = alpm_list_next(t)) {
int found = 0;
char *filename = alpm_list_getdata(t);
- char *bname;
- char *dname;
- char *rpath;
+ char *bname, *dname, *rpath;
+ const char *root;
struct stat buf;
alpm_list_t *i, *j;
if(stat(filename, &buf) == -1) {
- fprintf(stderr, _("error: failed to read file '%s': %s\n"),
+ pm_fprintf(stderr, PM_LOG_ERROR, _("failed to read file '%s': %s\n"),
filename, strerror(errno));
ret++;
continue;
}
if(S_ISDIR(buf.st_mode)) {
- fprintf(stderr, _("error: cannot determine ownership of a directory\n"));
+ pm_fprintf(stderr, PM_LOG_ERROR,
+ _("cannot determine ownership of a directory\n"));
ret++;
continue;
}
@@ -94,20 +94,22 @@ static int query_fileowner(alpm_list_t *targets)
free(dname);
if(!rpath) {
- fprintf(stderr, _("error: cannot determine real path for '%s': %s\n"),
+ pm_fprintf(stderr, PM_LOG_ERROR, _("cannot determine real path for '%s': %s\n"),
filename, strerror(errno));
free(rpath);
ret++;
continue;
}
+ root = alpm_option_get_root();
+
for(i = alpm_db_getpkgcache(db_local); i && !found; i = alpm_list_next(i)) {
pmpkg_t *info = alpm_list_getdata(i);
for(j = alpm_pkg_get_files(info); j && !found; j = alpm_list_next(j)) {
char path[PATH_MAX], *ppath, *pdname;
snprintf(path, PATH_MAX, "%s%s",
- alpm_option_get_root(), (const char *)alpm_list_getdata(j));
+ root, (const char *)alpm_list_getdata(j));
/* avoid the costly resolve_path usage if the basenames don't match */
if(strcmp(mbasename(path), bname) != 0) {
@@ -119,15 +121,20 @@ static int query_fileowner(alpm_list_t *targets)
free(pdname);
if(ppath && strcmp(ppath, rpath) == 0) {
- printf(_("%s is owned by %s %s\n"), filename,
- alpm_pkg_get_name(info), alpm_pkg_get_version(info));
+ if (!config->quiet) {
+ printf(_("%s is owned by %s %s\n"), filename,
+ alpm_pkg_get_name(info), alpm_pkg_get_version(info));
+ } else {
+ printf("%s %s\n", alpm_pkg_get_name(info),
+ alpm_pkg_get_version(info));
+ }
found = 1;
}
free(ppath);
}
}
if(!found) {
- fprintf(stderr, _("error: No package owns %s\n"), filename);
+ pm_fprintf(stderr, PM_LOG_ERROR, _("No package owns %s\n"), filename);
ret++;
}
free(rpath);
@@ -155,7 +162,6 @@ static int query_search(alpm_list_t *targets)
}
for(i = searchlist; i; i = alpm_list_next(i)) {
- char *group = NULL;
alpm_list_t *grp;
pmpkg_t *pkg = alpm_list_getdata(i);
@@ -176,8 +182,17 @@ static int query_search(alpm_list_t *targets)
if (!config->quiet) {
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
- group = alpm_list_getdata(grp);
- printf(" (%s)", (char *)alpm_list_getdata(grp));
+ alpm_list_t *k;
+ printf(" (");
+ for(k = grp; k; k = alpm_list_next(k)) {
+ const char *group = alpm_list_getdata(k);
+ printf("%s", group);
+ if(alpm_list_next(k)) {
+ /* only print a spacer if there are more groups */
+ printf(" ");
+ }
+ }
+ printf(")");
}
/* we need a newline and initial indent first */
@@ -197,33 +212,33 @@ static int query_search(alpm_list_t *targets)
static int query_group(alpm_list_t *targets)
{
alpm_list_t *i, *j;
- char *package = NULL;
+ char *grpname = NULL;
int ret = 0;
if(targets == NULL) {
for(j = alpm_db_getgrpcache(db_local); j; j = alpm_list_next(j)) {
pmgrp_t *grp = alpm_list_getdata(j);
- const alpm_list_t *p, *pkgnames;
+ const alpm_list_t *p, *packages;
const char *grpname;
grpname = alpm_grp_get_name(grp);
- pkgnames = alpm_grp_get_pkgs(grp);
+ packages = alpm_grp_get_pkgs(grp);
- for(p = pkgnames; p; p = alpm_list_next(p)) {
- printf("%s %s\n", grpname, (char *)alpm_list_getdata(p));
+ for(p = packages; p; p = alpm_list_next(p)) {
+ printf("%s %s\n", grpname, alpm_pkg_get_name(alpm_list_getdata(p)));
}
}
} else {
for(i = targets; i; i = alpm_list_next(i)) {
pmgrp_t *grp;
- package = alpm_list_getdata(i);
- grp = alpm_db_readgrp(db_local, package);
+ grpname = alpm_list_getdata(i);
+ grp = alpm_db_readgrp(db_local, grpname);
if(grp) {
- const alpm_list_t *p, *pkgnames = alpm_grp_get_pkgs(grp);
- for(p = pkgnames; p; p = alpm_list_next(p)) {
- printf("%s %s\n", package, (char *)alpm_list_getdata(p));
+ const alpm_list_t *p, *packages = alpm_grp_get_pkgs(grp);
+ for(p = packages; p; p = alpm_list_next(p)) {
+ printf("%s %s\n", grpname, alpm_pkg_get_name(alpm_list_getdata(p)));
}
} else {
- fprintf(stderr, _("error: group \"%s\" was not found\n"), package);
+ pm_fprintf(stderr, PM_LOG_ERROR, _("group \"%s\" was not found\n"), grpname);
ret++;
}
}
@@ -401,7 +416,7 @@ int pacman_query(alpm_list_t *targets)
}
if(pkg == NULL) {
- fprintf(stderr, _("error: package \"%s\" not found\n"), strname);
+ pm_fprintf(stderr, PM_LOG_ERROR, _("package \"%s\" not found\n"), strname);
ret++;
continue;
}