rendered paste body/* * sortpkg.c : Display the locally installed packages sorted by size. * */#include <stdio.h>#include <inttypes.h>#include <alpm.h>#include <alpm_list.h>int pkg_cmp(const void *v1, const void *v2){ pmpkg_t *p1 = (pmpkg_t *)v1; pmpkg_t *p2 = (pmpkg_t *)v2; unsigned long int s1 = alpm_pkg_get_size(p1); unsigned long int s2 = alpm_pkg_get_size(p2); return(s2 - s1);}int main(int argc, char **argv){ pmdb_t *db = NULL; alpm_list_t *i; 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); } alpm_list_t *list = alpm_db_get_pkgcache(db); list = alpm_list_msort(list, alpm_list_count(list), pkg_cmp); for(i = list; i; i = alpm_list_next(i)) { pmpkg_t *pkg = alpm_list_getdata(i); printf("%s %"PRId64"\n", alpm_pkg_get_name(pkg), alpm_pkg_get_size(pkg)/1024); } 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: */