Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=9eb0d714fa2e7375edfeca9e054a5cc8efa37c7e
commit 9eb0d714fa2e7375edfeca9e054a5cc8efa37c7e Author: Michel Hermier <herm...@frugalware.org> Date: Thu May 23 09:00:56 2013 +0200 libflib: Add f_foreach and f_rforeach macros to iterate inline block. diff --git a/lib/libflib/flist.h b/lib/libflib/flist.h index b2d045f..7ff1706 100644 --- a/lib/libflib/flist.h +++ b/lib/libflib/flist.h @@ -87,6 +87,12 @@ void _f_list_exclude (FList **list, FList **excludelist, FDetectFunc dfn, void void _f_list_remove (FList **list, FListItem *item); FList *f_list_remove_find_custom (FList *haystack, void *needle, FCompareFunc fn, void **data); +#define f_foreach(it, list) \ + for (it = f_list_begin (list); it != f_list_end (list); it = f_listitem_next (it)) + +#define f_rforeach(it, list) \ + for (it = f_list_rbegin (list); it != f_list_rend (list); it = f_listitem_prev (it)) + #endif /* F_LIST_H */ /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/backup.c b/lib/libpacman/backup.c index c90c00a..c0bf100 100644 --- a/lib/libpacman/backup.c +++ b/lib/libpacman/backup.c @@ -42,7 +42,7 @@ char *_pacman_needbackup(char *file, pmlist_t *backup) } /* run through the backup list and parse out the md5 or sha1 hash for our file */ - for(lp = backup; lp; lp = lp->next) { + f_foreach (lp, backup) { char *str = strdup(lp->data); char *ptr; diff --git a/lib/libpacman/be_files.c b/lib/libpacman/be_files.c index 956a2e6..3722892 100644 --- a/lib/libpacman/be_files.c +++ b/lib/libpacman/be_files.c @@ -331,7 +331,7 @@ static int _pacman_db_read_desc(pmdb_t *db, unsigned int inforeq, pmpkg_t *info) info->desc_localized = f_stringlist_append (info->desc_localized, line); } STRNCPY(info->desc, (char*)info->desc_localized->data, sizeof(info->desc)); - for (i = info->desc_localized; i; i = i->next) { + f_foreach (i, info->desc_localized) { if (!strncmp(i->data, handle->language, strlen(handle->language)) && *((char*)i->data+strlen(handle->language)) == ' ') { STRNCPY(info->desc, (char*)i->data+strlen(handle->language)+1, sizeof(info->desc)); @@ -630,7 +630,7 @@ void _pacman_db_write_item_list (FILE *fp, const char *item_name, pmlist_t *item pmlist_t *i = item_list; fprintf(fp, "%%%s%%\n", item_name); - for(i = item_list; i; i = i->next) { + f_foreach (i, item_list) { fprintf(fp, "%s\n", (char *)i->data); } fprintf(fp, "\n"); diff --git a/lib/libpacman/cache.c b/lib/libpacman/cache.c index c21ada7..350c897 100644 --- a/lib/libpacman/cache.c +++ b/lib/libpacman/cache.c @@ -163,7 +163,7 @@ int _pacman_db_load_grpcache(pmdb_t *db) _pacman_log(PM_LOG_DEBUG, _("loading group cache for repository '%s'"), db->treename); - for(lp = db->pkgcache; lp; lp = lp->next) { + f_foreach (lp, db->pkgcache) { pmlist_t *i; pmpkg_t *pkg = lp->data; @@ -171,7 +171,7 @@ int _pacman_db_load_grpcache(pmdb_t *db) _pacman_db_read(pkg->db, INFRQ_DESC, pkg); } - for(i = pkg->groups; i; i = i->next) { + f_foreach (i, pkg->groups) { if(!f_stringlist_find (db->grpcache, i->data)) { pmgrp_t *grp = _pacman_grp_new(); @@ -181,7 +181,7 @@ int _pacman_db_load_grpcache(pmdb_t *db) } else { pmlist_t *j; - for(j = db->grpcache; j; j = j->next) { + f_foreach (j, db->grpcache) { pmgrp_t *grp = j->data; if(strcmp(grp->name, i->data) == 0) { @@ -205,7 +205,7 @@ void _pacman_db_free_grpcache(pmdb_t *db) return; } - for(lg = db->grpcache; lg; lg = lg->next) { + f_foreach (lg, db->grpcache) { pmgrp_t *grp = lg->data; FREELISTPTR(grp->packages); @@ -273,7 +273,7 @@ int _pacman_sync_cleancache(int level) } closedir(dir); - for(i = cache; i; i = i->next) { + f_foreach (i, cache) { char *str = i->data; char name[256], version[64]; @@ -312,7 +312,7 @@ int _pacman_sync_cleancache(int level) } FREELIST(cache); - for(i = clean; i; i = i->next) { + f_foreach (i, clean) { char path[PATH_MAX]; snprintf(path, PATH_MAX, "%s/%s", dirpath, (char *)i->data); diff --git a/lib/libpacman/conflict.c b/lib/libpacman/conflict.c index 685dcd0..0b7d916 100644 --- a/lib/libpacman/conflict.c +++ b/lib/libpacman/conflict.c @@ -60,7 +60,7 @@ pmlist_t *_pacman_checkconflicts(pmtrans_t *trans) { howmany = f_list_count (trans->packages); - for(i = trans->packages; i; i = i->next) { + f_foreach (i, trans->packages) { pmtranspkg_t *transpkg = i->data; const char *transpkg_name = __pacman_transpkg_name (transpkg); @@ -106,7 +106,7 @@ pmlist_t *_pacman_checkconflicts(pmtrans_t *trans) { } /* CHECK 2: check targets against targets */ _pacman_log(PM_LOG_DEBUG, _("checkconflicts: targ '%s' vs targs"), transpkg_name); - for(k = trans->packages; k; k = k->next) { + f_foreach (k, trans->packages) { pmtranspkg_t *other_transpkg = k->data; const char *other_transpkg_name = __pacman_transpkg_name (other_transpkg); @@ -143,7 +143,7 @@ pmlist_t *_pacman_checkconflicts(pmtrans_t *trans) { /* If this package (*info) is also in our packages pmlist_t, use the * conflicts list from the new package, not the old one (*info) */ - for(j = trans->packages; j; j = j->next) { + f_foreach (j, trans->packages) { pmtranspkg_t *transpkg = j->data; if (transpkg->type & PM_TRANS_TYPE_ADD && @@ -157,13 +157,14 @@ pmlist_t *_pacman_checkconflicts(pmtrans_t *trans) { /* Use the old package's conflicts, it's the only set we have */ conflicts = _pacman_pkg_getinfo(info, PM_PKG_CONFLICTS); } - for(j = conflicts; j; j = j->next) { + f_foreach (j, conflicts) { if(!strcmp((char *)j->data, transpkg_name)) { _pacman_depmissinglist_add (&baddeps, transpkg_name, PM_DEP_TYPE_CONFLICT, PM_DEP_MOD_ANY, info->name, NULL); } else { /* see if the db package conflicts with something we provide */ pmlist_t *m; - for(m = conflicts; m; m = m->next) { + + f_foreach (m, conflicts) { pmlist_t *n; for(n = _pacman_pkg_getinfo(transpkg->pkg_new, PM_PKG_PROVIDES); n; n = n->next) { if(!strcmp(m->data, n->data)) { @@ -233,7 +234,7 @@ pmlist_t *_pacman_db_find_conflicts(pmtrans_t *trans, pmlist_t **skip_list) } /* CHECK 1: check every target against every target */ - for (i = trans->packages; i; i = i->next) { + f_foreach (i, trans->packages) { pmtranspkg_t *p1 = i->data; if (p1->pkg_new == NULL) { diff --git a/lib/libpacman/trans.c b/lib/libpacman/trans.c index 2c25bbe..26d347b 100644 --- a/lib/libpacman/trans.c +++ b/lib/libpacman/trans.c @@ -570,7 +570,7 @@ int check_olddelay(void) memset(&tm,0,sizeof(struct tm)); - for(i = handle->dbs_sync; i; i= i->next) { + f_foreach (i, handle->dbs_sync) { pmdb_t *db = i->data; if(_pacman_db_getlastupdate(db, lastupdate) == -1) { continue; @@ -648,10 +648,11 @@ int _pacman_sync_prepare (pmtrans_t *trans, pmlist_t **data) /* check if the conflicting package is one that's about to be removed/replaced. * if so, then just ignore it */ - for(j = trans->packages; j && !found; j = j->next) { + f_foreach (j, trans->packages) { ps = j->data; if(_pacman_pkg_isin(miss->depend.name, ps->replaces)) { found = 1; + break; } } if(found) { @@ -803,7 +804,7 @@ int _pacman_sync_prepare (pmtrans_t *trans, pmlist_t **data) _pacman_trans_checkdeps (trans, &deps); if(deps) { int errorout = 0; - for(i = deps; i; i = i->next) { + f_foreach (i, deps) { pmdepmissing_t *miss = i->data; if(!__pacman_trans_get_trans_pkg(trans, miss->depend.name)) { int pfound = 0; @@ -952,9 +953,9 @@ int _pacman_trans_prepare(pmtrans_t *trans, pmlist_t **data) /* Cleaning up */ EVENT(trans, PM_TRANS_EVT_CLEANUP_START, NULL, NULL); _pacman_log(PM_LOG_FLOW1, _("cleaning up")); - for (lp=trans->_packages; lp!=NULL; lp=lp->next) { + f_foreach (lp, trans->_packages) { info=(pmpkg_t *)lp->data; - for (rmlist=info->removes; rmlist!=NULL; rmlist=rmlist->next) { + f_foreach (rmlist, info->removes) { snprintf(rm_fname, PATH_MAX, "%s%s", handle->root, (char *)rmlist->data); remove(rm_fname); } @@ -1002,7 +1003,7 @@ int _pacman_trans_prepare(pmtrans_t *trans, pmlist_t **data) if(trans->flags & PM_TRANS_FLAG_CASCADE) { while(lp) { pmlist_t *i; - for(i = lp; i; i = i->next) { + f_foreach (i, lp) { pmdepmissing_t *miss = (pmdepmissing_t *)i->data; pmpkg_t *info = _pacman_db_scan(db_local, miss->depend.name, INFRQ_ALL); if(info) { @@ -1080,7 +1081,7 @@ int _pacman_remove_commit(pmtrans_t *trans, pmlist_t **data) howmany = f_list_count (trans->packages); - for(targ = trans->packages; targ; targ = targ->next) { + f_foreach (targ, trans->packages) { int position = 0; char pm_install[PATH_MAX]; info = ((pmtranspkg_t*)targ->data)->pkg_local; @@ -1146,9 +1147,10 @@ int _pacman_remove_commit(pmtrans_t *trans, pmlist_t **data) * explanation. */ int skipit = 0; pmlist_t *j; - for(j = trans->skiplist; j; j = j->next) { + f_foreach (j, trans->skiplist) { if(!strcmp(file, (char*)j->data)) { skipit = 1; + break; } } if(skipit) { @@ -1210,7 +1212,7 @@ int _pacman_remove_commit(pmtrans_t *trans, pmlist_t **data) /* update dependency packages' REQUIREDBY fields */ _pacman_log(PM_LOG_FLOW2, _("updating dependency packages 'requiredby' fields")); - for(lp = info->depends; lp; lp = lp->next) { + f_foreach (lp, info->depends) { pmpkg_t *depinfo = NULL; pmdepend_t depend; char *data; @@ -1307,7 +1309,7 @@ int _pacman_trans_commit(pmtrans_t *trans, pmlist_t **data) pmlist_t *targ, *lp; const int howmany = f_list_count (trans->packages); - for(targ = trans->_packages; targ; targ = targ->next) { + f_foreach (targ, trans->_packages) { pmtranstype_t transtype; char pm_install[PATH_MAX]; pmpkg_t *info = (pmpkg_t *)targ->data; @@ -1511,7 +1513,7 @@ int _pacman_trans_commit(pmtrans_t *trans, pmlist_t **data) /* append the new md5 or sha1 hash to it's respective entry in info->backup * (it will be the new orginal) */ - for(lp = info->backup; lp; lp = lp->next) { + f_foreach (lp, info->backup) { char *fn; char *file = lp->data; @@ -1653,7 +1655,7 @@ int _pacman_trans_commit(pmtrans_t *trans, pmlist_t **data) errors++; } /* calculate an md5 or sha1 hash if this is in info->backup */ - for(lp = info->backup; lp; lp = lp->next) { + f_foreach (lp, info->backup) { char *fn, *md5, *sha1; char path[PATH_MAX]; char *file = lp->data; @@ -1719,7 +1721,7 @@ int _pacman_trans_commit(pmtrans_t *trans, pmlist_t **data) if(tmpp == NULL) { continue; } - for(tmppm = tmpp->depends; tmppm; tmppm = tmppm->next) { + f_foreach (tmppm, tmpp->depends) { pmdepend_t depend; if(_pacman_splitdep(tmppm->data, &depend)) { continue; @@ -1752,7 +1754,7 @@ int _pacman_trans_commit(pmtrans_t *trans, pmlist_t **data) if(info->depends) { _pacman_log(PM_LOG_FLOW2, _("updating dependency packages 'requiredby' fields")); } - for(lp = info->depends; lp; lp = lp->next) { + f_foreach (lp, info->depends) { pmpkg_t *depinfo; pmdepend_t depend; if(_pacman_splitdep(lp->data, &depend)) { diff --git a/lib/libpacman/trans_sysupgrade.c b/lib/libpacman/trans_sysupgrade.c index 10a786d..7eb418a 100644 --- a/lib/libpacman/trans_sysupgrade.c +++ b/lib/libpacman/trans_sysupgrade.c @@ -81,7 +81,7 @@ int _pacman_sync_sysupgrade(pmtrans_t *trans) /* check for "recommended" package replacements */ _pacman_log(PM_LOG_FLOW1, _("checking for package replacements")); - for(i = dbs_sync; i; i = i->next) { + f_foreach (i, dbs_sync) { for(j = _pacman_db_get_pkgcache(i->data); j; j = j->next) { pmpkg_t *spkg = j->data; for(k = _pacman_pkg_getinfo(spkg, PM_PKG_REPLACES); k; k = k->next) { @@ -144,10 +144,11 @@ int _pacman_sync_sysupgrade(pmtrans_t *trans) } /* we don't care about a to-be-replaced package's newer version */ - for(j = trans->packages; j && !replace; j=j->next) { + f_foreach (j, trans->packages) { ps = j->data; if(_pacman_pkg_isin(spkg->name, ps->replaces)) { replace=1; + break; } } if(replace) { diff --git a/lib/libpacman/util.c b/lib/libpacman/util.c index a2f4c9b..12aedc8 100644 --- a/lib/libpacman/util.c +++ b/lib/libpacman/util.c @@ -278,7 +278,7 @@ static int list_startswith(char *needle, pmlist_t *haystack) { pmlist_t *i; - for (i = haystack; i; i = i->next) { + f_foreach (i, haystack) { cache_t *c = i->data; if (!strncmp(c->str, needle, strlen(c->str))) { c->hit = 1; @@ -354,7 +354,7 @@ int _pacman_unpack(const char *archive, const char *prefix, const char *fn) archive_read_finish (_archive); /* finally delete the old ones */ - for (i = cache; i; i = i->next) { + f_foreach (i, cache) { cache_t *c = i->data; if (!c->hit) { snprintf(expath, PATH_MAX, "%s/%s", prefix, c->str); @@ -752,7 +752,7 @@ int _pacman_check_freespace(pmtrans_t *trans, pmlist_t **data) pmlist_t *i; long long pkgsize=0, freespace; - for (i = trans->packages; i; i = i->next) { + f_foreach (i, trans->packages) { pmsyncpkg_t *ps = i->data; if(ps->type & PM_TRANS_TYPE_ADD) { pmpkg_t *pkg = ps->pkg_new; _______________________________________________ Frugalware-git mailing list Frugalware-git@frugalware.org http://frugalware.org/mailman/listinfo/frugalware-git