From aa1c0ba9f8787fc3b1a1190103e394b0c1c95922 Mon Sep 17 00:00:00 2001 From: Aaron Griffin Date: Mon, 20 Nov 2006 09:10:23 +0000 Subject: * repo-add script - to add entries to a db file directly from package data (no PKGBUILD) * libalpm api changes - move from a _getinfo(p, WHAT_WE_WANT) scheme to a typesafe _get_what_we_want(p) scheme [not 100% complete yet] * some const correctness changes * removal of PM_* types in alpm.h in favor of the pm*_t types used throughout libalpm --- src/pacman/Makefile.am | 3 +- src/pacman/add.c | 10 ++-- src/pacman/conf.c | 3 +- src/pacman/conf.h | 8 +-- src/pacman/deptest.c | 8 +-- src/pacman/downloadprog.c | 2 +- src/pacman/list.c | 14 +++--- src/pacman/list.h | 12 ++--- src/pacman/package.c | 108 ++++++++++++++++++++-------------------- src/pacman/package.h | 8 +-- src/pacman/pacman.c | 64 +++++++++--------------- src/pacman/query.c | 103 +++++++++++++++++++------------------- src/pacman/remove.c | 24 ++++----- src/pacman/sync.c | 122 +++++++++++++++++++++++----------------------- src/pacman/sync.h | 2 +- src/pacman/trans.c | 40 +++++++-------- src/pacman/util.c | 16 ++++-- src/pacman/util.h | 4 +- 18 files changed, 267 insertions(+), 284 deletions(-) (limited to 'src') diff --git a/src/pacman/Makefile.am b/src/pacman/Makefile.am index 956cdecb..216633a6 100644 --- a/src/pacman/Makefile.am +++ b/src/pacman/Makefile.am @@ -5,8 +5,7 @@ SUBDIRS = po localedir = $(datadir)/locale DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ -AM_CFLAGS = $(CFLAGS) -D_GNU_SOURCE \ - -I$(top_srcdir)/lib/libalpm +AM_CFLAGS = -D_GNU_SOURCE -I$(top_srcdir)/lib/libalpm $(CFLAGS) pacman_SOURCES = util.c log.c list.c package.c downloadprog.c trans.c add.c \ remove.c upgrade.c query.c sync.c conf.c deptest.c pacman.c diff --git a/src/pacman/add.c b/src/pacman/add.c index 600bc625..9b5a650f 100644 --- a/src/pacman/add.c +++ b/src/pacman/add.c @@ -38,7 +38,7 @@ extern config_t *config; int pacman_add(list_t *targets) { - PM_LIST *data; + pmlist_t *data; list_t *i; int retval = 0; @@ -87,13 +87,13 @@ int pacman_add(list_t *targets) */ if(alpm_trans_prepare(&data) == -1) { long long *pkgsize, *freespace; - PM_LIST *i; + pmlist_t *i; ERR(NL, _("failed to prepare transaction (%s)\n"), alpm_strerror(pm_errno)); switch(pm_errno) { case PM_ERR_UNSATISFIED_DEPS: for(i = alpm_list_first(data); i; i = alpm_list_next(i)) { - PM_DEPMISS *miss = alpm_list_getdata(i); + pmdepmissing_t *miss = alpm_list_getdata(i); MSG(NL, _(":: %s: requires %s"), alpm_dep_getinfo(miss, PM_DEP_TARGET), alpm_dep_getinfo(miss, PM_DEP_NAME)); switch((long)alpm_dep_getinfo(miss, PM_DEP_MOD)) { @@ -107,7 +107,7 @@ int pacman_add(list_t *targets) break; case PM_ERR_CONFLICTING_DEPS: for(i = alpm_list_first(data); i; i = alpm_list_next(i)) { - PM_DEPMISS *miss = alpm_list_getdata(i); + pmdepmissing_t *miss = alpm_list_getdata(i); MSG(NL, _(":: %s: conflicts with %s"), alpm_dep_getinfo(miss, PM_DEP_TARGET), alpm_dep_getinfo(miss, PM_DEP_NAME)); } @@ -115,7 +115,7 @@ int pacman_add(list_t *targets) break; case PM_ERR_FILE_CONFLICTS: for(i = alpm_list_first(data); i; i = alpm_list_next(i)) { - PM_CONFLICT *conflict = alpm_list_getdata(i); + pmconflict_t *conflict = alpm_list_getdata(i); switch((long)alpm_conflict_getinfo(conflict, PM_CONFLICT_TYPE)) { case PM_CONFLICT_TYPE_TARGET: MSG(NL, _("%s%s exists in \"%s\" (target) and \"%s\" (target)"), diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 72c55f35..ef380580 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -53,7 +53,6 @@ int config_free(config_t *config) return(-1); } - FREE(config->root); FREE(config->configfile); FREELIST(config->op_s_ignore); free(config); @@ -61,7 +60,7 @@ int config_free(config_t *config) return(0); } -void cb_db_register(char *section, PM_DB *db) +void cb_db_register(char *section, pmdb_t *db) { sync_t *sync; diff --git a/src/pacman/conf.h b/src/pacman/conf.h index f7b5d2fb..79f9c0ec 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -23,9 +23,9 @@ typedef struct __config_t { /* command line options */ - char *root; - char *dbpath; - char *cachedir; + const char *root; + const char *dbpath; + const char *cachedir; char *configfile; unsigned short op; unsigned short verbose; @@ -63,7 +63,7 @@ typedef struct __config_t { config_t *config_new(void); int config_free(config_t *config); -void cb_db_register(char *section, PM_DB *db); +void cb_db_register(char *section, pmdb_t *db); #endif /* _PM_CONF_H */ diff --git a/src/pacman/deptest.c b/src/pacman/deptest.c index 4f6723e7..4caaf3c7 100644 --- a/src/pacman/deptest.c +++ b/src/pacman/deptest.c @@ -38,7 +38,7 @@ extern config_t *config; int pacman_deptest(list_t *targets) { - PM_LIST *data; + pmlist_t *data; list_t *i; char *str; int retval = 0; @@ -94,7 +94,7 @@ int pacman_deptest(list_t *targets) FREE(str); if(alpm_trans_prepare(&data) == -1) { - PM_LIST *lp; + pmlist_t *lp; list_t *synctargs = NULL; retval = 126; /* return 126 = deps were missing, but successfully resolved @@ -105,7 +105,7 @@ int pacman_deptest(list_t *targets) switch(pm_errno) { case PM_ERR_UNSATISFIED_DEPS: for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) { - PM_DEPMISS *miss = alpm_list_getdata(lp); + pmdepmissing_t *miss = alpm_list_getdata(lp); if(!config->op_d_resolve) { MSG(NL, _("requires: %s"), alpm_dep_getinfo(miss, PM_DEP_NAME)); switch((long)alpm_dep_getinfo(miss, PM_DEP_MOD)) { @@ -122,7 +122,7 @@ int pacman_deptest(list_t *targets) case PM_ERR_CONFLICTING_DEPS: /* we can't auto-resolve conflicts */ for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) { - PM_DEPMISS *miss = alpm_list_getdata(lp); + pmdepmissing_t *miss = alpm_list_getdata(lp); MSG(NL, _("conflict: %s"), alpm_dep_getinfo(miss, PM_DEP_NAME)); } retval = 127; diff --git a/src/pacman/downloadprog.c b/src/pacman/downloadprog.c index 0de34d3d..f831656b 100644 --- a/src/pacman/downloadprog.c +++ b/src/pacman/downloadprog.c @@ -77,7 +77,7 @@ void log_progress(const char *filename, int xfered, int total) } /* a little hard to conceal easter eggs in open-source software, but they're still fun. ;) */ - alpm_get_option(PM_OPT_CHOMP, &chomp); + chomp = alpm_option_get_chomp(); gettimeofday(¤t_time, NULL); total_timediff = current_time.tv_sec-initial_time.tv_sec diff --git a/src/pacman/list.c b/src/pacman/list.c index 0a080373..0c271978 100644 --- a/src/pacman/list.c +++ b/src/pacman/list.c @@ -101,7 +101,7 @@ static list_t *list_last(list_t *list) /* Test for existence of a string in a list_t */ -int list_is_strin(char *needle, list_t *haystack) +int list_is_strin(const char *needle, list_t *haystack) { list_t *lp; @@ -144,9 +144,9 @@ void list_display(const char *title, list_t *list) } } -void PM_LIST_display(const char *title, PM_LIST *list) +void pmlist_display(const char *title, pmlist_t *list) { - PM_LIST *lp; + pmlist_t *lp; int cols, len; len = strlen(title); @@ -172,17 +172,17 @@ void PM_LIST_display(const char *title, PM_LIST *list) } } -/* Filter out any duplicate strings in a PM_LIST +/* Filter out any duplicate strings in a pmlist_t * * Not the most efficient way, but simple to implement -- we assemble * a new list, using is_in() to check for dupes at each iteration. * - * This function takes a PM_LIST* and returns a list_t* + * This function takes a pmlist_t* and returns a list_t* * */ -list_t *PM_LIST_remove_dupes(PM_LIST *list) +list_t *pmlist_remove_dupes(pmlist_t *list) { - PM_LIST *i; + pmlist_t *i; list_t *newlist = NULL; for(i = alpm_list_first(list); i; i = alpm_list_next(i)) { diff --git a/src/pacman/list.h b/src/pacman/list.h index 68f080e4..30830aae 100644 --- a/src/pacman/list.h +++ b/src/pacman/list.h @@ -18,8 +18,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ -#ifndef _PM_LIST_H -#define _PM_LIST_H +#ifndef _LIST_H +#define _LIST_H #include @@ -42,12 +42,12 @@ list_t *list_new(void); void list_free(list_t *list); list_t *list_add(list_t *list, void *data); int list_count(list_t *list); -int list_is_strin(char *needle, list_t *haystack); +int list_is_strin(const char *needle, list_t *haystack); void list_display(const char *title, list_t *list); -void PM_LIST_display(const char *title, PM_LIST *list); -list_t *PM_LIST_remove_dupes(PM_LIST *list); +void pmlist_display(const char *title, pmlist_t *list); +list_t *pmlist_remove_dupes(pmlist_t *list); -#endif /* _PM_LIST_H */ +#endif /*_LIST_H*/ /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/package.c b/src/pacman/package.c index 498b6988..bf26c5c2 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -35,36 +35,36 @@ /* Display the content of an installed package */ -void dump_pkg_full(PM_PKG *pkg, int level) +void dump_pkg_full(pmpkg_t *pkg, int level) { - char *date, *type; + const char *date, *type; if(pkg == NULL) { return; } - printf(_("Name : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME)); - printf(_("Version : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION)); + printf(_("Name : %s\n"), (char *)alpm_pkg_get_name(pkg)); + printf(_("Version : %s\n"), (char *)alpm_pkg_get_version(pkg)); - PM_LIST_display(_("Groups :"), alpm_pkg_getinfo(pkg, PM_PKG_GROUPS)); + pmlist_display(_("Groups :"), alpm_pkg_get_groups(pkg)); - printf(_("Packager : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_PACKAGER)); - printf("URL : %s\n", (char *)alpm_pkg_getinfo(pkg, PM_PKG_URL)); - PM_LIST_display(_("License :"), alpm_pkg_getinfo(pkg, PM_PKG_LICENSE)); - printf(_("Architecture : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_ARCH)); - printf(_("Size : %ld\n"), (long int)alpm_pkg_getinfo(pkg, PM_PKG_SIZE)); + printf(_("Packager : %s\n"), (char *)alpm_pkg_get_packager(pkg)); + printf("URL : %s\n", (char *)alpm_pkg_get_url(pkg)); + pmlist_display(_("License :"), alpm_pkg_get_licenses(pkg)); + printf(_("Architecture : %s\n"), (char *)alpm_pkg_get_arch(pkg)); + printf(_("Size : %ld\n"), (long int)alpm_pkg_get_size(pkg)); - date = alpm_pkg_getinfo(pkg, PM_PKG_BUILDDATE); + date = alpm_pkg_get_builddate(pkg); printf(_("Build Date : %s %s\n"), date, strlen(date) ? "UTC" : ""); - type = alpm_pkg_getinfo(pkg, PM_PKG_BUILDTYPE); + type = alpm_pkg_get_buildtype(pkg); printf(_("Build Type : %s\n"), strlen(type) ? type : _("Unknown")); - date = alpm_pkg_getinfo(pkg, PM_PKG_INSTALLDATE); + date = alpm_pkg_get_installdate(pkg); printf(_("Install Date : %s %s\n"), date, strlen(date) ? "UTC" : ""); - printf(_("Install Script : %s\n"), alpm_pkg_getinfo(pkg, PM_PKG_SCRIPLET) ? _("Yes") : _("No")); + printf(_("Install Script : %s\n"), alpm_pkg_has_scriptlet(pkg) ? _("Yes") : _("No")); printf(_("Reason : ")); - switch((long)alpm_pkg_getinfo(pkg, PM_PKG_REASON)) { + switch((long)alpm_pkg_get_reason(pkg)) { case PM_PKG_REASON_EXPLICIT: printf(_("Explicitly installed\n")); break; @@ -76,24 +76,21 @@ void dump_pkg_full(PM_PKG *pkg, int level) break; } - PM_LIST_display(_("Provides :"), alpm_pkg_getinfo(pkg, PM_PKG_PROVIDES)); - PM_LIST_display(_("Depends On :"), alpm_pkg_getinfo(pkg, PM_PKG_DEPENDS)); - PM_LIST_display(_("Removes :"), alpm_pkg_getinfo(pkg, PM_PKG_REMOVES)); - PM_LIST_display(_("Required By :"), alpm_pkg_getinfo(pkg, PM_PKG_REQUIREDBY)); - PM_LIST_display(_("Conflicts With :"), alpm_pkg_getinfo(pkg, PM_PKG_CONFLICTS)); + pmlist_display(_("Provides :"), alpm_pkg_get_provides(pkg)); + pmlist_display(_("Depends On :"), alpm_pkg_get_depends(pkg)); + pmlist_display(_("Removes :"), alpm_pkg_get_removes(pkg)); + pmlist_display(_("Required By :"), alpm_pkg_get_requiredby(pkg)); + pmlist_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg)); printf(_("Description : ")); - indentprint(alpm_pkg_getinfo(pkg, PM_PKG_DESC), 17); + indentprint(alpm_pkg_get_desc(pkg), 17); printf("\n"); if(level > 1) { - PM_LIST *i; - long lroot; - char *root; - alpm_get_option(PM_OPT_ROOT, &lroot); - root = (void *)lroot; + pmlist_t *i; + const char *root = alpm_option_get_root(); fprintf(stdout, "\n"); - for(i = alpm_list_first(alpm_pkg_getinfo(pkg, PM_PKG_BACKUP)); i; i = alpm_list_next(i)) { + for(i = alpm_list_first(alpm_pkg_get_backup(pkg)); i; i = alpm_list_next(i)) { struct stat buf; char path[PATH_MAX]; char *str = strdup(alpm_list_getdata(i)); @@ -131,46 +128,47 @@ void dump_pkg_full(PM_PKG *pkg, int level) /* Display the content of a sync package */ -void dump_pkg_sync(PM_PKG *pkg, char *treename) +void dump_pkg_sync(pmpkg_t *pkg, char *treename) { - char *tmp1, *tmp2; + char *sum; if(pkg == NULL) { return; } printf(_("Repository : %s\n"), treename); - printf(_("Name : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME)); - printf(_("Version : %s\n"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION)); - - PM_LIST_display(_("Groups :"), alpm_pkg_getinfo(pkg, PM_PKG_GROUPS)); - PM_LIST_display(_("Provides :"), alpm_pkg_getinfo(pkg, PM_PKG_PROVIDES)); - PM_LIST_display(_("Depends On :"), alpm_pkg_getinfo(pkg, PM_PKG_DEPENDS)); - PM_LIST_display(_("Removes :"), alpm_pkg_getinfo(pkg, PM_PKG_REMOVES)); - PM_LIST_display(_("Conflicts With :"), alpm_pkg_getinfo(pkg, PM_PKG_CONFLICTS)); - PM_LIST_display(_("Replaces :"), alpm_pkg_getinfo(pkg, PM_PKG_REPLACES)); - - printf(_("Size (compressed) : %ld\n"), (long)alpm_pkg_getinfo(pkg, PM_PKG_SIZE)); - printf(_("Size (uncompressed):%ld\n"), (long)alpm_pkg_getinfo(pkg, PM_PKG_USIZE)); + printf(_("Name : %s\n"), (char *)alpm_pkg_get_name(pkg)); + printf(_("Version : %s\n"), (char *)alpm_pkg_get_version(pkg)); + + pmlist_display(_("Groups :"), alpm_pkg_get_groups(pkg)); + pmlist_display(_("Provides :"), alpm_pkg_get_provides(pkg)); + pmlist_display(_("Depends On :"), alpm_pkg_get_depends(pkg)); + pmlist_display(_("Removes :"), alpm_pkg_get_removes(pkg)); + pmlist_display(_("Conflicts With :"), alpm_pkg_get_conflicts(pkg)); + pmlist_display(_("Replaces :"), alpm_pkg_get_replaces(pkg)); + + printf(_("Size (compressed) : %ld\n"), (long)alpm_pkg_get_size(pkg)); + printf(_("Size (uncompressed):%ld\n"), (long)alpm_pkg_get_usize(pkg)); printf(_("Description : ")); - indentprint(alpm_pkg_getinfo(pkg, PM_PKG_DESC), 20); - tmp1 = (char *)alpm_pkg_getinfo(pkg, PM_PKG_MD5SUM); - if (tmp1 != NULL && tmp1[0] != '\0') { - printf(_("\nMD5 Sum : %s"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_MD5SUM)); - } - tmp2 = (char *)alpm_pkg_getinfo(pkg, PM_PKG_SHA1SUM); - if (tmp2 != NULL && tmp2[0] != '\0') { - printf(_("\nSHA1 Sum : %s"), (char *)alpm_pkg_getinfo(pkg, PM_PKG_SHA1SUM)); + indentprint(alpm_pkg_get_desc(pkg), 20); + + sum = (char *)alpm_pkg_get_md5sum(pkg); + if (sum != NULL && sum[0] != '\0') { + printf(_("\nMD5 Sum : %s"), sum); + } + sum = (char *)alpm_pkg_get_sha1sum(pkg); + if (sum != NULL && sum[0] != '\0') { + printf(_("\nSHA1 Sum : %s"), sum); } printf("\n"); } -void dump_pkg_files(PM_PKG *pkg) +void dump_pkg_files(pmpkg_t *pkg) { - char *pkgname; - PM_LIST *i, *pkgfiles; + const char *pkgname; + pmlist_t *i, *pkgfiles; - pkgname = alpm_pkg_getinfo(pkg, PM_PKG_NAME); - pkgfiles = alpm_pkg_getinfo(pkg, PM_PKG_FILES); + pkgname = alpm_pkg_get_name(pkg); + pkgfiles = alpm_pkg_get_files(pkg); for(i = pkgfiles; i; i = alpm_list_next(i)) { fprintf(stdout, "%s %s\n", (char *)pkgname, (char *)alpm_list_getdata(i)); @@ -181,7 +179,7 @@ void dump_pkg_files(PM_PKG *pkg) /* Display the changelog of an installed package */ -void dump_pkg_changelog(char *clfile, char *pkgname) +void dump_pkg_changelog(char *clfile, const char *pkgname) { FILE* fp = NULL; char line[PATH_MAX+1]; diff --git a/src/pacman/package.h b/src/pacman/package.h index 284105cb..e8c89c9b 100644 --- a/src/pacman/package.h +++ b/src/pacman/package.h @@ -21,11 +21,11 @@ #ifndef _PM_PACKAGE_H #define _PM_PACKAGE_H -void dump_pkg_full(PM_PKG *pkg, int level); -void dump_pkg_sync(PM_PKG *pkg, char *treename); +void dump_pkg_full(pmpkg_t *pkg, int level); +void dump_pkg_sync(pmpkg_t *pkg, char *treename); -void dump_pkg_files(PM_PKG *pkg); -void dump_pkg_changelog(char *clfile, char *pkgname); +void dump_pkg_files(pmpkg_t *pkg); +void dump_pkg_changelog(char *clfile, const char *pkgname); int split_pkgname(char *target, char *name, char *version); diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 79c15c3f..c138c2c4 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -75,7 +75,7 @@ enum { config_t *config = NULL; -PM_DB *db_local; +pmdb_t *db_local; /* list of (sync_t *) structs for sync locations */ list_t *pmc_syncs = NULL; /* list of targets specified on command line */ @@ -322,10 +322,8 @@ static int parseargs(int argc, char *argv[]) config->op_d_vertest = 1; break; case 'b': - if(config->dbpath) { - FREE(config->dbpath); - } - config->dbpath = strdup(optarg); + alpm_option_set_dbpath(optarg); + config->dbpath = alpm_option_get_dbpath(optarg); break; case 'c': config->op_s_clean++; @@ -355,10 +353,8 @@ static int parseargs(int argc, char *argv[]) perror(_("bad root path")); return(1); } - if(config->root) { - free(config->root); - } - config->root = strdup(root); + alpm_option_set_root(root); + config->root = alpm_option_get_root(); break; case 's': config->op_s_search = 1; @@ -404,7 +400,7 @@ static int parseargs(int argc, char *argv[]) int main(int argc, char *argv[]) { int ret = 0; - char *cenv = NULL, *lang = NULL; + char *lang = NULL; #ifndef CYGWIN uid_t myuid; #endif @@ -414,10 +410,7 @@ int main(int argc, char *argv[]) /*setenv("MALLOC_TRACE","pacman.mtrace", 0);*/ mtrace(); #endif - cenv = getenv("COLUMNS"); - if(cenv != NULL) { - maxcols = atoi(cenv); - } + maxcols = getcols(); /* set signal handlers */ signal(SIGINT, cleanup); @@ -490,34 +483,33 @@ int main(int argc, char *argv[]) #endif if(config->root == NULL) { - config->root = strdup(PM_ROOT); + config->root = PM_ROOT; } + char *initroot = NULL; /* add a trailing '/' if there isn't one */ if(config->root[strlen(config->root)-1] != '/') { char *ptr; MALLOC(ptr, strlen(config->root)+2); strcpy(ptr, config->root); strcat(ptr, "/"); - FREE(config->root); - config->root = ptr; + initroot = ptr; + } else { + initroot = strdup(config->root); } /* initialize pm library */ - if(alpm_initialize(config->root) == -1) { + if(alpm_initialize(initroot) == -1) { ERR(NL, _("failed to initilize alpm library (%s)\n"), alpm_strerror(pm_errno)); cleanup(1); } + FREE(initroot); + config->root = alpm_option_get_root(); + /* Setup logging as soon as possible, to print out maximum debugging info */ - if(alpm_set_option(PM_OPT_LOGMASK, (long)config->debug) == -1) { - ERR(NL, _("failed to set option LOGMASK (%s)\n"), alpm_strerror(pm_errno)); - cleanup(1); - } - if(alpm_set_option(PM_OPT_LOGCB, (long)cb_log) == -1) { - ERR(NL, _("failed to set option LOGCB (%s)\n"), alpm_strerror(pm_errno)); - cleanup(1); - } + alpm_option_set_logmask(config->debug); + alpm_option_set_logcb(cb_log); if(config->configfile == NULL) { config->configfile = strdup(PACCONF); @@ -528,23 +520,13 @@ int main(int argc, char *argv[]) } /* set library parameters */ - if(alpm_set_option(PM_OPT_DLCB, (long)log_progress) == -1) { - ERR(NL, _("failed to set option DLCB (%s)\n"), alpm_strerror(pm_errno)); - cleanup(1); - } - FREE(config->dbpath); - long ldbpath, lcachedir; - alpm_get_option(PM_OPT_DBPATH, &ldbpath); - config->dbpath = (char *)ldbpath; - FREE(config->cachedir); - alpm_get_option(PM_OPT_CACHEDIR, &lcachedir); - config->cachedir = (char *)lcachedir; + alpm_option_set_dlcb(log_progress); + + config->dbpath = alpm_option_get_dbpath(); + config->cachedir = alpm_option_get_cachedir(); for(lp = config->op_s_ignore; lp; lp = lp->next) { - if(alpm_set_option(PM_OPT_IGNOREPKG, (long)lp->data) == -1) { - ERR(NL, _("failed to set option IGNOREPKG (%s)\n"), alpm_strerror(pm_errno)); - cleanup(1); - } + alpm_option_add_ignorepkg(lp->data); } if(config->verbose > 0) { diff --git a/src/pacman/query.c b/src/pacman/query.c index 517ade74..e080ddf6 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -37,17 +37,16 @@ #include "util.h" extern config_t *config; -extern PM_DB *db_local; +extern pmdb_t *db_local; extern list_t *pmc_syncs; -static int query_fileowner(PM_DB *db, char *filename) +static int query_fileowner(pmdb_t *db, char *filename) { struct stat buf; int gotcha = 0; char rpath[PATH_MAX]; - PM_LIST *lp; - long lroot; - char *root; + pmlist_t *lp; + const char *root; if(db == NULL) { return(0); @@ -62,23 +61,22 @@ static int query_fileowner(PM_DB *db, char *filename) return(1); } - alpm_get_option(PM_OPT_ROOT, &lroot); - root = (char *)lroot; + root = alpm_option_get_root(); for(lp = alpm_db_getpkgcache(db); lp && !gotcha; lp = alpm_list_next(lp)) { - PM_PKG *info; - PM_LIST *i; + pmpkg_t *info; + pmlist_t *i; info = alpm_list_getdata(lp); - for(i = alpm_pkg_getinfo(info, PM_PKG_FILES); i && !gotcha; i = alpm_list_next(i)) { + for(i = alpm_pkg_get_files(info); i && !gotcha; i = alpm_list_next(i)) { char path[PATH_MAX]; char *filename = (char *)alpm_list_getdata(i); snprintf(path, PATH_MAX, "%s%s", root, filename); if(!strcmp(path, rpath)) { - printf(_("%s is owned by %s %s\n"), path, (char *)alpm_pkg_getinfo(info, PM_PKG_NAME), - (char *)alpm_pkg_getinfo(info, PM_PKG_VERSION)); + printf(_("%s is owned by %s %s\n"), path, (char *)alpm_pkg_get_name(info), + (char *)alpm_pkg_get_version(info)); gotcha = 1; break; } @@ -94,29 +92,29 @@ static int query_fileowner(PM_DB *db, char *filename) int pacman_query(list_t *targets) { - PM_PKG *info = NULL; + pmpkg_t *info = NULL; list_t *targ; list_t *i; - PM_LIST *j, *ret; + pmlist_t *j, *ret; char *package = NULL; int done = 0; if(config->op_q_search) { for(i = targets; i; i = i->next) { - alpm_set_option(PM_OPT_NEEDLES, (long)i->data); + alpm_option_add_needle(i->data); } ret = alpm_db_search(db_local); if(ret == NULL) { return(1); } for(j = ret; j; j = alpm_list_next(j)) { - PM_PKG *pkg = alpm_list_getdata(j); + pmpkg_t *pkg = alpm_list_getdata(j); printf("local/%s/%s %s\n ", - (char*)alpm_list_getdata(alpm_pkg_getinfo(pkg, PM_PKG_GROUPS)), - (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME), - (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION)); - indentprint((char *)alpm_pkg_getinfo(pkg, PM_PKG_DESC), 4); + (char *)alpm_list_getdata(alpm_pkg_get_groups(pkg)), + alpm_pkg_get_name(pkg), + alpm_pkg_get_version(pkg)); + indentprint(alpm_pkg_get_desc(pkg), 4); printf("\n"); } alpm_list_free_outer(ret); @@ -142,24 +140,24 @@ int pacman_query(list_t *targets) /* looking for groups */ if(config->group) { - PM_LIST *lp; + pmlist_t *lp; if(targets == NULL) { for(lp = alpm_db_getgrpcache(db_local); lp; lp = alpm_list_next(lp)) { - PM_GRP *grp = alpm_list_getdata(lp); - PM_LIST *i, *pkgnames; - char *grpname; + pmgrp_t *grp = alpm_list_getdata(lp); + pmlist_t *i, *pkgnames; + const char *grpname; - grpname = alpm_grp_getinfo(grp, PM_GRP_NAME); - pkgnames = alpm_grp_getinfo(grp, PM_GRP_PKGNAMES); + grpname = alpm_grp_get_name(grp); + pkgnames = alpm_grp_get_packages(grp); for(i = pkgnames; i; i = alpm_list_next(i)) { MSG(NL, "%s %s\n", grpname, (char *)alpm_list_getdata(i)); } } } else { - PM_GRP *grp = alpm_db_readgrp(db_local, package); + pmgrp_t *grp = alpm_db_readgrp(db_local, package); if(grp) { - PM_LIST *i, *pkgnames = alpm_grp_getinfo(grp, PM_GRP_PKGNAMES); + pmlist_t *i, *pkgnames = alpm_grp_get_packages(grp); for(i = pkgnames; i; i = alpm_list_next(i)) { MSG(NL, "%s %s\n", package, (char *)alpm_list_getdata(i)); } @@ -189,8 +187,8 @@ int pacman_query(list_t *targets) dump_pkg_files(info); } if(!config->op_q_info && !config->op_q_list) { - MSG(NL, "%s %s\n", (char *)alpm_pkg_getinfo(info, PM_PKG_NAME), - (char *)alpm_pkg_getinfo(info, PM_PKG_VERSION)); + MSG(NL, "%s %s\n", alpm_pkg_get_name(info), + alpm_pkg_get_version(info)); } FREEPKG(info); continue; @@ -203,17 +201,17 @@ int pacman_query(list_t *targets) /* find packages in the db */ if(package == NULL) { - PM_LIST *lp; + pmlist_t *lp; /* no target */ for(lp = alpm_db_getpkgcache(db_local); lp; lp = alpm_list_next(lp)) { - PM_PKG *tmpp = alpm_list_getdata(lp); - char *pkgname, *pkgver; + pmpkg_t *tmpp = alpm_list_getdata(lp); + const char *pkgname, *pkgver; - pkgname = alpm_pkg_getinfo(tmpp, PM_PKG_NAME); - pkgver = alpm_pkg_getinfo(tmpp, PM_PKG_VERSION); + pkgname = alpm_pkg_get_name(tmpp); + pkgver = alpm_pkg_get_version(tmpp); if(config->op_q_list || config->op_q_orphans || config->op_q_foreign) { - info = alpm_db_readpkg(db_local, pkgname); + info = alpm_db_readpkg(db_local, (char *)pkgname); if(info == NULL) { /* something weird happened */ ERR(NL, _("package \"%s\" not found\n"), pkgname); @@ -224,11 +222,11 @@ int pacman_query(list_t *targets) for(i = pmc_syncs; i; i = i->next) { sync_t *sync = (sync_t *)i->data; for(j = alpm_db_getpkgcache(sync->db); j; j = alpm_list_next(j)) { - PM_PKG *pkg = alpm_list_getdata(j); + pmpkg_t *pkg = alpm_list_getdata(j); char *haystack; char *needle; - haystack = strdup(alpm_pkg_getinfo(pkg, PM_PKG_NAME)); - needle = strdup(alpm_pkg_getinfo(info, PM_PKG_NAME)); + haystack = strdup(alpm_pkg_get_name(pkg)); + needle = strdup(alpm_pkg_get_name(info)); if(!strcmp(haystack, needle)) { match = 1; } @@ -244,8 +242,8 @@ int pacman_query(list_t *targets) dump_pkg_files(info); } if(config->op_q_orphans) { - if(alpm_pkg_getinfo(info, PM_PKG_REQUIREDBY) == NULL - && (long)alpm_pkg_getinfo(info, PM_PKG_REASON) == PM_PKG_REASON_DEPEND) { + if(alpm_pkg_get_requiredby(info) == NULL + && (long)alpm_pkg_get_reason(info) == PM_PKG_REASON_DEPEND) { MSG(NL, "%s %s\n", pkgname, pkgver); } } @@ -254,7 +252,8 @@ int pacman_query(list_t *targets) } } } else { - char *pkgname = NULL, *pkgver = NULL, changelog[PATH_MAX]; + const char *pkgname = NULL, *pkgver = NULL; + char changelog[PATH_MAX]; info = alpm_db_readpkg(db_local, package); if(info == NULL) { @@ -265,16 +264,14 @@ int pacman_query(list_t *targets) /* find a target */ if(config->op_q_changelog || config->op_q_info || config->op_q_list) { if(config->op_q_changelog) { - long ldbpath; - char *dbpath; - alpm_get_option(PM_OPT_DBPATH, &ldbpath); - dbpath = (char *)ldbpath; + const char *dbpath; + dbpath = alpm_option_get_dbpath(); snprintf(changelog, PATH_MAX, "%s%s/%s/%s-%s/changelog", config->root, dbpath, - (char*)alpm_db_getinfo(db_local, PM_DB_TREENAME), - (char*)alpm_pkg_getinfo(info, PM_PKG_NAME), - (char*)alpm_pkg_getinfo(info, PM_PKG_VERSION)); - dump_pkg_changelog(changelog, (char*)alpm_pkg_getinfo(info, PM_PKG_NAME)); + alpm_db_get_name(db_local), + alpm_pkg_get_name(info), + alpm_pkg_get_version(info)); + dump_pkg_changelog(changelog, alpm_pkg_get_name(info)); } if(config->op_q_info) { dump_pkg_full(info, config->op_q_info); @@ -283,12 +280,12 @@ int pacman_query(list_t *targets) dump_pkg_files(info); } } else if(config->op_q_orphans) { - if(alpm_pkg_getinfo(info, PM_PKG_REQUIREDBY) == NULL) { + if(alpm_pkg_get_requiredby(info) == NULL) { MSG(NL, "%s %s\n", pkgname, pkgver); } } else { - pkgname = alpm_pkg_getinfo(info, PM_PKG_NAME); - pkgver = alpm_pkg_getinfo(info, PM_PKG_VERSION); + pkgname = alpm_pkg_get_name(info); + pkgver = alpm_pkg_get_version(info); MSG(NL, "%s %s\n", pkgname, pkgver); } } diff --git a/src/pacman/remove.c b/src/pacman/remove.c index 475df393..ddc22e7e 100644 --- a/src/pacman/remove.c +++ b/src/pacman/remove.c @@ -35,11 +35,11 @@ extern config_t *config; -extern PM_DB *db_local; +extern pmdb_t *db_local; int pacman_remove(list_t *targets) { - PM_LIST *data; + pmlist_t *data; list_t *i; list_t *finaltargs = NULL; int retval = 0; @@ -52,17 +52,17 @@ int pacman_remove(list_t *targets) * (the library can't remove groups for now) */ for(i = targets; i; i = i->next) { - PM_GRP *grp; + pmgrp_t *grp; grp = alpm_db_readgrp(db_local, i->data); if(grp) { - PM_LIST *lp, *pkgnames; + pmlist_t *lp, *pkgnames; int all; - pkgnames = alpm_grp_getinfo(grp, PM_GRP_PKGNAMES); + pkgnames = alpm_grp_get_packages(grp); - MSG(NL, _(":: group %s:\n"), alpm_grp_getinfo(grp, PM_GRP_NAME)); - PM_LIST_display(" ", pkgnames); + MSG(NL, _(":: group %s:\n"), alpm_grp_get_name(grp)); + pmlist_display(" ", pkgnames); all = yesno(_(" Remove whole content? [Y/n] ")); for(lp = alpm_list_first(pkgnames); lp; lp = alpm_list_next(lp)) { if(all || yesno(_(":: Remove %s from group %s? [Y/n] "), (char *)alpm_list_getdata(lp), i->data)) { @@ -98,12 +98,12 @@ int pacman_remove(list_t *targets) /* Step 2: prepare the transaction based on its type, targets and flags */ if(alpm_trans_prepare(&data) == -1) { - PM_LIST *lp; + pmlist_t *lp; ERR(NL, _("failed to prepare transaction (%s)\n"), alpm_strerror(pm_errno)); switch(pm_errno) { case PM_ERR_UNSATISFIED_DEPS: for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) { - PM_DEPMISS *miss = alpm_list_getdata(lp); + pmdepmissing_t *miss = alpm_list_getdata(lp); MSG(NL, _(" %s: is required by %s\n"), alpm_dep_getinfo(miss, PM_DEP_TARGET), alpm_dep_getinfo(miss, PM_DEP_NAME)); } @@ -119,12 +119,12 @@ int pacman_remove(list_t *targets) /* Warn user in case of dangerous operation */ if(config->flags & PM_TRANS_FLAG_RECURSE || config->flags & PM_TRANS_FLAG_CASCADE) { - PM_LIST *lp; + pmlist_t *lp; /* list transaction targets */ i = NULL; for(lp = alpm_list_first(alpm_trans_getinfo(PM_TRANS_PACKAGES)); lp; lp = alpm_list_next(lp)) { - PM_PKG *pkg = alpm_list_getdata(lp); - i = list_add(i, strdup(alpm_pkg_getinfo(pkg, PM_PKG_NAME))); + pmpkg_t *pkg = alpm_list_getdata(lp); + i = list_add(i, strdup(alpm_pkg_get_name(pkg))); } list_display(_("\nTargets:"), i); FREELIST(i); diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 345f9fd4..e40a27bc 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -54,14 +54,11 @@ extern list_t *pmc_syncs; static int sync_cleancache(int level) { - long lroot, lcachedir; - char *root, *cachedir; + const char *root, *cachedir; char dirpath[PATH_MAX]; - alpm_get_option(PM_OPT_ROOT, &lroot); - root = (void *)lroot; - alpm_get_option(PM_OPT_CACHEDIR, &lcachedir); - cachedir = (void *)lcachedir; + root = alpm_option_get_root(); + cachedir = alpm_option_get_cachedir(); snprintf(dirpath, PATH_MAX, "%s%s", root, cachedir); @@ -191,40 +188,41 @@ static int sync_synctree(int level, list_t *syncs) static int sync_search(list_t *syncs, list_t *targets) { list_t *i; - PM_LIST *ret; + pmlist_t *ret; for(i = targets; i; i = i->next) { - alpm_set_option(PM_OPT_NEEDLES, (long)i->data); + alpm_option_add_needle(i->data); } + for(i = syncs; i; i = i->next) { sync_t *sync = i->data; if(targets) { - PM_LIST *lp; + pmlist_t *lp; ret = alpm_db_search(sync->db); if(ret == NULL) { continue; } for(lp = ret; lp; lp = alpm_list_next(lp)) { - PM_PKG *pkg = alpm_list_getdata(lp); + pmpkg_t *pkg = alpm_list_getdata(lp); - char *group = (char *)alpm_list_getdata(alpm_pkg_getinfo(pkg,PM_PKG_GROUPS)); + char *group = (char *)alpm_list_getdata(alpm_pkg_get_groups(pkg)); printf("%s/%s %s %s%s%s\n ", - (char *)alpm_db_getinfo(sync->db, PM_DB_TREENAME), - (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME), - (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION), + alpm_db_get_name(sync->db), + alpm_pkg_get_name(pkg), + alpm_pkg_get_version(pkg), (group ? " (" : ""), (group ? group : ""), (group ? ") " : "")); - indentprint((char *)alpm_pkg_getinfo(pkg, PM_PKG_DESC), 4); + indentprint(alpm_pkg_get_desc(pkg), 4); printf("\n\n"); } alpm_list_free_outer(ret); } else { - PM_LIST *lp; + pmlist_t *lp; for(lp = alpm_db_getpkgcache(sync->db); lp; lp = alpm_list_next(lp)) { - PM_PKG *pkg = alpm_list_getdata(lp); + pmpkg_t *pkg = alpm_list_getdata(lp); - MSG(NL, "%s/%s %s\n ", sync->treename, (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME), (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION)); - indentprint(alpm_pkg_getinfo(pkg, PM_PKG_DESC), 4); + MSG(NL, "%s/%s %s\n ", sync->treename, alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg)); + indentprint(alpm_pkg_get_desc(pkg), 4); MSG(NL, "\n"); } } @@ -241,25 +239,25 @@ static int sync_group(int level, list_t *syncs, list_t *targets) for(i = targets; i; i = i->next) { for(j = syncs; j; j = j->next) { sync_t *sync = j->data; - PM_GRP *grp = alpm_db_readgrp(sync->db, i->data); + pmgrp_t *grp = alpm_db_readgrp(sync->db, i->data); if(grp) { - MSG(NL, "%s\n", (char *)alpm_grp_getinfo(grp, PM_GRP_NAME)); - PM_LIST_display(" ", alpm_grp_getinfo(grp, PM_GRP_PKGNAMES)); + MSG(NL, "%s\n", (char *)alpm_grp_get_name(grp)); + pmlist_display(" ", alpm_grp_get_packages(grp)); } } } } else { for(j = syncs; j; j = j->next) { sync_t *sync = j->data; - PM_LIST *lp; + pmlist_t *lp; for(lp = alpm_db_getgrpcache(sync->db); lp; lp = alpm_list_next(lp)) { - PM_GRP *grp = alpm_list_getdata(lp); + pmgrp_t *grp = alpm_list_getdata(lp); - MSG(NL, "%s\n", (char *)alpm_grp_getinfo(grp, PM_GRP_NAME)); + MSG(NL, "%s\n", (char *)alpm_grp_get_name(grp)); if(grp && level > 1) { - PM_LIST_display(" ", alpm_grp_getinfo(grp, PM_GRP_PKGNAMES)); + pmlist_display(" ", alpm_grp_get_packages(grp)); } } } @@ -278,12 +276,12 @@ static int sync_info(list_t *syncs, list_t *targets) for(j = syncs; j && !found; j = j->next) { sync_t *sync = j->data; - PM_LIST *lp; + pmlist_t *lp; for(lp = alpm_db_getpkgcache(sync->db); !found && lp; lp = alpm_list_next(lp)) { - PM_PKG *pkg = alpm_list_getdata(lp); + pmpkg_t *pkg = alpm_list_getdata(lp); - if(!strcmp(alpm_pkg_getinfo(pkg, PM_PKG_NAME), i->data)) { + if(!strcmp(alpm_pkg_get_name(pkg), i->data)) { dump_pkg_sync(pkg, sync->treename); MSG(NL, "\n"); found = 1; @@ -298,7 +296,7 @@ static int sync_info(list_t *syncs, list_t *targets) } else { for(j = syncs; j; j = j->next) { sync_t *sync = j->data; - PM_LIST *lp; + pmlist_t *lp; for(lp = alpm_db_getpkgcache(sync->db); lp; lp = alpm_list_next(lp)) { dump_pkg_sync(alpm_list_getdata(lp), sync->treename); @@ -341,13 +339,13 @@ static int sync_list(list_t *syncs, list_t *targets) } for(i = ls; i; i = i->next) { - PM_LIST *lp; + pmlist_t *lp; sync_t *sync = i->data; for(lp = alpm_db_getpkgcache(sync->db); lp; lp = alpm_list_next(lp)) { - PM_PKG *pkg = alpm_list_getdata(lp); + pmpkg_t *pkg = alpm_list_getdata(lp); - MSG(NL, "%s %s %s\n", (char *)sync->treename, (char *)alpm_pkg_getinfo(pkg, PM_PKG_NAME), (char *)alpm_pkg_getinfo(pkg, PM_PKG_VERSION)); + MSG(NL, "%s %s %s\n", (char *)sync->treename, alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg)); } } @@ -363,7 +361,7 @@ int pacman_sync(list_t *targets) int confirm = 0; int retval = 0; list_t *i = NULL; - PM_LIST *packages, *data, *lp; + pmlist_t *packages, *data, *lp; if(pmc_syncs == NULL || !list_count(pmc_syncs)) { ERR(NL, _("no usable package repositories configured.\n")); @@ -428,9 +426,9 @@ int pacman_sync(list_t *targets) */ data = alpm_trans_getinfo(PM_TRANS_PACKAGES); for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) { - PM_SYNCPKG *sync = alpm_list_getdata(lp); - PM_PKG *spkg = alpm_sync_getinfo(sync, PM_SYNC_PKG); - if(!strcmp("pacman", alpm_pkg_getinfo(spkg, PM_PKG_NAME)) && alpm_list_count(data) > 1) { + pmsyncpkg_t *sync = alpm_list_getdata(lp); + pmpkg_t *spkg = alpm_sync_get_package(sync); + if(!strcmp("pacman", alpm_pkg_get_name(spkg)) && alpm_list_count(data) > 1) { MSG(NL, _("\n:: pacman has detected a newer version of the \"pacman\" package.\n")); MSG(NL, _(":: It is recommended that you allow pacman to upgrade itself\n")); MSG(NL, _(":: first, then you can re-run the operation with the newer version.\n")); @@ -463,7 +461,7 @@ int pacman_sync(list_t *targets) for(i = targets; i; i = i->next) { char *targ = i->data; if(alpm_trans_addtarget(targ) == -1) { - PM_GRP *grp = NULL; + pmgrp_t *grp = NULL; list_t *j; int found=0; if(pm_errno == PM_ERR_TRANS_DUP_TARGET) { @@ -480,14 +478,14 @@ int pacman_sync(list_t *targets) sync_t *sync = j->data; grp = alpm_db_readgrp(sync->db, targ); if(grp) { - PM_LIST *pmpkgs; + pmlist_t *pmpkgs; list_t *k, *pkgs; found++; MSG(NL, _(":: group %s:\n"), targ); - pmpkgs = alpm_grp_getinfo(grp, PM_GRP_PKGNAMES); + pmpkgs = alpm_grp_get_packages(grp); /* remove dupe entries in case a package exists in multiple repos */ - /* (the dupe function takes a PM_LIST* and returns a list_t*) */ - pkgs = PM_LIST_remove_dupes(pmpkgs); + /* (the dupe function takes a pmlist_t* and returns a list_t*) */ + pkgs = pmlist_remove_dupes(pmpkgs); list_display(" ", pkgs); if(yesno(_(":: Install whole content? [Y/n] "))) { for(k = pkgs; k; k = k->next) { @@ -506,14 +504,14 @@ int pacman_sync(list_t *targets) } if(!found) { /* targ not found in sync db, searching for providers... */ - PM_LIST *k = NULL; - PM_PKG *pkg; - char *pname = NULL; + pmlist_t *k = NULL; + pmpkg_t *pkg; + const char *pname = NULL; for(j = pmc_syncs; j && !k; j = j->next) { sync_t *sync = j->data; k = alpm_db_whatprovides(sync->db, targ); - pkg = (PM_PKG*)alpm_list_getdata(alpm_list_first(k)); - pname = (char*)alpm_pkg_getinfo(pkg, PM_PKG_NAME); + pkg = (pmpkg_t*)alpm_list_getdata(alpm_list_first(k)); + pname = alpm_pkg_get_name(pkg); } if(pname != NULL) { /* targ is provided by pname */ @@ -536,7 +534,7 @@ int pacman_sync(list_t *targets) switch(pm_errno) { case PM_ERR_UNSATISFIED_DEPS: for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) { - PM_DEPMISS *miss = alpm_list_getdata(lp); + pmdepmissing_t *miss = alpm_list_getdata(lp); MSG(NL, ":: %s: %s %s", alpm_dep_getinfo(miss, PM_DEP_TARGET), (long)alpm_dep_getinfo(miss, PM_DEP_TYPE) == PM_DEP_TYPE_DEPEND ? _("requires") : _("is required by"), alpm_dep_getinfo(miss, PM_DEP_NAME)); @@ -550,7 +548,7 @@ int pacman_sync(list_t *targets) break; case PM_ERR_CONFLICTING_DEPS: for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) { - PM_DEPMISS *miss = alpm_list_getdata(lp); + pmdepmissing_t *miss = alpm_list_getdata(lp); MSG(NL, _(":: %s: conflicts with %s"), alpm_dep_getinfo(miss, PM_DEP_TARGET), alpm_dep_getinfo(miss, PM_DEP_NAME)); @@ -588,26 +586,26 @@ int pacman_sync(list_t *targets) double mb, umb; for(lp = alpm_list_first(packages); lp; lp = alpm_list_next(lp)) { - PM_SYNCPKG *sync = alpm_list_getdata(lp); - PM_PKG *pkg = alpm_sync_getinfo(sync, PM_SYNC_PKG); - char *pkgname, *pkgver; + pmsyncpkg_t *sync = alpm_list_getdata(lp); + pmpkg_t *pkg = alpm_sync_get_package(sync); + const char *pkgname, *pkgver; - if((long)alpm_sync_getinfo(sync, PM_SYNC_TYPE) == PM_SYNC_TYPE_REPLACE) { - PM_LIST *j, *data; - data = alpm_sync_getinfo(sync, PM_SYNC_DATA); + if(alpm_sync_get_type(sync) == PM_SYNC_TYPE_REPLACE) { + pmlist_t *j, *data; + data = alpm_sync_get_data(sync); for(j = alpm_list_first(data); j; j = alpm_list_next(j)) { - PM_PKG *p = alpm_list_getdata(j); - char *pkgname = alpm_pkg_getinfo(p, PM_PKG_NAME); + pmpkg_t *p = alpm_list_getdata(j); + const char *pkgname = alpm_pkg_get_name(p); if(!list_is_strin(pkgname, list_remove)) { list_remove = list_add(list_remove, strdup(pkgname)); } } } - pkgname = alpm_pkg_getinfo(pkg, PM_PKG_NAME); - pkgver = alpm_pkg_getinfo(pkg, PM_PKG_VERSION); - totalsize += (long)alpm_pkg_getinfo(pkg, PM_PKG_SIZE); - totalusize += (long)alpm_pkg_getinfo(pkg, PM_PKG_USIZE); + pkgname = alpm_pkg_get_name(pkg); + pkgver = alpm_pkg_get_version(pkg); + totalsize += alpm_pkg_get_size(pkg); + totalusize += alpm_pkg_get_usize(pkg); asprintf(&str, "%s-%s", pkgname, pkgver); list_install = list_add(list_install, str); @@ -673,7 +671,7 @@ int pacman_sync(list_t *targets) switch(pm_errno) { case PM_ERR_FILE_CONFLICTS: for(lp = alpm_list_first(data); lp; lp = alpm_list_next(lp)) { - PM_CONFLICT *conflict = alpm_list_getdata(lp); + pmconflict_t *conflict = alpm_list_getdata(lp); switch((long)alpm_conflict_getinfo(conflict, PM_CONFLICT_TYPE)) { case PM_CONFLICT_TYPE_TARGET: MSG(NL, _("%s%s exists in \"%s\" (target) and \"%s\" (target)"), diff --git a/src/pacman/sync.h b/src/pacman/sync.h index 0452f1c2..e61668e4 100644 --- a/src/pacman/sync.h +++ b/src/pacman/sync.h @@ -24,7 +24,7 @@ /* Repositories */ typedef struct __sync_t { char *treename; - PM_DB *db; + pmdb_t *db; } sync_t; int pacman_sync(list_t *targets); diff --git a/src/pacman/trans.c b/src/pacman/trans.c index ce032dc4..0b141906 100644 --- a/src/pacman/trans.c +++ b/src/pacman/trans.c @@ -84,7 +84,7 @@ void cb_trans_evt(unsigned char event, void *data1, void *data2) break; case PM_TRANS_EVT_ADD_START: if(config->noprogressbar) { - MSG(NL, _("installing %s... "), (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME)); + MSG(NL, _("installing %s... "), alpm_pkg_get_name(data1)); } break; case PM_TRANS_EVT_ADD_DONE: @@ -92,13 +92,13 @@ void cb_trans_evt(unsigned char event, void *data1, void *data2) MSG(CL, _("done.\n")); } snprintf(str, LOG_STR_LEN, _("installed %s (%s)"), - (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME), - (char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION)); + alpm_pkg_get_name(data1), + alpm_pkg_get_version(data1)); alpm_logaction(str); break; case PM_TRANS_EVT_REMOVE_START: if(config->noprogressbar) { - MSG(NL, _("removing %s... "), (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME)); + MSG(NL, _("removing %s... "), alpm_pkg_get_name(data1)); } break; case PM_TRANS_EVT_REMOVE_DONE: @@ -106,13 +106,13 @@ void cb_trans_evt(unsigned char event, void *data1, void *data2) MSG(CL, _("done.\n")); } snprintf(str, LOG_STR_LEN, _("removed %s (%s)"), - (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME), - (char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION)); + alpm_pkg_get_name(data1), + alpm_pkg_get_version(data1)); alpm_logaction(str); break; case PM_TRANS_EVT_UPGRADE_START: if(config->noprogressbar) { - MSG(NL, _("upgrading %s... "), (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME)); + MSG(NL, _("upgrading %s... "), alpm_pkg_get_name(data1)); } break; case PM_TRANS_EVT_UPGRADE_DONE: @@ -120,9 +120,9 @@ void cb_trans_evt(unsigned char event, void *data1, void *data2) MSG(CL, _("done.\n")); } snprintf(str, LOG_STR_LEN, _("upgraded %s (%s -> %s)"), - (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME), - (char *)alpm_pkg_getinfo(data2, PM_PKG_VERSION), - (char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION)); + (char *)alpm_pkg_get_name(data1), + (char *)alpm_pkg_get_version(data2), + (char *)alpm_pkg_get_version(data1)); alpm_logaction(str); break; case PM_TRANS_EVT_INTEGRITY_START: @@ -178,8 +178,8 @@ void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, i } } else { snprintf(str, LOG_STR_LEN, _(":: %s requires %s, but it is in IgnorePkg. Install anyway? [Y/n] "), - (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME), - (char *)alpm_pkg_getinfo(data2, PM_PKG_NAME)); + alpm_pkg_get_name(data1), + alpm_pkg_get_name(data2)); *response = yesno(str); } break; @@ -192,7 +192,7 @@ void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, i } } else { snprintf(str, LOG_STR_LEN, _(":: %s is designated as a HoldPkg. Remove anyway? [Y/n] "), - (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME)); + alpm_pkg_get_name(data1)); *response = yesno(str); } break; @@ -205,9 +205,9 @@ void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, i } } else { snprintf(str, LOG_STR_LEN, _(":: Replace %s with %s/%s? [Y/n] "), - (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME), + alpm_pkg_get_name(data1), (char *)data3, - (char *)alpm_pkg_getinfo(data2, PM_PKG_NAME)); + alpm_pkg_get_name(data2)); *response = yesno(str); } break; @@ -236,8 +236,8 @@ void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, i } else { if(!config->op_s_downloadonly) { snprintf(str, LOG_STR_LEN, _(":: %s-%s: local version is newer. Upgrade anyway? [Y/n] "), - (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME), - (char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION)); + alpm_pkg_get_name(data1), + alpm_pkg_get_version(data1)); *response = yesno(str); } else { *response = 1; @@ -254,8 +254,8 @@ void cb_trans_conv(unsigned char event, void *data1, void *data2, void *data3, i } else { if(!config->op_s_downloadonly) { snprintf(str, LOG_STR_LEN, _(":: %s-%s: local version is up to date. Upgrade anyway? [Y/n] "), - (char *)alpm_pkg_getinfo(data1, PM_PKG_NAME), - (char *)alpm_pkg_getinfo(data1, PM_PKG_VERSION)); + alpm_pkg_get_name(data1), + alpm_pkg_get_version(data1)); *response = yesno(str); } else { *response = 1; @@ -349,7 +349,7 @@ void cb_trans_progress(unsigned char event, char *pkgname, int percent, int howm break; } - alpm_get_option(PM_OPT_CHOMP, &chomp); + chomp = alpm_option_get_chomp(); /* hide the cursor, prevent flicker during fancy graphics printf("\033[?25l\033[?1c["); diff --git a/src/pacman/util.c b/src/pacman/util.c index 8dd0f11d..68f39e38 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -49,6 +49,16 @@ extern int maxcols; extern config_t *config; extern int neednl; +/* gets the current screen column width */ +int getcols() +{ + const char *cenv = getenv("COLUMNS"); + if(cenv != NULL) { + return atoi(cenv); + } + return -1; +} + /* does the same thing as 'mkdir -p' */ int makepath(char *path) { @@ -126,14 +136,14 @@ int rmrf(char *path) /* output a string, but wrap words properly with a specified indentation */ -void indentprint(char *str, int indent) +void indentprint(const char *str, int indent) { - char *p = str; + const char *p = str; int cidx = indent; while(*p) { if(*p == ' ') { - char *next = NULL; + const char *next = NULL; int len; p++; if(p == NULL || *p == ' ') continue; diff --git a/src/pacman/util.h b/src/pacman/util.h index 2eab6c79..b1730385 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -43,10 +43,10 @@ } while(0) #define _(str) gettext(str) - +int getcols(); int makepath(char *path); int rmrf(char *path); -void indentprint(char *str, int indent); +void indentprint(const char *str, int indent); char *buildstring(list_t *strlist); char *strtoupper(char *str); char *strtrim(char *str); -- cgit v1.2.3-70-g09d2