#include #include #include void displaydeps(pmpkg_t *pkg) { alpm_list_t *i; for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) { char *dep = alpm_list_getdata(i); printf("%s \n", dep); } } int main(int argc, char **argv) { pmdb_t *db = NULL; alpm_list_t *i; if(argc != 2) { printf("usage : displaydeps \n"); exit(EXIT_FAILURE); } if(alpm_initialize() == -1) { fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(pm_errno)); exit(EXIT_FAILURE); } alpm_option_set_dbpath("/var/lib/pacman"); db = alpm_db_register_local(); if(db == NULL) { fprintf(stderr, "error: could not register 'local' database (%s)\n", alpm_strerror(pm_errno)); exit(EXIT_FAILURE); } /* if the package exists, list its dependencies */ pmpkg_t *pkg = alpm_db_get_pkg(db, argv[1]); if(pkg) { displaydeps(pkg); } else { /* otherwise, search for matching packages */ fprintf(stderr, "error: package %s does not exist\n", argv[1]); alpm_list_t *targets = alpm_list_add(NULL, argv[1]); alpm_list_t *res = alpm_db_search(db, targets); fprintf(stderr, "matching packages : "); for(i = res; i; i = alpm_list_next(i)) { pmpkg_t *pkg = alpm_list_getdata(i); printf("%s \n", alpm_pkg_get_name(pkg)); } } if(alpm_release() == -1) { fprintf(stderr, "error releasing alpm: %s\n", alpm_strerror(pm_errno)); } exit(EXIT_SUCCESS); } /* vim: set ts=2 sw=2 noet: */